@codecademy/styleguide 78.5.5-alpha.86116a.0 → 78.5.5-alpha.86d3e6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/package.json +2 -2
- package/src/lib/Atoms/FormElements/FormGroup/FormGroup.mdx +0 -6
- package/src/lib/Atoms/FormElements/FormGroup/FormGroup.stories.tsx +0 -11
- package/src/lib/Molecules/Coachmark/Coachmark.mdx +6 -0
- package/src/lib/Molecules/Coachmark/Coachmark.stories.tsx +37 -1
- package/src/lib/Molecules/Modals/Modal/Modal.mdx +10 -0
- package/src/lib/Molecules/Modals/Overlay/Overlay.mdx +6 -0
- package/src/lib/Molecules/Modals/Overlay/Overlay.stories.tsx +67 -2
- package/src/lib/Molecules/Tips/InfoTip/InfoTip.mdx +10 -11
- package/src/lib/Molecules/Tips/InfoTip/InfoTip.stories.tsx +105 -95
- package/src/lib/Molecules/Tips/PreviewTip/PreviewTip.mdx +6 -0
- package/src/lib/Molecules/Tips/PreviewTip/PreviewTip.stories.tsx +68 -1
- package/src/lib/Molecules/Tips/ToolTip/ToolTip.mdx +6 -0
- package/src/lib/Molecules/Tips/ToolTip/ToolTip.stories.tsx +59 -0
- package/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.mdx +0 -20
- package/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.stories.tsx +0 -80
- package/src/lib/Organisms/GridForm/Fields.mdx +0 -20
- package/src/lib/Organisms/GridForm/Fields.stories.tsx +1 -72
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
### [78.5.5-alpha.
|
|
6
|
+
### [78.5.5-alpha.86d3e6.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@78.5.4...@codecademy/styleguide@78.5.5-alpha.86d3e6.0) (2026-01-06)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @codecademy/styleguide
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/styleguide",
|
|
3
3
|
"description": "Styleguide & Component library for codecademy.com",
|
|
4
|
-
"version": "78.5.5-alpha.
|
|
4
|
+
"version": "78.5.5-alpha.86d3e6.0",
|
|
5
5
|
"author": "Codecademy Engineering",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"repository": "git@github.com:Codecademy/gamut.git",
|
|
11
|
-
"gitHead": "
|
|
11
|
+
"gitHead": "2988ef3b1571897c2359c9031389d08356b819be"
|
|
12
12
|
}
|
|
@@ -69,12 +69,6 @@ A field can include <LinkTo id="Molecules/Tips/InfoTip"> our existing `InfoTip`<
|
|
|
69
69
|
|
|
70
70
|
<Canvas of={FormGroupStories.HighEmphasisInfoTip} />
|
|
71
71
|
|
|
72
|
-
#### Accessibility
|
|
73
|
-
|
|
74
|
-
InfoTip buttons are automatically labelled by string field labels for accessibility.
|
|
75
|
-
|
|
76
|
-
<Canvas of={FormGroupStories.InfoTipAutoLabelling} />
|
|
77
|
-
|
|
78
72
|
## Playground
|
|
79
73
|
|
|
80
74
|
<Canvas sourceState="shown" of={FormGroupStories.Default} />
|
|
@@ -97,14 +97,3 @@ export const HighEmphasisInfoTip: Story = {
|
|
|
97
97
|
children: <Input />,
|
|
98
98
|
},
|
|
99
99
|
};
|
|
100
|
-
|
|
101
|
-
export const InfoTipAutoLabelling: Story = {
|
|
102
|
-
args: {
|
|
103
|
-
label: 'Email address',
|
|
104
|
-
htmlFor: 'auto-label-input',
|
|
105
|
-
infotip: {
|
|
106
|
-
info: 'We will never share your email with third parties.',
|
|
107
|
-
},
|
|
108
|
-
children: <Input htmlFor="auto-label-input" type="email" />,
|
|
109
|
-
},
|
|
110
|
-
};
|
|
@@ -94,6 +94,12 @@ Using `popoverProps`, you can customize the look of the rendered popover. For ex
|
|
|
94
94
|
|
|
95
95
|
<Canvas of={CoachmarkStories.Customized} />
|
|
96
96
|
|
|
97
|
+
### Z-Index
|
|
98
|
+
|
|
99
|
+
You can customize the `zIndex` of the Coachmark's popover by passing `zIndex` through `popoverProps`. This is useful when the popover needs to appear above other positioned elements.
|
|
100
|
+
|
|
101
|
+
<Canvas of={CoachmarkStories.ZIndex} />
|
|
102
|
+
|
|
97
103
|
## Playground
|
|
98
104
|
|
|
99
105
|
<Canvas sourceState="shown" of={CoachmarkStories.Default} />
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Coachmark, FillButton, FlexBox, Text } from '@codecademy/gamut';
|
|
1
|
+
import { Box, Coachmark, FillButton, FlexBox, Text } from '@codecademy/gamut';
|
|
2
2
|
import * as patterns from '@codecademy/gamut-patterns';
|
|
3
3
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
4
|
import { ComponentProps, useEffect, useState } from 'react';
|
|
@@ -197,3 +197,39 @@ export const Customized: Story = {
|
|
|
197
197
|
);
|
|
198
198
|
},
|
|
199
199
|
};
|
|
200
|
+
|
|
201
|
+
export const ZIndex: Story = {
|
|
202
|
+
args: {
|
|
203
|
+
popoverProps: {
|
|
204
|
+
position: 'below',
|
|
205
|
+
zIndex: 5,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
render: function ZIndexExample(args) {
|
|
209
|
+
const [shouldShow, setShouldShow] = useState(true);
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<FlexBox flexDirection="column" gap={16}>
|
|
213
|
+
<Box bg="paleBlue" p={16} zIndex={3} position="relative">
|
|
214
|
+
Element with z-index: 3
|
|
215
|
+
</Box>
|
|
216
|
+
<Coachmark
|
|
217
|
+
{...args}
|
|
218
|
+
renderPopover={() => (
|
|
219
|
+
<FlexBox alignItems="flex-start" flexDirection="column" p={16}>
|
|
220
|
+
<Text mb={8}>This coachmark has z-index: 5 via popoverProps</Text>
|
|
221
|
+
<FillButton size="small" onClick={() => setShouldShow(false)}>
|
|
222
|
+
Got it
|
|
223
|
+
</FillButton>
|
|
224
|
+
</FlexBox>
|
|
225
|
+
)}
|
|
226
|
+
shouldShow={shouldShow}
|
|
227
|
+
>
|
|
228
|
+
<FillButton onClick={() => setShouldShow(true)}>
|
|
229
|
+
Show Coachmark
|
|
230
|
+
</FillButton>
|
|
231
|
+
</Coachmark>
|
|
232
|
+
</FlexBox>
|
|
233
|
+
);
|
|
234
|
+
},
|
|
235
|
+
};
|
|
@@ -89,6 +89,16 @@ A Modal can be made scrollable by including large content inside.
|
|
|
89
89
|
|
|
90
90
|
<Canvas of={ModalStories.Scrollable} />
|
|
91
91
|
|
|
92
|
+
## Z-Index
|
|
93
|
+
|
|
94
|
+
Modal accepts a `zIndex` prop (defaults to `3`) that controls the stacking order of its underlying Overlay. Use this when the modal needs to appear above other positioned elements like sticky headers or custom floating UI.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
<Modal zIndex={10} isOpen={isOpen} onRequestClose={handleClose}>
|
|
98
|
+
Content that needs to appear above other positioned elements
|
|
99
|
+
</Modal>
|
|
100
|
+
```
|
|
101
|
+
|
|
92
102
|
## Focus management
|
|
93
103
|
|
|
94
104
|
The `containerFocusRef` prop allows you to programmatically control focus on the Modal container. This is useful for advanced focus management scenarios where you need to override the default focus behavior (the Modal has `data-autofocus` by default).
|
|
@@ -32,6 +32,12 @@ Unlike the legacy `Modal` implementations in the monolith, this:
|
|
|
32
32
|
|
|
33
33
|
- If you need styles such as a background behind content, see `Modal` for general modals and `Dialog` for confirmation flows.
|
|
34
34
|
|
|
35
|
+
## Z-Index
|
|
36
|
+
|
|
37
|
+
The `zIndex` prop controls the stacking order of the overlay. It defaults to `3`, which places it above most common UI elements. Increase this value when the overlay needs to appear above other positioned elements like sticky headers or floating UI.
|
|
38
|
+
|
|
39
|
+
<Canvas of={OverlayStories.ZIndex} />
|
|
40
|
+
|
|
35
41
|
## Playground
|
|
36
42
|
|
|
37
43
|
<Canvas sourceState="shown" of={OverlayStories.Default} />
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FillButton, FlexBox, Overlay, Text } from '@codecademy/gamut';
|
|
2
|
-
import type { Meta } from '@storybook/react';
|
|
1
|
+
import { Box, FillButton, FlexBox, Overlay, Text } from '@codecademy/gamut';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof Overlay> = {
|
|
@@ -8,6 +8,7 @@ const meta: Meta<typeof Overlay> = {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export default meta;
|
|
11
|
+
type Story = StoryObj<typeof Overlay>;
|
|
11
12
|
|
|
12
13
|
export const Default: React.FC<React.ComponentProps<typeof Overlay>> = (
|
|
13
14
|
args
|
|
@@ -34,3 +35,67 @@ export const Default: React.FC<React.ComponentProps<typeof Overlay>> = (
|
|
|
34
35
|
</>
|
|
35
36
|
);
|
|
36
37
|
};
|
|
38
|
+
|
|
39
|
+
export const ZIndex: Story = {
|
|
40
|
+
render: function ZIndexExample() {
|
|
41
|
+
const [defaultOpen, setDefaultOpen] = useState(false);
|
|
42
|
+
const [customOpen, setCustomOpen] = useState(false);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<FlexBox flexDirection="column" gap={16}>
|
|
46
|
+
<FlexBox gap={16}>
|
|
47
|
+
<FillButton onClick={() => setDefaultOpen(true)}>
|
|
48
|
+
Open Overlay (default z-index: 3)
|
|
49
|
+
</FillButton>
|
|
50
|
+
<FillButton onClick={() => setCustomOpen(true)}>
|
|
51
|
+
Open Overlay (z-index: 10)
|
|
52
|
+
</FillButton>
|
|
53
|
+
</FlexBox>
|
|
54
|
+
|
|
55
|
+
<Box position="relative" height="100px">
|
|
56
|
+
<Box
|
|
57
|
+
position="absolute"
|
|
58
|
+
top={0}
|
|
59
|
+
left={0}
|
|
60
|
+
bg="paleYellow"
|
|
61
|
+
p={16}
|
|
62
|
+
zIndex={5}
|
|
63
|
+
>
|
|
64
|
+
<Text>Element with z-index: 5</Text>
|
|
65
|
+
</Box>
|
|
66
|
+
</Box>
|
|
67
|
+
|
|
68
|
+
<Overlay
|
|
69
|
+
isOpen={defaultOpen}
|
|
70
|
+
onRequestClose={() => setDefaultOpen(false)}
|
|
71
|
+
shroud
|
|
72
|
+
>
|
|
73
|
+
<FlexBox bg="white" p={24} borderRadius="md" flexDirection="column" gap={16}>
|
|
74
|
+
<Text>
|
|
75
|
+
This overlay uses the default z-index of 3.
|
|
76
|
+
<br />
|
|
77
|
+
It may appear behind elements with higher z-index values.
|
|
78
|
+
</Text>
|
|
79
|
+
<FillButton onClick={() => setDefaultOpen(false)}>Close</FillButton>
|
|
80
|
+
</FlexBox>
|
|
81
|
+
</Overlay>
|
|
82
|
+
|
|
83
|
+
<Overlay
|
|
84
|
+
isOpen={customOpen}
|
|
85
|
+
onRequestClose={() => setCustomOpen(false)}
|
|
86
|
+
shroud
|
|
87
|
+
zIndex={10}
|
|
88
|
+
>
|
|
89
|
+
<FlexBox bg="white" p={24} borderRadius="md" flexDirection="column" gap={16}>
|
|
90
|
+
<Text>
|
|
91
|
+
This overlay uses z-index: 10.
|
|
92
|
+
<br />
|
|
93
|
+
It will appear above the yellow element with z-index: 5.
|
|
94
|
+
</Text>
|
|
95
|
+
<FillButton onClick={() => setCustomOpen(false)}>Close</FillButton>
|
|
96
|
+
</FlexBox>
|
|
97
|
+
</Overlay>
|
|
98
|
+
</FlexBox>
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
};
|
|
@@ -28,7 +28,8 @@ export const parameters = {
|
|
|
28
28
|
A tip is triggered by clicking on an information icon button and can be closed by clicking outside, pressing <kbd>Esc</kbd>, or clicking the info button again.
|
|
29
29
|
|
|
30
30
|
Use an infotip to provide additional info about a nearby element or content.
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
Infotip consists of an icon button and the .tip-bg subcomponent. The info button has low and high emphasis variants and the `.tip` has 4 alignment variants.
|
|
32
33
|
|
|
33
34
|
## Variants
|
|
34
35
|
|
|
@@ -56,18 +57,16 @@ This `floating` variant should only be used as needed.
|
|
|
56
57
|
|
|
57
58
|
### InfoTips with links or buttons
|
|
58
59
|
|
|
59
|
-
Links or buttons within InfoTips should be used sparingly and only when the information is critical to the user's understanding of the content.
|
|
60
|
+
Links or buttons within InfoTips should be used sparingly and only when the information is critical to the user's understanding of the content. If an infotip _absolutely requires_ a link or button, it needs to provide a programmatic focus by way of the `onClick` prop. The `onClick` prop accepts a function that can accept an `{isTipHidden}` argument and using that you can set programmatic focus as needed.
|
|
60
61
|
|
|
61
62
|
<Canvas of={InfoTipStories.WithLinksOrButtons} />
|
|
62
63
|
|
|
63
|
-
###
|
|
64
|
+
### Floating placement
|
|
64
65
|
|
|
65
|
-
InfoTips
|
|
66
|
+
When using `placement="floating"`, InfoTips implements focus management for easier navigation:
|
|
66
67
|
|
|
67
|
-
- **
|
|
68
|
-
- **Tab
|
|
69
|
-
- **Shift+Tab (Floating)**: Navigate backward naturally - from the button, exits to the previous page element
|
|
70
|
-
- **Tab/Shift+Tab (Inline)**: Follows normal document flow
|
|
68
|
+
- **Tab**: Navigate forward through focusable elements (links, buttons) inside the tip. When reaching the last element, wraps back to the InfoTip button for convenience
|
|
69
|
+
- **Shift+Tab**: Navigate backward naturally through the page
|
|
71
70
|
- **Escape**: Closes the tip and returns focus to the InfoTip button
|
|
72
71
|
|
|
73
72
|
<Canvas of={InfoTipStories.KeyboardNavigation} />
|
|
@@ -94,13 +93,13 @@ The InfoTip button's accessible label can be customized using either prop:
|
|
|
94
93
|
|
|
95
94
|
### Custom Role Description
|
|
96
95
|
|
|
97
|
-
The `InfoTipButton` uses [`aria-roledescription`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-roledescription) to provide additional context to screen reader users about the button's specific purpose.
|
|
96
|
+
The `InfoTipButton` uses [`aria-roledescription="More information button"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-roledescription) to provide additional context to screen reader users about the button's specific purpose.
|
|
98
97
|
|
|
99
98
|
<Canvas of={InfoTipStories.AriaLabel} />
|
|
100
99
|
|
|
101
|
-
##
|
|
100
|
+
## Z-Index
|
|
102
101
|
|
|
103
|
-
You can
|
|
102
|
+
You can customize the `zIndex` of the InfoTip's portal with the `zIndex` prop. This works for both `inline` and `floating` placements, and is useful when the tip needs to appear above other positioned elements.
|
|
104
103
|
|
|
105
104
|
<Canvas of={InfoTipStories.ZIndex} />
|
|
106
105
|
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Anchor,
|
|
3
3
|
Box,
|
|
4
|
+
Coachmark,
|
|
4
5
|
FillButton,
|
|
5
6
|
FlexBox,
|
|
6
7
|
GridBox,
|
|
7
|
-
IconButton,
|
|
8
8
|
InfoTip,
|
|
9
9
|
Modal,
|
|
10
10
|
Text,
|
|
11
11
|
} from '@codecademy/gamut';
|
|
12
|
-
import { SparkleIcon } from '@codecademy/gamut-icons';
|
|
13
12
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
14
|
-
import { useState } from 'react';
|
|
13
|
+
import { useRef, useState } from 'react';
|
|
15
14
|
|
|
16
15
|
const meta: Meta<typeof InfoTip> = {
|
|
17
16
|
component: InfoTip,
|
|
18
17
|
args: {
|
|
19
18
|
alignment: 'top-left',
|
|
20
|
-
ariaLabel: 'More information',
|
|
21
19
|
info: `I am additional information about a nearby element or content.`,
|
|
22
20
|
},
|
|
23
21
|
};
|
|
@@ -31,10 +29,7 @@ export const Emphasis: Story = {
|
|
|
31
29
|
},
|
|
32
30
|
render: (args) => (
|
|
33
31
|
<FlexBox center m={24} py={64}>
|
|
34
|
-
<Text
|
|
35
|
-
Some text that needs info
|
|
36
|
-
</Text>
|
|
37
|
-
<InfoTip {...args} ariaLabelledby="emphasis-text" />
|
|
32
|
+
<Text mr={4}>Some text that needs info</Text> <InfoTip {...args} />
|
|
38
33
|
</FlexBox>
|
|
39
34
|
),
|
|
40
35
|
};
|
|
@@ -44,15 +39,10 @@ export const Alignments: Story = {
|
|
|
44
39
|
<GridBox gap={24} gridTemplateColumns="1fr 1fr" ml={8} py={64}>
|
|
45
40
|
{(['top-right', 'top-left', 'bottom-right', 'bottom-left'] as const).map(
|
|
46
41
|
(alignment) => {
|
|
47
|
-
const labelId = `alignment-${alignment}`;
|
|
48
42
|
return (
|
|
49
43
|
<Box key={alignment}>
|
|
50
|
-
<Text
|
|
51
|
-
<InfoTip
|
|
52
|
-
{...args}
|
|
53
|
-
alignment={alignment}
|
|
54
|
-
ariaLabelledby={labelId}
|
|
55
|
-
/>
|
|
44
|
+
<Text>{alignment}</Text>
|
|
45
|
+
<InfoTip {...args} alignment={alignment} />
|
|
56
46
|
</Box>
|
|
57
47
|
);
|
|
58
48
|
}
|
|
@@ -67,52 +57,10 @@ export const Placement: Story = {
|
|
|
67
57
|
},
|
|
68
58
|
render: (args) => (
|
|
69
59
|
<FlexBox center>
|
|
70
|
-
<Text
|
|
60
|
+
<Text mr={4}>
|
|
71
61
|
This text is in a small space and needs floating placement
|
|
72
62
|
</Text>{' '}
|
|
73
|
-
<InfoTip {...args}
|
|
74
|
-
</FlexBox>
|
|
75
|
-
),
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export const AriaLabel: Story = {
|
|
79
|
-
render: (args) => (
|
|
80
|
-
<FlexBox center column gap={24} my={48} width={1}>
|
|
81
|
-
<FlexBox alignItems="center" gap={8}>
|
|
82
|
-
<Text fontSize={16} fontWeight="bold">
|
|
83
|
-
Using ariaLabel (no visible label text):
|
|
84
|
-
</Text>
|
|
85
|
-
</FlexBox>
|
|
86
|
-
<FlexBox alignItems="center" gap={8}>
|
|
87
|
-
<IconButton
|
|
88
|
-
icon={SparkleIcon}
|
|
89
|
-
tip="This tool needs to be explained in the InfoTip"
|
|
90
|
-
tipProps={{ placement: 'floating' }}
|
|
91
|
-
onClick={() => null}
|
|
92
|
-
/>
|
|
93
|
-
<InfoTip
|
|
94
|
-
{...args}
|
|
95
|
-
ariaLabel="Learn more about this tool"
|
|
96
|
-
info="This is some helpful info about the tool represented by the IconButton"
|
|
97
|
-
/>
|
|
98
|
-
</FlexBox>
|
|
99
|
-
|
|
100
|
-
<FlexBox alignItems="center" gap={8}>
|
|
101
|
-
<Text fontSize={16} fontWeight="bold">
|
|
102
|
-
Using ariaLabelledby (references visible text):
|
|
103
|
-
</Text>
|
|
104
|
-
</FlexBox>
|
|
105
|
-
<FlexBox alignItems="center" gap={8}>
|
|
106
|
-
<Text id="custom-info-id">
|
|
107
|
-
I am some helpful yet concise text that needs more explanation
|
|
108
|
-
</Text>
|
|
109
|
-
<InfoTip
|
|
110
|
-
{...args}
|
|
111
|
-
alignment="bottom-left"
|
|
112
|
-
ariaLabelledby="custom-info-id"
|
|
113
|
-
info="I am clarifying information related to the concise text."
|
|
114
|
-
/>
|
|
115
|
-
</FlexBox>
|
|
63
|
+
<InfoTip {...args} />
|
|
116
64
|
</FlexBox>
|
|
117
65
|
),
|
|
118
66
|
};
|
|
@@ -122,16 +70,19 @@ export const WithLinksOrButtons: Story = {
|
|
|
122
70
|
placement: 'floating',
|
|
123
71
|
},
|
|
124
72
|
render: function WithLinksOrButtons(args) {
|
|
73
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
74
|
+
|
|
75
|
+
const onClick = ({ isTipHidden }: { isTipHidden: boolean }) => {
|
|
76
|
+
if (!isTipHidden) ref.current?.focus();
|
|
77
|
+
};
|
|
78
|
+
|
|
125
79
|
return (
|
|
126
80
|
<FlexBox center py={64}>
|
|
127
|
-
<Text
|
|
128
|
-
This text is in a small space and needs info
|
|
129
|
-
</Text>{' '}
|
|
81
|
+
<Text mr={4}>This text is in a small space and needs info </Text>{' '}
|
|
130
82
|
<InfoTip
|
|
131
83
|
{...args}
|
|
132
|
-
ariaLabelledby="links-text"
|
|
133
84
|
info={
|
|
134
|
-
<Text tabIndex={-1}>
|
|
85
|
+
<Text ref={ref} tabIndex={-1}>
|
|
135
86
|
Hey! Here is a{' '}
|
|
136
87
|
<Anchor href="https://giphy.com/search/nichijou">
|
|
137
88
|
cool link
|
|
@@ -143,6 +94,7 @@ export const WithLinksOrButtons: Story = {
|
|
|
143
94
|
that is also super important.
|
|
144
95
|
</Text>
|
|
145
96
|
}
|
|
97
|
+
onClick={onClick}
|
|
146
98
|
/>
|
|
147
99
|
</FlexBox>
|
|
148
100
|
);
|
|
@@ -151,35 +103,42 @@ export const WithLinksOrButtons: Story = {
|
|
|
151
103
|
|
|
152
104
|
export const KeyboardNavigation: Story = {
|
|
153
105
|
render: function KeyboardNavigation() {
|
|
106
|
+
const floatingRef = useRef<HTMLDivElement>(null);
|
|
107
|
+
const inlineRef = useRef<HTMLDivElement>(null);
|
|
108
|
+
|
|
154
109
|
const examples = [
|
|
155
110
|
{
|
|
156
111
|
title: 'Floating Placement',
|
|
157
112
|
placement: 'floating' as const,
|
|
113
|
+
ref: floatingRef,
|
|
158
114
|
links: ['Link 1', 'Link 2', 'Link 3'],
|
|
159
115
|
},
|
|
160
116
|
{
|
|
161
117
|
title: 'Inline Placement',
|
|
162
118
|
placement: 'inline' as const,
|
|
163
119
|
alignment: 'bottom-right' as const,
|
|
120
|
+
ref: inlineRef,
|
|
164
121
|
links: ['Link A', 'Link B'],
|
|
165
122
|
},
|
|
166
123
|
];
|
|
167
124
|
|
|
168
125
|
return (
|
|
169
|
-
<FlexBox center
|
|
126
|
+
<FlexBox center column gap={24} py={64}>
|
|
170
127
|
<GridBox gap={16} gridTemplateColumns="1fr 1fr">
|
|
171
|
-
{examples.map(({ title, placement, alignment, links }) => {
|
|
172
|
-
const
|
|
128
|
+
{examples.map(({ title, placement, alignment, ref, links }) => {
|
|
129
|
+
const onClick = ({ isTipHidden }: { isTipHidden: boolean }) => {
|
|
130
|
+
if (!isTipHidden) ref.current?.focus();
|
|
131
|
+
};
|
|
132
|
+
|
|
173
133
|
return (
|
|
174
134
|
<FlexBox gap={8} key={placement}>
|
|
175
|
-
<Text fontSize={16} fontWeight="bold"
|
|
135
|
+
<Text fontSize={16} fontWeight="bold">
|
|
176
136
|
{title}
|
|
177
137
|
</Text>
|
|
178
138
|
<InfoTip
|
|
179
139
|
alignment={alignment}
|
|
180
|
-
ariaLabelledby={labelId}
|
|
181
140
|
info={
|
|
182
|
-
<Text>
|
|
141
|
+
<Text ref={ref} tabIndex={-1}>
|
|
183
142
|
{links.map((label, idx) => (
|
|
184
143
|
<>
|
|
185
144
|
{idx > 0 && ', '}
|
|
@@ -192,6 +151,7 @@ export const KeyboardNavigation: Story = {
|
|
|
192
151
|
</Text>
|
|
193
152
|
}
|
|
194
153
|
placement={placement}
|
|
154
|
+
onClick={onClick}
|
|
195
155
|
/>
|
|
196
156
|
</FlexBox>
|
|
197
157
|
);
|
|
@@ -203,10 +163,6 @@ export const KeyboardNavigation: Story = {
|
|
|
203
163
|
Keyboard Navigation:
|
|
204
164
|
</Text>
|
|
205
165
|
<Box as="ul" fontSize={14} pl={16}>
|
|
206
|
-
<li>
|
|
207
|
-
<strong>Opening:</strong> Focus automatically moves to the tip
|
|
208
|
-
content when opened
|
|
209
|
-
</li>
|
|
210
166
|
<li>
|
|
211
167
|
<strong>Floating - Tab:</strong> Navigates forward through links,
|
|
212
168
|
then wraps to button (contained)
|
|
@@ -240,6 +196,7 @@ export const InfoTipInsideModal: Story = {
|
|
|
240
196
|
},
|
|
241
197
|
render: function InfoTipInsideModal(args) {
|
|
242
198
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
199
|
+
const [showCoachmark, setShowCoachmark] = useState(false);
|
|
243
200
|
|
|
244
201
|
return (
|
|
245
202
|
<FlexBox center flexDirection="column" gap={16} py={64}>
|
|
@@ -269,10 +226,8 @@ export const InfoTipInsideModal: Story = {
|
|
|
269
226
|
<Text>This modal contains an InfoTip below:</Text>
|
|
270
227
|
|
|
271
228
|
<FlexBox alignItems="center" gap={8}>
|
|
272
|
-
<Text
|
|
273
|
-
|
|
274
|
-
</Text>
|
|
275
|
-
<InfoTip {...args} ariaLabelledby="modal-infotip-text" />
|
|
229
|
+
<Text>Some text that needs explanation</Text>
|
|
230
|
+
<InfoTip {...args} />
|
|
276
231
|
</FlexBox>
|
|
277
232
|
|
|
278
233
|
<Text color="text-disabled" fontSize={14}>
|
|
@@ -280,6 +235,37 @@ export const InfoTipInsideModal: Story = {
|
|
|
280
235
|
closing the modal itself. Inline placement works correctly.
|
|
281
236
|
</Text>
|
|
282
237
|
|
|
238
|
+
<FlexBox alignItems="center" borderTop={1} gap={8} mt={8} pt={16}>
|
|
239
|
+
<Text id="modal-coachmark-text">
|
|
240
|
+
This modal also contains a Coachmark
|
|
241
|
+
</Text>
|
|
242
|
+
<Coachmark
|
|
243
|
+
popoverProps={{ zIndex: 3 }}
|
|
244
|
+
renderPopover={() => (
|
|
245
|
+
<FlexBox
|
|
246
|
+
alignItems="flex-start"
|
|
247
|
+
flexDirection="column"
|
|
248
|
+
p={16}
|
|
249
|
+
>
|
|
250
|
+
<Text mb={8}>
|
|
251
|
+
This Coachmark is inside a Modal. Try pressing Escape!
|
|
252
|
+
</Text>
|
|
253
|
+
<FillButton
|
|
254
|
+
size="small"
|
|
255
|
+
onClick={() => setShowCoachmark(false)}
|
|
256
|
+
>
|
|
257
|
+
Got it
|
|
258
|
+
</FillButton>
|
|
259
|
+
</FlexBox>
|
|
260
|
+
)}
|
|
261
|
+
shouldShow={showCoachmark}
|
|
262
|
+
>
|
|
263
|
+
<FillButton size="small" onClick={() => setShowCoachmark(true)}>
|
|
264
|
+
Show Coachmark
|
|
265
|
+
</FillButton>
|
|
266
|
+
</Coachmark>
|
|
267
|
+
</FlexBox>
|
|
268
|
+
|
|
283
269
|
<FillButton onClick={() => setIsModalOpen(false)}>
|
|
284
270
|
Close Modal
|
|
285
271
|
</FillButton>
|
|
@@ -292,22 +278,49 @@ export const InfoTipInsideModal: Story = {
|
|
|
292
278
|
|
|
293
279
|
export const ZIndex: Story = {
|
|
294
280
|
args: {
|
|
295
|
-
info: 'I
|
|
281
|
+
info: 'I have a custom z-index',
|
|
296
282
|
zIndex: 5,
|
|
297
283
|
},
|
|
298
284
|
render: (args) => (
|
|
299
|
-
<FlexBox center flexDirection="column" m={24} py={64}>
|
|
300
|
-
<
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
info="
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
285
|
+
<FlexBox center flexDirection="column" gap={16} m={24} py={64}>
|
|
286
|
+
<Text variant="p-small">Inline placement:</Text>
|
|
287
|
+
<FlexBox alignItems="center" gap={8}>
|
|
288
|
+
<Box bg="paleBlue" p={8} zIndex={3} position="relative">
|
|
289
|
+
z-index: 3
|
|
290
|
+
</Box>
|
|
291
|
+
<InfoTip ariaLabel="inline default" info="Default z-index (inline)" />
|
|
292
|
+
<Box bg="paleBlue" p={8} zIndex={3} position="relative">
|
|
293
|
+
z-index: 3
|
|
294
|
+
</Box>
|
|
295
|
+
<InfoTip
|
|
296
|
+
{...args}
|
|
297
|
+
ariaLabel="inline custom"
|
|
298
|
+
info="z-index: 5 (inline)"
|
|
299
|
+
/>
|
|
300
|
+
</FlexBox>
|
|
301
|
+
|
|
302
|
+
<Text variant="p-small" mt={24}>
|
|
303
|
+
Floating placement:
|
|
304
|
+
</Text>
|
|
305
|
+
<FlexBox alignItems="center" gap={8}>
|
|
306
|
+
<Box bg="paleGreen" p={8} zIndex={3} position="relative">
|
|
307
|
+
z-index: 3
|
|
308
|
+
</Box>
|
|
309
|
+
<InfoTip
|
|
310
|
+
ariaLabel="floating default"
|
|
311
|
+
info="Default z-index (floating)"
|
|
312
|
+
placement="floating"
|
|
313
|
+
/>
|
|
314
|
+
<Box bg="paleGreen" p={8} zIndex={3} position="relative">
|
|
315
|
+
z-index: 3
|
|
316
|
+
</Box>
|
|
317
|
+
<InfoTip
|
|
318
|
+
{...args}
|
|
319
|
+
ariaLabel="floating custom"
|
|
320
|
+
info="z-index: 5 (floating)"
|
|
321
|
+
placement="floating"
|
|
322
|
+
/>
|
|
323
|
+
</FlexBox>
|
|
311
324
|
</FlexBox>
|
|
312
325
|
),
|
|
313
326
|
};
|
|
@@ -315,10 +328,7 @@ export const ZIndex: Story = {
|
|
|
315
328
|
export const Default: Story = {
|
|
316
329
|
render: (args) => (
|
|
317
330
|
<FlexBox center m={24} py={64}>
|
|
318
|
-
<Text
|
|
319
|
-
Some text that needs info
|
|
320
|
-
</Text>
|
|
321
|
-
<InfoTip {...args} ariaLabelledby="default-text" />
|
|
331
|
+
<Text mr={4}>Some text that needs info</Text> <InfoTip {...args} />
|
|
322
332
|
</FlexBox>
|
|
323
333
|
),
|
|
324
334
|
};
|
|
@@ -55,6 +55,12 @@ The `truncateLines` prop allows you to set the maximum number of lines that the
|
|
|
55
55
|
|
|
56
56
|
<Canvas of={PreviewTipStories.Truncation} />
|
|
57
57
|
|
|
58
|
+
## Z-Index
|
|
59
|
+
|
|
60
|
+
You can customize the `zIndex` of the PreviewTip's portal with the `zIndex` prop. This works for both `inline` and `floating` placements, and is useful when the tip needs to appear above other positioned elements.
|
|
61
|
+
|
|
62
|
+
<Canvas of={PreviewTipStories.ZIndex} />
|
|
63
|
+
|
|
58
64
|
## Playground
|
|
59
65
|
|
|
60
66
|
<Canvas sourceState="shown" of={PreviewTipStories.Default} />
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Box, FlexBox, PreviewTip } from '@codecademy/gamut';
|
|
1
|
+
import { Box, FlexBox, PreviewTip, Text } from '@codecademy/gamut';
|
|
2
2
|
import { SmileyIndifferentIcon } from '@codecademy/gamut-icons';
|
|
3
3
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
4
|
import { useState } from 'react';
|
|
@@ -110,3 +110,70 @@ const TruncationExample = (args: React.ComponentProps<typeof PreviewTip>) => {
|
|
|
110
110
|
export const Truncation: Story = {
|
|
111
111
|
render: (args) => <TruncationExample {...args} />,
|
|
112
112
|
};
|
|
113
|
+
|
|
114
|
+
export const ZIndex: Story = {
|
|
115
|
+
args: {
|
|
116
|
+
zIndex: 5,
|
|
117
|
+
},
|
|
118
|
+
render: (args) => (
|
|
119
|
+
<FlexBox center flexDirection="column" gap={16} py={64}>
|
|
120
|
+
<Text variant="p-small">Inline placement:</Text>
|
|
121
|
+
<FlexBox alignItems="center" gap={16}>
|
|
122
|
+
<Box bg="paleBlue" p={8} zIndex={3} position="relative">
|
|
123
|
+
z-index: 3
|
|
124
|
+
</Box>
|
|
125
|
+
<PreviewTip
|
|
126
|
+
{...args}
|
|
127
|
+
alignment="bottom-right"
|
|
128
|
+
href="#"
|
|
129
|
+
linkDescription="Default z-index (inline)"
|
|
130
|
+
>
|
|
131
|
+
Default z-index
|
|
132
|
+
</PreviewTip>
|
|
133
|
+
<Box bg="paleBlue" p={8} zIndex={3} position="relative">
|
|
134
|
+
z-index: 3
|
|
135
|
+
</Box>
|
|
136
|
+
<PreviewTip
|
|
137
|
+
{...args}
|
|
138
|
+
alignment="top-right"
|
|
139
|
+
href="#"
|
|
140
|
+
linkDescription="z-index: 5 (inline)"
|
|
141
|
+
zIndex={5}
|
|
142
|
+
>
|
|
143
|
+
z-index: 5
|
|
144
|
+
</PreviewTip>
|
|
145
|
+
</FlexBox>
|
|
146
|
+
|
|
147
|
+
<Text variant="p-small" mt={24}>
|
|
148
|
+
Floating placement:
|
|
149
|
+
</Text>
|
|
150
|
+
<FlexBox alignItems="center" gap={16}>
|
|
151
|
+
<Box bg="paleGreen" p={8} zIndex={3} position="relative">
|
|
152
|
+
z-index: 3
|
|
153
|
+
</Box>
|
|
154
|
+
<PreviewTip
|
|
155
|
+
{...args}
|
|
156
|
+
alignment="bottom-right"
|
|
157
|
+
href="#"
|
|
158
|
+
linkDescription="Default z-index (floating)"
|
|
159
|
+
placement="floating"
|
|
160
|
+
>
|
|
161
|
+
Default z-index
|
|
162
|
+
</PreviewTip>
|
|
163
|
+
<Box bg="paleGreen" p={8} zIndex={3} position="relative">
|
|
164
|
+
z-index: 3
|
|
165
|
+
</Box>
|
|
166
|
+
<PreviewTip
|
|
167
|
+
{...args}
|
|
168
|
+
alignment="top-right"
|
|
169
|
+
href="#"
|
|
170
|
+
linkDescription="z-index: 5 (floating)"
|
|
171
|
+
placement="floating"
|
|
172
|
+
zIndex={5}
|
|
173
|
+
>
|
|
174
|
+
z-index: 5
|
|
175
|
+
</PreviewTip>
|
|
176
|
+
</FlexBox>
|
|
177
|
+
</FlexBox>
|
|
178
|
+
),
|
|
179
|
+
};
|
|
@@ -63,6 +63,12 @@ When a Button is disabled with a tooltip, you must use the `aria-disabled` prop
|
|
|
63
63
|
|
|
64
64
|
<Canvas of={ToolTipStories.Disabled} />
|
|
65
65
|
|
|
66
|
+
## Z-Index
|
|
67
|
+
|
|
68
|
+
You can customize the `zIndex` of the ToolTip's portal with the `zIndex` prop. This works for both `inline` and `floating` placements, and is useful when the tip needs to appear above other positioned elements.
|
|
69
|
+
|
|
70
|
+
<Canvas of={ToolTipStories.ZIndex} />
|
|
71
|
+
|
|
66
72
|
## Playground
|
|
67
73
|
|
|
68
74
|
<Canvas sourceState="shown" of={ToolTipStories.Default} />
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Box,
|
|
2
3
|
FillButton,
|
|
3
4
|
FlexBox,
|
|
4
5
|
IconButton,
|
|
5
6
|
StrokeButton,
|
|
7
|
+
Text,
|
|
6
8
|
ToolTip,
|
|
7
9
|
} from '@codecademy/gamut';
|
|
8
10
|
import {
|
|
@@ -133,3 +135,60 @@ export const Disabled: Story = {
|
|
|
133
135
|
</FlexBox>
|
|
134
136
|
),
|
|
135
137
|
};
|
|
138
|
+
|
|
139
|
+
export const ZIndex: Story = {
|
|
140
|
+
render: () => (
|
|
141
|
+
<FlexBox center flexDirection="column" gap={16} m={24} py={64}>
|
|
142
|
+
<Text variant="p-small">Inline placement:</Text>
|
|
143
|
+
<FlexBox alignItems="center" gap={16}>
|
|
144
|
+
<Box bg="paleBlue" p={8} zIndex={3} position="relative">
|
|
145
|
+
z-index: 3
|
|
146
|
+
</Box>
|
|
147
|
+
<ToolTip id="zindex-inline-default" info="Default z-index (inline)">
|
|
148
|
+
<FillButton aria-describedby="zindex-inline-default">
|
|
149
|
+
Default
|
|
150
|
+
</FillButton>
|
|
151
|
+
</ToolTip>
|
|
152
|
+
<Box bg="paleBlue" p={8} zIndex={3} position="relative">
|
|
153
|
+
z-index: 3
|
|
154
|
+
</Box>
|
|
155
|
+
<ToolTip id="zindex-inline-custom" info="z-index: 5 (inline)" zIndex={5}>
|
|
156
|
+
<FillButton aria-describedby="zindex-inline-custom">
|
|
157
|
+
z-index: 5
|
|
158
|
+
</FillButton>
|
|
159
|
+
</ToolTip>
|
|
160
|
+
</FlexBox>
|
|
161
|
+
|
|
162
|
+
<Text variant="p-small" mt={24}>
|
|
163
|
+
Floating placement:
|
|
164
|
+
</Text>
|
|
165
|
+
<FlexBox alignItems="center" gap={16}>
|
|
166
|
+
<Box bg="paleGreen" p={8} zIndex={3} position="relative">
|
|
167
|
+
z-index: 3
|
|
168
|
+
</Box>
|
|
169
|
+
<ToolTip
|
|
170
|
+
id="zindex-floating-default"
|
|
171
|
+
info="Default z-index (floating)"
|
|
172
|
+
placement="floating"
|
|
173
|
+
>
|
|
174
|
+
<FillButton aria-describedby="zindex-floating-default">
|
|
175
|
+
Default
|
|
176
|
+
</FillButton>
|
|
177
|
+
</ToolTip>
|
|
178
|
+
<Box bg="paleGreen" p={8} zIndex={3} position="relative">
|
|
179
|
+
z-index: 3
|
|
180
|
+
</Box>
|
|
181
|
+
<ToolTip
|
|
182
|
+
id="zindex-floating-custom"
|
|
183
|
+
info="z-index: 5 (floating)"
|
|
184
|
+
placement="floating"
|
|
185
|
+
zIndex={5}
|
|
186
|
+
>
|
|
187
|
+
<FillButton aria-describedby="zindex-floating-custom">
|
|
188
|
+
z-index: 5
|
|
189
|
+
</FillButton>
|
|
190
|
+
</ToolTip>
|
|
191
|
+
</FlexBox>
|
|
192
|
+
</FlexBox>
|
|
193
|
+
),
|
|
194
|
+
};
|
|
@@ -61,26 +61,6 @@ A `ConnectedFormGroup` can be in one of three states: `default`, `error`, or `di
|
|
|
61
61
|
|
|
62
62
|
<Canvas of={ConnectedFormGroupStories.States} />
|
|
63
63
|
|
|
64
|
-
## InfoTip
|
|
65
|
-
|
|
66
|
-
A `ConnectedFormGroup` can include an `infotip` prop to provide additional context.
|
|
67
|
-
|
|
68
|
-
### Automatic labelling
|
|
69
|
-
|
|
70
|
-
InfoTip buttons are automatically labelled by string field labels for accessibility.
|
|
71
|
-
|
|
72
|
-
<Canvas of={ConnectedFormGroupStories.InfoTipAutoLabelling} />
|
|
73
|
-
|
|
74
|
-
### ReactNode labels
|
|
75
|
-
|
|
76
|
-
For ReactNode labels (e.g., styled text or icons), you have three options:
|
|
77
|
-
|
|
78
|
-
- `labelledByFieldLabel: true` - opt into automatic labelling by the field label
|
|
79
|
-
- `ariaLabel` - provide a custom accessible name
|
|
80
|
-
- `ariaLabelledby` - reference another element on the page, such as a section heading
|
|
81
|
-
|
|
82
|
-
<Canvas of={ConnectedFormGroupStories.InfoTipWithReactNodeLabel} />
|
|
83
|
-
|
|
84
64
|
## Playground
|
|
85
65
|
|
|
86
66
|
To see how a `ConnectedFormGroup` can be used in a `ConnectedForm`, check out the <LinkTo id="Organisms/ConnectedForm/ConnectedForm">ConnectedForm</LinkTo> page.
|
|
@@ -2,9 +2,7 @@ import {
|
|
|
2
2
|
ConnectedForm,
|
|
3
3
|
ConnectedFormGroup,
|
|
4
4
|
ConnectedFormGroupProps,
|
|
5
|
-
ConnectedInput,
|
|
6
5
|
ConnectedRadioGroupInput,
|
|
7
|
-
Text,
|
|
8
6
|
useConnectedForm,
|
|
9
7
|
} from '@codecademy/gamut';
|
|
10
8
|
import { action } from '@storybook/addon-actions';
|
|
@@ -121,81 +119,3 @@ export const States = () => {
|
|
|
121
119
|
</ConnectedForm>
|
|
122
120
|
);
|
|
123
121
|
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* InfoTip buttons are automatically labelled by string field labels for accessibility.
|
|
127
|
-
* Screen readers will announce "Field Label, button" when focusing the InfoTip.
|
|
128
|
-
*/
|
|
129
|
-
export const InfoTipAutoLabelling: Story = {
|
|
130
|
-
render: () => (
|
|
131
|
-
<ConnectedForm
|
|
132
|
-
defaultValues={{ email: '' }}
|
|
133
|
-
onSubmit={(values) => action('Form Submitted')(values)}
|
|
134
|
-
>
|
|
135
|
-
<ConnectedFormGroup
|
|
136
|
-
field={{ component: ConnectedInput, type: 'email' }}
|
|
137
|
-
infotip={{ info: 'We will never share your email with third parties.' }}
|
|
138
|
-
label="Email address"
|
|
139
|
-
name="email"
|
|
140
|
-
/>
|
|
141
|
-
</ConnectedForm>
|
|
142
|
-
),
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* For ReactNode labels, you have three options for accessible InfoTip labelling:
|
|
147
|
-
* - `labelledByFieldLabel: true` - uses the field label
|
|
148
|
-
* - `ariaLabel` - provides a custom accessible name
|
|
149
|
-
* - `ariaLabelledby` - references another element on the page
|
|
150
|
-
*/
|
|
151
|
-
export const InfoTipWithReactNodeLabel: Story = {
|
|
152
|
-
render: () => (
|
|
153
|
-
<ConnectedForm
|
|
154
|
-
defaultValues={{ username: '', password: '', apiKey: '' }}
|
|
155
|
-
onSubmit={(values) => action('Form Submitted')(values)}
|
|
156
|
-
>
|
|
157
|
-
<Text as="h3" id="api-section-heading" mb={8}>
|
|
158
|
-
API Configuration
|
|
159
|
-
</Text>
|
|
160
|
-
<ConnectedFormGroup
|
|
161
|
-
field={{ component: ConnectedInput }}
|
|
162
|
-
infotip={{
|
|
163
|
-
info: 'Choose a unique username between 3-20 characters.',
|
|
164
|
-
labelledByFieldLabel: true,
|
|
165
|
-
}}
|
|
166
|
-
label={
|
|
167
|
-
<Text as="span" fontWeight="bold">
|
|
168
|
-
Username (labelledByFieldLabel)
|
|
169
|
-
</Text>
|
|
170
|
-
}
|
|
171
|
-
name="username"
|
|
172
|
-
/>
|
|
173
|
-
<ConnectedFormGroup
|
|
174
|
-
field={{ component: ConnectedInput, type: 'password' }}
|
|
175
|
-
infotip={{
|
|
176
|
-
info: 'Password must be at least 8 characters with one uppercase letter and one number.',
|
|
177
|
-
ariaLabel: 'Password requirements',
|
|
178
|
-
}}
|
|
179
|
-
label={
|
|
180
|
-
<Text as="span" fontWeight="bold">
|
|
181
|
-
Password (ariaLabel)
|
|
182
|
-
</Text>
|
|
183
|
-
}
|
|
184
|
-
name="password"
|
|
185
|
-
/>
|
|
186
|
-
<ConnectedFormGroup
|
|
187
|
-
field={{ component: ConnectedInput }}
|
|
188
|
-
infotip={{
|
|
189
|
-
info: 'You can find your API key in the developer settings dashboard.',
|
|
190
|
-
ariaLabelledby: 'api-section-heading',
|
|
191
|
-
}}
|
|
192
|
-
label={
|
|
193
|
-
<Text as="span" fontWeight="bold">
|
|
194
|
-
API Key (ariaLabelledby)
|
|
195
|
-
</Text>
|
|
196
|
-
}
|
|
197
|
-
name="apiKey"
|
|
198
|
-
/>
|
|
199
|
-
</ConnectedForm>
|
|
200
|
-
),
|
|
201
|
-
};
|
|
@@ -95,23 +95,3 @@ Hidden inputs can be used to include data that users can't see or modify with th
|
|
|
95
95
|
We call it a "sweet container" so that bots do not immediately detect it as a honeypot input.
|
|
96
96
|
|
|
97
97
|
<Canvas of={FieldsStories.SweetContainer} />
|
|
98
|
-
|
|
99
|
-
## InfoTip
|
|
100
|
-
|
|
101
|
-
Any field can include an `infotip` prop to provide additional context to users.
|
|
102
|
-
|
|
103
|
-
### Automatic labelling
|
|
104
|
-
|
|
105
|
-
InfoTip buttons are automatically labelled by string field labels for accessibility.
|
|
106
|
-
|
|
107
|
-
<Canvas of={FieldsStories.InfoTipAutoLabelling} />
|
|
108
|
-
|
|
109
|
-
### ReactNode labels
|
|
110
|
-
|
|
111
|
-
For ReactNode labels, you have three options:
|
|
112
|
-
|
|
113
|
-
- `labelledByFieldLabel: true` - opt into automatic labelling by the field label
|
|
114
|
-
- `ariaLabel` - provide a custom accessible name
|
|
115
|
-
- `ariaLabelledby` - reference another element on the page, such as a section heading
|
|
116
|
-
|
|
117
|
-
<Canvas of={FieldsStories.InfoTipWithReactNodeLabel} />
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormGroup, GridForm, Input
|
|
1
|
+
import { FormGroup, GridForm, Input } from '@codecademy/gamut';
|
|
2
2
|
import { action } from '@storybook/addon-actions';
|
|
3
3
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
4
|
|
|
@@ -328,74 +328,3 @@ export const SweetContainer: Story = {
|
|
|
328
328
|
],
|
|
329
329
|
},
|
|
330
330
|
};
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* InfoTip buttons are automatically labelled by string field labels for accessibility.
|
|
334
|
-
* Screen readers will announce "Field Label, button" when focusing the InfoTip.
|
|
335
|
-
*/
|
|
336
|
-
export const InfoTipAutoLabelling: Story = {
|
|
337
|
-
args: {
|
|
338
|
-
fields: [
|
|
339
|
-
{
|
|
340
|
-
label: 'Email address',
|
|
341
|
-
name: 'email',
|
|
342
|
-
size: 9,
|
|
343
|
-
type: 'email',
|
|
344
|
-
infotip: {
|
|
345
|
-
info: 'We will never share your email with third parties.',
|
|
346
|
-
},
|
|
347
|
-
},
|
|
348
|
-
],
|
|
349
|
-
},
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* For ReactNode labels, you have three options for accessible InfoTip labelling:
|
|
354
|
-
* - `labelledByFieldLabel: true` - uses the field label
|
|
355
|
-
* - `ariaLabel` - provides a custom accessible name
|
|
356
|
-
* - `ariaLabelledby` - references another element on the page
|
|
357
|
-
*/
|
|
358
|
-
export const InfoTipWithReactNodeLabel: Story = {
|
|
359
|
-
render: (args) => (
|
|
360
|
-
<>
|
|
361
|
-
<Text as="h3" id="api-section-heading" mb={8}>
|
|
362
|
-
API Configuration
|
|
363
|
-
</Text>
|
|
364
|
-
<GridForm {...args} />
|
|
365
|
-
</>
|
|
366
|
-
),
|
|
367
|
-
args: {
|
|
368
|
-
fields: [
|
|
369
|
-
{
|
|
370
|
-
label: <strong>Username (labelledByFieldLabel)</strong>,
|
|
371
|
-
name: 'username',
|
|
372
|
-
size: 9,
|
|
373
|
-
type: 'text',
|
|
374
|
-
infotip: {
|
|
375
|
-
info: 'Choose a unique username between 3-20 characters.',
|
|
376
|
-
labelledByFieldLabel: true,
|
|
377
|
-
},
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
label: <strong>Password (ariaLabel)</strong>,
|
|
381
|
-
name: 'password',
|
|
382
|
-
size: 9,
|
|
383
|
-
type: 'password',
|
|
384
|
-
infotip: {
|
|
385
|
-
info: 'Password must be at least 8 characters with one uppercase letter and one number.',
|
|
386
|
-
ariaLabel: 'Password requirements',
|
|
387
|
-
},
|
|
388
|
-
},
|
|
389
|
-
{
|
|
390
|
-
label: <strong>API Key (ariaLabelledby)</strong>,
|
|
391
|
-
name: 'apiKey',
|
|
392
|
-
size: 9,
|
|
393
|
-
type: 'text',
|
|
394
|
-
infotip: {
|
|
395
|
-
info: 'You can find your API key in the developer settings dashboard.',
|
|
396
|
-
ariaLabelledby: 'api-section-heading',
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
|
-
],
|
|
400
|
-
},
|
|
401
|
-
};
|