forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storybook: Add BorderRadiusControl story (WordPress#67383)
* Storybook: Add BorderRadiusControl story * Update BorderRadiusControl story to CSF 3 * Update BorderRadiusControl story to enhance argTypes documentation * Add README for BorderRadiusControl component * Update BorderRadiusControl README with correct prop requirements and defaults * Update BorderRadiusControl README and Story * Remove Unnecessary file * Update README Co-authored-by: Sukhendu2002 <[email protected]> Co-authored-by: t-hamano <[email protected]>
- Loading branch information
1 parent
37a06bd
commit a28455c
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/block-editor/src/components/border-radius-control/README.md
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,59 @@ | ||
# BorderRadiusControl | ||
|
||
`BorderRadiusControl` is a React component that provides a user interface for managing border radius values. It allows users to control the border radius of each corner independently or link them together for uniform values. | ||
|
||
## Usage | ||
|
||
```jsx | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalBorderRadiusControl as BorderRadiusControl } from '@wordpress/block-editor'; | ||
import { useState } from '@wordpress/element'; | ||
|
||
const MyBorderRadiusControl = () => { | ||
const [values, setValues] = useState({ | ||
topLeft: '10px', | ||
topRight: '10px', | ||
bottomLeft: '10px', | ||
bottomRight: '10px', | ||
}); | ||
|
||
return ( | ||
<BorderRadiusControl | ||
values={values} | ||
onChange={setValues} | ||
/> | ||
); | ||
}; | ||
``` | ||
|
||
## Props | ||
|
||
### values | ||
|
||
An object containing the border radius values for each corner. | ||
|
||
- **Type:** `Object` | ||
- **Required:** No | ||
- **Default:** `undefined` | ||
|
||
The values object has the following schema: | ||
|
||
| Property | Description | Type | | ||
| ----------- | ------------------------------------ | ------ | | ||
| topLeft | Border radius for top left corner | string | | ||
| topRight | Border radius for top right corner | string | | ||
| bottomLeft | Border radius for bottom left corner | string | | ||
| bottomRight | Border radius for bottom right corner| string | | ||
|
||
Each value should be a valid CSS border radius value (e.g., '10px', '1em'). | ||
|
||
### onChange | ||
|
||
Callback function that is called when any border radius value changes. | ||
|
||
- **Type:** `Function` | ||
- **Required:** Yes | ||
|
||
The function receives the updated values object as its argument. |
58 changes: 58 additions & 0 deletions
58
packages/block-editor/src/components/border-radius-control/stories/index.story.js
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,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BorderRadiusControl from '../'; | ||
|
||
const meta = { | ||
title: 'BlockEditor/BorderRadiusControl', | ||
component: BorderRadiusControl, | ||
parameters: { | ||
docs: { | ||
canvas: { sourceState: 'shown' }, | ||
description: { | ||
component: 'Control to display border radius options.', | ||
}, | ||
}, | ||
}, | ||
argTypes: { | ||
values: { | ||
control: 'object', | ||
description: 'Border radius values.', | ||
table: { | ||
type: { summary: 'object' }, | ||
}, | ||
}, | ||
onChange: { | ||
action: 'onChange', | ||
control: { type: null }, | ||
table: { | ||
type: { summary: 'function' }, | ||
}, | ||
description: 'Callback to handle onChange.', | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const Default = { | ||
render: function Template( { onChange, ...args } ) { | ||
const [ values, setValues ] = useState( args.values ); | ||
|
||
return ( | ||
<BorderRadiusControl | ||
{ ...args } | ||
values={ values } | ||
onChange={ ( ...changeArgs ) => { | ||
setValues( ...changeArgs ); | ||
onChange( ...changeArgs ); | ||
} } | ||
/> | ||
); | ||
}, | ||
}; |