Skip to content

Commit

Permalink
BoxControl: Add allowReset option (#32345)
Browse files Browse the repository at this point in the history
* Add option to hide BoxControl reset button
  • Loading branch information
aaronrobertshaw authored May 31, 2021
1 parent 4346306 commit bce9630
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
14 changes: 14 additions & 0 deletions packages/components/src/box-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ const Example = () => {
```

## Props
### allowReset

If this property is true, a button to reset the box control is rendered.

- Type: `Boolean`
- Required: No
- Default: `true`

### inputProps

Expand Down Expand Up @@ -127,6 +134,13 @@ A callback function for visualizer changes, based on input hover interactions.
- Type: `Function`
- Required: Yes

### resetValues

The `top`, `right`, `bottom`, and `left` box dimension values to use when the control is reset.

- Type: `Object`
- Required: No

### sides

Collection of sides to allow control of. If omitted or empty, all sides will be available.
Expand Down
25 changes: 14 additions & 11 deletions packages/components/src/box-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function BoxControl( {
values: valuesProp,
units,
sides,
allowReset = true,
resetValues = DEFAULT_VALUES,
} ) {
const [ values, setValues ] = useControlledState( valuesProp, {
Expand Down Expand Up @@ -123,17 +124,19 @@ export default function BoxControl( {
{ label }
</Text>
</FlexItem>
<FlexItem>
<Button
className="component-box-control__reset-button"
variant="secondary"
isSmall
onClick={ handleOnReset }
disabled={ ! isDirty }
>
{ __( 'Reset' ) }
</Button>
</FlexItem>
{ allowReset && (
<FlexItem>
<Button
className="component-box-control__reset-button"
isSecondary
isSmall
onClick={ handleOnReset }
disabled={ ! isDirty }
>
{ __( 'Reset' ) }
</Button>
</FlexItem>
) }
</Header>
<HeaderControlWrapper className="component-box-control__header-control-wrapper">
<FlexItem>
Expand Down

0 comments on commit bce9630

Please sign in to comment.