@codecademy/styleguide 78.5.6-alpha.fb9da9.0 → 79.0.1-alpha.06259a.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/.storybook/components/Elements/Markdown.tsx +1 -0
- package/.storybook/preview.ts +5 -1
- package/CHANGELOG.md +11 -1
- package/package.json +2 -2
- package/src/lib/Atoms/Badge/Badge.mdx +1 -1
- package/src/lib/Atoms/FormElements/FormGroup/FormGroup.mdx +6 -0
- package/src/lib/Atoms/FormElements/FormGroup/FormGroup.stories.tsx +45 -4
- package/src/lib/Atoms/FormInputs/Checkbox/Checkbox.mdx +7 -1
- package/src/lib/Atoms/FormInputs/Checkbox/Checkbox.stories.tsx +21 -1
- package/src/lib/Atoms/FormInputs/Radio/Radio.mdx +8 -0
- package/src/lib/Atoms/FormInputs/Radio/Radio.stories.tsx +38 -4
- package/src/lib/Foundations/System/About.mdx +1 -1
- package/src/lib/Foundations/System/Compose.mdx +1 -1
- package/src/lib/Foundations/System/Props.mdx +230 -0
- package/src/lib/Foundations/System/ResponsiveProperties/ResponsiveProperties.mdx +3 -3
- package/src/lib/Foundations/System/ResponsiveProperties/ResponsiveProperties.stories.tsx +0 -1
- package/src/lib/Foundations/shared/elements.tsx +4 -16
- package/src/lib/Layouts/Boxes/Box/Box.stories.tsx +0 -1
- package/src/lib/Meta/About.mdx +2 -0
- package/src/lib/Meta/MCP/About.mdx +28 -0
- package/src/lib/Meta/MCP/Code Connect.mdx +38 -0
- package/src/lib/Meta/MCP/Figma MCP.mdx +89 -0
- package/src/lib/Molecules/Alert/Alert.mdx +1 -1
- package/src/lib/Molecules/Tips/InfoTip/InfoTip.mdx +24 -8
- package/src/lib/Molecules/Tips/InfoTip/InfoTip.stories.tsx +86 -34
- package/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.mdx +19 -0
- package/src/lib/Organisms/ConnectedForm/ConnectedFormGroup/ConnectedFormGroup.stories.tsx +73 -0
- package/src/lib/Organisms/GridForm/Fields.mdx +19 -0
- package/src/lib/Organisms/GridForm/Fields.stories.tsx +62 -1
- package/src/lib/Organisms/GridForm/Layout.mdx +1 -1
- package/src/static/mcp/component_playground.png +0 -0
- package/src/static/mcp/component_with_code_connect.png +0 -0
- package/src/lib/Foundations/System/Props/About.mdx +0 -81
- package/src/lib/Foundations/System/Props/Background.mdx +0 -30
- package/src/lib/Foundations/System/Props/Border.mdx +0 -33
- package/src/lib/Foundations/System/Props/Color.mdx +0 -28
- package/src/lib/Foundations/System/Props/Flex.mdx +0 -28
- package/src/lib/Foundations/System/Props/Grid.mdx +0 -31
- package/src/lib/Foundations/System/Props/Layout.mdx +0 -34
- package/src/lib/Foundations/System/Props/List.mdx +0 -38
- package/src/lib/Foundations/System/Props/Positioning.mdx +0 -29
- package/src/lib/Foundations/System/Props/Shadow.mdx +0 -31
- package/src/lib/Foundations/System/Props/Space.mdx +0 -28
- package/src/lib/Foundations/System/Props/Typography.mdx +0 -28
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AboutHeader,
|
|
5
|
+
addParentPath,
|
|
6
|
+
TableOfContents,
|
|
7
|
+
} from '~styleguide/blocks';
|
|
8
|
+
|
|
9
|
+
import { parameters as codeConnectParameters } from './Code Connect.mdx';
|
|
10
|
+
import { parameters as figmaMcpParameters } from './Figma MCP.mdx';
|
|
11
|
+
|
|
12
|
+
export const parameters = {
|
|
13
|
+
id: 'Meta/MCP',
|
|
14
|
+
title: 'MCP',
|
|
15
|
+
subtitle: 'Documentation related to the Figma Model Context Protocol.',
|
|
16
|
+
status: 'static',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
<Meta title="Meta/MCP/About" />
|
|
20
|
+
|
|
21
|
+
<AboutHeader {...parameters} />
|
|
22
|
+
|
|
23
|
+
<TableOfContents
|
|
24
|
+
links={addParentPath(parameters.id, [
|
|
25
|
+
codeConnectParameters,
|
|
26
|
+
figmaMcpParameters,
|
|
27
|
+
])}
|
|
28
|
+
/>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
import { AboutHeader, Callout, ImageWrapper } from '~styleguide/blocks';
|
|
4
|
+
|
|
5
|
+
export const parameters = {
|
|
6
|
+
id: 'Code Connect',
|
|
7
|
+
title: 'Code Connect',
|
|
8
|
+
subtitle: 'Exploring Code Connect features in Figma.',
|
|
9
|
+
status: 'static',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
<Meta title="Meta/MCP/Code Connect" />
|
|
13
|
+
|
|
14
|
+
<AboutHeader {...parameters} />
|
|
15
|
+
|
|
16
|
+
Code Connect provides Figma with the actual code for Figma components. In providing accurate code, this helps the Figma MCP generate accurate code snippets for designs that use these components.
|
|
17
|
+
|
|
18
|
+
More information can be found at [Figma Code Connect documentation](https://www.figma.com/code-connect-docs/)
|
|
19
|
+
|
|
20
|
+
<Callout text="Any changes to Code Connect files should be requested through the Gamut team and NOT done on an individual or a separate team." />
|
|
21
|
+
|
|
22
|
+
## Code Connected components
|
|
23
|
+
|
|
24
|
+
When visiting the Figma file, you'll know if a component is set up with Code Connect if you select the component and see the sidebar includes a "Code Connect" section.
|
|
25
|
+
|
|
26
|
+
<ImageWrapper
|
|
27
|
+
src="./mcp/component_with_code_connect.png"
|
|
28
|
+
alt="A Figma component, Badge, with the Code Connect sidebar open."
|
|
29
|
+
/>
|
|
30
|
+
|
|
31
|
+
### Exploring behavior
|
|
32
|
+
|
|
33
|
+
For components with Code Connect, you can also click on the "Explore behavior" button to open a modal that allows you to edit the component's props. Editing these props will automatically update the code in the modal's Code Connect section to give you a sense of how to adapt your component accordingly.
|
|
34
|
+
|
|
35
|
+
<ImageWrapper
|
|
36
|
+
src="./mcp/component_playground.png"
|
|
37
|
+
alt="The 'Component playground' modal, with the Badge component's props editable."
|
|
38
|
+
/>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Meta } from '@storybook/blocks';
|
|
2
|
+
|
|
3
|
+
import { AboutHeader, Callout } from '~styleguide/blocks';
|
|
4
|
+
|
|
5
|
+
export const parameters = {
|
|
6
|
+
id: 'Figma MCP',
|
|
7
|
+
title: 'Figma MCP',
|
|
8
|
+
subtitle:
|
|
9
|
+
'Set up the Figma MCP locally to enable design to code generation, exclusive to Codecademy + Skillsoft employees.',
|
|
10
|
+
status: 'static',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
<Meta title="Meta/MCP/Figma MCP" />
|
|
14
|
+
|
|
15
|
+
<AboutHeader {...parameters} />
|
|
16
|
+
|
|
17
|
+
<Callout text="Any MCP generated code is EXPERIMENTAL! You should always validate the code generated and adapt it to your own needs — do NOT simply use the MCP to generate code and push it to production! Additionally, you must have a Dev or Full account to be able to be able to use the Figma MCP." />
|
|
18
|
+
|
|
19
|
+
The offical guidance and documentation comes from Figma. Please reference [Figma Dev Mode MCP documentation](https://help.figma.com/hc/en-us/articles/32132100833559-Guide-to-the-Dev-Mode-MCP-Server) for the most up to date information. This documentation below has been adapted to fit the context of the Gamut repository.
|
|
20
|
+
|
|
21
|
+
## Figma (desktop client app)
|
|
22
|
+
|
|
23
|
+
Go to [Figma's download page](https://www.figma.com/downloads/) to download the appropriate version of the Figma desktop client for your OS.
|
|
24
|
+
|
|
25
|
+
### Start up local Figma MCP server
|
|
26
|
+
|
|
27
|
+
1. In the Figma desktop client, check that you have dev mode enabled.
|
|
28
|
+
2. The right-hand sidebar should have a "MCP server" section
|
|
29
|
+
3. Click on the "Open settings modal" button
|
|
30
|
+
4. In the modal, toggle the status to "On", the the color of the toggle should be green.
|
|
31
|
+
OR
|
|
32
|
+
5. Click on the Figma icon in the top left-hand corner and select "Actions"
|
|
33
|
+
6. Type "Enable desktop MCP server"
|
|
34
|
+
7. Click on the checkbox, if it's not already checked, to enable the MCP server.
|
|
35
|
+
|
|
36
|
+
## Set up MCP Client for your text editor/IDE
|
|
37
|
+
|
|
38
|
+
We currently support Figma MCP for Cursor. Please let the Gamut team know if you'd like support for other editors.
|
|
39
|
+
|
|
40
|
+
### Cursor
|
|
41
|
+
|
|
42
|
+
1. Open **Cursor** → **Settings** → **Cursor Settings**.
|
|
43
|
+
2. Go to the **MCP** tab (might be called **MCP & Integrations**) from the left-hand sidebar.
|
|
44
|
+
3. Under **MCP Tools**, click **+ Add MCP server**.
|
|
45
|
+
4. Enter the following configuration and save:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
{
|
|
49
|
+
"mcpServers": {
|
|
50
|
+
"Figma": {
|
|
51
|
+
"url": "http://127.0.0.1:3845/mcp"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Verify your MCP server is running
|
|
58
|
+
|
|
59
|
+
To check if your MCP server is running, you can visit the endpoint: `http://127.0.0.1:3845/mcp`. You should see a response, e.g.: `{"jsonrpc":"2.0","error":{"code":-32001,"message":"Invalid sessionId"},"id":null}`.
|
|
60
|
+
Yes, it's an odd response, but it indicates that the MCP server is running — otherwise if it's not running you'll see an error "This site can’t be reached" on the page.
|
|
61
|
+
|
|
62
|
+
Similarly you can test the end point using:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
curl http://127.0.0.1:3845/mcp
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Prompt your MCP client
|
|
69
|
+
|
|
70
|
+
You can prompt the MCP in two main ways:
|
|
71
|
+
|
|
72
|
+
1. Provide a link to the node of the design you'd like to generate code for, e.g.:
|
|
73
|
+
|
|
74
|
+
> Generate the code for this node: https://www.figma.com/design/ReGfRNillGABAj5SlITalN/%F0%9F%93%90-Gamut?node-id=79202-13690&m=dev
|
|
75
|
+
|
|
76
|
+
2. Selecting the node in the Figma interface, e.g.:
|
|
77
|
+
> Generate the code for the current selection
|
|
78
|
+
|
|
79
|
+
In the chat, you may be prompted to allow the Figma commands like `get_code()` to run. You can also add these commands to an allow list in your code editor's settings.
|
|
80
|
+
|
|
81
|
+
## Feedback for the Gamut team
|
|
82
|
+
|
|
83
|
+
Please let the Gamut team of any feedback you have, things like:
|
|
84
|
+
|
|
85
|
+
- If you find that a new rule that you'd like implemented in this repo, please let the Gamut team know.
|
|
86
|
+
- Support for another text editor/IDE.
|
|
87
|
+
- Incorrect code generation
|
|
88
|
+
|
|
89
|
+
If you have any other feedback or suggestions, feel free to share those as well!
|
|
@@ -62,7 +62,7 @@ Use an alert to display an important, succinct message with actions for users to
|
|
|
62
62
|
4. Dismiss button (optional)
|
|
63
63
|
|
|
64
64
|
- Use to allow users to remove the alert after they've acknowledged it or when it's no longer needed
|
|
65
|
-
- Only exclude when the information must remain visible until specific conditions are met to ensure users don
|
|
65
|
+
- Only exclude when the information must remain visible until specific conditions are met to ensure users don't miss critical information
|
|
66
66
|
|
|
67
67
|
## Variants
|
|
68
68
|
|
|
@@ -28,8 +28,7 @@ export const parameters = {
|
|
|
28
28
|
A tip is triggered by clicking on an information icon button and can be closed by clicking outside, pressing <KeyboardKey>Esc</KeyboardKey>, or clicking the info button again.
|
|
29
29
|
|
|
30
30
|
Use an infotip to provide additional info about a nearby element or content.
|
|
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.
|
|
31
|
+
The info button has low and high emphasis variants and the `Tip` has 4 alignment variants.
|
|
33
32
|
|
|
34
33
|
## Variants
|
|
35
34
|
|
|
@@ -57,17 +56,19 @@ This `floating` variant should only be used as needed.
|
|
|
57
56
|
|
|
58
57
|
### InfoTips with links or buttons
|
|
59
58
|
|
|
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.
|
|
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. When an InfoTip opens, focus automatically moves to the tip content, allowing keyboard users to immediately interact with any links or buttons inside.
|
|
61
60
|
|
|
62
61
|
<Canvas of={InfoTipStories.WithLinksOrButtons} />
|
|
63
62
|
|
|
64
|
-
###
|
|
63
|
+
### Automatic Focus Management
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
InfoTips automatically manage focus for optimal keyboard accessibility:
|
|
67
66
|
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
- **<KeyboardKey>
|
|
67
|
+
- **Opening**: Focus automatically moves to the tip content when opened
|
|
68
|
+
- ** <KeyboardKey>Tab</KeyboardKey> (Floating)**: Navigate forward through focusable elements (links, buttons) inside the tip. When reaching the last element, wraps back to the InfoTip button
|
|
69
|
+
- **<KeyboardKey>Shift </KeyboardKey> + <KeyboardKey>Tab</KeyboardKey> (Floating)**: Navigate backward naturally - from the button, exits to the previous page element
|
|
70
|
+
- **<KeyboardKey>Tab</KeyboardKey> or <KeyboardKey>Shift</KeyboardKey> +<KeyboardKey>Tab</KeyboardKey> (Inline)**: Follows normal document flow
|
|
71
|
+
- **<KeyboardKey>Escape</KeyboardKey>**: Closes the tip and returns focus to the InfoTip button
|
|
71
72
|
|
|
72
73
|
<Canvas of={InfoTipStories.KeyboardNavigation} />
|
|
73
74
|
|
|
@@ -82,6 +83,21 @@ InfoTips have intelligent Escape key handling that works correctly both inside a
|
|
|
82
83
|
|
|
83
84
|
<Canvas of={InfoTipStories.InfoTipInsideModal} />
|
|
84
85
|
|
|
86
|
+
## Custom Accessible Labeling
|
|
87
|
+
|
|
88
|
+
Provide either `ariaLabel` or `ariaLabelledby` to ensure screen reader users understand the purpose of the InfoTip button.
|
|
89
|
+
|
|
90
|
+
The InfoTip button's accessible label can be customized using either prop:
|
|
91
|
+
|
|
92
|
+
- **`ariaLabel`**: Directly sets the accessible label text. Useful when you want to provide a custom label without referencing another element.
|
|
93
|
+
- **`ariaLabelledby`**: References the ID of another element to use as the label. Useful when you want the InfoTip button to be labeled by visible text elsewhere on the page. This is useful for when the `InfoTip` is beside text that contextualizes it.
|
|
94
|
+
|
|
95
|
+
### Custom Role Description
|
|
96
|
+
|
|
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. This defaults to `"More information button"` but can be customized via the `ariaRoleDescription` prop for translation or other accessibility needs.
|
|
98
|
+
|
|
99
|
+
<Canvas of={InfoTipStories.AriaLabel} />
|
|
100
|
+
|
|
85
101
|
## InfoTips and zIndex
|
|
86
102
|
|
|
87
103
|
You can change the zIndex of your `InfoTip` with the zIndex property.
|
|
@@ -4,17 +4,20 @@ import {
|
|
|
4
4
|
FillButton,
|
|
5
5
|
FlexBox,
|
|
6
6
|
GridBox,
|
|
7
|
+
IconButton,
|
|
7
8
|
InfoTip,
|
|
8
9
|
Modal,
|
|
9
10
|
Text,
|
|
10
11
|
} from '@codecademy/gamut';
|
|
12
|
+
import { SparkleIcon } from '@codecademy/gamut-icons';
|
|
11
13
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
12
|
-
import {
|
|
14
|
+
import { useState } from 'react';
|
|
13
15
|
|
|
14
16
|
const meta: Meta<typeof InfoTip> = {
|
|
15
17
|
component: InfoTip,
|
|
16
18
|
args: {
|
|
17
19
|
alignment: 'top-left',
|
|
20
|
+
ariaLabel: 'More information',
|
|
18
21
|
info: `I am additional information about a nearby element or content.`,
|
|
19
22
|
},
|
|
20
23
|
};
|
|
@@ -28,7 +31,10 @@ export const Emphasis: Story = {
|
|
|
28
31
|
},
|
|
29
32
|
render: (args) => (
|
|
30
33
|
<FlexBox center m={24} py={64}>
|
|
31
|
-
<Text mr={4}>
|
|
34
|
+
<Text id="emphasis-text" mr={4}>
|
|
35
|
+
Some text that needs info
|
|
36
|
+
</Text>
|
|
37
|
+
<InfoTip {...args} ariaLabelledby="emphasis-text" />
|
|
32
38
|
</FlexBox>
|
|
33
39
|
),
|
|
34
40
|
};
|
|
@@ -38,10 +44,15 @@ export const Alignments: Story = {
|
|
|
38
44
|
<GridBox gap={24} gridTemplateColumns="1fr 1fr" ml={8} py={64}>
|
|
39
45
|
{(['top-right', 'top-left', 'bottom-right', 'bottom-left'] as const).map(
|
|
40
46
|
(alignment) => {
|
|
47
|
+
const labelId = `alignment-${alignment}`;
|
|
41
48
|
return (
|
|
42
49
|
<Box key={alignment}>
|
|
43
|
-
<Text>{alignment}</Text>
|
|
44
|
-
<InfoTip
|
|
50
|
+
<Text id={labelId}>{alignment}</Text>
|
|
51
|
+
<InfoTip
|
|
52
|
+
{...args}
|
|
53
|
+
alignment={alignment}
|
|
54
|
+
ariaLabelledby={labelId}
|
|
55
|
+
/>
|
|
45
56
|
</Box>
|
|
46
57
|
);
|
|
47
58
|
}
|
|
@@ -56,10 +67,51 @@ export const Placement: Story = {
|
|
|
56
67
|
},
|
|
57
68
|
render: (args) => (
|
|
58
69
|
<FlexBox center>
|
|
59
|
-
<Text mr={4}>
|
|
70
|
+
<Text id="placement-text" mr={4}>
|
|
60
71
|
This text is in a small space and needs floating placement
|
|
61
72
|
</Text>{' '}
|
|
62
|
-
<InfoTip {...args} />
|
|
73
|
+
<InfoTip {...args} ariaLabelledby="placement-text" />
|
|
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
|
+
alignment="bottom-left"
|
|
111
|
+
ariaLabelledby="custom-info-id"
|
|
112
|
+
info="I am clarifying information related to the concise text."
|
|
113
|
+
/>
|
|
114
|
+
</FlexBox>
|
|
63
115
|
</FlexBox>
|
|
64
116
|
),
|
|
65
117
|
};
|
|
@@ -69,19 +121,16 @@ export const WithLinksOrButtons: Story = {
|
|
|
69
121
|
placement: 'floating',
|
|
70
122
|
},
|
|
71
123
|
render: function WithLinksOrButtons(args) {
|
|
72
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
73
|
-
|
|
74
|
-
const onClick = ({ isTipHidden }: { isTipHidden: boolean }) => {
|
|
75
|
-
if (!isTipHidden) ref.current?.focus();
|
|
76
|
-
};
|
|
77
|
-
|
|
78
124
|
return (
|
|
79
125
|
<FlexBox center py={64}>
|
|
80
|
-
<Text mr={4}>
|
|
126
|
+
<Text id="links-text" mr={4}>
|
|
127
|
+
This text is in a small space and needs info
|
|
128
|
+
</Text>{' '}
|
|
81
129
|
<InfoTip
|
|
82
130
|
{...args}
|
|
131
|
+
ariaLabelledby="links-text"
|
|
83
132
|
info={
|
|
84
|
-
<Text
|
|
133
|
+
<Text tabIndex={-1}>
|
|
85
134
|
Hey! Here is a{' '}
|
|
86
135
|
<Anchor href="https://giphy.com/search/nichijou">
|
|
87
136
|
cool link
|
|
@@ -93,7 +142,6 @@ export const WithLinksOrButtons: Story = {
|
|
|
93
142
|
that is also super important.
|
|
94
143
|
</Text>
|
|
95
144
|
}
|
|
96
|
-
onClick={onClick}
|
|
97
145
|
/>
|
|
98
146
|
</FlexBox>
|
|
99
147
|
);
|
|
@@ -102,42 +150,35 @@ export const WithLinksOrButtons: Story = {
|
|
|
102
150
|
|
|
103
151
|
export const KeyboardNavigation: Story = {
|
|
104
152
|
render: function KeyboardNavigation() {
|
|
105
|
-
const floatingRef = useRef<HTMLDivElement>(null);
|
|
106
|
-
const inlineRef = useRef<HTMLDivElement>(null);
|
|
107
|
-
|
|
108
153
|
const examples = [
|
|
109
154
|
{
|
|
110
155
|
title: 'Floating Placement',
|
|
111
156
|
placement: 'floating' as const,
|
|
112
|
-
ref: floatingRef,
|
|
113
157
|
links: ['Link 1', 'Link 2', 'Link 3'],
|
|
114
158
|
},
|
|
115
159
|
{
|
|
116
160
|
title: 'Inline Placement',
|
|
117
161
|
placement: 'inline' as const,
|
|
118
162
|
alignment: 'bottom-right' as const,
|
|
119
|
-
ref: inlineRef,
|
|
120
163
|
links: ['Link A', 'Link B'],
|
|
121
164
|
},
|
|
122
165
|
];
|
|
123
166
|
|
|
124
167
|
return (
|
|
125
|
-
<FlexBox center column gap={24} py={64}>
|
|
168
|
+
<FlexBox center flexDirection="column" gap={24} py={64}>
|
|
126
169
|
<GridBox gap={16} gridTemplateColumns="1fr 1fr">
|
|
127
|
-
{examples.map(({ title, placement, alignment,
|
|
128
|
-
const
|
|
129
|
-
if (!isTipHidden) ref.current?.focus();
|
|
130
|
-
};
|
|
131
|
-
|
|
170
|
+
{examples.map(({ title, placement, alignment, links }) => {
|
|
171
|
+
const labelId = `keyboard-nav-${placement}`;
|
|
132
172
|
return (
|
|
133
173
|
<FlexBox gap={8} key={placement}>
|
|
134
|
-
<Text fontSize={16} fontWeight="bold">
|
|
174
|
+
<Text fontSize={16} fontWeight="bold" id={labelId}>
|
|
135
175
|
{title}
|
|
136
176
|
</Text>
|
|
137
177
|
<InfoTip
|
|
138
178
|
alignment={alignment}
|
|
179
|
+
ariaLabelledby={labelId}
|
|
139
180
|
info={
|
|
140
|
-
<Text
|
|
181
|
+
<Text>
|
|
141
182
|
{links.map((label, idx) => (
|
|
142
183
|
<>
|
|
143
184
|
{idx > 0 && ', '}
|
|
@@ -150,7 +191,6 @@ export const KeyboardNavigation: Story = {
|
|
|
150
191
|
</Text>
|
|
151
192
|
}
|
|
152
193
|
placement={placement}
|
|
153
|
-
onClick={onClick}
|
|
154
194
|
/>
|
|
155
195
|
</FlexBox>
|
|
156
196
|
);
|
|
@@ -162,6 +202,10 @@ export const KeyboardNavigation: Story = {
|
|
|
162
202
|
Keyboard Navigation:
|
|
163
203
|
</Text>
|
|
164
204
|
<Box as="ul" fontSize={14} pl={16}>
|
|
205
|
+
<li>
|
|
206
|
+
<strong>Opening:</strong> Focus automatically moves to the tip
|
|
207
|
+
content when opened
|
|
208
|
+
</li>
|
|
165
209
|
<li>
|
|
166
210
|
<strong>Floating - Tab:</strong> Navigates forward through links,
|
|
167
211
|
then wraps to button (contained)
|
|
@@ -224,8 +268,10 @@ export const InfoTipInsideModal: Story = {
|
|
|
224
268
|
<Text>This modal contains an InfoTip below:</Text>
|
|
225
269
|
|
|
226
270
|
<FlexBox alignItems="center" gap={8}>
|
|
227
|
-
<Text
|
|
228
|
-
|
|
271
|
+
<Text id="modal-infotip-text">
|
|
272
|
+
Some text that needs explanation
|
|
273
|
+
</Text>
|
|
274
|
+
<InfoTip {...args} ariaLabelledby="modal-infotip-text" />
|
|
229
275
|
</FlexBox>
|
|
230
276
|
|
|
231
277
|
<Text color="text-disabled" fontSize={14}>
|
|
@@ -253,11 +299,14 @@ export const ZIndex: Story = {
|
|
|
253
299
|
<Box bg="paleBlue" zIndex={3}>
|
|
254
300
|
I will not be behind the infotip, sad + unreadable
|
|
255
301
|
</Box>
|
|
256
|
-
<InfoTip
|
|
302
|
+
<InfoTip
|
|
303
|
+
ariaLabel="z-index example without override"
|
|
304
|
+
info="I am inline, cool"
|
|
305
|
+
/>
|
|
257
306
|
<Box bg="paleBlue" zIndex={3}>
|
|
258
307
|
I will be behind the infotip, nice + great
|
|
259
308
|
</Box>
|
|
260
|
-
<InfoTip {...args} />
|
|
309
|
+
<InfoTip {...args} ariaLabel="z-index example with override" />
|
|
261
310
|
</FlexBox>
|
|
262
311
|
),
|
|
263
312
|
};
|
|
@@ -265,7 +314,10 @@ export const ZIndex: Story = {
|
|
|
265
314
|
export const Default: Story = {
|
|
266
315
|
render: (args) => (
|
|
267
316
|
<FlexBox center m={24} py={64}>
|
|
268
|
-
<Text mr={4}>
|
|
317
|
+
<Text id="default-text" mr={4}>
|
|
318
|
+
Some text that needs info
|
|
319
|
+
</Text>
|
|
320
|
+
<InfoTip {...args} ariaLabelledby="default-text" />
|
|
269
321
|
</FlexBox>
|
|
270
322
|
),
|
|
271
323
|
};
|
|
@@ -61,6 +61,25 @@ 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), the InfoTip is automatically labelled by the field label. You can override this behavior by providing:
|
|
77
|
+
|
|
78
|
+
- `ariaLabel` - provide a custom accessible name
|
|
79
|
+
- `ariaLabelledby` - reference another element on the page, such as a section heading
|
|
80
|
+
|
|
81
|
+
<Canvas of={ConnectedFormGroupStories.InfoTipWithReactNodeLabel} />
|
|
82
|
+
|
|
64
83
|
## Playground
|
|
65
84
|
|
|
66
85
|
To see how a `ConnectedFormGroup` can be used in a `ConnectedForm`, check out the <LinkTo id="Organisms/ConnectedForm/ConnectedForm">ConnectedForm</LinkTo> page.
|
|
@@ -2,7 +2,9 @@ import {
|
|
|
2
2
|
ConnectedForm,
|
|
3
3
|
ConnectedFormGroup,
|
|
4
4
|
ConnectedFormGroupProps,
|
|
5
|
+
ConnectedInput,
|
|
5
6
|
ConnectedRadioGroupInput,
|
|
7
|
+
Text,
|
|
6
8
|
useConnectedForm,
|
|
7
9
|
} from '@codecademy/gamut';
|
|
8
10
|
import { action } from '@storybook/addon-actions';
|
|
@@ -119,3 +121,74 @@ export const States = () => {
|
|
|
119
121
|
</ConnectedForm>
|
|
120
122
|
);
|
|
121
123
|
};
|
|
124
|
+
|
|
125
|
+
export const InfoTipAutoLabelling: Story = {
|
|
126
|
+
render: () => (
|
|
127
|
+
<ConnectedForm
|
|
128
|
+
defaultValues={{ email: '' }}
|
|
129
|
+
onSubmit={(values) => action('Form Submitted')(values)}
|
|
130
|
+
>
|
|
131
|
+
<ConnectedFormGroup
|
|
132
|
+
field={{ component: ConnectedInput, type: 'email' }}
|
|
133
|
+
infotip={{
|
|
134
|
+
info: 'We will never share your email with third parties.',
|
|
135
|
+
placement: 'floating',
|
|
136
|
+
}}
|
|
137
|
+
label="Email address"
|
|
138
|
+
name="email"
|
|
139
|
+
/>
|
|
140
|
+
</ConnectedForm>
|
|
141
|
+
),
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const InfoTipWithReactNodeLabel: Story = {
|
|
145
|
+
render: () => (
|
|
146
|
+
<ConnectedForm
|
|
147
|
+
defaultValues={{ username: '', password: '', apiKey: '' }}
|
|
148
|
+
onSubmit={(values) => action('Form Submitted')(values)}
|
|
149
|
+
>
|
|
150
|
+
<Text as="h3" id="api-section-heading" mb={8}>
|
|
151
|
+
API Configuration
|
|
152
|
+
</Text>
|
|
153
|
+
<ConnectedFormGroup
|
|
154
|
+
field={{ component: ConnectedInput }}
|
|
155
|
+
infotip={{
|
|
156
|
+
alignment: 'bottom-left',
|
|
157
|
+
info: 'Choose a unique username between 3-20 characters.',
|
|
158
|
+
}}
|
|
159
|
+
label={
|
|
160
|
+
<Text as="span" fontWeight="bold">
|
|
161
|
+
Username (automatic label)
|
|
162
|
+
</Text>
|
|
163
|
+
}
|
|
164
|
+
name="username"
|
|
165
|
+
/>
|
|
166
|
+
<ConnectedFormGroup
|
|
167
|
+
field={{ component: ConnectedInput, type: 'password' }}
|
|
168
|
+
infotip={{
|
|
169
|
+
info: 'Password must be at least 8 characters with one uppercase letter and one number.',
|
|
170
|
+
ariaLabel: 'Password requirements',
|
|
171
|
+
}}
|
|
172
|
+
label={
|
|
173
|
+
<Text as="span" fontWeight="bold">
|
|
174
|
+
Password (ariaLabel)
|
|
175
|
+
</Text>
|
|
176
|
+
}
|
|
177
|
+
name="password"
|
|
178
|
+
/>
|
|
179
|
+
<ConnectedFormGroup
|
|
180
|
+
field={{ component: ConnectedInput }}
|
|
181
|
+
infotip={{
|
|
182
|
+
info: 'You can find your API key in the developer settings dashboard.',
|
|
183
|
+
ariaLabelledby: 'api-section-heading',
|
|
184
|
+
}}
|
|
185
|
+
label={
|
|
186
|
+
<Text as="span" fontWeight="bold">
|
|
187
|
+
API Key (ariaLabelledby)
|
|
188
|
+
</Text>
|
|
189
|
+
}
|
|
190
|
+
name="apiKey"
|
|
191
|
+
/>
|
|
192
|
+
</ConnectedForm>
|
|
193
|
+
),
|
|
194
|
+
};
|
|
@@ -95,3 +95,22 @@ 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, the InfoTip is automatically labelled by the field label. You can override this behavior by providing:
|
|
112
|
+
|
|
113
|
+
- `ariaLabel` - provide a custom accessible name
|
|
114
|
+
- `ariaLabelledby` - reference another element on the page, such as a section heading
|
|
115
|
+
|
|
116
|
+
<Canvas of={FieldsStories.InfoTipWithReactNodeLabel} />
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormGroup, GridForm, Input } from '@codecademy/gamut';
|
|
1
|
+
import { FormGroup, GridForm, Input, Text } from '@codecademy/gamut';
|
|
2
2
|
import { action } from '@storybook/addon-actions';
|
|
3
3
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
4
|
|
|
@@ -328,3 +328,64 @@ export const SweetContainer: Story = {
|
|
|
328
328
|
],
|
|
329
329
|
},
|
|
330
330
|
};
|
|
331
|
+
|
|
332
|
+
export const InfoTipAutoLabelling: Story = {
|
|
333
|
+
args: {
|
|
334
|
+
fields: [
|
|
335
|
+
{
|
|
336
|
+
label: 'Email address',
|
|
337
|
+
name: 'email',
|
|
338
|
+
size: 9,
|
|
339
|
+
type: 'email',
|
|
340
|
+
infotip: {
|
|
341
|
+
info: 'We will never share your email with third parties.',
|
|
342
|
+
placement: 'floating',
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
],
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
export const InfoTipWithReactNodeLabel: Story = {
|
|
350
|
+
render: (args) => (
|
|
351
|
+
<>
|
|
352
|
+
<Text as="h3" id="api-section-heading" mb={8}>
|
|
353
|
+
API Configuration
|
|
354
|
+
</Text>
|
|
355
|
+
<GridForm {...args} />
|
|
356
|
+
</>
|
|
357
|
+
),
|
|
358
|
+
args: {
|
|
359
|
+
fields: [
|
|
360
|
+
{
|
|
361
|
+
label: <strong>Username (automatic label)</strong>,
|
|
362
|
+
name: 'username',
|
|
363
|
+
size: 9,
|
|
364
|
+
type: 'text',
|
|
365
|
+
infotip: {
|
|
366
|
+
info: 'Choose a unique username between 3-20 characters.',
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
label: <strong>Password (ariaLabel)</strong>,
|
|
371
|
+
name: 'password',
|
|
372
|
+
size: 9,
|
|
373
|
+
type: 'password',
|
|
374
|
+
infotip: {
|
|
375
|
+
info: 'Password must be at least 8 characters with one uppercase letter and one number.',
|
|
376
|
+
ariaLabel: 'Password requirements',
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
label: <strong>API Key (ariaLabelledby)</strong>,
|
|
381
|
+
name: 'apiKey',
|
|
382
|
+
size: 9,
|
|
383
|
+
type: 'text',
|
|
384
|
+
infotip: {
|
|
385
|
+
info: 'You can find your API key in the developer settings dashboard.',
|
|
386
|
+
ariaLabelledby: 'api-section-heading',
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
],
|
|
390
|
+
},
|
|
391
|
+
};
|