-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: ResizableBox, add showHandle prop (#18097)
* Components: ResizableBox, Add showHandle prop This update adds a new prop to the ResizableBox component. This new prop `showHandle` (`bool`) determines if the draggable resize handles should be visible or not. * Add ResizableBox storybook example This update adds a default story for ResizableBox. Knobs have been added to the story to better demonstrate the effects of the props. * Rename is-show-handle to has-show-handle Refactor styles to consolidate selected and show handle * Refactor ResizableBox story example Moves the inline-styled div to the parent. Allows for the Example component to read more clearly.
- Loading branch information
Showing
4 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { boolean, number, text } from '@storybook/addon-knobs'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ResizableBox from '../'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
|
||
export default { title: 'ResizableBox', component: ResizableBox }; | ||
|
||
const Example = ( props ) => { | ||
const [ attributes, setAttributes ] = useState( { height: 200, width: 400 } ); | ||
const { height, width } = attributes; | ||
const { children, ...restProps } = props; | ||
|
||
return ( | ||
<div style={ { margin: 30 } }> | ||
<ResizableBox | ||
{ ...restProps } | ||
size={ { | ||
height, | ||
width, | ||
} } | ||
onResizeStop={ ( event, direction, elt, delta ) => { | ||
setAttributes( { | ||
height: parseInt( height + delta.height, 10 ), | ||
width: parseInt( width + delta.width, 10 ), | ||
} ); | ||
} } | ||
> | ||
{ children } | ||
</ResizableBox> | ||
</div> | ||
); | ||
}; | ||
|
||
export const _default = () => { | ||
const content = text( 'Example: Content', 'Resize' ); | ||
const showHandle = boolean( 'showHandle', true ); | ||
const minHeight = number( 'minHeight', 50 ); | ||
const minWidth = number( 'minWidth', 50 ); | ||
const enable = { | ||
top: boolean( 'enable.top', false ), | ||
right: boolean( 'enable.right', true ), | ||
bottom: boolean( 'enable.bottom', true ), | ||
left: boolean( 'enable.left', false ), | ||
topRight: boolean( 'enable.topRight', false ), | ||
bottomRight: boolean( 'enable.bottomRight', true ), | ||
bottomLeft: boolean( 'enable.bottomLeft', false ), | ||
topLeft: boolean( 'enable.topLeft', false ), | ||
}; | ||
|
||
const props = { | ||
enable, | ||
minHeight, | ||
minWidth, | ||
showHandle, | ||
}; | ||
|
||
return ( | ||
<Example { ...props }> | ||
<div | ||
style={ { | ||
background: '#eee', | ||
display: 'flex', | ||
height: '100%', | ||
width: '100%', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
} } | ||
> | ||
<span>{ content }</span> | ||
</div> | ||
</Example> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters