-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.tsx
78 lines (70 loc) · 2.17 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* External dependencies
*/
import type { ComponentMeta, ComponentStory } from '@storybook/react';
/**
* Internal dependencies
*/
import BaseControl, { useBaseControlProps } from '..';
import Button from '../../button';
const meta: ComponentMeta< typeof BaseControl > = {
title: 'Components/BaseControl',
component: BaseControl,
argTypes: {
children: { control: { type: null } },
help: { control: { type: 'text' } },
label: { control: { type: 'text' } },
},
parameters: {
controls: { expanded: true },
docs: { source: { state: 'open' } },
},
};
export default meta;
const BaseControlWithTextarea: ComponentStory< typeof BaseControl > = (
props
) => {
const { baseControlProps, controlProps } = useBaseControlProps( props );
return (
<BaseControl { ...baseControlProps }>
<textarea style={ { display: 'block' } } { ...controlProps } />
</BaseControl>
);
};
export const Default: ComponentStory< typeof BaseControl > =
BaseControlWithTextarea.bind( {} );
Default.args = {
__nextHasNoMarginBottom: true,
label: 'Label text',
};
export const WithHelpText = BaseControlWithTextarea.bind( {} );
WithHelpText.args = {
...Default.args,
help: 'Help text adds more explanation.',
};
/**
* `BaseControl.VisualLabel` is used to render a purely visual label inside a `BaseControl` component.
*
* It should only be used in cases where the children being rendered inside `BaseControl` are already accessibly labeled,
* e.g., a button, but we want an additional visual label for that section equivalent to the labels `BaseControl` would
* otherwise use if the `label` prop was passed.
*/
export const WithVisualLabel: ComponentStory< typeof BaseControl > = (
props
) => {
// @ts-expect-error - Unclear how to fix, see also https://github.com/WordPress/gutenberg/pull/39468#discussion_r827150516
BaseControl.VisualLabel.displayName = 'BaseControl.VisualLabel';
return (
<BaseControl { ...props }>
<BaseControl.VisualLabel>Visual label</BaseControl.VisualLabel>
<div>
<Button variant="secondary">Select an author</Button>
</div>
</BaseControl>
);
};
WithVisualLabel.args = {
...Default.args,
help: 'This button is already accessibly labeled.',
label: undefined,
};