@codecademy/styleguide 78.5.5-alpha.7a284c.0 → 78.5.5-alpha.86116a.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 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.7a284c.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@78.5.4...@codecademy/styleguide@78.5.5-alpha.7a284c.0) (2025-12-22)
6
+ ### [78.5.5-alpha.86116a.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@78.5.4...@codecademy/styleguide@78.5.5-alpha.86116a.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.7a284c.0",
4
+ "version": "78.5.5-alpha.86116a.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": "e99b74184c1913ae709cec5eb952402e7f241b8d"
11
+ "gitHead": "40580b721fdf4aecae402662ba002deedcceb4eb"
12
12
  }
@@ -69,6 +69,12 @@ 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
+
72
78
  ## Playground
73
79
 
74
80
  <Canvas sourceState="shown" of={FormGroupStories.Default} />
@@ -97,3 +97,14 @@ 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
+ };
@@ -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 <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
-
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,16 +56,18 @@ 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. 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.
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
- ### Floating placement
63
+ ### Automatic Focus Management
65
64
 
66
- When using `placement="floating"`, InfoTips implements focus management for easier navigation:
65
+ InfoTips automatically manage focus for optimal keyboard accessibility:
67
66
 
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
67
+ - **Opening**: Focus automatically moves to the tip content when opened
68
+ - **Tab (Floating)**: Navigate forward through focusable elements (links, buttons) inside the tip. When reaching the last element, wraps back to the InfoTip button
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
70
71
  - **Escape**: Closes the tip and returns focus to the InfoTip button
71
72
 
72
73
  <Canvas of={InfoTipStories.KeyboardNavigation} />
@@ -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 { useRef, useState } from 'react';
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}>Some text that needs info</Text> <InfoTip {...args} />
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 {...args} alignment={alignment} />
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,52 @@ 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
+ {...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
116
  </FlexBox>
64
117
  ),
65
118
  };
@@ -69,19 +122,16 @@ export const WithLinksOrButtons: Story = {
69
122
  placement: 'floating',
70
123
  },
71
124
  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
125
  return (
79
126
  <FlexBox center py={64}>
80
- <Text mr={4}>This text is in a small space and needs info </Text>{' '}
127
+ <Text id="links-text" mr={4}>
128
+ This text is in a small space and needs info
129
+ </Text>{' '}
81
130
  <InfoTip
82
131
  {...args}
132
+ ariaLabelledby="links-text"
83
133
  info={
84
- <Text ref={ref} tabIndex={-1}>
134
+ <Text tabIndex={-1}>
85
135
  Hey! Here is a{' '}
86
136
  <Anchor href="https://giphy.com/search/nichijou">
87
137
  cool link
@@ -93,7 +143,6 @@ export const WithLinksOrButtons: Story = {
93
143
  that is also super important.
94
144
  </Text>
95
145
  }
96
- onClick={onClick}
97
146
  />
98
147
  </FlexBox>
99
148
  );
@@ -102,42 +151,35 @@ export const WithLinksOrButtons: Story = {
102
151
 
103
152
  export const KeyboardNavigation: Story = {
104
153
  render: function KeyboardNavigation() {
105
- const floatingRef = useRef<HTMLDivElement>(null);
106
- const inlineRef = useRef<HTMLDivElement>(null);
107
-
108
154
  const examples = [
109
155
  {
110
156
  title: 'Floating Placement',
111
157
  placement: 'floating' as const,
112
- ref: floatingRef,
113
158
  links: ['Link 1', 'Link 2', 'Link 3'],
114
159
  },
115
160
  {
116
161
  title: 'Inline Placement',
117
162
  placement: 'inline' as const,
118
163
  alignment: 'bottom-right' as const,
119
- ref: inlineRef,
120
164
  links: ['Link A', 'Link B'],
121
165
  },
122
166
  ];
123
167
 
124
168
  return (
125
- <FlexBox center column gap={24} py={64}>
169
+ <FlexBox center flexDirection="column" gap={24} py={64}>
126
170
  <GridBox gap={16} gridTemplateColumns="1fr 1fr">
127
- {examples.map(({ title, placement, alignment, ref, links }) => {
128
- const onClick = ({ isTipHidden }: { isTipHidden: boolean }) => {
129
- if (!isTipHidden) ref.current?.focus();
130
- };
131
-
171
+ {examples.map(({ title, placement, alignment, links }) => {
172
+ const labelId = `keyboard-nav-${placement}`;
132
173
  return (
133
174
  <FlexBox gap={8} key={placement}>
134
- <Text fontSize={16} fontWeight="bold">
175
+ <Text fontSize={16} fontWeight="bold" id={labelId}>
135
176
  {title}
136
177
  </Text>
137
178
  <InfoTip
138
179
  alignment={alignment}
180
+ ariaLabelledby={labelId}
139
181
  info={
140
- <Text ref={ref} tabIndex={-1}>
182
+ <Text>
141
183
  {links.map((label, idx) => (
142
184
  <>
143
185
  {idx > 0 && ', '}
@@ -150,7 +192,6 @@ export const KeyboardNavigation: Story = {
150
192
  </Text>
151
193
  }
152
194
  placement={placement}
153
- onClick={onClick}
154
195
  />
155
196
  </FlexBox>
156
197
  );
@@ -162,6 +203,10 @@ export const KeyboardNavigation: Story = {
162
203
  Keyboard Navigation:
163
204
  </Text>
164
205
  <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>
165
210
  <li>
166
211
  <strong>Floating - Tab:</strong> Navigates forward through links,
167
212
  then wraps to button (contained)
@@ -224,8 +269,10 @@ export const InfoTipInsideModal: Story = {
224
269
  <Text>This modal contains an InfoTip below:</Text>
225
270
 
226
271
  <FlexBox alignItems="center" gap={8}>
227
- <Text>Some text that needs explanation</Text>
228
- <InfoTip {...args} />
272
+ <Text id="modal-infotip-text">
273
+ Some text that needs explanation
274
+ </Text>
275
+ <InfoTip {...args} ariaLabelledby="modal-infotip-text" />
229
276
  </FlexBox>
230
277
 
231
278
  <Text color="text-disabled" fontSize={14}>
@@ -253,11 +300,14 @@ export const ZIndex: Story = {
253
300
  <Box bg="paleBlue" zIndex={3}>
254
301
  I will not be behind the infotip, sad + unreadable
255
302
  </Box>
256
- <InfoTip info="I am inline, cool" />
303
+ <InfoTip
304
+ ariaLabel="z-index example without override"
305
+ info="I am inline, cool"
306
+ />
257
307
  <Box bg="paleBlue" zIndex={3}>
258
308
  I will be behind the infotip, nice + great
259
309
  </Box>
260
- <InfoTip {...args} />
310
+ <InfoTip {...args} ariaLabel="z-index example with override" />
261
311
  </FlexBox>
262
312
  ),
263
313
  };
@@ -265,7 +315,10 @@ export const ZIndex: Story = {
265
315
  export const Default: Story = {
266
316
  render: (args) => (
267
317
  <FlexBox center m={24} py={64}>
268
- <Text mr={4}>Some text that needs info</Text> <InfoTip {...args} />
318
+ <Text id="default-text" mr={4}>
319
+ Some text that needs info
320
+ </Text>
321
+ <InfoTip {...args} ariaLabelledby="default-text" />
269
322
  </FlexBox>
270
323
  ),
271
324
  };
@@ -61,6 +61,26 @@ 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
+
64
84
  ## Playground
65
85
 
66
86
  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,81 @@ export const States = () => {
119
121
  </ConnectedForm>
120
122
  );
121
123
  };
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,3 +95,23 @@ 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 } 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,74 @@ 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
+ };
@@ -1,92 +0,0 @@
1
- import { Canvas, Controls, Meta } from '@storybook/blocks';
2
-
3
- import { ComponentHeader } from '~styleguide/blocks';
4
-
5
- import * as BarChartStories from './BarChart.stories';
6
-
7
- export const parameters = {
8
- subtitle: `A horizontal bar chart for visualizing comparative data`,
9
- design: {
10
- type: 'figma',
11
- url: 'https://www.figma.com/design/ReGfRNillGABAj5SlITalN/%F0%9F%93%90-Gamut?node-id=55123-4176',
12
- },
13
- status: 'current',
14
- source: {
15
- repo: 'gamut',
16
- githubLink:
17
- 'https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/BarChart',
18
- },
19
- };
20
-
21
- <Meta of={BarChartStories} />;
22
-
23
- <ComponentHeader {...parameters} />
24
-
25
- ## Usage
26
-
27
- Use BarChart to display comparative data across categories, such as skills progress, XP earned, or any quantitative metrics that benefit from visual comparison.
28
-
29
- ### Best practices:
30
-
31
- - Use consistent units across all bars in a chart
32
- - Limit the number of bars to maintain readability (5-10 is optimal)
33
- - Consider using the stacked variant to show progress toward a goal
34
- - Sort bars by value (descending) when ranking is important
35
-
36
- When NOT to use
37
-
38
- - For showing trends over time - use a line chart instead
39
- - For showing parts of a whole - use a pie or donut chart
40
- - For very small datasets (1-2 items) - consider using ProgressBar
41
-
42
- ## Variants
43
-
44
- ### Simple (Non-stacked)
45
-
46
- Use the simple variant when showing single values per category. Only `seriesOneValue` is provided.
47
-
48
- <Canvas of={BarChartStories.Default} />
49
-
50
- ### Stacked
51
-
52
- Use the stacked variant when showing progress within a total. Provide both `seriesOneValue` (progress) and `seriesTwoValue` (total).
53
-
54
- <Canvas of={BarChartStories.Stacked} />
55
-
56
- ### With Icons
57
-
58
- Add icons to labels for better visual identification of categories.
59
-
60
- <Canvas of={BarChartStories.WithIcons} />
61
-
62
- ### Animated
63
-
64
- Enable entrance animations for a more engaging experience.
65
-
66
- <Canvas of={BarChartStories.Animated} />
67
-
68
- ### Interactive
69
-
70
- Rows can be made interactive with `onClick` handlers or `href` links.
71
-
72
- <Canvas of={BarChartStories.Interactive} />
73
-
74
- ## Playground
75
-
76
- <Canvas sourceState="shown" of={BarChartStories.Default} />
77
-
78
- <Controls />
79
-
80
- ## Accessibility considerations
81
-
82
- - Always provide either `aria-label` or `aria-labelledby` to describe the chart
83
- - Each row automatically generates an accessible label summarizing its values
84
- - Interactive rows (with onClick/href) are properly announced as buttons/links
85
- - Grid lines are marked as decorative and hidden from screen readers
86
- - The scale header is hidden on small screens and marked as decorative
87
-
88
- ## UX writing
89
-
90
- - Keep y-axis labels concise (1-3 words)
91
- - Use consistent unit labels (e.g., "XP", "hours", "points")
92
- - Consider locale-aware number formatting for international audiences
@@ -1,183 +0,0 @@
1
- import { BarChart, BarProps } from '@codecademy/gamut';
2
- import {
3
- BookFlipPageIcon,
4
- CodeIcon,
5
- DataScienceIcon,
6
- GameControllerIcon,
7
- TerminalIcon,
8
- } from '@codecademy/gamut-icons';
9
- import { action } from '@storybook/addon-actions';
10
- import type { Meta, StoryObj } from '@storybook/react';
11
-
12
- const meta: Meta<typeof BarChart> = {
13
- component: BarChart,
14
- args: {
15
- 'aria-label': 'Skills experience chart',
16
- minRange: 0,
17
- maxRange: 2000,
18
- unit: 'XP',
19
- },
20
- };
21
-
22
- export default meta;
23
- type Story = StoryObj<typeof BarChart>;
24
-
25
- // Sample data for non-stacked (simple) bars
26
- const simpleBarData: BarProps[] = [
27
- { yLabel: 'Python', seriesOneValue: 1500 },
28
- { yLabel: 'JavaScript', seriesOneValue: 1200 },
29
- { yLabel: 'HTML/CSS', seriesOneValue: 800 },
30
- { yLabel: 'SQL', seriesOneValue: 600 },
31
- { yLabel: 'React', seriesOneValue: 450 },
32
- ];
33
-
34
- // Sample data for stacked bars (with seriesTwoValue)
35
- const stackedBarData: BarProps[] = [
36
- { yLabel: 'Python', seriesOneValue: 200, seriesTwoValue: 1500 },
37
- { yLabel: 'JavaScript', seriesOneValue: 150, seriesTwoValue: 1200 },
38
- { yLabel: 'HTML/CSS', seriesOneValue: 100, seriesTwoValue: 800 },
39
- { yLabel: 'SQL', seriesOneValue: 50, seriesTwoValue: 600 },
40
- { yLabel: 'React', seriesOneValue: 75, seriesTwoValue: 450 },
41
- ];
42
-
43
- // Sample data with icons
44
- const barDataWithIcons: BarProps[] = [
45
- {
46
- yLabel: 'Python',
47
- seriesOneValue: 200,
48
- seriesTwoValue: 1500,
49
- icon: CodeIcon,
50
- },
51
- {
52
- yLabel: 'JavaScript',
53
- seriesOneValue: 150,
54
- seriesTwoValue: 1200,
55
- icon: TerminalIcon,
56
- },
57
- {
58
- yLabel: 'Data Science',
59
- seriesOneValue: 100,
60
- seriesTwoValue: 800,
61
- icon: DataScienceIcon,
62
- },
63
- {
64
- yLabel: 'Game Dev',
65
- seriesOneValue: 50,
66
- seriesTwoValue: 600,
67
- icon: GameControllerIcon,
68
- },
69
- {
70
- yLabel: 'Reading',
71
- seriesOneValue: 75,
72
- seriesTwoValue: 450,
73
- icon: BookFlipPageIcon,
74
- },
75
- ];
76
-
77
- /**
78
- * Default non-stacked bar chart showing single values
79
- */
80
- export const Default: Story = {
81
- args: {
82
- barValues: simpleBarData,
83
- },
84
- };
85
-
86
- /**
87
- * Stacked bar chart showing progress (seriesOneValue) over total (seriesTwoValue)
88
- */
89
- export const Stacked: Story = {
90
- args: {
91
- barValues: stackedBarData,
92
- },
93
- };
94
-
95
- /**
96
- * Bar chart with icons next to labels
97
- */
98
- export const WithIcons: Story = {
99
- args: {
100
- barValues: barDataWithIcons,
101
- },
102
- };
103
-
104
- /**
105
- * Animated bar chart with staggered entrance
106
- */
107
- export const Animated: Story = {
108
- args: {
109
- barValues: stackedBarData,
110
- animate: true,
111
- },
112
- };
113
-
114
- /**
115
- * Bar chart sorted by value in descending order
116
- */
117
- export const SortedByValue: Story = {
118
- args: {
119
- barValues: simpleBarData,
120
- sortBy: 'value',
121
- order: 'descending',
122
- },
123
- };
124
-
125
- /**
126
- * Bar chart sorted alphabetically by label
127
- */
128
- export const SortedByLabel: Story = {
129
- args: {
130
- barValues: simpleBarData,
131
- sortBy: 'label',
132
- order: 'ascending',
133
- },
134
- };
135
-
136
- /**
137
- * Interactive bar chart with clickable rows
138
- */
139
- export const Interactive: Story = {
140
- args: {
141
- barValues: simpleBarData.map((bar) => ({
142
- ...bar,
143
- onClick: action(`Clicked ${bar.yLabel}`),
144
- })),
145
- },
146
- };
147
-
148
- /**
149
- * Interactive bar chart with linked rows
150
- */
151
- export const WithLinks: Story = {
152
- args: {
153
- barValues: simpleBarData.map((bar) => ({
154
- ...bar,
155
- href: `#${bar.yLabel.toLowerCase().replace(/\s+/g, '-')}`,
156
- })),
157
- },
158
- };
159
-
160
- /**
161
- * Bar chart with custom styling
162
- */
163
- export const CustomStyles: Story = {
164
- args: {
165
- barValues: stackedBarData,
166
- styleConfig: {
167
- backgroundBarColor: 'paleGreen',
168
- foregroundBarColor: 'feedback-success',
169
- textColor: 'navy',
170
- },
171
- },
172
- };
173
-
174
- /**
175
- * Bar chart with custom xScale interval
176
- */
177
- export const CustomScale: Story = {
178
- args: {
179
- barValues: simpleBarData,
180
- maxRange: 2000,
181
- xScale: 250,
182
- },
183
- };