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

Storybook: Add BlockAlignmentMatrixControl Stories and update README #68007

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
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,36 @@ const controls = (
/>
</BlockControls>
</>
}
);
```

### Props

| Name | Type | Default | Description |
| ---------- | ---------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `label` | `string` | `Change matrix alignment` | concise description of tool's functionality. |
| `onChange` | `function` | `noop` | the function to execute upon a user's change of the matrix state |
| `value` | `string` | `center` | describes the content alignment location and can be `top`, `right`, `bottom`, `left`, `topRight`, `bottomRight`, `bottomLeft`, `topLeft` |
### `label`

- **Type:** `string`
- **Default:** `'Change matrix alignment'`

Label for the control.

### `onChange`

- **Type:** `Function`
- **Default:** `noop`

Function to execute upon a user's change of the matrix state.

### `value`

- **Type:** `string`
- **Default:** `'center'`
- **Options:** `'center'`, `'center center'`, `'center left'`, `'center right'`, `'top center'`, `'top left'`, `'top right'`, `'bottom center'`, `'bottom left'`, `'bottom right'`

Content alignment location.

### `isDisabled`

- **Type:** `boolean`
- **Default:** `false`

Whether the control should be disabled.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ import {

const noop = () => {};

/**
* The alignment matrix control allows users to quickly adjust inner block alignment.
*
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-alignment-matrix-control/README.md
*
* @example
* ```jsx
* function Example() {
* return (
* <BlockControls>
* <BlockAlignmentMatrixControl
* label={ __( 'Change content position' ) }
* value="center"
* onChange={ ( nextPosition ) =>
* setAttributes( { contentPosition: nextPosition } )
* }
* />
* </BlockControls>
* );
* }
* ```
*
* @param {Object} props Component props.
* @param {string} props.label Label for the control. Defaults to 'Change matrix alignment'.
* @param {Function} props.onChange Function to execute upon change of matrix state.
* @param {string} props.value Content alignment location. One of: 'center', 'center center',
* 'center left', 'center right', 'top center', 'top left',
* 'top right', 'bottom center', 'bottom left', 'bottom right'.
* @param {boolean} props.isDisabled Whether the control should be disabled.
* @return {Element} The BlockAlignmentMatrixControl component.
*/
function BlockAlignmentMatrixControl( props ) {
const {
label = __( 'Change matrix alignment' ),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import BlockAlignmentMatrixControl from '../';

const meta = {
title: 'BlockEditor/BlockAlignmentMatrixControl',
component: BlockAlignmentMatrixControl,
parameters: {
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'Renders a control for selecting block alignment using a matrix of alignment options.',
},
},
},
argTypes: {
label: {
control: 'text',
table: {
type: { summary: 'string' },
defaultValue: { summary: "'Change matrix alignment'" },
},
description: 'Label for the control.',
},
onChange: {
action: 'onChange',
control: { type: null },
table: {
type: { summary: 'function' },
defaultValue: { summary: '() => {}' },
},
description:
"Function to execute upon a user's change of the matrix state.",
},
isDisabled: {
control: 'boolean',
table: {
type: { summary: 'boolean' },
defaultValue: { summary: 'false' },
},
description: 'Whether the control should be disabled.',
},
value: {
control: { type: null },
table: {
type: { summary: 'string' },
defaultValue: { summary: "'center'" },
},
description: 'Content alignment location.',
},
},
};

export default meta;

export const Default = {
render: function Template( { onChange, ...args } ) {
const [ value, setValue ] = useState();

return (
<BlockAlignmentMatrixControl
{ ...args }
value={ value }
onChange={ ( ...changeArgs ) => {
onChange( ...changeArgs );
setValue( ...changeArgs );
} }
/>
);
},
};
Loading