@codecademy/styleguide 79.1.3-alpha.f0b0f3.0 → 79.1.3

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.
@@ -12,6 +12,8 @@ import {
12
12
  } from '@codecademy/gamut-styles/src';
13
13
  import { Theme } from '@emotion/react';
14
14
 
15
+ const STORYBOOK_CSP_NONCE = 'storybook-csp-nonce';
16
+
15
17
  /**
16
18
  * Story functions must be called as a regular function to avoid full-remounts
17
19
  * See: https://github.com/storybookjs/storybook/issues/12255
package/CHANGELOG.md CHANGED
@@ -3,9 +3,11 @@
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
- ### [79.1.3-alpha.f0b0f3.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@79.1.2...@codecademy/styleguide@79.1.3-alpha.f0b0f3.0) (2026-02-25)
6
+ ### [79.1.3](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@79.1.2...@codecademy/styleguide@79.1.3) (2026-03-02)
7
7
 
8
- **Note:** Version bump only for package @codecademy/styleguide
8
+ ### Bug Fixes
9
+
10
+ - **GamutProvider:** CSP improvements ([1026353](https://github.com/Codecademy/gamut/commit/10263537c190aff0e5686872da2be2a30b1d9201)), closes [/github.com/adobe/react-spectrum/issues/8273#issuecomment-3897820426](https://github.com/Codecademy//github.com/adobe/react-spectrum/issues/8273/issues/issuecomment-3897820426)
9
11
 
10
12
  ### [79.1.2](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@79.1.1...@codecademy/styleguide@79.1.2) (2026-02-12)
11
13
 
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": "79.1.3-alpha.f0b0f3.0",
4
+ "version": "79.1.3",
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": "8ced1bded433aeabb7a65f61ad54fb289431308b"
11
+ "gitHead": "3e7f8b5d0df3e4617e5dc93eef096b6dce16d096"
12
12
  }
@@ -68,7 +68,7 @@ GamutProvider handles a few critical tasks that need to happen in order for comp
68
68
  - **Next** `_app.tsx`
69
69
  - **Gatsby** `gatsby-ssr.js` `gatsby-browser.js` and use `wrapRootElement` in each.
70
70
 
71
- 4. Add required types for your theme, which will determine what props Gamut components allow.
71
+ 5. Add required types for your theme, which will determine what props Gamut components allow.
72
72
 
73
73
  ```tsx
74
74
  // theme.d.ts
@@ -84,7 +84,7 @@ declare module '@emotion/react' {
84
84
 
85
85
  For more information this declaration please checkout the [official emotion documentation](https://emotion.sh/docs/typescript#define-a-theme)!
86
86
 
87
- 5. Start Building!
87
+ 6. Start Building!
88
88
 
89
89
  ```tsx
90
90
  import { Background } from '@codecademy/gamut-styles';
@@ -96,3 +96,15 @@ export const App = () => (
96
96
  </Background>
97
97
  );
98
98
  ```
99
+
100
+ ### Content Security Policy (CSP)
101
+
102
+ If your app uses a strict Content-Security-Policy (e.g. `style-src` without `'unsafe-inline'`), pass a nonce to `GamutProvider` so Emotion and other Gamut-managed style tags are allowed:
103
+
104
+ ```tsx
105
+ <GamutProvider nonce={yourCspNonce}>
106
+ <App />
107
+ </GamutProvider>
108
+ ```
109
+
110
+ Your nonce should be the same value you use in your CSP header (e.g. `style-src 'self' 'nonce-{value}'`).
@@ -11,7 +11,7 @@ export const parameters = {
11
11
  type: 'figma',
12
12
  url: 'https://www.figma.com/file/ReGfRNillGABAj5SlITalN/branch/ayKNSg6QvZUjsgw0FFysW4/%F0%9F%93%90-Gamut?type=design&node-id=41538-55277&mode=design&t=fGkWf5GSl5cj5fQo-0',
13
13
  },
14
- status: 'current',
14
+ status: 'updating',
15
15
  source: {
16
16
  repo: 'gamut',
17
17
  githubLink:
@@ -1,427 +0,0 @@
1
- import { Canvas, Controls, Meta } from '@storybook/blocks';
2
-
3
- import {
4
- Callout,
5
- ComponentHeader,
6
- ImageWrapper,
7
- LinkTo,
8
- } from '~styleguide/blocks';
9
-
10
- import * as BarChartStories from './BarChart.stories';
11
-
12
- export const parameters = {
13
- title: 'BarChart',
14
- subtitle: `A horizontal bar chart for visualizing comparative data`,
15
- design: {
16
- type: 'figma',
17
- url: 'https://www.figma.com/design/ReGfRNillGABAj5SlITalN/%F0%9F%93%90-Gamut?node-id=55123-4176',
18
- },
19
- status: 'current',
20
- source: {
21
- repo: 'gamut',
22
- githubLink:
23
- 'https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/BarChart',
24
- },
25
- };
26
-
27
- <Meta of={BarChartStories} />
28
-
29
- <ComponentHeader {...parameters} />
30
-
31
- ## Usage
32
-
33
- Use BarChart to display comparative data across categories, such as skills progress, XP earned, or any quantitative metrics that benefit from visual comparison.
34
-
35
- ### Best practices:
36
-
37
- - Use consistent units across all bars in a chart
38
- - Limit the number of bars to maintain readability (5-10 is optimal)
39
- - Consider using the stacked variant to show progress toward a goal
40
- - Sort bars by value (descending) when ranking is important
41
- - Ensure bar colors maintain at least a 3:1 contrast ratio with the background
42
-
43
- ### When NOT to use:
44
-
45
- - **Progress tracking** – for displaying the completion status of a task, use the <LinkTo id="Atoms/ProgressBar">ProgressBar</LinkTo> component.
46
-
47
- ## Anatomy
48
-
49
- <ImageWrapper
50
- src="./organisms/barchart.png"
51
- alt="The anatomy of the BarChart component, detailed below."
52
- />
53
-
54
- 1. **Bar row**
55
-
56
- - Represents a single category and its values.
57
-
58
- 2. **Category icon** (optional)
59
-
60
- - Use to clarify or reinforce the category name.
61
-
62
- 3. **Category label**
63
-
64
- - Displays the category name on the y-axis (e.g. skill or metric name).
65
-
66
- 4. **Scale / value axis**
67
-
68
- - Displays gridlines and labels to indicate the scale of the data values.
69
- - The number of dividers, as well as the minimum and maximum values on the value axis, are adjustable.
70
- - The minimum value should always be 0.
71
-
72
- 5. **Series one value**
73
-
74
- - Displays the numerical value of the series one bar for clarity and precise data representation.
75
-
76
- 6. **Series two value** (optional)
77
-
78
- - Displays the numerical value of the series two bar for clarity and precise data representation.
79
- - Include a second series value by using the stacked property. Stacked bar charts compare parts of a whole and are best suited for displaying discrete data segmented into meaningful categories.
80
-
81
- 7. **Series one bar**
82
-
83
- - A visual representation of the first value for the associated category.
84
- - By default, the first series bars use the text color, however, it can be overridden to any color.
85
- - Bars include a required border that uses white or navy, chosen automatically to ensure the highest contrast with the bar color.
86
-
87
- 8. **Series two bar** _(bars with zero value)_
88
-
89
- - A visual representation of the second value for the associated category.
90
- - By default, the second series bars use the primary color, however, it can be overridden to any color.
91
- - Bars include a required border that uses white or navy, chosen automatically to ensure the highest contrast with the bar color.
92
-
93
- ## Variants
94
-
95
- ### Simple (Non-stacked)
96
-
97
- Use the simple variant when showing single values per category. Only `seriesOneValue` is provided.
98
-
99
- <Canvas of={BarChartStories.Default} />
100
-
101
- ### Stacked
102
-
103
- Use the stacked variant when showing progress within a total. Provide both `seriesOneValue` (progress) and `seriesTwoValue` (total).
104
-
105
- <Canvas of={BarChartStories.Stacked} />
106
-
107
- ### With Icons
108
-
109
- Add icons to labels for better visual identification of categories.
110
-
111
- <Canvas of={BarChartStories.WithIcons} />
112
-
113
- ### Animated
114
-
115
- Enable entrance animations for a more engaging experience.
116
-
117
- <Canvas of={BarChartStories.Animated} />
118
-
119
- ### Interactive
120
-
121
- Rows can be made interactive with `onClick` handlers or `href` links.
122
-
123
- <Canvas of={BarChartStories.Interactive} />
124
-
125
- ### With Links
126
-
127
- When a bar has an `href` link, an `aria-label` is automatically generated from the bar's data and applied to the anchor. The label summarizes the bar's values (e.g., "100 XP in Python" for a simple bar, or "200 XP gained - now at 1500 XP in Python" for a stacked bar), so screen reader users get a clear, data-driven description without manual `aria-label` props.
128
-
129
- <Canvas of={BarChartStories.WithLinks} />
130
-
131
- ## Title and description
132
-
133
- The BarChart component uses semantic HTML to provide context and accessibility. The chart is wrapped in a [`<figure>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure) element, and the description is displayed in a [`<figcaption>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption) element. This semantic structure helps screen readers and other assistive technologies understand the relationship between the chart and its description. **Visual title + description is the greatly preferred pattern** for accessibility and user experience.
134
-
135
- **Preferred pattern: Visual title + description**
136
-
137
- Provide both `title` and `description` props to make the chart's purpose and key takeaways clear to all users:
138
-
139
- - `title`: A heading that identifies the chart. Can be a string or an object with `{ as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6', title: string, variant?: Text['variant'] }` to specify the heading level and optionally override the default styling with a <LinkTo id="Typography/Text">Text variant</LinkTo>.
140
- - `description`: A summary of the information or the overall takeaway displayed in the `<figcaption>` element.
141
-
142
- <Canvas of={BarChartStories.WithVisualTitleAndDescription} />
143
-
144
- **Alternative patterns:**
145
- `hideTitle` and `hideDescription` will keep the screenreader text but hide the visual descriptions.
146
-
147
- <Canvas of={BarChartStories.WithHiddenTitleAndDescription} />
148
-
149
- **External title with visual description:** Use `aria-labelledby` for the title when the title exists elsewhere but you want to display the description.
150
-
151
- <Canvas of={BarChartStories.WithExternalTitle} />
152
-
153
- **Best practices:**
154
-
155
- - Always provide a `description` prop - it's required and should summarize the chart's key information
156
- - Use semantic heading levels for titles (h1-h6) to maintain proper document structure
157
- - When using `aria-labelledby`, ensure the referenced element exists and is properly labeled
158
-
159
- ## Sorting
160
-
161
- BarChart includes an optional sorting dropdown in the title area. The dropdown only renders when the `sortFns` prop is provided. You can control which sort options appear by including string literals or custom sort functions in the array.
162
-
163
- **String Literals:**
164
-
165
- - `'alphabetically'` - Adds both "Label (A-Z)" and "Label (Z-A)" options
166
- - `'numerically'` - Adds both "Value (Low-High)" and "Value (High-Low)" options
167
- - `'none'` - Adds "None" option (preserves original order)
168
-
169
- **Custom Sort Functions:**
170
- You can also provide custom sort functions as objects with:
171
-
172
- - `label`: The text displayed in the dropdown
173
- - `value`: A unique identifier for the sort option
174
- - `sortFn`: A function that takes an array of bars and returns a sorted array
175
-
176
- **Type Definition:**
177
-
178
- ```typescript
179
- type CustomSortOption<TBar extends BarProps = BarProps> = {
180
- label: string;
181
- value: string;
182
- sortFn: (bars: TBar[]) => TBar[];
183
- };
184
-
185
- // sortFns prop accepts:
186
- sortFns?: ('alphabetically' | 'numerically' | 'none' | CustomSortOption<TBar>)[]
187
- ```
188
-
189
- **Automatic Type Inference:**
190
- TypeScript automatically infers the bar type from your `barValues` prop. This means custom properties (like `dateAdded`, `category`, etc.) are automatically typed in your sort functions - no type assertions needed!
191
-
192
- ```typescript
193
- const barsWithDates = [
194
- { yLabel: 'Python', seriesOneValue: 1500, dateAdded: new Date('2023-01-15') },
195
- {
196
- yLabel: 'JavaScript',
197
- seriesOneValue: 2000,
198
- dateAdded: new Date('2023-03-20'),
199
- },
200
- // ...
201
- ];
202
-
203
- <BarChart
204
- barValues={barsWithDates}
205
- sortFns={[
206
- {
207
- label: 'Recently Added',
208
- value: 'recent',
209
- sortFn: (bars) => {
210
- // TypeScript automatically knows bars have dateAdded property!
211
- return [...bars].sort((a, b) => {
212
- const aDate = a.dateAdded as Date | undefined;
213
- const bDate = b.dateAdded as Date | undefined;
214
- if (!aDate || !bDate) return 0;
215
- return bDate.getTime() - aDate.getTime();
216
- });
217
- },
218
- },
219
- ]}
220
- />;
221
- ```
222
-
223
- **Note:** Since `BarProps` uses `Record<string, unknown>` for extensibility, custom properties are typed as `unknown` by default. You may need a simple type assertion (`as Date | undefined`) when accessing them, but the property names are fully type-checked.
224
-
225
- <Canvas of={BarChartStories.WithSorting} />
226
-
227
- **Example with Custom Sort Functions:**
228
-
229
- Custom sort functions can access additional properties on `BarProps` for domain-specific sorting, such as sorting by dates or categories.
230
-
231
- <Canvas of={BarChartStories.WithCustomSorting} />
232
-
233
- ## Custom styling
234
-
235
- BarChart supports custom color styling through the `styleConfig` prop, allowing you to customize the appearance of chart elements to match your design needs.
236
-
237
- ### Style configuration options
238
-
239
- The `styleConfig` prop accepts an object with the following optional properties:
240
-
241
- - **`textColor`**: Color for text labels (y-axis labels). Defaults to `'text'`
242
- - **`seriesOneBarColor`**: Color for the series one bar (seriesOneValue: overlay in stacked charts, only bar in simple charts). Defaults to `'text'`
243
- - **`seriesTwoBarColor`**: Color for the series two bar (seriesTwoValue: full bar in stacked charts; unused in simple charts). Defaults to `'primary'`
244
- - **`seriesOneLabel`**: Color for the series one value label (first right label when stacked, or displayValue when not stacked). Defaults to `'text-secondary'`
245
- - **`seriesTwoLabel`**: Color for the series two value label (displayValue when stacked). Defaults to `'primary'`
246
-
247
- All color values should be valid color tokens from the Gamut design system. When customizing colors, ensure they maintain at least a 3:1 contrast ratio with the background for accessibility.
248
-
249
- ### Default values
250
-
251
- If `styleConfig` is not provided, BarChart uses these default colors:
252
-
253
- ```typescript
254
- {
255
- textColor: 'text',
256
- seriesOneBarColor: 'text',
257
- seriesTwoBarColor: 'primary',
258
- seriesOneLabel: 'text-secondary',
259
- seriesTwoLabel: 'primary',
260
- }
261
- ```
262
-
263
- ### Example
264
-
265
- <Canvas of={BarChartStories.CustomStyles} />
266
-
267
- ## Custom scale
268
-
269
- BarChart allows you to customize the x-axis scale interval using the `xScale` prop, which controls the spacing and granularity of scale markers along the horizontal axis.
270
-
271
- ### Scale configuration
272
-
273
- The `xScale` prop determines the interval between scale markers on the x-axis. By default, BarChart automatically calculates an appropriate scale interval based on the `maxRange` value (the scale always starts at 0). However, you can override this with a custom interval to achieve more granular or specific scale markings.
274
-
275
- **When to use custom scale:**
276
-
277
- - When you need specific scale intervals (e.g., increments of 250, 500, or 1000)
278
- - When the automatic scale calculation doesn't provide the desired granularity
279
- - When you want to match scale intervals across multiple charts for consistency
280
- - When you need scale markers at specific values for better data interpretation
281
-
282
- **How it works:**
283
-
284
- The `xScale` value represents the interval between consecutive scale markers. For example:
285
-
286
- - `xScale: 250` creates markers at 0, 250, 500, 750, 1000, etc.
287
- - `xScale: 500` creates markers at 0, 500, 1000, 1500, 2000, etc.
288
-
289
- The number of tick marks is automatically calculated as: `Math.ceil(maxRange / xScale) + 1`
290
-
291
- ### Example
292
-
293
- <Canvas of={BarChartStories.CustomScale} />
294
-
295
- ## Color modes
296
-
297
- BarChart automatically adapts to both light and dark color modes, ensuring proper contrast and readability in all themes. The component uses semantic color tokens that adjust based on the current color mode. The `styleConfig` prop should be provided by semantic color tokens to ensure the `BarChart` is accessible in all color modes.
298
-
299
- ## Accessibility considerations
300
-
301
- ### Chart and row labeling
302
-
303
- **Chart-level labeling:**
304
-
305
- - Always provide either `title` or `aria-labelledby` to describe the chart (see Title and description section below for details)
306
- - The chart is wrapped in a semantic `<figure>` element for proper structure
307
-
308
- **Row-level labeling:**
309
-
310
- - For non-interactive bars: A hidden text element (visible only to screen readers) is automatically added as the first child of each list item, summarizing the bar's values (e.g., "100 XP in Python")
311
- - For interactive bars (with `onClick` or `href`): An `aria-label` is automatically generated from the bar's data and applied to the button or link element, ensuring proper screen reader announcements
312
- - All accessibility labels are automatically generated from the bar's data - no manual `aria-label` props are required
313
-
314
- ## UX writing
315
-
316
- - Keep y-axis labels concise (1-3 words)
317
- - Use consistent unit labels (e.g., "XP", "hours", "points")
318
- - Consider locale-aware number formatting for international audiences
319
-
320
- ## Interactive states
321
-
322
- BarChart supports both interactive and static bar rows, each with distinct visual states.
323
-
324
- ### Static bars
325
-
326
- When bars have neither `onClick` handlers nor `href` links, they are rendered as static, non-interactive elements.
327
-
328
- <Canvas of={BarChartStories.Default} />
329
-
330
- ### Interactive bars
331
-
332
- When bars have `onClick` handlers or `href` links, they become interactive. Interactive bars are rendered as buttons or anchor elements, providing full keyboard accessibility and proper semantic HTML.
333
-
334
- <Canvas of={BarChartStories.Interactive} />
335
-
336
- ## Internationalization
337
-
338
- <Callout text="We are currently updating global internationalization in Gamut, so the following features are subject to change." />
339
-
340
- BarChart supports internationalization through the `translations` prop. You can customize user-facing strings (including sort dropdown and accessibility summaries) and configure locale-aware number formatting. The prop accepts `PartialBarChartTranslations`: override only the keys you need; nested `accessibility` and `sortOptions` are merged with defaults at runtime.
341
-
342
- ### Translation structure
343
-
344
- - **sortLabel**, **sortOptions**, and **locale** — Always strings. Control the sort dropdown label, option labels, and number-formatting locale.
345
- - **Accessibility keys** (`gainedNowAt`, `inLabel`, `inOnly`) — Used in auto-generated `aria-label` and screen reader text for bars. Each key can be:
346
- - **String** — A fragment interpolated into the built-in template (e.g. `"in"`, `"gained - now at"`). Use when the default word order works for your language.
347
- - **Function** — Receives scoped context (values, label, unit, locale) and returns the **entire** summary string. Use for pluralization, different word order, or locale-specific phrasing.
348
-
349
- ### Basic usage
350
-
351
- Provide only the translations you want to override; the rest fall back to default English.
352
-
353
- ```tsx
354
- <BarChart
355
- barValues={barData}
356
- description="Progreso de habilidades"
357
- maxRange={200}
358
- sortFns={['alphabetically', 'none']}
359
- title="Habilidades"
360
- translations={{
361
- accessibility: {
362
- gainedNowAt: 'ganado - ahora en',
363
- inLabel: 'en',
364
- inOnly: 'en ',
365
- },
366
- locale: 'es',
367
- sortLabel: 'Ordenar por:',
368
- sortOptions: {
369
- labelAsc: 'Etiqueta (A-Z)',
370
- labelDesc: 'Etiqueta (Z-A)',
371
- none: 'Ninguno',
372
- valueAsc: 'Valor (Bajo-Alto)',
373
- valueDesc: 'Valor (Alto-Bajo)',
374
- },
375
- }}
376
- />
377
- ```
378
-
379
- <Canvas of={BarChartStories.WithStringTranslations} />
380
-
381
- ### Partial translations and locale
382
-
383
- You can override a single key; the rest keep their defaults. The **locale** property controls number formatting (scale labels, value labels) via `Intl.NumberFormat`:
384
-
385
- ```tsx
386
- // Only change locale; sort and accessibility use defaults
387
- translations={{ locale: 'de-DE' }}
388
-
389
- // Override just sort label and locale
390
- translations={{
391
- locale: 'en-GB',
392
- sortLabel: 'Sort by:',
393
- }}
394
- ```
395
-
396
- ### Accessibility: strings vs functions
397
-
398
- **Strings** — Use when the built-in template order fits your language. Fragments are plugged into the default pattern (e.g. `"{value} {unit} {inLabel} {yLabel}"`).
399
-
400
- **Functions** — Use when you need full control. Each function receives context (`yLabel`, values, `unit`, `locale`) and returns the complete summary string.
401
-
402
- <Canvas of={BarChartStories.WithFunctionTranslations} />
403
-
404
- **Best practices:**
405
-
406
- - Provide complete translations for the language your app uses; use partial overrides for one-off changes.
407
- - Prefer string accessibility keys when the default order works; use functions for pluralization, word order, or locale-specific phrasing.
408
- - Use appropriate locale codes (e.g. `'en-US'`, `'es-ES'`, `'fr-FR'`) for number formatting.
409
- - Test accessibility summaries with screen readers in the target language.
410
- - Reuse translation objects across BarChart instances where possible.
411
-
412
- ## Container query
413
-
414
- BarChart uses CSS container queries to determine responsive behavior based on the **chart container width** rather than viewport width. This ensures optimal display when the chart is placed in constrained layouts like sidebars or narrow columns.
415
-
416
- **Layout behavior:**
417
-
418
- - **Narrow container (below 480px)**: Label and value appear together above the bar in a single row.
419
- - **Wide container (480px and up, `c_xs` breakpoint)**: Label on the left, bar in the center, value on the right.
420
-
421
- The chart establishes a size container via `containerType="inline-size"` on the figure wrapper, so the layout responds to the width of the BarChart’s parent. For more on container queries in Gamut, see <LinkTo id="Foundations/System/Responsive Properties">Responsive properties</LinkTo>.
422
-
423
- ## Playground
424
-
425
- <Canvas sourceState="shown" of={BarChartStories.Default} />
426
-
427
- <Controls />
@@ -1,351 +0,0 @@
1
- import {
2
- BarChart,
3
- BarProps,
4
- Box,
5
- PartialBarChartTranslations,
6
- } from '@codecademy/gamut';
7
- import {
8
- BookFlipPageIcon,
9
- DataScienceIcon,
10
- TerminalIcon,
11
- } from '@codecademy/gamut-icons';
12
- import { action } from '@storybook/addon-actions';
13
- import type { Meta, StoryObj } from '@storybook/react';
14
-
15
- const meta: Meta<typeof BarChart> = {
16
- component: BarChart,
17
- args: {
18
- description: 'Chart showing programming language experience levels',
19
- maxRange: 2000,
20
- title: 'Skills experience chart',
21
- unit: 'XP',
22
- },
23
- };
24
-
25
- export default meta;
26
- type Story = StoryObj<typeof BarChart>;
27
-
28
- const simpleBarData: BarProps[] = [
29
- { yLabel: 'Python', seriesOneValue: 1500 },
30
- { yLabel: 'JavaScript', seriesOneValue: 2000 },
31
- { yLabel: 'HTML/CSS', seriesOneValue: 800 },
32
- { yLabel: 'SQL', seriesOneValue: 600 },
33
- { yLabel: 'React', seriesOneValue: 450 },
34
- ];
35
-
36
- const stackedBarData: BarProps[] = [
37
- { yLabel: 'Python', seriesOneValue: 200, seriesTwoValue: 1500 },
38
- {
39
- yLabel: 'JavaScript',
40
- icon: TerminalIcon,
41
- seriesOneValue: 1800,
42
- seriesTwoValue: 2000,
43
- },
44
- { yLabel: 'HTML/CSS', seriesOneValue: 600, seriesTwoValue: 800 },
45
- { yLabel: 'SQL', seriesOneValue: 550, seriesTwoValue: 600 },
46
- { yLabel: 'React', seriesOneValue: 300, seriesTwoValue: 450 },
47
- ];
48
-
49
- const accessibilityBarData: BarProps[] = [
50
- { yLabel: 'Python', seriesOneValue: 200, seriesTwoValue: 1500 },
51
- {
52
- yLabel: 'JavaScript',
53
- seriesOneValue: 1800,
54
- seriesTwoValue: 2000,
55
- href: '/javascript',
56
- },
57
- { yLabel: 'HTML/CSS', seriesOneValue: 600, seriesTwoValue: 800 },
58
- { yLabel: 'SQL', seriesOneValue: 550, href: '/sql' },
59
- { yLabel: 'Rust', seriesOneValue: 400 },
60
- { yLabel: 'React', seriesOneValue: 300, seriesTwoValue: 450 },
61
- ];
62
-
63
- const accessibilityTranslations: PartialBarChartTranslations = {
64
- accessibility: {
65
- gainedNowAt: (ctx) =>
66
- `${ctx.seriesOneValue} ${ctx.unit} gained — now at ${ctx.seriesTwoValue} ${ctx.unit} in ${ctx.yLabel}`,
67
- inLabel: (ctx) => `${ctx.value} ${ctx.unit} in ${ctx.yLabel}`,
68
- inOnly: (ctx) => `${ctx.value} ${ctx.unit}`.trim(),
69
- },
70
- locale: 'en',
71
- };
72
-
73
- const barDataWithIcons: BarProps[] = [
74
- {
75
- yLabel: 'Python',
76
- seriesOneValue: 200,
77
- seriesTwoValue: 1500,
78
- icon: TerminalIcon,
79
- },
80
- {
81
- yLabel: 'JavaScript',
82
- seriesOneValue: 150,
83
- seriesTwoValue: 2000,
84
- icon: TerminalIcon,
85
- },
86
- {
87
- yLabel: 'Data Science',
88
- seriesOneValue: 100,
89
- seriesTwoValue: 800,
90
- icon: DataScienceIcon,
91
- },
92
- {
93
- yLabel: 'Backend',
94
- seriesOneValue: 50,
95
- seriesTwoValue: 600,
96
- icon: TerminalIcon,
97
- },
98
- {
99
- yLabel: 'Reading',
100
- seriesOneValue: 75,
101
- seriesTwoValue: 450,
102
- icon: BookFlipPageIcon,
103
- },
104
- ];
105
-
106
- export const Default: Story = {
107
- args: {
108
- barValues: simpleBarData,
109
- title: 'Skills experience chart',
110
- description: 'Chart showing programming language experience levels',
111
- },
112
- };
113
-
114
- export const Stacked: Story = {
115
- args: {
116
- barValues: stackedBarData,
117
- title: 'Skills progress chart',
118
- description: 'Progress toward total goals for each programming language',
119
- },
120
- };
121
-
122
- export const WithIcons: Story = {
123
- args: {
124
- barValues: barDataWithIcons,
125
- title: 'Skills progress with icons',
126
- description: 'Skills progress with visual icons for each category',
127
- },
128
- };
129
-
130
- export const Animated: Story = {
131
- args: {
132
- barValues: stackedBarData,
133
- animate: true,
134
- title: 'Animated skills chart',
135
- description: 'Animated chart showing progress with entrance animations',
136
- },
137
- };
138
-
139
- export const Interactive: Story = {
140
- args: {
141
- barValues: simpleBarData.map((bar) => ({
142
- ...bar,
143
- onClick: action(`Clicked ${bar.yLabel}`),
144
- })),
145
- title: 'Interactive skills chart',
146
- description: 'Click on any row to view detailed course information',
147
- },
148
- };
149
-
150
- export const WithLinks: Story = {
151
- args: {
152
- barValues: simpleBarData.map((bar) => ({
153
- ...bar,
154
- href: `#${bar.yLabel.toLowerCase().replace(/\s+/g, '-')}`,
155
- })),
156
- title: 'Skills chart with links',
157
- description: 'Each row links to its corresponding course page',
158
- },
159
- };
160
-
161
- export const WithVisualTitleAndDescription: Story = {
162
- args: {
163
- barValues: simpleBarData,
164
- title: 'Programming Skills Overview',
165
- description:
166
- 'Experience points earned across different programming languages',
167
- },
168
- };
169
-
170
- export const WithHiddenTitleAndDescription: Story = {
171
- render: () => {
172
- return (
173
- <BarChart
174
- barValues={simpleBarData}
175
- description="Experience points earned across different programming languages"
176
- hideDescription
177
- hideTitle
178
- maxRange={2000}
179
- title="Programming Skills Overview"
180
- unit="XP"
181
- />
182
- );
183
- },
184
- };
185
-
186
- export const WithExternalTitle: Story = {
187
- render: () => {
188
- return (
189
- <>
190
- <Box
191
- as="h2"
192
- bg="paleBlue"
193
- border={1}
194
- borderRadius="lg"
195
- id="external-chart-title"
196
- p={16}
197
- textAlign="right"
198
- >
199
- Programming Skills Overview
200
- </Box>
201
- <BarChart
202
- aria-labelledby="external-title"
203
- barValues={simpleBarData}
204
- description="Experience points earned across different programming languages"
205
- hideDescription={false}
206
- maxRange={2000}
207
- unit="XP"
208
- />
209
- </>
210
- );
211
- },
212
- };
213
-
214
- export const WithSorting: Story = {
215
- args: {
216
- barValues: simpleBarData,
217
- sortFns: ['alphabetically', 'numerically', 'none'],
218
- title: 'Skills experience chart',
219
- description: 'Use the dropdown to sort bars by different criteria',
220
- },
221
- };
222
-
223
- const customSortingBarValues = [
224
- {
225
- yLabel: 'Python',
226
- seriesOneValue: 1500,
227
- dateAdded: new Date('2023-01-15'),
228
- },
229
- {
230
- yLabel: 'JavaScript',
231
- seriesOneValue: 2000,
232
- dateAdded: new Date('2023-03-20'),
233
- },
234
- {
235
- yLabel: 'React',
236
- seriesOneValue: 450,
237
- dateAdded: new Date('2023-06-10'),
238
- },
239
- {
240
- yLabel: 'TypeScript',
241
- seriesOneValue: 300,
242
- dateAdded: new Date('2023-08-05'),
243
- },
244
- {
245
- yLabel: 'SQL',
246
- seriesOneValue: 600,
247
- dateAdded: new Date('2023-02-28'),
248
- },
249
- ];
250
-
251
- export const WithCustomSorting: Story = {
252
- args: {
253
- barValues: customSortingBarValues,
254
- sortFns: [
255
- 'none',
256
- {
257
- label: 'Recently Added',
258
- value: 'recent',
259
- sortFn: (bars) => {
260
- return [...bars].sort((a, b) => {
261
- const aDate = a.dateAdded as Date | undefined;
262
- const bDate = b.dateAdded as Date | undefined;
263
- if (!aDate && !bDate) return 0;
264
- if (!aDate) return 1;
265
- if (!bDate) return -1;
266
- return bDate.getTime() - aDate.getTime();
267
- });
268
- },
269
- },
270
- {
271
- label: 'Oldest First',
272
- value: 'oldest',
273
- sortFn: (bars) => {
274
- return [...bars].sort((a, b) => {
275
- const aDate = a.dateAdded as Date | undefined;
276
- const bDate = b.dateAdded as Date | undefined;
277
- if (!aDate && !bDate) return 0;
278
- if (!aDate) return 1;
279
- if (!bDate) return -1;
280
- return aDate.getTime() - bDate.getTime();
281
- });
282
- },
283
- },
284
- ],
285
- title: 'Skills chart with date sorting',
286
- description:
287
- 'Custom sort functions can access additional properties on BarProps, such as dates',
288
- },
289
- };
290
-
291
- export const CustomStyles: Story = {
292
- args: {
293
- barValues: stackedBarData,
294
- styleConfig: {
295
- seriesTwoBarColor: 'text',
296
- seriesOneBarColor: 'primary',
297
- textColor: 'primary',
298
- seriesOneLabel: 'feedback-error',
299
- seriesTwoLabel: 'feedback-success',
300
- },
301
- title: 'Custom styled skills chart',
302
- description: 'Custom color scheme applied to chart elements',
303
- },
304
- };
305
-
306
- export const CustomScale: Story = {
307
- args: {
308
- barValues: simpleBarData,
309
- maxRange: 2000,
310
- xScale: 250,
311
- title: 'Skills chart with custom scale',
312
- description: 'Custom scale intervals for more granular value display',
313
- },
314
- };
315
-
316
- export const WithStringTranslations: Story = {
317
- args: {
318
- barValues: stackedBarData,
319
- sortFns: ['alphabetically', 'numerically', 'none'],
320
- title: 'Gráfico de habilidades',
321
- description: 'Progreso hacia los objetivos totales por lenguaje',
322
- unit: 'XP',
323
- translations: {
324
- locale: 'es',
325
- sortLabel: 'Ordenar por:',
326
- sortOptions: {
327
- none: 'Ninguno',
328
- labelAsc: 'Etiqueta (A-Z)',
329
- labelDesc: 'Etiqueta (Z-A)',
330
- valueAsc: 'Valor (Bajo-Alto)',
331
- valueDesc: 'Valor (Alto-Bajo)',
332
- },
333
- accessibility: {
334
- gainedNowAt: 'ganado - ahora en',
335
- inLabel: 'en',
336
- inOnly: 'en ',
337
- },
338
- },
339
- },
340
- };
341
-
342
- export const WithFunctionTranslations: Story = {
343
- args: {
344
- barValues: accessibilityBarData,
345
- description:
346
- 'Custom aria-label summaries via translation functions (stacked, link, and non-interactive bars)',
347
- title: 'Skills experience (accessibility functions)',
348
- translations: accessibilityTranslations,
349
- unit: 'XP',
350
- },
351
- };