@codecademy/styleguide 79.2.3-alpha.78c04d.0 → 79.2.3-alpha.9808a5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/package.json +2 -2
- package/src/lib/Organisms/BarChart/BarChart.mdx +17 -38
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
|
-
### [79.2.3-alpha.
|
|
6
|
+
### [79.2.3-alpha.9808a5.0](https://github.com/Codecademy/gamut/compare/@codecademy/styleguide@79.2.2...@codecademy/styleguide@79.2.3-alpha.9808a5.0) (2026-03-19)
|
|
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": "79.2.3-alpha.
|
|
4
|
+
"version": "79.2.3-alpha.9808a5.0",
|
|
5
5
|
"author": "Codecademy Engineering",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"repository": "git@github.com:Codecademy/gamut.git",
|
|
11
|
-
"gitHead": "
|
|
11
|
+
"gitHead": "3d8b09cbaeb9e885da137c9bb125b41a3a327015"
|
|
12
12
|
}
|
|
@@ -131,14 +131,15 @@ When a bar has an `href` link, an `aria-label` is automatically generated from t
|
|
|
131
131
|
|
|
132
132
|
## Title and description
|
|
133
133
|
|
|
134
|
-
The `BarChart` component uses semantic HTML to provide context and accessibility. The chart is wrapped in a [`<figure>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure), and the description is displayed in a [`<figcaption>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption). This semantic structure helps screen readers and other assistive technologies understand the relationship between the chart and its description.
|
|
134
|
+
The `BarChart` component uses semantic HTML to provide context and accessibility. The chart is wrapped in a [`<figure>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure), and the description is displayed in a [`<figcaption>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption). This semantic structure helps screen readers and other assistive technologies understand the relationship between the chart and its description.
|
|
135
135
|
|
|
136
136
|
**Preferred pattern: Visual title + description**
|
|
137
137
|
|
|
138
138
|
Provide both `title` and `description` props to make the chart's purpose and key takeaways clear to all users:
|
|
139
139
|
|
|
140
|
-
- `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>.
|
|
141
|
-
- `description`: A summary of the information or the overall takeaway displayed in the `<figcaption>` element.
|
|
140
|
+
- `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>. Use semantic heading levels (h1–h6) so the surrounding document outline stays correct.
|
|
141
|
+
- `description`: **Required.** A summary of the information or the overall takeaway displayed in the `<figcaption>` element.
|
|
142
|
+
- When the visible title lives outside the chart, use `aria-labelledby` to point at that heading (see below). The referenced element must exist and have an accessible name.
|
|
142
143
|
|
|
143
144
|
<Canvas of={BarChartStories.WithVisualTitleAndDescription} />
|
|
144
145
|
|
|
@@ -151,12 +152,6 @@ Provide both `title` and `description` props to make the chart's purpose and key
|
|
|
151
152
|
|
|
152
153
|
<Canvas of={BarChartStories.WithExternalTitle} />
|
|
153
154
|
|
|
154
|
-
**Best practices:**
|
|
155
|
-
|
|
156
|
-
- Always provide a `description` prop - it's required and should summarize the chart's key information
|
|
157
|
-
- Use semantic heading levels for titles (h1-h6) to maintain proper document structure
|
|
158
|
-
- When using `aria-labelledby`, ensure the referenced element exists and is properly labeled
|
|
159
|
-
|
|
160
155
|
## Sorting
|
|
161
156
|
|
|
162
157
|
`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.
|
|
@@ -237,45 +232,29 @@ Custom sort functions can access additional properties on `BarProps` for domain-
|
|
|
237
232
|
|
|
238
233
|
## Custom styling
|
|
239
234
|
|
|
240
|
-
BarChart supports custom color styling through the `styleConfig` prop, allowing you to customize the appearance of chart elements to match your design needs.
|
|
235
|
+
`BarChart` supports custom color styling through the `styleConfig` prop, allowing you to customize the appearance of chart elements to match your design needs.
|
|
241
236
|
|
|
242
237
|
### Style configuration options
|
|
243
238
|
|
|
244
239
|
The `styleConfig` prop accepts an object with the following optional properties:
|
|
245
240
|
|
|
246
|
-
- **`textColor`**: Color for
|
|
247
|
-
- **`seriesOneBarColor`**: Color for the
|
|
248
|
-
- **`seriesTwoBarColor`**: Color for the
|
|
249
|
-
- **`seriesOneLabel`**: Color for the
|
|
250
|
-
- **`seriesTwoLabel`**: Color for the
|
|
241
|
+
- **`textColor`**: Color for each bar row's `categoryLabel`. Defaults to `'text'`
|
|
242
|
+
- **`seriesOneBarColor`**: Color for the bar that represents `seriesOneValue` (the only bar in simple charts; the overlay segment in stacked charts). Defaults to `'text'`
|
|
243
|
+
- **`seriesTwoBarColor`**: Color for the bar that represents `seriesTwoValue` (the full-length bar behind the overlay in stacked charts; unused when only `seriesOneValue` is set). Defaults to `'primary'`
|
|
244
|
+
- **`seriesOneLabel`**: Color for the numeric label for `seriesOneValue` (when stacked: the value before the arrow). In simple charts, color for the value label beside the bar (`seriesOneValue`). Defaults to `'text-secondary'`
|
|
245
|
+
- **`seriesTwoLabel`**: Color for the numeric label for `seriesTwoValue` (stacked charts only—the total at the end of the bar). Defaults to `'primary'`
|
|
251
246
|
|
|
252
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.
|
|
253
248
|
|
|
254
|
-
### Default values
|
|
255
|
-
|
|
256
|
-
If `styleConfig` is not provided, BarChart uses these default colors:
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
{
|
|
260
|
-
textColor: 'text',
|
|
261
|
-
seriesOneBarColor: 'text',
|
|
262
|
-
seriesTwoBarColor: 'primary',
|
|
263
|
-
seriesOneLabel: 'text-secondary',
|
|
264
|
-
seriesTwoLabel: 'primary',
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### Example
|
|
269
|
-
|
|
270
249
|
<Canvas of={BarChartStories.CustomStyles} />
|
|
271
250
|
|
|
272
251
|
## Custom scale
|
|
273
252
|
|
|
274
|
-
BarChart allows you to customize the
|
|
253
|
+
`BarChart` allows you to customize the scale interval using the `scaleInterval` prop, which controls the spacing and granularity of scale markers that measure the length of the bars.
|
|
275
254
|
|
|
276
255
|
### Scale configuration
|
|
277
256
|
|
|
278
|
-
The `scaleInterval` prop determines the interval between scale markers
|
|
257
|
+
The `scaleInterval` prop determines the interval between scale markers that show the length of the bars. By default, `BarChart` automatically calculates an appropriate scale interval based on the `maxScaleValue` value (the scale always starts at 0). However, you can override this with a custom interval to achieve more granular or specific scale markings.
|
|
279
258
|
|
|
280
259
|
**When to use custom scale:**
|
|
281
260
|
|
|
@@ -299,7 +278,7 @@ The number of tick marks is automatically calculated as: `Math.ceil(maxScaleValu
|
|
|
299
278
|
|
|
300
279
|
## Color modes
|
|
301
280
|
|
|
302
|
-
BarChart
|
|
281
|
+
`BarChart` uses semantic color tokens via `styleConfig`, so colors automatically adapt to light and dark color modes to ensure proper contrast and readability in all themes.
|
|
303
282
|
|
|
304
283
|
## Accessibility considerations
|
|
305
284
|
|
|
@@ -318,13 +297,13 @@ BarChart automatically adapts to both light and dark color modes, ensuring prope
|
|
|
318
297
|
|
|
319
298
|
## UX writing
|
|
320
299
|
|
|
321
|
-
- Keep
|
|
300
|
+
- Keep the category labels concise (1-3 words)
|
|
322
301
|
- Use consistent unit labels (e.g., "XP", "hours", "points")
|
|
323
302
|
- Consider locale-aware number formatting for international audiences
|
|
324
303
|
|
|
325
304
|
## Interactive states
|
|
326
305
|
|
|
327
|
-
BarChart supports both interactive and static bar rows, each with distinct visual states.
|
|
306
|
+
`BarChart` supports both interactive and static bar rows, each with distinct visual states.
|
|
328
307
|
|
|
329
308
|
### Static bars
|
|
330
309
|
|
|
@@ -342,11 +321,11 @@ When bars have `onClick` handlers or `href` links, they become interactive. Inte
|
|
|
342
321
|
|
|
343
322
|
<Callout text="We are currently updating global internationalization in Gamut, so the following features are subject to change." />
|
|
344
323
|
|
|
345
|
-
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.
|
|
324
|
+
`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.
|
|
346
325
|
|
|
347
326
|
### Translation structure
|
|
348
327
|
|
|
349
|
-
-
|
|
328
|
+
- `**sortLabel**`, `**sortOptions**`, and `**locale**` — Always strings. Control the sort dropdown label, option labels, and number-formatting locale.
|
|
350
329
|
- **Accessibility** — Two optional summary functions; when omitted, default English summaries are used. Each function receives context and returns the full summary string.
|
|
351
330
|
- `**stackedBarSummary**` — Used for stacked (two-value) rows. Context includes `seriesOneValue`, `seriesTwoValue`, **gained** (seriesTwoValue - seriesOneValue), `unit`, `locale`, `categoryLabel`.
|
|
352
331
|
- `**singleValueBarSummary**` — Used for all single-value rows. Context includes `value`, `unit`, `locale`, `categoryLabel`.
|