diff --git a/.changeset/color-roles-component-behavior.md b/.changeset/color-roles-component-behavior.md new file mode 100644 index 0000000000..2742edd04b --- /dev/null +++ b/.changeset/color-roles-component-behavior.md @@ -0,0 +1,9 @@ +--- +'@skillsoft/gamut': minor +--- + +Component behavior from design's component map that the role swap didn't cover. + +- A selected DataList or DataTable row takes the `state-selected` veil over its fill, with the hover veil on top when hovered. `ListRow` takes an `isSelected` prop for the same tint. +- Table rows are `surface-raised`, with `surface-sunken` stripes, instead of transparent. +- ProgressBar's label at `large` and `xl` sizes is two-tone: `text-inverse` on the bar and `text-default` where it runs onto the track, so a short bar's label stays readable. diff --git a/.changeset/color-system-brands.md b/.changeset/color-system-brands.md index 867f98a899..322500b181 100644 --- a/.changeset/color-system-brands.md +++ b/.changeset/color-system-brands.md @@ -6,7 +6,6 @@ Brands on the generated color system. -- Color CSS variables keep the `--color-*` names from `main`, in `@skillsoft/variance`'s `createTheme` and in `tokens.css`. Raw CSS that reads `var(--color-…)` needs no changes. - **Breaking:** `tokens.css` puts its rules in `@layer tokens`, with `reset, base, tokens, recipes, utilities` declared first. - Adds `originalCodecademyTheme`, today's core colors, fonts and hard-offset elevation rebuilt on the generated system. `tokens.css` carries a palette block per brand under `[data-brand]`. - A brand can override a palette step with an exact hex, or point a role at a different step (and, optionally, a different alpha) in one mode. Overrides go through the same contrast checks as generated values. diff --git a/packages/gamut/src/DataList/DataGrid.test.tsx b/packages/gamut/src/DataList/DataGrid.test.tsx new file mode 100644 index 0000000000..fd0c24b6e1 --- /dev/null +++ b/packages/gamut/src/DataList/DataGrid.test.tsx @@ -0,0 +1,64 @@ +import { setupRtl } from '@skillsoft/gamut-tests'; +import type { RenderResult } from '@testing-library/react'; +import { screen } from '@testing-library/react'; +import { describe, expect, it, vi } from 'vitest'; + +import type { DataGridProps } from './DataGrid'; +import { DataGrid } from './DataGrid'; +import type { ColumnConfig } from './types'; + +type Row = { id: string; name: string; sin: string }; +type Columns = ColumnConfig[]; + +type Props = DataGridProps; + +const onRowSelect = vi.fn(); +const onRowExpand = vi.fn(); +const onQueryChange = vi.fn(); + +const props = { + id: 'test', + idKey: 'id', + rows: [ + { id: '1', name: 'Hari Seldon', sin: 'Messiah Complex' }, + { id: '2', name: 'Bel Roise', sin: 'Competence' }, + { id: '3', name: 'Cleon II', sin: 'Hubris' }, + ], + columns: [{ key: 'name' }, { key: 'sin' }], + onRowSelect, + onRowExpand, + onQueryChange, + expandedContent: ({ row: { id } }) =>
Expanded {id}
, +} as Props; + +const renderView = setupRtl(DataGrid, props as any) as < + T extends Partial +>( + props?: T +) => { view: RenderResult }; + +describe('DataGrid', () => { + describe('Selecting Rows', () => { + it('tints a selected row with the state-selected veil', () => { + renderView({ selected: ['1'] }); + + const rows = screen.getAllByRole('row'); + const selectedRow = screen + .getByRole('checkbox', { name: 'Select 1' }) + .closest('tr')!; + const otherRow = screen + .getByRole('checkbox', { name: 'Select 2' }) + .closest('tr')!; + + expect(rows).toContain(selectedRow); + expect(selectedRow).toHaveStyleRule( + 'background-image', + expect.stringContaining('var(--color-state-selected)') + ); + expect(otherRow).not.toHaveStyleRule( + 'background-image', + expect.stringContaining('var(--color-state-selected)') + ); + }); + }); +}); diff --git a/packages/gamut/src/DataList/Tables/Rows/TableRow.tsx b/packages/gamut/src/DataList/Tables/Rows/TableRow.tsx index 4d872d8642..3282072d62 100644 --- a/packages/gamut/src/DataList/Tables/Rows/TableRow.tsx +++ b/packages/gamut/src/DataList/Tables/Rows/TableRow.tsx @@ -77,7 +77,7 @@ export const TableRow: DataRow = ({ : {}; return ( - + {selectable && ( ())( space ); +/* A veil as a background layer, so it sits over the row's own fill. */ +const veil = (role: 'state-hover' | 'state-selected') => + `linear-gradient(${theme.colors[role]}, ${theme.colors[role]})`; + const rowStates = states({ isOl: { '&::before': { @@ -81,6 +85,16 @@ const rowStates = states({ transparentBg: { bg: 'transparent', }, + /* + * A selected row takes the `state-selected` veil over its own fill + * (design's list map). Hovering it stacks the hover veil on top. + */ + isSelected: { + backgroundImage: veil('state-selected'), + '&:hover': { + backgroundImage: `${veil('state-hover')}, ${veil('state-selected')}`, + }, + }, }); const interactiveState = states({ @@ -89,7 +103,7 @@ const interactiveState = states({ /* Hover is a veil over the row's own fill; focus is the ring alone. */ '&:hover': { - backgroundImage: `linear-gradient(${theme.colors['state-hover']}, ${theme.colors['state-hover']})`, + backgroundImage: veil('state-hover'), }, '&:focus-visible, &:focus-within': { outline: `1px solid ${theme.colors['action-primary']}`, @@ -132,9 +146,9 @@ const rowVariants = variant({ borderColorTop: 'border-subtle', }, }, + /* Rows are `surface-raised`; a stripe is sunken, so it never reads as a selection. */ table: { - bg: 'transparent', - /* A stripe is a sunken surface, so it never reads as a selection. */ + bg: 'surface-raised', '&:nth-of-type(2n)': { bg: 'surface-sunken', }, diff --git a/packages/gamut/src/ProgressBar/ProgressBar.stories.tsx b/packages/gamut/src/ProgressBar/ProgressBar.stories.tsx index a8d2eab7cb..d339a8d53f 100644 --- a/packages/gamut/src/ProgressBar/ProgressBar.stories.tsx +++ b/packages/gamut/src/ProgressBar/ProgressBar.stories.tsx @@ -71,10 +71,13 @@ export const Large: Story = { }, play: async ({ canvas }) => { canvas.getByText('Progress: 75%'); - await expect(canvas.getByText('75%')).toHaveAttribute( - 'aria-hidden', - 'true' - ); + // Two copies of the label (track and bar), both decorative: the screen + // reader value comes from the visually hidden "Progress" label. + const copies = canvas.getAllByText('75%'); + await expect(copies).toHaveLength(2); + for (const copy of copies) { + await expect(copy.closest('[aria-hidden="true"]')).not.toBeNull(); + } }, }; diff --git a/packages/gamut/src/ProgressBar/ProgressBar.test.tsx b/packages/gamut/src/ProgressBar/ProgressBar.test.tsx index 646fc39f4b..b699e71b09 100644 --- a/packages/gamut/src/ProgressBar/ProgressBar.test.tsx +++ b/packages/gamut/src/ProgressBar/ProgressBar.test.tsx @@ -42,3 +42,35 @@ describe('ProgressBar', () => { } ); }); + +describe('ProgressBar label', () => { + const renderBar = (props: Partial = {}) => + render( + + + + ); + + /* Design's two-tone label: text-inverse on the bar, text-default on the track. */ + it('draws the label on the bar and on the track at large sizes', () => { + renderBar({ size: 'large' }); + + const labels = screen.getAllByText('10%'); + expect(labels).toHaveLength(2); + expect(screen.getByTestId('progress-bar-bar')).toContainElement(labels[1]); + expect(labels[0].parentElement).toHaveStyleRule( + 'color', + 'var(--color-text-default)' + ); + expect(screen.getByTestId('progress-bar-bar')).toHaveStyleRule( + 'overflow', + 'hidden' + ); + }); + + it('draws no label at small sizes', () => { + renderBar({ size: 'small' }); + + expect(screen.queryByText('10%')).toBeNull(); + }); +}); diff --git a/packages/gamut/src/ProgressBar/index.tsx b/packages/gamut/src/ProgressBar/index.tsx index 03a9b72a90..eb78845616 100644 --- a/packages/gamut/src/ProgressBar/index.tsx +++ b/packages/gamut/src/ProgressBar/index.tsx @@ -1,6 +1,6 @@ import styled from '@emotion/styled'; import type { PatternProps } from '@skillsoft/gamut-patterns'; -import { variant } from '@skillsoft/gamut-styles'; +import { css, variant } from '@skillsoft/gamut-styles'; import * as React from 'react'; import { Box } from '../Box'; @@ -116,6 +116,8 @@ const progressBarForegroundVariants = variant({ display: 'flex', transition: 'width 0.5s', position: 'relative', + /* Clips the bar's copy of the label to the bar. */ + overflow: 'hidden', }, /* Every bar is `text-default`, blue and yellow included. */ variants: { @@ -156,9 +158,28 @@ const DisplayedPercent = styled.span` font-weight: bold; padding: 0.5rem; text-align: right; + white-space: nowrap; width: 100%; `; +/* + * Design's two-tone label: `text-inverse` where it sits on the bar, + * `text-default` where it runs onto the track. The track's copy sits at the + * same place under the bar, so the bar covers it and the wrapper clips it. + */ +const TrackLabel = styled(Box)( + css({ + alignItems: 'center', + color: 'text-default', + display: 'flex', + height: '100%', + left: 0, + position: 'absolute', + top: 0, + transition: 'width 0.5s', + }) +); + export const ProgressBar: React.FC = ({ flat, minimumPercent = 0, @@ -168,6 +189,8 @@ export const ProgressBar: React.FC = ({ variant, }) => { const id = React.useId(); + const width = `${Math.max(minimumPercent, percent)}%`; + const showLabel = ['large', 'xl'].includes(size); return ( = ({ > {`Progress: ${percent}%`} {Pattern && } + {showLabel && ( + + {percent}% + + )} - {['large', 'xl'].includes(size) && ( + {showLabel && ( {percent}% )}