@slipstream-ui/core 0.11.4 → 0.11.7
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/dist/index.d.mts +107 -4
- package/dist/index.d.ts +107 -4
- package/dist/index.js +594 -442
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +489 -338
- package/dist/index.mjs.map +1 -1
- package/dist/manifests/accordion.manifest.json +1 -1
- package/dist/manifests/alert.manifest.json +1 -1
- package/dist/manifests/announcement-bar.manifest.json +1 -1
- package/dist/manifests/app-shell.manifest.json +1 -1
- package/dist/manifests/applied-filters.manifest.json +1 -1
- package/dist/manifests/article-card.manifest.json +1 -1
- package/dist/manifests/auth-layout.manifest.json +1 -1
- package/dist/manifests/autocomplete.manifest.json +1 -1
- package/dist/manifests/avatar.manifest.json +1 -1
- package/dist/manifests/badge.manifest.json +1 -1
- package/dist/manifests/block.manifest.json +1 -1
- package/dist/manifests/bottom-nav.manifest.json +1 -1
- package/dist/manifests/breadcrumb.manifest.json +1 -1
- package/dist/manifests/button-group.manifest.json +1 -1
- package/dist/manifests/button.manifest.json +1 -1
- package/dist/manifests/calendar.manifest.json +1 -1
- package/dist/manifests/card.manifest.json +1 -1
- package/dist/manifests/checkbox.manifest.json +1 -1
- package/dist/manifests/comparison-table.manifest.json +1 -1
- package/dist/manifests/confirm-dialog.manifest.json +1 -1
- package/dist/manifests/contact-strip.manifest.json +1 -1
- package/dist/manifests/container.manifest.json +1 -1
- package/dist/manifests/cover-image.manifest.json +151 -0
- package/dist/manifests/cta-section.manifest.json +1 -1
- package/dist/manifests/data-table.manifest.json +1 -1
- package/dist/manifests/date-picker-popover.manifest.json +1 -1
- package/dist/manifests/date-picker.manifest.json +1 -1
- package/dist/manifests/date-range-picker.manifest.json +1 -1
- package/dist/manifests/deal-card.manifest.json +1 -1
- package/dist/manifests/dialog.manifest.json +1 -1
- package/dist/manifests/document-card.manifest.json +1 -1
- package/dist/manifests/drawer.manifest.json +1 -1
- package/dist/manifests/empty-state.manifest.json +45 -1
- package/dist/manifests/entity-card.manifest.json +1 -1
- package/dist/manifests/feature-grid.manifest.json +1 -1
- package/dist/manifests/feature-row.manifest.json +1 -1
- package/dist/manifests/fieldset.manifest.json +1 -1
- package/dist/manifests/file-upload.manifest.json +1 -1
- package/dist/manifests/filter-bar.manifest.json +1 -1
- package/dist/manifests/filter-chips.manifest.json +1 -1
- package/dist/manifests/filter-panel.manifest.json +1 -1
- package/dist/manifests/flex.manifest.json +1 -1
- package/dist/manifests/form-field.manifest.json +1 -1
- package/dist/manifests/form-layout.manifest.json +1 -1
- package/dist/manifests/form.manifest.json +1 -1
- package/dist/manifests/grid.manifest.json +1 -1
- package/dist/manifests/heading.manifest.json +1 -1
- package/dist/manifests/hero.manifest.json +1 -1
- package/dist/manifests/image.manifest.json +7 -1
- package/dist/manifests/input-group.manifest.json +1 -1
- package/dist/manifests/input.manifest.json +1 -1
- package/dist/manifests/label.manifest.json +1 -1
- package/dist/manifests/link-tabs.manifest.json +1 -1
- package/dist/manifests/link.manifest.json +1 -1
- package/dist/manifests/list.manifest.json +1 -1
- package/dist/manifests/load-more.manifest.json +1 -1
- package/dist/manifests/logo-cloud.manifest.json +1 -1
- package/dist/manifests/menu.manifest.json +1 -1
- package/dist/manifests/metric-card.manifest.json +1 -1
- package/dist/manifests/multi-select.manifest.json +1 -1
- package/dist/manifests/newsletter.manifest.json +1 -1
- package/dist/manifests/page-header.manifest.json +1 -1
- package/dist/manifests/pagination.manifest.json +1 -1
- package/dist/manifests/password-input.manifest.json +1 -1
- package/dist/manifests/popover.manifest.json +1 -1
- package/dist/manifests/process-steps.manifest.json +1 -1
- package/dist/manifests/progress.manifest.json +1 -1
- package/dist/manifests/prose.manifest.json +1 -1
- package/dist/manifests/radio.manifest.json +1 -1
- package/dist/manifests/range-slider.manifest.json +1 -1
- package/dist/manifests/search.manifest.json +1 -1
- package/dist/manifests/section-heading.manifest.json +1 -1
- package/dist/manifests/section.manifest.json +1 -1
- package/dist/manifests/segmented-control.manifest.json +29 -2
- package/dist/manifests/select-menu.manifest.json +1 -1
- package/dist/manifests/select.manifest.json +1 -1
- package/dist/manifests/separator.manifest.json +1 -1
- package/dist/manifests/site-footer.manifest.json +1 -1
- package/dist/manifests/site-header.manifest.json +22 -1
- package/dist/manifests/skeleton.manifest.json +1 -1
- package/dist/manifests/spinner.manifest.json +1 -1
- package/dist/manifests/stat-band.manifest.json +23 -1
- package/dist/manifests/stepper.manifest.json +1 -1
- package/dist/manifests/switch.manifest.json +1 -1
- package/dist/manifests/table-card.manifest.json +1 -1
- package/dist/manifests/table-of-contents.manifest.json +1 -1
- package/dist/manifests/table.manifest.json +1 -1
- package/dist/manifests/tabs.manifest.json +1 -1
- package/dist/manifests/testimonial.manifest.json +1 -1
- package/dist/manifests/text.manifest.json +1 -1
- package/dist/manifests/textarea.manifest.json +1 -1
- package/dist/manifests/theme-toggle.manifest.json +1 -1
- package/dist/manifests/time-picker.manifest.json +1 -1
- package/dist/manifests/timeline.manifest.json +1 -1
- package/dist/manifests/toast.manifest.json +1 -1
- package/dist/manifests/tombstone-card.manifest.json +1 -1
- package/dist/manifests/tooltip.manifest.json +1 -1
- package/dist/src/components/cover-image/CoverImage.d.ts +34 -0
- package/dist/src/components/cover-image/CoverImage.js +94 -0
- package/dist/src/components/cover-image/CoverImage.js.map +1 -0
- package/dist/src/components/cover-image/CoverImage.mjs +70 -0
- package/dist/src/components/cover-image/CoverImage.mjs.map +1 -0
- package/dist/src/components/cover-image/index.d.ts +1 -0
- package/dist/src/components/cover-image/index.js +29 -0
- package/dist/src/components/cover-image/index.js.map +1 -0
- package/dist/src/components/cover-image/index.mjs +5 -0
- package/dist/src/components/cover-image/index.mjs.map +1 -0
- package/dist/src/components/empty-state/EmptyState.d.ts +24 -0
- package/dist/src/components/empty-state/EmptyState.js +16 -6
- package/dist/src/components/empty-state/EmptyState.js.map +1 -1
- package/dist/src/components/empty-state/EmptyState.mjs +16 -6
- package/dist/src/components/empty-state/EmptyState.mjs.map +1 -1
- package/dist/src/components/image/Image.d.ts +3 -1
- package/dist/src/components/image/Image.js +2 -0
- package/dist/src/components/image/Image.js.map +1 -1
- package/dist/src/components/image/Image.mjs +2 -0
- package/dist/src/components/image/Image.mjs.map +1 -1
- package/dist/src/components/segmented-control/SegmentedControl.d.ts +21 -0
- package/dist/src/components/segmented-control/SegmentedControl.js +47 -16
- package/dist/src/components/segmented-control/SegmentedControl.js.map +1 -1
- package/dist/src/components/segmented-control/SegmentedControl.mjs +48 -17
- package/dist/src/components/segmented-control/SegmentedControl.mjs.map +1 -1
- package/dist/src/components/site-header/SiteHeader.d.ts +7 -1
- package/dist/src/components/site-header/SiteHeader.js +5 -1
- package/dist/src/components/site-header/SiteHeader.js.map +1 -1
- package/dist/src/components/site-header/SiteHeader.mjs +5 -1
- package/dist/src/components/site-header/SiteHeader.mjs.map +1 -1
- package/dist/src/components/stat-band/StatBand.d.ts +16 -0
- package/dist/src/components/stat-band/StatBand.js +46 -9
- package/dist/src/components/stat-band/StatBand.js.map +1 -1
- package/dist/src/components/stat-band/StatBand.mjs +46 -9
- package/dist/src/components/stat-band/StatBand.mjs.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/styles-full.css +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- package/src/components/cover-image/CoverImage.test.tsx +88 -0
- package/src/components/cover-image/CoverImage.tsx +109 -0
- package/src/components/cover-image/index.ts +1 -0
- package/src/components/empty-state/EmptyState.test.tsx +33 -0
- package/src/components/empty-state/EmptyState.tsx +34 -6
- package/src/components/image/Image.tsx +4 -0
- package/src/components/segmented-control/SegmentedControl.test.tsx +64 -0
- package/src/components/segmented-control/SegmentedControl.tsx +69 -15
- package/src/components/site-header/SiteHeader.test.tsx +18 -0
- package/src/components/site-header/SiteHeader.tsx +11 -1
- package/src/components/stat-band/StatBand.test.tsx +26 -0
- package/src/components/stat-band/StatBand.tsx +52 -7
- package/src/index.ts +1 -0
- package/src/manifests/accordion.manifest.json +1 -1
- package/src/manifests/alert.manifest.json +1 -1
- package/src/manifests/announcement-bar.manifest.json +1 -1
- package/src/manifests/app-shell.manifest.json +1 -1
- package/src/manifests/applied-filters.manifest.json +1 -1
- package/src/manifests/article-card.manifest.json +1 -1
- package/src/manifests/auth-layout.manifest.json +1 -1
- package/src/manifests/autocomplete.manifest.json +1 -1
- package/src/manifests/avatar.manifest.json +1 -1
- package/src/manifests/badge.manifest.json +1 -1
- package/src/manifests/block.manifest.json +1 -1
- package/src/manifests/bottom-nav.manifest.json +1 -1
- package/src/manifests/breadcrumb.manifest.json +1 -1
- package/src/manifests/button-group.manifest.json +1 -1
- package/src/manifests/button.manifest.json +1 -1
- package/src/manifests/calendar.manifest.json +1 -1
- package/src/manifests/card.manifest.json +1 -1
- package/src/manifests/checkbox.manifest.json +1 -1
- package/src/manifests/comparison-table.manifest.json +1 -1
- package/src/manifests/confirm-dialog.manifest.json +1 -1
- package/src/manifests/contact-strip.manifest.json +1 -1
- package/src/manifests/container.manifest.json +1 -1
- package/src/manifests/cover-image.manifest.json +151 -0
- package/src/manifests/cta-section.manifest.json +1 -1
- package/src/manifests/data-table.manifest.json +1 -1
- package/src/manifests/date-picker-popover.manifest.json +1 -1
- package/src/manifests/date-picker.manifest.json +1 -1
- package/src/manifests/date-range-picker.manifest.json +1 -1
- package/src/manifests/deal-card.manifest.json +1 -1
- package/src/manifests/dialog.manifest.json +1 -1
- package/src/manifests/document-card.manifest.json +1 -1
- package/src/manifests/drawer.manifest.json +1 -1
- package/src/manifests/empty-state.manifest.json +45 -1
- package/src/manifests/entity-card.manifest.json +1 -1
- package/src/manifests/feature-grid.manifest.json +1 -1
- package/src/manifests/feature-row.manifest.json +1 -1
- package/src/manifests/fieldset.manifest.json +1 -1
- package/src/manifests/file-upload.manifest.json +1 -1
- package/src/manifests/filter-bar.manifest.json +1 -1
- package/src/manifests/filter-chips.manifest.json +1 -1
- package/src/manifests/filter-panel.manifest.json +1 -1
- package/src/manifests/flex.manifest.json +1 -1
- package/src/manifests/form-field.manifest.json +1 -1
- package/src/manifests/form-layout.manifest.json +1 -1
- package/src/manifests/form.manifest.json +1 -1
- package/src/manifests/grid.manifest.json +1 -1
- package/src/manifests/heading.manifest.json +1 -1
- package/src/manifests/hero.manifest.json +1 -1
- package/src/manifests/image.manifest.json +7 -1
- package/src/manifests/input-group.manifest.json +1 -1
- package/src/manifests/input.manifest.json +1 -1
- package/src/manifests/label.manifest.json +1 -1
- package/src/manifests/link-tabs.manifest.json +1 -1
- package/src/manifests/link.manifest.json +1 -1
- package/src/manifests/list.manifest.json +1 -1
- package/src/manifests/load-more.manifest.json +1 -1
- package/src/manifests/logo-cloud.manifest.json +1 -1
- package/src/manifests/menu.manifest.json +1 -1
- package/src/manifests/metric-card.manifest.json +1 -1
- package/src/manifests/multi-select.manifest.json +1 -1
- package/src/manifests/newsletter.manifest.json +1 -1
- package/src/manifests/page-header.manifest.json +1 -1
- package/src/manifests/pagination.manifest.json +1 -1
- package/src/manifests/password-input.manifest.json +1 -1
- package/src/manifests/popover.manifest.json +1 -1
- package/src/manifests/process-steps.manifest.json +1 -1
- package/src/manifests/progress.manifest.json +1 -1
- package/src/manifests/prose.manifest.json +1 -1
- package/src/manifests/radio.manifest.json +1 -1
- package/src/manifests/range-slider.manifest.json +1 -1
- package/src/manifests/search.manifest.json +1 -1
- package/src/manifests/section-heading.manifest.json +1 -1
- package/src/manifests/section.manifest.json +1 -1
- package/src/manifests/segmented-control.manifest.json +29 -2
- package/src/manifests/select-menu.manifest.json +1 -1
- package/src/manifests/select.manifest.json +1 -1
- package/src/manifests/separator.manifest.json +1 -1
- package/src/manifests/site-footer.manifest.json +1 -1
- package/src/manifests/site-header.manifest.json +22 -1
- package/src/manifests/skeleton.manifest.json +1 -1
- package/src/manifests/spinner.manifest.json +1 -1
- package/src/manifests/stat-band.manifest.json +23 -1
- package/src/manifests/stepper.manifest.json +1 -1
- package/src/manifests/switch.manifest.json +1 -1
- package/src/manifests/table-card.manifest.json +1 -1
- package/src/manifests/table-of-contents.manifest.json +1 -1
- package/src/manifests/table.manifest.json +1 -1
- package/src/manifests/tabs.manifest.json +1 -1
- package/src/manifests/testimonial.manifest.json +1 -1
- package/src/manifests/text.manifest.json +1 -1
- package/src/manifests/textarea.manifest.json +1 -1
- package/src/manifests/theme-toggle.manifest.json +1 -1
- package/src/manifests/time-picker.manifest.json +1 -1
- package/src/manifests/timeline.manifest.json +1 -1
- package/src/manifests/toast.manifest.json +1 -1
- package/src/manifests/tombstone-card.manifest.json +1 -1
- package/src/manifests/tooltip.manifest.json +1 -1
- package/src/styles.css +5 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
+
import { renderToString } from 'react-dom/server';
|
|
3
|
+
import { axe } from 'jest-axe';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { CoverImage } from './CoverImage';
|
|
6
|
+
|
|
7
|
+
describe('CoverImage', () => {
|
|
8
|
+
it('renders the image inside an aspect-ratio box', () => {
|
|
9
|
+
render(<CoverImage src="/cover.jpg" alt="Fall Classic" />);
|
|
10
|
+
const img = screen.getByRole('img', { name: 'Fall Classic' });
|
|
11
|
+
expect(img).toHaveAttribute('src', '/cover.jpg');
|
|
12
|
+
expect(img.parentElement).toHaveClass('aspect-video', 'overflow-hidden');
|
|
13
|
+
expect(img).toHaveClass('object-cover');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('supports aspect presets and custom ratios', () => {
|
|
17
|
+
const { container, rerender } = render(
|
|
18
|
+
<CoverImage src="/a.jpg" alt="A" aspect="square" />
|
|
19
|
+
);
|
|
20
|
+
expect(container.firstElementChild).toHaveClass('aspect-square');
|
|
21
|
+
rerender(<CoverImage src="/a.jpg" alt="A" aspect="16/10" />);
|
|
22
|
+
expect((container.firstElementChild as HTMLElement).style.aspectRatio).toBe('16 / 10');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('renders the seeded gradient fallback when src is absent', () => {
|
|
26
|
+
const { container } = render(<CoverImage alt="No art" seed="entity-42" />);
|
|
27
|
+
expect(screen.queryByRole('img')).not.toBeInTheDocument();
|
|
28
|
+
const fallback = container.querySelector('[style*="linear-gradient"]');
|
|
29
|
+
expect(fallback).not.toBeNull();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('picks a stable gradient per seed', () => {
|
|
33
|
+
const a = render(<CoverImage alt="A" seed="same" />).container.querySelector('[style*="linear-gradient"]') as HTMLElement;
|
|
34
|
+
const b = render(<CoverImage alt="B" seed="same" />).container.querySelector('[style*="linear-gradient"]') as HTMLElement;
|
|
35
|
+
const c = render(<CoverImage alt="C" seed="other" />).container.querySelector('[style*="linear-gradient"]') as HTMLElement;
|
|
36
|
+
expect(a.style.backgroundImage).toBe(b.style.backgroundImage);
|
|
37
|
+
expect(a.style.backgroundImage).toContain('linear-gradient');
|
|
38
|
+
// different seeds may collide by chance; assert determinism only for same seed
|
|
39
|
+
expect(c.style.backgroundImage).toContain('linear-gradient');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('degrades a broken image to the fallback gradient', () => {
|
|
43
|
+
render(<CoverImage src="/broken.jpg" alt="Event" seed="x" />);
|
|
44
|
+
fireEvent.error(screen.getByRole('img', { name: 'Event' }));
|
|
45
|
+
expect(screen.queryByRole('img')).not.toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('honors priority and sizes on the image', () => {
|
|
49
|
+
render(<CoverImage src="/hero.jpg" alt="Hero" priority sizes="100vw" />);
|
|
50
|
+
const img = screen.getByRole('img', { name: 'Hero' });
|
|
51
|
+
expect(img).toHaveAttribute('loading', 'eager');
|
|
52
|
+
expect(img).toHaveAttribute('fetchpriority', 'high');
|
|
53
|
+
expect(img).toHaveAttribute('sizes', '100vw');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('renders a custom fallback and mark', () => {
|
|
57
|
+
render(
|
|
58
|
+
<CoverImage
|
|
59
|
+
alt="Event"
|
|
60
|
+
mark={<svg data-testid="mark" />}
|
|
61
|
+
fallback={<div data-testid="custom">Custom</div>}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
expect(screen.getByTestId('custom')).toBeInTheDocument();
|
|
65
|
+
expect(screen.queryByTestId('mark')).not.toBeInTheDocument();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('renders the mark on the default gradient', () => {
|
|
69
|
+
render(<CoverImage alt="Event" mark={<svg data-testid="mark" />} />);
|
|
70
|
+
expect(screen.getByTestId('mark')).toBeInTheDocument();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('keeps the aspect box in server-rendered markup', () => {
|
|
74
|
+
const html = renderToString(<CoverImage src="/c.jpg" alt="Cover" />);
|
|
75
|
+
expect(html).toContain('aspect-video');
|
|
76
|
+
expect(html).toContain('alt="Cover"');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('has no accessibility violations', async () => {
|
|
80
|
+
const { container } = render(
|
|
81
|
+
<>
|
|
82
|
+
<CoverImage src="/c.jpg" alt="With image" />
|
|
83
|
+
<CoverImage alt="Placeholder" seed="s" />
|
|
84
|
+
</>
|
|
85
|
+
);
|
|
86
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import { Image } from '../image/Image';
|
|
4
|
+
|
|
5
|
+
export type CoverImageProps = {
|
|
6
|
+
/** Cover URL. When absent or broken, the seeded fallback renders instead. */
|
|
7
|
+
src?: string | null;
|
|
8
|
+
/** Required: describes the image for assistive tech. */
|
|
9
|
+
alt: string;
|
|
10
|
+
/**
|
|
11
|
+
* Aspect ratio: 'video' (16:9), 'square' (1:1), 'wide' (2:1), or any CSS
|
|
12
|
+
* aspect-ratio value such as '16/9' or '4/3'.
|
|
13
|
+
*/
|
|
14
|
+
aspect?: 'video' | 'square' | 'wide' | string;
|
|
15
|
+
/** Stable key selecting the fallback gradient (e.g. entity slug). */
|
|
16
|
+
seed?: string;
|
|
17
|
+
/** Load eagerly and fetch at high priority for the LCP image. */
|
|
18
|
+
priority?: boolean;
|
|
19
|
+
/** Responsive `sizes` hint forwarded to the image. */
|
|
20
|
+
sizes?: string;
|
|
21
|
+
/** Custom fallback content; defaults to the seed-derived gradient. */
|
|
22
|
+
fallback?: React.ReactNode;
|
|
23
|
+
/** Optional mark centered on the default gradient (icon, monogram). */
|
|
24
|
+
mark?: React.ReactNode;
|
|
25
|
+
className?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const aspectClasses = {
|
|
29
|
+
video: 'aspect-video',
|
|
30
|
+
square: 'aspect-square',
|
|
31
|
+
wide: 'aspect-[2/1]',
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
// Token-derived gradients: every entry uses theme variables so covers stay on
|
|
35
|
+
// the active palette in light and dark mode and pass the token audit.
|
|
36
|
+
const gradients = [
|
|
37
|
+
'linear-gradient(135deg, hsl(var(--primary) / 0.18), hsl(var(--info) / 0.10))',
|
|
38
|
+
'linear-gradient(135deg, hsl(var(--info) / 0.16), hsl(var(--primary) / 0.08))',
|
|
39
|
+
'linear-gradient(135deg, hsl(var(--warning) / 0.14), hsl(var(--primary) / 0.10))',
|
|
40
|
+
'linear-gradient(135deg, hsl(var(--success) / 0.14), hsl(var(--info) / 0.08))',
|
|
41
|
+
] as const;
|
|
42
|
+
|
|
43
|
+
function hashSeed(seed: string): number {
|
|
44
|
+
let hash = 0;
|
|
45
|
+
for (let i = 0; i < seed.length; i += 1) {
|
|
46
|
+
hash = (hash * 31 + seed.charCodeAt(i)) >>> 0;
|
|
47
|
+
}
|
|
48
|
+
return hash;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function seededGradient(seed: string): React.CSSProperties {
|
|
52
|
+
return { backgroundImage: gradients[hashSeed(seed) % gradients.length] };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Media cover with a deterministic placeholder: a fixed-aspect box that shows
|
|
57
|
+
* the image when present and a seed-derived token gradient (plus optional
|
|
58
|
+
* mark) when the entity has no art. Broken images degrade to the same
|
|
59
|
+
* gradient through Image's fallback chain, so imageless grids still look
|
|
60
|
+
* intentional.
|
|
61
|
+
*/
|
|
62
|
+
export function CoverImage({
|
|
63
|
+
src,
|
|
64
|
+
alt,
|
|
65
|
+
aspect = 'video',
|
|
66
|
+
seed,
|
|
67
|
+
priority = false,
|
|
68
|
+
sizes,
|
|
69
|
+
fallback,
|
|
70
|
+
mark,
|
|
71
|
+
className,
|
|
72
|
+
}: CoverImageProps) {
|
|
73
|
+
const preset = aspectClasses[aspect as keyof typeof aspectClasses];
|
|
74
|
+
const aspectStyle =
|
|
75
|
+
preset === undefined && typeof aspect === 'string' ? { aspectRatio: aspect } : undefined;
|
|
76
|
+
|
|
77
|
+
const fallbackNode =
|
|
78
|
+
fallback ?? (
|
|
79
|
+
<div
|
|
80
|
+
className="flex h-full w-full items-center justify-center"
|
|
81
|
+
style={seededGradient(seed ?? alt)}
|
|
82
|
+
aria-hidden="true"
|
|
83
|
+
>
|
|
84
|
+
{mark && <span className="text-muted-foreground [&_svg]:size-8">{mark}</span>}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div
|
|
90
|
+
className={cn('relative overflow-hidden rounded-lg bg-muted', preset, className)}
|
|
91
|
+
style={aspectStyle}
|
|
92
|
+
>
|
|
93
|
+
{src ? (
|
|
94
|
+
<Image
|
|
95
|
+
src={src}
|
|
96
|
+
alt={alt}
|
|
97
|
+
priority={priority}
|
|
98
|
+
sizes={sizes}
|
|
99
|
+
fallback={fallbackNode}
|
|
100
|
+
className="h-full w-full object-cover"
|
|
101
|
+
/>
|
|
102
|
+
) : (
|
|
103
|
+
fallbackNode
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
CoverImage.displayName = 'CoverImage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CoverImage, type CoverImageProps } from './CoverImage';
|
|
@@ -64,4 +64,37 @@ describe('action object form', () => {
|
|
|
64
64
|
render(<EmptyState title="No results" action={<button type="button">Custom</button>} />);
|
|
65
65
|
expect(screen.getByRole('button', { name: 'Custom' })).toBeInTheDocument();
|
|
66
66
|
});
|
|
67
|
+
|
|
68
|
+
it('routes action hrefs through linkComponent and linkHrefProp', () => {
|
|
69
|
+
const RouterLink = ({ to, children, ...rest }: { to: string; children: React.ReactNode }) => (
|
|
70
|
+
<a href={to} data-to={to} {...rest}>{children}</a>
|
|
71
|
+
);
|
|
72
|
+
render(
|
|
73
|
+
<EmptyState
|
|
74
|
+
title="No results"
|
|
75
|
+
linkComponent={RouterLink}
|
|
76
|
+
linkHrefProp="to"
|
|
77
|
+
action={{ label: 'Create one', href: '/new' }}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
expect(screen.getByRole('link', { name: 'Create one' })).toHaveAttribute('data-to', '/new');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('align and tone', () => {
|
|
85
|
+
it('renders a left-aligned tinted panel', () => {
|
|
86
|
+
const { container } = render(
|
|
87
|
+
<EmptyState align="start" tone="panel" title="No matches" description="Try widening the filters." />
|
|
88
|
+
);
|
|
89
|
+
const root = container.firstChild as HTMLElement;
|
|
90
|
+
expect(root).toHaveClass('items-start', 'text-left', 'bg-muted', 'border-border');
|
|
91
|
+
expect(root).not.toHaveClass('border-dashed');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('keeps the centered dashed default', () => {
|
|
95
|
+
const { container } = render(<EmptyState title="Empty" />);
|
|
96
|
+
const root = container.firstChild as HTMLElement;
|
|
97
|
+
expect(root).toHaveClass('items-center', 'text-center', 'border-dashed');
|
|
98
|
+
expect(root).not.toHaveClass('bg-muted');
|
|
99
|
+
});
|
|
67
100
|
});
|
|
@@ -26,6 +26,18 @@ export type EmptyStateProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
|
26
26
|
titleAs?: 'p' | 'h2' | 'h3' | 'h4';
|
|
27
27
|
/** Compact padding for use inside panels and table bodies. */
|
|
28
28
|
size?: 'sm' | 'md';
|
|
29
|
+
/** Horizontal alignment of content and actions. Default 'center'. */
|
|
30
|
+
align?: 'center' | 'start';
|
|
31
|
+
/**
|
|
32
|
+
* Surface treatment. 'panel' renders a tinted, solid-bordered surface for
|
|
33
|
+
* content pages (typically paired with align="start"); 'plain' keeps the
|
|
34
|
+
* default dashed outline. Default 'plain'.
|
|
35
|
+
*/
|
|
36
|
+
tone?: 'plain' | 'panel';
|
|
37
|
+
/** Custom link element for action hrefs (Next Link, react-router Link). */
|
|
38
|
+
linkComponent?: React.ElementType;
|
|
39
|
+
/** Prop used to pass the destination to `linkComponent`. */
|
|
40
|
+
linkHrefProp?: 'href' | 'to';
|
|
29
41
|
};
|
|
30
42
|
|
|
31
43
|
function isActionObject(value: unknown): value is EmptyStateAction {
|
|
@@ -38,13 +50,19 @@ function isActionObject(value: unknown): value is EmptyStateAction {
|
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
/** Normalizes the node and object forms into a single element. */
|
|
41
|
-
function renderAction(
|
|
53
|
+
function renderAction(
|
|
54
|
+
action: React.ReactNode | EmptyStateAction | undefined,
|
|
55
|
+
linkComponent?: React.ElementType,
|
|
56
|
+
linkHrefProp: 'href' | 'to' = 'href'
|
|
57
|
+
): React.ReactNode {
|
|
42
58
|
if (!isActionObject(action)) return action;
|
|
43
59
|
const { label, onClick, href, variant } = action;
|
|
44
60
|
if (href) {
|
|
61
|
+
const LinkEl = linkComponent ?? 'a';
|
|
62
|
+
const destination = linkHrefProp === 'to' ? { to: href } : { href };
|
|
45
63
|
return (
|
|
46
64
|
<Button variant={variant} asChild>
|
|
47
|
-
<
|
|
65
|
+
<LinkEl {...destination}>{label}</LinkEl>
|
|
48
66
|
</Button>
|
|
49
67
|
);
|
|
50
68
|
}
|
|
@@ -70,18 +88,28 @@ export const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(func
|
|
|
70
88
|
secondaryAction,
|
|
71
89
|
titleAs: Title = 'p',
|
|
72
90
|
size = 'md',
|
|
91
|
+
align = 'center',
|
|
92
|
+
tone = 'plain',
|
|
93
|
+
linkComponent,
|
|
94
|
+
linkHrefProp = 'href',
|
|
73
95
|
className,
|
|
74
96
|
children,
|
|
75
97
|
...props
|
|
76
98
|
},
|
|
77
99
|
ref
|
|
78
100
|
) {
|
|
79
|
-
const primaryAction = renderAction(action) ?? actions;
|
|
101
|
+
const primaryAction = renderAction(action, linkComponent, linkHrefProp) ?? actions;
|
|
102
|
+
const start = align === 'start';
|
|
80
103
|
return (
|
|
81
104
|
<div
|
|
82
105
|
ref={ref}
|
|
83
106
|
className={cn(
|
|
84
|
-
'flex flex-col
|
|
107
|
+
'flex flex-col rounded-lg text-center',
|
|
108
|
+
start ? 'items-start text-left' : 'items-center text-center',
|
|
109
|
+
'justify-center',
|
|
110
|
+
tone === 'panel'
|
|
111
|
+
? 'border border-border bg-muted'
|
|
112
|
+
: 'border border-dashed border-border',
|
|
85
113
|
size === 'md' ? 'gap-3 px-6 py-12' : 'gap-2 px-4 py-6',
|
|
86
114
|
className
|
|
87
115
|
)}
|
|
@@ -89,10 +117,10 @@ export const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(func
|
|
|
89
117
|
>
|
|
90
118
|
{icon && <div className="text-muted-foreground [&_svg]:size-8">{icon}</div>}
|
|
91
119
|
<Title className={cn('font-semibold', size === 'md' ? 'text-base' : 'text-sm')}>{title}</Title>
|
|
92
|
-
{description && <p className=
|
|
120
|
+
{description && <p className={cn('max-w-sm text-sm text-muted-foreground', start && 'max-w-md')}>{description}</p>}
|
|
93
121
|
{children}
|
|
94
122
|
{(primaryAction || secondaryAction) && (
|
|
95
|
-
<div className=
|
|
123
|
+
<div className={cn('mt-1 flex flex-wrap items-center gap-2', start ? 'justify-start' : 'justify-center')}>
|
|
96
124
|
{primaryAction}
|
|
97
125
|
{secondaryAction}
|
|
98
126
|
</div>
|
|
@@ -22,6 +22,8 @@ export type ImageProps = {
|
|
|
22
22
|
className?: string;
|
|
23
23
|
/** Classes for the image when a consumer wants to keep them separate. */
|
|
24
24
|
imgClassName?: string;
|
|
25
|
+
/** Responsive `sizes` hint for the browser's source selection. */
|
|
26
|
+
sizes?: string;
|
|
25
27
|
style?: React.CSSProperties;
|
|
26
28
|
};
|
|
27
29
|
|
|
@@ -43,6 +45,7 @@ export function Image({
|
|
|
43
45
|
height = 630,
|
|
44
46
|
className,
|
|
45
47
|
imgClassName,
|
|
48
|
+
sizes,
|
|
46
49
|
style,
|
|
47
50
|
}: ImageProps) {
|
|
48
51
|
const [stage, setStage] = React.useState<0 | 1 | 2>(0);
|
|
@@ -68,6 +71,7 @@ export function Image({
|
|
|
68
71
|
loading={priority ? 'eager' : 'lazy'}
|
|
69
72
|
fetchPriority={priority ? 'high' : 'auto'}
|
|
70
73
|
decoding="async"
|
|
74
|
+
sizes={sizes}
|
|
71
75
|
className={cn(className, imgClassName)}
|
|
72
76
|
style={style}
|
|
73
77
|
onError={onError}
|
|
@@ -59,4 +59,68 @@ describe('SegmentedControl', () => {
|
|
|
59
59
|
const { container } = render(<ControlledExample />);
|
|
60
60
|
expect(await axe(container)).toHaveNoViolations();
|
|
61
61
|
});
|
|
62
|
+
|
|
63
|
+
it('renders options with href as links and marks the active segment', () => {
|
|
64
|
+
render(
|
|
65
|
+
<SegmentedControl
|
|
66
|
+
aria-label="View"
|
|
67
|
+
value="grid"
|
|
68
|
+
options={[
|
|
69
|
+
{ value: 'list', label: 'List', href: '/items?view=list' },
|
|
70
|
+
{ value: 'grid', label: 'Grid', href: '/items?view=grid' },
|
|
71
|
+
]}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
expect(screen.getByRole('link', { name: 'List' })).toHaveAttribute('href', '/items?view=list');
|
|
75
|
+
expect(screen.queryByRole('link', { name: 'Grid' })).not.toBeInTheDocument();
|
|
76
|
+
expect(screen.getByText('Grid').closest('[aria-current]')).toHaveAttribute('aria-current', 'page');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('honors linkComponent and linkHrefProp', () => {
|
|
80
|
+
const RouterLink = ({ to, children, ...rest }: { to: string; children: React.ReactNode }) => (
|
|
81
|
+
<a href={to} data-to={to} {...rest}>{children}</a>
|
|
82
|
+
);
|
|
83
|
+
render(
|
|
84
|
+
<SegmentedControl
|
|
85
|
+
aria-label="View"
|
|
86
|
+
value="list"
|
|
87
|
+
linkComponent={RouterLink}
|
|
88
|
+
linkHrefProp="to"
|
|
89
|
+
options={[
|
|
90
|
+
{ value: 'list', label: 'List', href: '/items?view=list' },
|
|
91
|
+
{ value: 'grid', label: 'Grid', href: '/items?view=grid' },
|
|
92
|
+
]}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
expect(screen.getByRole('link', { name: 'Grid' })).toHaveAttribute('data-to', '/items?view=grid');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('renders a disabled link option as a non-interactive marker', () => {
|
|
99
|
+
render(
|
|
100
|
+
<SegmentedControl
|
|
101
|
+
aria-label="View"
|
|
102
|
+
value="list"
|
|
103
|
+
options={[
|
|
104
|
+
{ value: 'list', label: 'List', href: '/items?view=list' },
|
|
105
|
+
{ value: 'grid', label: 'Grid', href: '/items?view=grid', disabled: true },
|
|
106
|
+
]}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
expect(screen.queryByRole('link', { name: 'Grid' })).not.toBeInTheDocument();
|
|
110
|
+
expect(screen.getByText('Grid').closest('[aria-disabled]')).toHaveAttribute('aria-disabled', 'true');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('has no accessibility violations in link mode', async () => {
|
|
114
|
+
const { container } = render(
|
|
115
|
+
<SegmentedControl
|
|
116
|
+
aria-label="View"
|
|
117
|
+
value="grid"
|
|
118
|
+
options={[
|
|
119
|
+
{ value: 'list', label: 'List', href: '/items?view=list' },
|
|
120
|
+
{ value: 'grid', label: 'Grid', href: '/items?view=grid' },
|
|
121
|
+
]}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
125
|
+
});
|
|
62
126
|
});
|
|
@@ -9,6 +9,13 @@ export type SegmentedOption = {
|
|
|
9
9
|
/** Optional leading icon. */
|
|
10
10
|
icon?: React.ReactNode;
|
|
11
11
|
disabled?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Destination URL. When set the segment renders as a link instead of a
|
|
14
|
+
* button - use this for view switches that must survive refresh and work
|
|
15
|
+
* without JavaScript. The active segment renders as a non-link
|
|
16
|
+
* `aria-current="page"` marker.
|
|
17
|
+
*/
|
|
18
|
+
href?: string;
|
|
12
19
|
};
|
|
13
20
|
|
|
14
21
|
export type SegmentedControlProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {
|
|
@@ -26,6 +33,10 @@ export type SegmentedControlProps = Omit<React.HTMLAttributes<HTMLDivElement>, '
|
|
|
26
33
|
size?: 'sm' | 'md' | 'lg';
|
|
27
34
|
/** Stretch segments to fill the container width. */
|
|
28
35
|
fullWidth?: boolean;
|
|
36
|
+
/** Custom link element for routers (Next Link, react-router Link). */
|
|
37
|
+
linkComponent?: React.ElementType;
|
|
38
|
+
/** Prop used to pass the destination to `linkComponent`. */
|
|
39
|
+
linkHrefProp?: 'href' | 'to';
|
|
29
40
|
};
|
|
30
41
|
|
|
31
42
|
const sizeClasses = {
|
|
@@ -39,6 +50,12 @@ const sizeClasses = {
|
|
|
39
50
|
* semantics and arrow-key navigation; multiple-select uses pressed buttons.
|
|
40
51
|
* Use it for filters such as All / Investors / Advisors, not for tab panels
|
|
41
52
|
* (use Tabs when each segment owns a tabpanel).
|
|
53
|
+
*
|
|
54
|
+
* Give an option an `href` to render it as a real link - the pattern for
|
|
55
|
+
* view switches that must survive refresh, work without JavaScript, and stay
|
|
56
|
+
* cacheable. The active segment then renders as a non-link
|
|
57
|
+
* `aria-current="page"` marker and link segments use normal tab navigation
|
|
58
|
+
* instead of roving tabindex. Link mode is intended for single-select.
|
|
42
59
|
*/
|
|
43
60
|
export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedControlProps>(
|
|
44
61
|
function SegmentedControl(
|
|
@@ -50,6 +67,8 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
50
67
|
multiple = false,
|
|
51
68
|
size = 'md',
|
|
52
69
|
fullWidth = false,
|
|
70
|
+
linkComponent,
|
|
71
|
+
linkHrefProp = 'href',
|
|
53
72
|
className,
|
|
54
73
|
'aria-label': ariaLabel = 'Segmented control',
|
|
55
74
|
...props
|
|
@@ -75,6 +94,10 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
75
94
|
? current
|
|
76
95
|
: '';
|
|
77
96
|
|
|
97
|
+
const linkMode = options.some((option) => option.href !== undefined);
|
|
98
|
+
const LinkEl = linkComponent ?? 'a';
|
|
99
|
+
const destination = (href: string) => (linkHrefProp === 'to' ? { to: href } : { href });
|
|
100
|
+
|
|
78
101
|
const refs = React.useRef<Array<HTMLButtonElement | null>>([]);
|
|
79
102
|
|
|
80
103
|
const commit = (next: string | string[]) => {
|
|
@@ -137,7 +160,7 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
137
160
|
return (
|
|
138
161
|
<div
|
|
139
162
|
ref={ref}
|
|
140
|
-
role={multiple ? 'group' : 'radiogroup'}
|
|
163
|
+
role={multiple || linkMode ? 'group' : 'radiogroup'}
|
|
141
164
|
aria-label={ariaLabel}
|
|
142
165
|
className={cn(
|
|
143
166
|
'inline-flex items-center gap-1 rounded-lg border border-border bg-muted p-1',
|
|
@@ -152,6 +175,46 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
152
175
|
: selected === option.value;
|
|
153
176
|
const firstEnabled = options.findIndex((entry) => !entry.disabled);
|
|
154
177
|
const focusable = multiple || active || (!selected && index === firstEnabled);
|
|
178
|
+
const segmentClass = cn(
|
|
179
|
+
'inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors',
|
|
180
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
|
181
|
+
'disabled:pointer-events-none disabled:opacity-50',
|
|
182
|
+
sizeClasses[size],
|
|
183
|
+
fullWidth && 'flex-1',
|
|
184
|
+
active
|
|
185
|
+
? 'bg-background text-foreground shadow-sm'
|
|
186
|
+
: 'text-muted-foreground hover:text-foreground'
|
|
187
|
+
);
|
|
188
|
+
const segmentContent = (
|
|
189
|
+
<>
|
|
190
|
+
{option.icon && <span className="shrink-0 [&_svg]:size-4">{option.icon}</span>}
|
|
191
|
+
<span className="truncate">{option.label}</span>
|
|
192
|
+
</>
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
if (option.href !== undefined) {
|
|
196
|
+
if (option.disabled || active) {
|
|
197
|
+
return (
|
|
198
|
+
<span
|
|
199
|
+
key={option.value}
|
|
200
|
+
aria-current={active ? 'page' : undefined}
|
|
201
|
+
aria-disabled={option.disabled || undefined}
|
|
202
|
+
className={cn(segmentClass, option.disabled && 'opacity-50')}
|
|
203
|
+
>
|
|
204
|
+
{segmentContent}
|
|
205
|
+
</span>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
return (
|
|
209
|
+
<LinkEl
|
|
210
|
+
key={option.value}
|
|
211
|
+
{...destination(option.href)}
|
|
212
|
+
className={segmentClass}
|
|
213
|
+
>
|
|
214
|
+
{segmentContent}
|
|
215
|
+
</LinkEl>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
155
218
|
|
|
156
219
|
return (
|
|
157
220
|
<button
|
|
@@ -160,26 +223,17 @@ export const SegmentedControl = React.forwardRef<HTMLDivElement, SegmentedContro
|
|
|
160
223
|
refs.current[index] = node;
|
|
161
224
|
}}
|
|
162
225
|
type="button"
|
|
163
|
-
role={multiple ? undefined : 'radio'}
|
|
164
|
-
aria-checked={multiple ? undefined : active}
|
|
226
|
+
role={multiple || linkMode ? undefined : 'radio'}
|
|
227
|
+
aria-checked={multiple || linkMode ? undefined : active}
|
|
165
228
|
aria-pressed={multiple ? active : undefined}
|
|
229
|
+
aria-current={linkMode && active ? 'page' : undefined}
|
|
166
230
|
disabled={option.disabled}
|
|
167
231
|
tabIndex={focusable ? 0 : -1}
|
|
168
232
|
onClick={() => select(option)}
|
|
169
233
|
onKeyDown={onKeyDown}
|
|
170
|
-
className={
|
|
171
|
-
'inline-flex items-center justify-center gap-2 rounded-md font-medium transition-colors',
|
|
172
|
-
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
|
173
|
-
'disabled:pointer-events-none disabled:opacity-50',
|
|
174
|
-
sizeClasses[size],
|
|
175
|
-
fullWidth && 'flex-1',
|
|
176
|
-
active
|
|
177
|
-
? 'bg-background text-foreground shadow-sm'
|
|
178
|
-
: 'text-muted-foreground hover:text-foreground'
|
|
179
|
-
)}
|
|
234
|
+
className={segmentClass}
|
|
180
235
|
>
|
|
181
|
-
{
|
|
182
|
-
<span className="truncate">{option.label}</span>
|
|
236
|
+
{segmentContent}
|
|
183
237
|
</button>
|
|
184
238
|
);
|
|
185
239
|
})}
|
|
@@ -79,6 +79,24 @@ describe('SiteHeader', () => {
|
|
|
79
79
|
expect(screen.getByRole('dialog', { name: 'Menu' })).toBeInTheDocument();
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
+
it('localizes the mobile trigger and drawer close labels', async () => {
|
|
83
|
+
const user = userEvent.setup();
|
|
84
|
+
render(
|
|
85
|
+
<SiteHeader
|
|
86
|
+
brand={<span>Acme</span>}
|
|
87
|
+
items={items}
|
|
88
|
+
mobileMenuOpenLabel="Abrir menú"
|
|
89
|
+
mobileMenuCloseLabel="Cerrar menú"
|
|
90
|
+
mobileDrawerCloseLabel="Cerrar panel"
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
const trigger = screen.getByRole('button', { name: 'Abrir menú' });
|
|
94
|
+
await user.click(trigger);
|
|
95
|
+
expect(screen.getByRole('button', { name: 'Cerrar menú' })).toBeInTheDocument();
|
|
96
|
+
const drawer = screen.getByRole('dialog', { name: 'Menu' });
|
|
97
|
+
expect(within(drawer).getByRole('button', { name: 'Cerrar panel' })).toBeInTheDocument();
|
|
98
|
+
});
|
|
99
|
+
|
|
82
100
|
it('has no accessibility violations', async () => {
|
|
83
101
|
const { container } = render(<SiteHeader brand={<span>Acme</span>} items={items} activeHref="/docs" />);
|
|
84
102
|
expect(await axe(container)).toHaveNoViolations();
|
|
@@ -68,6 +68,12 @@ export type SiteHeaderProps = React.HTMLAttributes<HTMLElement> & {
|
|
|
68
68
|
sticky?: boolean;
|
|
69
69
|
/** Title of the mobile navigation drawer. Default 'Menu'. */
|
|
70
70
|
mobileLabel?: string;
|
|
71
|
+
/** Accessible name for the mobile menu trigger when closed (default "Open menu"). */
|
|
72
|
+
mobileMenuOpenLabel?: string;
|
|
73
|
+
/** Accessible name for the mobile menu trigger when open (default "Close menu"). */
|
|
74
|
+
mobileMenuCloseLabel?: string;
|
|
75
|
+
/** Accessible name for the mobile drawer close button (default "Close drawer"). */
|
|
76
|
+
mobileDrawerCloseLabel?: string;
|
|
71
77
|
/** Render the built-in mobile trigger and drawer (default true). Set false when the host owns mobile navigation. */
|
|
72
78
|
showMobileTrigger?: boolean;
|
|
73
79
|
/** Breakpoint where the horizontal navigation appears (default 'md'). */
|
|
@@ -128,6 +134,9 @@ export function SiteHeader({
|
|
|
128
134
|
mobileNavLabel = 'Mobile',
|
|
129
135
|
sticky = true,
|
|
130
136
|
mobileLabel = 'Menu',
|
|
137
|
+
mobileMenuOpenLabel = 'Open menu',
|
|
138
|
+
mobileMenuCloseLabel = 'Close menu',
|
|
139
|
+
mobileDrawerCloseLabel = 'Close drawer',
|
|
131
140
|
showMobileTrigger = true,
|
|
132
141
|
desktopBreakpoint = 'md',
|
|
133
142
|
navClassName,
|
|
@@ -324,7 +333,7 @@ export function SiteHeader({
|
|
|
324
333
|
<button
|
|
325
334
|
type="button"
|
|
326
335
|
onClick={() => setMobileOpen((open) => !open)}
|
|
327
|
-
aria-label={mobileOpen ?
|
|
336
|
+
aria-label={mobileOpen ? mobileMenuCloseLabel : mobileMenuOpenLabel}
|
|
328
337
|
aria-expanded={mobileOpen}
|
|
329
338
|
aria-controls={menuId}
|
|
330
339
|
aria-haspopup="dialog"
|
|
@@ -358,6 +367,7 @@ export function SiteHeader({
|
|
|
358
367
|
open={mobileOpen}
|
|
359
368
|
onOpenChange={setMobileOpen}
|
|
360
369
|
title={mobileLabel}
|
|
370
|
+
closeLabel={mobileDrawerCloseLabel}
|
|
361
371
|
side="right"
|
|
362
372
|
size="sm"
|
|
363
373
|
animate
|
|
@@ -35,8 +35,34 @@ describe('StatBand', () => {
|
|
|
35
35
|
expect(screen.getByText('One').parentElement).toHaveClass('items-start', 'text-left');
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
+
it('renders a bordered panel variant with dense cells', () => {
|
|
39
|
+
const { container } = render(
|
|
40
|
+
<StatBand
|
|
41
|
+
variant="panel"
|
|
42
|
+
align="left"
|
|
43
|
+
valueClassName="font-mono"
|
|
44
|
+
items={[
|
|
45
|
+
{ value: '3', label: 'Deadlines', hint: 'closing soon' },
|
|
46
|
+
{ value: '12', label: 'Events' },
|
|
47
|
+
]}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
const dl = container.firstElementChild as HTMLElement;
|
|
51
|
+
expect(dl).toHaveClass('border', 'border-border', 'rounded-lg', 'divide-y', 'sm:divide-x');
|
|
52
|
+
expect(screen.getByText('3')).toHaveClass('font-mono', 'text-xl');
|
|
53
|
+
const label = screen.getByText('Deadlines');
|
|
54
|
+
expect(label).toHaveClass('uppercase');
|
|
55
|
+
});
|
|
56
|
+
|
|
38
57
|
it('has no accessibility violations', async () => {
|
|
39
58
|
const { container } = render(<StatBand items={[{ value: '10+', label: 'Years' }]} />);
|
|
40
59
|
expect(await axe(container)).toHaveNoViolations();
|
|
41
60
|
});
|
|
61
|
+
|
|
62
|
+
it('has no accessibility violations in panel variant', async () => {
|
|
63
|
+
const { container } = render(
|
|
64
|
+
<StatBand variant="panel" items={[{ value: '10+', label: 'Years', hint: 'and counting' }]} />
|
|
65
|
+
);
|
|
66
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
67
|
+
});
|
|
42
68
|
});
|