Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoxControl: Add allowReset option #32345

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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