@slipstream-ui/core 0.12.1 → 0.14.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/dist/index.d.mts +208 -4
- package/dist/index.d.ts +208 -4
- package/dist/index.js +471 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +463 -11
- 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/consent-banner.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 +1 -1
- 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 +1 -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/figure.manifest.json +105 -0
- 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/icon-button.manifest.json +101 -0
- package/dist/manifests/icon-tile.manifest.json +107 -0
- package/dist/manifests/icon.manifest.json +119 -0
- package/dist/manifests/image.manifest.json +1 -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-toolbar.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/media-card.manifest.json +1 -1
- package/dist/manifests/media.manifest.json +142 -0
- package/dist/manifests/menu.manifest.json +1 -1
- package/dist/manifests/metric-card.manifest.json +1 -1
- package/dist/manifests/month-schedule.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 +1 -1
- 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 +1 -1
- package/dist/manifests/skeleton.manifest.json +1 -1
- package/dist/manifests/social-links.manifest.json +120 -0
- package/dist/manifests/spinner.manifest.json +1 -1
- package/dist/manifests/stat-band.manifest.json +1 -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 +49 -6
- 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/figure/Figure.d.ts +23 -0
- package/dist/src/components/figure/Figure.js +60 -0
- package/dist/src/components/figure/Figure.js.map +1 -0
- package/dist/src/components/figure/Figure.mjs +26 -0
- package/dist/src/components/figure/Figure.mjs.map +1 -0
- package/dist/src/components/figure/index.d.ts +2 -0
- package/dist/src/components/figure/index.js +29 -0
- package/dist/src/components/figure/index.js.map +1 -0
- package/dist/src/components/figure/index.mjs +5 -0
- package/dist/src/components/figure/index.mjs.map +1 -0
- package/dist/src/components/icon/Icon.d.ts +33 -0
- package/dist/src/components/icon/Icon.js +82 -0
- package/dist/src/components/icon/Icon.js.map +1 -0
- package/dist/src/components/icon/Icon.mjs +47 -0
- package/dist/src/components/icon/Icon.mjs.map +1 -0
- package/dist/src/components/icon/index.d.ts +2 -0
- package/dist/src/components/icon/index.js +31 -0
- package/dist/src/components/icon/index.js.map +1 -0
- package/dist/src/components/icon/index.mjs +6 -0
- package/dist/src/components/icon/index.mjs.map +1 -0
- package/dist/src/components/icon-button/IconButton.d.ts +25 -0
- package/dist/src/components/icon-button/IconButton.js +60 -0
- package/dist/src/components/icon-button/IconButton.js.map +1 -0
- package/dist/src/components/icon-button/IconButton.mjs +26 -0
- package/dist/src/components/icon-button/IconButton.mjs.map +1 -0
- package/dist/src/components/icon-button/index.d.ts +2 -0
- package/dist/src/components/icon-button/index.js +29 -0
- package/dist/src/components/icon-button/index.js.map +1 -0
- package/dist/src/components/icon-button/index.mjs +5 -0
- package/dist/src/components/icon-button/index.mjs.map +1 -0
- package/dist/src/components/icon-tile/IconTile.d.ts +23 -0
- package/dist/src/components/icon-tile/IconTile.js +75 -0
- package/dist/src/components/icon-tile/IconTile.js.map +1 -0
- package/dist/src/components/icon-tile/IconTile.mjs +40 -0
- package/dist/src/components/icon-tile/IconTile.mjs.map +1 -0
- package/dist/src/components/icon-tile/index.d.ts +2 -0
- package/dist/src/components/icon-tile/index.js +31 -0
- package/dist/src/components/icon-tile/index.js.map +1 -0
- package/dist/src/components/icon-tile/index.mjs +6 -0
- package/dist/src/components/icon-tile/index.mjs.map +1 -0
- package/dist/src/components/media/Media.d.ts +48 -0
- package/dist/src/components/media/Media.js +97 -0
- package/dist/src/components/media/Media.js.map +1 -0
- package/dist/src/components/media/Media.mjs +63 -0
- package/dist/src/components/media/Media.mjs.map +1 -0
- package/dist/src/components/media/index.d.ts +2 -0
- package/dist/src/components/media/index.js +29 -0
- package/dist/src/components/media/index.js.map +1 -0
- package/dist/src/components/media/index.mjs +5 -0
- package/dist/src/components/media/index.mjs.map +1 -0
- package/dist/src/components/social-links/SocialLinks.d.ts +34 -0
- package/dist/src/components/social-links/SocialLinks.js +69 -0
- package/dist/src/components/social-links/SocialLinks.js.map +1 -0
- package/dist/src/components/social-links/SocialLinks.mjs +35 -0
- package/dist/src/components/social-links/SocialLinks.mjs.map +1 -0
- package/dist/src/components/social-links/index.d.ts +2 -0
- package/dist/src/components/social-links/index.js +29 -0
- package/dist/src/components/social-links/index.js.map +1 -0
- package/dist/src/components/social-links/index.mjs +5 -0
- package/dist/src/components/social-links/index.mjs.map +1 -0
- package/dist/src/components/time-picker/TimePicker.d.ts +31 -2
- package/dist/src/components/time-picker/TimePicker.js +244 -11
- package/dist/src/components/time-picker/TimePicker.js.map +1 -1
- package/dist/src/components/time-picker/TimePicker.mjs +244 -11
- package/dist/src/components/time-picker/TimePicker.mjs.map +1 -1
- package/dist/src/index.d.ts +6 -0
- package/dist/styles-full.css +1 -1
- package/dist/styles.css +1 -1
- package/package.json +4 -4
- package/src/components/figure/Figure.test.tsx +54 -0
- package/src/components/figure/Figure.tsx +38 -0
- package/src/components/figure/index.ts +2 -0
- package/src/components/icon/Icon.test.tsx +70 -0
- package/src/components/icon/Icon.tsx +61 -0
- package/src/components/icon/index.ts +2 -0
- package/src/components/icon-button/IconButton.test.tsx +76 -0
- package/src/components/icon-button/IconButton.tsx +38 -0
- package/src/components/icon-button/index.ts +2 -0
- package/src/components/icon-tile/IconTile.test.tsx +63 -0
- package/src/components/icon-tile/IconTile.tsx +55 -0
- package/src/components/icon-tile/index.ts +2 -0
- package/src/components/media/Media.test.tsx +53 -0
- package/src/components/media/Media.tsx +92 -0
- package/src/components/media/index.ts +2 -0
- package/src/components/social-links/SocialLinks.test.tsx +59 -0
- package/src/components/social-links/SocialLinks.tsx +73 -0
- package/src/components/social-links/index.ts +2 -0
- package/src/components/time-picker/TimePicker.test.tsx +77 -0
- package/src/components/time-picker/TimePicker.tsx +315 -12
- package/src/index.ts +6 -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/consent-banner.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 +1 -1
- 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 +1 -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/figure.manifest.json +105 -0
- 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/icon-button.manifest.json +101 -0
- package/src/manifests/icon-tile.manifest.json +107 -0
- package/src/manifests/icon.manifest.json +119 -0
- package/src/manifests/image.manifest.json +1 -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-toolbar.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/media-card.manifest.json +1 -1
- package/src/manifests/media.manifest.json +142 -0
- package/src/manifests/menu.manifest.json +1 -1
- package/src/manifests/metric-card.manifest.json +1 -1
- package/src/manifests/month-schedule.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 +1 -1
- 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 +1 -1
- package/src/manifests/skeleton.manifest.json +1 -1
- package/src/manifests/social-links.manifest.json +120 -0
- package/src/manifests/spinner.manifest.json +1 -1
- package/src/manifests/stat-band.manifest.json +1 -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 +49 -6
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slipstream-ui/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/michaelmcshinsky/slipstream-ui.git",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"tsup": "^9.0.0",
|
|
58
58
|
"typescript": "^5.3.3",
|
|
59
59
|
"vitest": "^5.0.5",
|
|
60
|
-
"@slipstream-ui/
|
|
61
|
-
"@slipstream-ui/vitest-config": "0.0.1",
|
|
60
|
+
"@slipstream-ui/eslint-config": "0.0.1",
|
|
62
61
|
"@slipstream-ui/tailwind-config": "0.0.1",
|
|
63
|
-
"@slipstream-ui/
|
|
62
|
+
"@slipstream-ui/typescript-config": "0.0.1",
|
|
63
|
+
"@slipstream-ui/vitest-config": "0.0.1"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { axe } from 'jest-axe';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { Figure } from './Figure';
|
|
5
|
+
|
|
6
|
+
describe('Figure', () => {
|
|
7
|
+
it('renders children without a caption', () => {
|
|
8
|
+
render(
|
|
9
|
+
<Figure>
|
|
10
|
+
<img src="/a.png" alt="A thing" />
|
|
11
|
+
</Figure>
|
|
12
|
+
);
|
|
13
|
+
expect(screen.getByRole('img', { name: 'A thing' })).toBeInTheDocument();
|
|
14
|
+
expect(document.querySelector('figcaption')).not.toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('renders caption and credit in figcaption', () => {
|
|
18
|
+
render(
|
|
19
|
+
<Figure caption="The practice floor" credit="Photo: Jane Doe">
|
|
20
|
+
<img src="/a.png" alt="A thing" />
|
|
21
|
+
</Figure>
|
|
22
|
+
);
|
|
23
|
+
const caption = document.querySelector('figcaption');
|
|
24
|
+
expect(caption).toHaveTextContent('The practice floor');
|
|
25
|
+
expect(caption).toHaveTextContent('Photo: Jane Doe');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('applies center alignment', () => {
|
|
29
|
+
render(
|
|
30
|
+
<Figure caption="Centered" align="center">
|
|
31
|
+
<span>media</span>
|
|
32
|
+
</Figure>
|
|
33
|
+
);
|
|
34
|
+
expect(document.querySelector('figcaption')).toHaveClass('text-center');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('forwards className', () => {
|
|
38
|
+
const { container } = render(
|
|
39
|
+
<Figure className="mb-4">
|
|
40
|
+
<span>media</span>
|
|
41
|
+
</Figure>
|
|
42
|
+
);
|
|
43
|
+
expect(container.querySelector('figure')).toHaveClass('mb-4');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('has no accessibility violations', async () => {
|
|
47
|
+
const { container } = render(
|
|
48
|
+
<Figure caption="Caption" credit="Credit">
|
|
49
|
+
<img src="/a.png" alt="Described image" />
|
|
50
|
+
</Figure>
|
|
51
|
+
);
|
|
52
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
|
|
4
|
+
export type FigureProps = React.HTMLAttributes<HTMLElement> & {
|
|
5
|
+
/** Caption rendered in <figcaption> below the media. */
|
|
6
|
+
caption?: React.ReactNode;
|
|
7
|
+
/** Optional credit/source line appended to the caption. */
|
|
8
|
+
credit?: React.ReactNode;
|
|
9
|
+
/** Caption alignment (default 'left'). */
|
|
10
|
+
align?: 'left' | 'center';
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Semantic figure wrapper: media plus an optional caption and credit line.
|
|
15
|
+
* Use for any illustrated or media content that needs a <figcaption>;
|
|
16
|
+
* Media builds on this for aspect-ratio frames.
|
|
17
|
+
*/
|
|
18
|
+
const Figure = React.forwardRef<HTMLElement, FigureProps>(
|
|
19
|
+
({ className, caption, credit, align = 'left', children, ...props }, ref) => (
|
|
20
|
+
<figure ref={ref} className={cn('m-0', className)} {...props}>
|
|
21
|
+
{children}
|
|
22
|
+
{(caption || credit) && (
|
|
23
|
+
<figcaption
|
|
24
|
+
className={cn(
|
|
25
|
+
'mt-2 text-xs text-muted-foreground',
|
|
26
|
+
align === 'center' && 'text-center'
|
|
27
|
+
)}
|
|
28
|
+
>
|
|
29
|
+
{caption}
|
|
30
|
+
{credit && <span className="mt-0.5 block text-muted-foreground/80">{credit}</span>}
|
|
31
|
+
</figcaption>
|
|
32
|
+
)}
|
|
33
|
+
</figure>
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
Figure.displayName = 'Figure';
|
|
37
|
+
|
|
38
|
+
export { Figure };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { axe } from 'jest-axe';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { Icon } from './Icon';
|
|
5
|
+
|
|
6
|
+
const Svg = (props: React.SVGProps<SVGSVGElement>) => (
|
|
7
|
+
<svg data-testid="svg" viewBox="0 0 24 24" {...props} />
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
describe('Icon', () => {
|
|
11
|
+
it('renders children svg at the default md size', () => {
|
|
12
|
+
const { container } = render(
|
|
13
|
+
<Icon>
|
|
14
|
+
<Svg />
|
|
15
|
+
</Icon>
|
|
16
|
+
);
|
|
17
|
+
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
18
|
+
expect(container.firstChild).toHaveClass('[&_svg]:h-4');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('applies size and tone classes', () => {
|
|
22
|
+
const { container } = render(
|
|
23
|
+
<Icon size="lg" tone="success">
|
|
24
|
+
<Svg />
|
|
25
|
+
</Icon>
|
|
26
|
+
);
|
|
27
|
+
expect(container.firstChild).toHaveClass('[&_svg]:h-5', 'text-success-ink');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('renders an icon component via the icon prop', () => {
|
|
31
|
+
render(<Icon icon={Svg} data-testid="icon" />);
|
|
32
|
+
expect(screen.getByTestId('svg')).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('is aria-hidden by default', () => {
|
|
36
|
+
const { container } = render(
|
|
37
|
+
<Icon>
|
|
38
|
+
<Svg />
|
|
39
|
+
</Icon>
|
|
40
|
+
);
|
|
41
|
+
expect(container.firstChild).toHaveAttribute('aria-hidden', 'true');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('exposes role=img with a name when label is set', () => {
|
|
45
|
+
render(
|
|
46
|
+
<Icon label="Verified badge">
|
|
47
|
+
<Svg />
|
|
48
|
+
</Icon>
|
|
49
|
+
);
|
|
50
|
+
expect(screen.getByRole('img', { name: 'Verified badge' })).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('forwards className', () => {
|
|
54
|
+
const { container } = render(
|
|
55
|
+
<Icon className="ml-2">
|
|
56
|
+
<Svg />
|
|
57
|
+
</Icon>
|
|
58
|
+
);
|
|
59
|
+
expect(container.firstChild).toHaveClass('ml-2');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('has no accessibility violations', async () => {
|
|
63
|
+
const { container } = render(
|
|
64
|
+
<Icon label="Star">
|
|
65
|
+
<Svg />
|
|
66
|
+
</Icon>
|
|
67
|
+
);
|
|
68
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { cn } from '../../utils/cn';
|
|
4
|
+
|
|
5
|
+
const iconVariants = cva('inline-flex shrink-0 items-center justify-center [&_svg]:shrink-0', {
|
|
6
|
+
variants: {
|
|
7
|
+
size: {
|
|
8
|
+
sm: '[&_svg]:h-3.5 [&_svg]:w-3.5',
|
|
9
|
+
md: '[&_svg]:h-4 [&_svg]:w-4',
|
|
10
|
+
lg: '[&_svg]:h-5 [&_svg]:w-5',
|
|
11
|
+
xl: '[&_svg]:h-6 [&_svg]:w-6',
|
|
12
|
+
},
|
|
13
|
+
tone: {
|
|
14
|
+
default: 'text-foreground',
|
|
15
|
+
muted: 'text-muted-foreground',
|
|
16
|
+
primary: 'text-primary-ink',
|
|
17
|
+
success: 'text-success-ink',
|
|
18
|
+
warning: 'text-warning-ink',
|
|
19
|
+
info: 'text-info-ink',
|
|
20
|
+
destructive: 'text-destructive',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: {
|
|
24
|
+
size: 'md',
|
|
25
|
+
tone: 'default',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export type IconProps = React.HTMLAttributes<HTMLSpanElement> &
|
|
30
|
+
VariantProps<typeof iconVariants> & {
|
|
31
|
+
/**
|
|
32
|
+
* The SVG to render (any icon component that forwards props to <svg>).
|
|
33
|
+
* Alternatively pass the SVG element as children.
|
|
34
|
+
*/
|
|
35
|
+
icon?: React.ComponentType<React.SVGProps<SVGSVGElement>>;
|
|
36
|
+
/** Accessible name when the icon carries meaning on its own. */
|
|
37
|
+
label?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Consistent sizing and tinting for consumer-supplied icons. Decorative by
|
|
42
|
+
* default (`aria-hidden`); pass `label` to expose the icon to assistive tech
|
|
43
|
+
* when it carries meaning on its own.
|
|
44
|
+
*/
|
|
45
|
+
const Icon = React.forwardRef<HTMLSpanElement, IconProps>(
|
|
46
|
+
({ className, size, tone, icon: IconComponent, label, children, ...props }, ref) => (
|
|
47
|
+
<span
|
|
48
|
+
ref={ref}
|
|
49
|
+
role={label ? 'img' : undefined}
|
|
50
|
+
aria-label={label}
|
|
51
|
+
aria-hidden={label ? undefined : true}
|
|
52
|
+
className={cn(iconVariants({ size, tone }), className)}
|
|
53
|
+
{...props}
|
|
54
|
+
>
|
|
55
|
+
{IconComponent ? <IconComponent aria-hidden="true" focusable="false" /> : children}
|
|
56
|
+
</span>
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
Icon.displayName = 'Icon';
|
|
60
|
+
|
|
61
|
+
export { Icon, iconVariants };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { axe } from 'jest-axe';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { IconButton } from './IconButton';
|
|
6
|
+
|
|
7
|
+
const Svg = (props: React.SVGProps<SVGSVGElement>) => <svg viewBox="0 0 24 24" {...props} />;
|
|
8
|
+
|
|
9
|
+
describe('IconButton', () => {
|
|
10
|
+
it('requires and applies an accessible label', () => {
|
|
11
|
+
render(
|
|
12
|
+
<IconButton label="Delete item">
|
|
13
|
+
<Svg />
|
|
14
|
+
</IconButton>
|
|
15
|
+
);
|
|
16
|
+
expect(screen.getByRole('button', { name: 'Delete item' })).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('uses the square icon size by default', () => {
|
|
20
|
+
render(
|
|
21
|
+
<IconButton label="Menu">
|
|
22
|
+
<Svg />
|
|
23
|
+
</IconButton>
|
|
24
|
+
);
|
|
25
|
+
expect(screen.getByRole('button')).toHaveClass('h-10', 'w-10');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('maps size sm/lg to square dimensions', () => {
|
|
29
|
+
const { rerender } = render(
|
|
30
|
+
<IconButton label="A" size="sm">
|
|
31
|
+
<Svg />
|
|
32
|
+
</IconButton>
|
|
33
|
+
);
|
|
34
|
+
expect(screen.getByRole('button')).toHaveClass('h-8', 'w-8');
|
|
35
|
+
rerender(
|
|
36
|
+
<IconButton label="A" size="lg">
|
|
37
|
+
<Svg />
|
|
38
|
+
</IconButton>
|
|
39
|
+
);
|
|
40
|
+
expect(screen.getByRole('button')).toHaveClass('h-11', 'w-11');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('inherits Button variant and loading behavior', async () => {
|
|
44
|
+
const user = userEvent.setup();
|
|
45
|
+
const onClick = vi.fn();
|
|
46
|
+
render(
|
|
47
|
+
<IconButton label="Refresh" variant="outline" onClick={onClick}>
|
|
48
|
+
<Svg />
|
|
49
|
+
</IconButton>
|
|
50
|
+
);
|
|
51
|
+
const button = screen.getByRole('button', { name: 'Refresh' });
|
|
52
|
+
expect(button).toHaveClass('border');
|
|
53
|
+
await user.click(button);
|
|
54
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('disables and marks aria-busy while loading', () => {
|
|
58
|
+
render(
|
|
59
|
+
<IconButton label="Save" loading>
|
|
60
|
+
<Svg />
|
|
61
|
+
</IconButton>
|
|
62
|
+
);
|
|
63
|
+
const button = screen.getByRole('button', { name: 'Save' });
|
|
64
|
+
expect(button).toBeDisabled();
|
|
65
|
+
expect(button).toHaveAttribute('aria-busy', 'true');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('has no accessibility violations', async () => {
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<IconButton label="Settings">
|
|
71
|
+
<Svg />
|
|
72
|
+
</IconButton>
|
|
73
|
+
);
|
|
74
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import { Button, type ButtonProps } from '../button/Button';
|
|
4
|
+
|
|
5
|
+
export type IconButtonProps = Omit<ButtonProps, 'size'> & {
|
|
6
|
+
/**
|
|
7
|
+
* Accessible name for the icon-only control. Required: an icon button
|
|
8
|
+
* without a label is invisible to screen readers.
|
|
9
|
+
*/
|
|
10
|
+
label: string;
|
|
11
|
+
/** Square edge length. `md` is Button's `icon` size (h-10 w-10). */
|
|
12
|
+
size?: 'sm' | 'md' | 'lg';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const sizeClasses = {
|
|
16
|
+
sm: 'h-8 w-8',
|
|
17
|
+
md: undefined,
|
|
18
|
+
lg: 'h-11 w-11',
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Square icon-only button built on Button's `icon` size. `label` is required
|
|
23
|
+
* and becomes `aria-label`, so the control always has an accessible name.
|
|
24
|
+
*/
|
|
25
|
+
const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
26
|
+
({ className, label, size = 'md', ...props }, ref) => (
|
|
27
|
+
<Button
|
|
28
|
+
ref={ref}
|
|
29
|
+
size="icon"
|
|
30
|
+
aria-label={label}
|
|
31
|
+
className={cn(sizeClasses[size], className)}
|
|
32
|
+
{...props}
|
|
33
|
+
/>
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
IconButton.displayName = 'IconButton';
|
|
37
|
+
|
|
38
|
+
export { IconButton };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { axe } from 'jest-axe';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { IconTile } from './IconTile';
|
|
5
|
+
|
|
6
|
+
const Svg = (props: React.SVGProps<SVGSVGElement>) => <svg viewBox="0 0 24 24" {...props} />;
|
|
7
|
+
|
|
8
|
+
describe('IconTile', () => {
|
|
9
|
+
it('renders children inside a tinted tile', () => {
|
|
10
|
+
const { container } = render(
|
|
11
|
+
<IconTile>
|
|
12
|
+
<Svg />
|
|
13
|
+
</IconTile>
|
|
14
|
+
);
|
|
15
|
+
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
16
|
+
expect(container.firstChild).toHaveClass('bg-muted', 'h-10', 'w-10');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('applies tone and size variants', () => {
|
|
20
|
+
const { container } = render(
|
|
21
|
+
<IconTile tone="success" size="lg">
|
|
22
|
+
<Svg />
|
|
23
|
+
</IconTile>
|
|
24
|
+
);
|
|
25
|
+
expect(container.firstChild).toHaveClass('bg-success/10', 'text-success-ink', 'h-12', 'w-12');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('renders a badge marker when provided', () => {
|
|
29
|
+
render(
|
|
30
|
+
<IconTile badge={3}>
|
|
31
|
+
<Svg />
|
|
32
|
+
</IconTile>
|
|
33
|
+
);
|
|
34
|
+
expect(screen.getByText('3')).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('omits the badge element when badge is not set', () => {
|
|
38
|
+
const { container } = render(
|
|
39
|
+
<IconTile>
|
|
40
|
+
<Svg />
|
|
41
|
+
</IconTile>
|
|
42
|
+
);
|
|
43
|
+
expect(container.querySelector('.absolute')).not.toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('forwards className', () => {
|
|
47
|
+
const { container } = render(
|
|
48
|
+
<IconTile className="mr-2">
|
|
49
|
+
<Svg />
|
|
50
|
+
</IconTile>
|
|
51
|
+
);
|
|
52
|
+
expect(container.firstChild).toHaveClass('mr-2');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('has no accessibility violations', async () => {
|
|
56
|
+
const { container } = render(
|
|
57
|
+
<IconTile tone="warning" badge="!">
|
|
58
|
+
<Svg />
|
|
59
|
+
</IconTile>
|
|
60
|
+
);
|
|
61
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { cn } from '../../utils/cn';
|
|
4
|
+
|
|
5
|
+
const iconTileVariants = cva(
|
|
6
|
+
'relative inline-flex shrink-0 items-center justify-center rounded-lg [&_svg]:shrink-0',
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
tone: {
|
|
10
|
+
default: 'bg-muted text-muted-foreground',
|
|
11
|
+
primary: 'bg-primary/10 text-primary-ink',
|
|
12
|
+
success: 'bg-success/10 text-success-ink',
|
|
13
|
+
warning: 'bg-warning/10 text-warning-ink',
|
|
14
|
+
info: 'bg-info/10 text-info-ink',
|
|
15
|
+
destructive: 'bg-destructive/10 text-destructive',
|
|
16
|
+
},
|
|
17
|
+
size: {
|
|
18
|
+
sm: 'h-8 w-8 [&_svg]:h-4 [&_svg]:w-4',
|
|
19
|
+
md: 'h-10 w-10 [&_svg]:h-5 [&_svg]:w-5',
|
|
20
|
+
lg: 'h-12 w-12 [&_svg]:h-6 [&_svg]:w-6',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: {
|
|
24
|
+
tone: 'default',
|
|
25
|
+
size: 'md',
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export type IconTileProps = React.HTMLAttributes<HTMLSpanElement> &
|
|
31
|
+
VariantProps<typeof iconTileVariants> & {
|
|
32
|
+
/** Optional count or status marker pinned to the tile's top-right corner. */
|
|
33
|
+
badge?: React.ReactNode;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Tinted square surface for an icon — feature bullets, status markers and
|
|
38
|
+
* empty-state accents. `badge` renders a small counter or dot over the
|
|
39
|
+
* corner; tone pairs follow the Alert convention (ink text on a tint).
|
|
40
|
+
*/
|
|
41
|
+
const IconTile = React.forwardRef<HTMLSpanElement, IconTileProps>(
|
|
42
|
+
({ className, tone, size, badge, children, ...props }, ref) => (
|
|
43
|
+
<span ref={ref} className={cn(iconTileVariants({ tone, size }), className)} {...props}>
|
|
44
|
+
{children}
|
|
45
|
+
{badge !== undefined && badge !== null && (
|
|
46
|
+
<span className="absolute -right-1.5 -top-1.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold leading-none text-primary-foreground">
|
|
47
|
+
{badge}
|
|
48
|
+
</span>
|
|
49
|
+
)}
|
|
50
|
+
</span>
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
IconTile.displayName = 'IconTile';
|
|
54
|
+
|
|
55
|
+
export { IconTile, iconTileVariants };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { axe } from 'jest-axe';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { Media } from './Media';
|
|
5
|
+
|
|
6
|
+
describe('Media', () => {
|
|
7
|
+
it('renders an aspect-ratio frame with the default video preset', () => {
|
|
8
|
+
const { container } = render(<Media src="/a.jpg" alt="A photo" />);
|
|
9
|
+
const frame = container.querySelector('.aspect-video');
|
|
10
|
+
expect(frame).toBeInTheDocument();
|
|
11
|
+
expect(frame).toHaveClass('overflow-hidden', 'rounded-lg');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('reserves space for custom aspect ratios', () => {
|
|
15
|
+
const { container } = render(<Media aspect="1/1" src="/a.jpg" alt="Square" />);
|
|
16
|
+
expect(container.querySelector('[style*="aspect-ratio"]')).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('renders src through the Image fallback chain', () => {
|
|
20
|
+
render(<Media src="/a.jpg" alt="A photo" priority sizes="100vw" />);
|
|
21
|
+
const img = screen.getByRole('img', { name: 'A photo' });
|
|
22
|
+
expect(img).toHaveAttribute('src', '/a.jpg');
|
|
23
|
+
expect(img).toHaveAttribute('loading', 'eager');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('renders arbitrary children inside the frame', () => {
|
|
27
|
+
render(
|
|
28
|
+
<Media aspect="video">
|
|
29
|
+
<video data-testid="clip" title="Clip" />
|
|
30
|
+
</Media>
|
|
31
|
+
);
|
|
32
|
+
expect(screen.getByTestId('clip')).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('shows fallback content when src is absent', () => {
|
|
36
|
+
render(<Media fallback={<div data-testid="placeholder">No art</div>} />);
|
|
37
|
+
expect(screen.getByTestId('placeholder')).toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('renders caption and credit via Figure', () => {
|
|
41
|
+
render(<Media src="/a.jpg" alt="A" caption="The floor" credit="Staff" />);
|
|
42
|
+
const caption = document.querySelector('figcaption');
|
|
43
|
+
expect(caption).toHaveTextContent('The floor');
|
|
44
|
+
expect(caption).toHaveTextContent('Staff');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('has no accessibility violations', async () => {
|
|
48
|
+
const { container } = render(
|
|
49
|
+
<Media src="/a.jpg" alt="Described photo" caption="Caption" />
|
|
50
|
+
);
|
|
51
|
+
expect(await axe(container)).toHaveNoViolations();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { cn } from '../../utils/cn';
|
|
3
|
+
import { Figure, type FigureProps } from '../figure/Figure';
|
|
4
|
+
import { Image } from '../image/Image';
|
|
5
|
+
|
|
6
|
+
export type MediaProps = Omit<FigureProps, 'children'> & {
|
|
7
|
+
/**
|
|
8
|
+
* Aspect ratio: 'video' (16:9), 'square' (1:1), 'wide' (2:1), or any CSS
|
|
9
|
+
* aspect-ratio value such as '16/9' or '4/3'. The box reserves space so
|
|
10
|
+
* grids never shift while media loads.
|
|
11
|
+
*/
|
|
12
|
+
aspect?: 'video' | 'square' | 'wide' | string;
|
|
13
|
+
/** Image URL. When set, rendered through Image's fallback chain. */
|
|
14
|
+
src?: string;
|
|
15
|
+
/** Alt text for `src` media (required for meaningful images). */
|
|
16
|
+
alt?: string;
|
|
17
|
+
/** Responsive `sizes` hint forwarded to the image. */
|
|
18
|
+
sizes?: string;
|
|
19
|
+
/** Load eagerly and fetch at high priority for the LCP image. */
|
|
20
|
+
priority?: boolean;
|
|
21
|
+
/** Fallback content when `src` is absent or fails (e.g. a placeholder). */
|
|
22
|
+
fallback?: React.ReactNode;
|
|
23
|
+
/** Arbitrary media (video, embed, illustration) rendered inside the frame. */
|
|
24
|
+
children?: React.ReactNode;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const aspectClasses = {
|
|
28
|
+
video: 'aspect-video',
|
|
29
|
+
square: 'aspect-square',
|
|
30
|
+
wide: 'aspect-[2/1]',
|
|
31
|
+
} as const;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Figure-level media frame: a fixed-aspect box that shows an Image (with its
|
|
35
|
+
* fallback chain) or arbitrary children, plus an optional caption and credit
|
|
36
|
+
* via Figure. Reserves layout space before media loads.
|
|
37
|
+
*/
|
|
38
|
+
const Media = React.forwardRef<HTMLElement, MediaProps>(
|
|
39
|
+
(
|
|
40
|
+
{
|
|
41
|
+
className,
|
|
42
|
+
aspect = 'video',
|
|
43
|
+
src,
|
|
44
|
+
alt = '',
|
|
45
|
+
sizes,
|
|
46
|
+
priority = false,
|
|
47
|
+
fallback,
|
|
48
|
+
caption,
|
|
49
|
+
credit,
|
|
50
|
+
align,
|
|
51
|
+
children,
|
|
52
|
+
...props
|
|
53
|
+
},
|
|
54
|
+
ref
|
|
55
|
+
) => {
|
|
56
|
+
const preset = aspectClasses[aspect as keyof typeof aspectClasses];
|
|
57
|
+
const aspectStyle =
|
|
58
|
+
preset === undefined && typeof aspect === 'string' ? { aspectRatio: aspect } : undefined;
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<Figure
|
|
62
|
+
ref={ref}
|
|
63
|
+
caption={caption}
|
|
64
|
+
credit={credit}
|
|
65
|
+
align={align}
|
|
66
|
+
className={className}
|
|
67
|
+
{...props}
|
|
68
|
+
>
|
|
69
|
+
<div
|
|
70
|
+
className={cn('relative overflow-hidden rounded-lg bg-muted', preset)}
|
|
71
|
+
style={aspectStyle}
|
|
72
|
+
>
|
|
73
|
+
{src ? (
|
|
74
|
+
<Image
|
|
75
|
+
src={src}
|
|
76
|
+
alt={alt}
|
|
77
|
+
priority={priority}
|
|
78
|
+
sizes={sizes}
|
|
79
|
+
fallback={fallback}
|
|
80
|
+
className="h-full w-full object-cover"
|
|
81
|
+
/>
|
|
82
|
+
) : (
|
|
83
|
+
(children ?? fallback)
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
</Figure>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
Media.displayName = 'Media';
|
|
91
|
+
|
|
92
|
+
export { Media };
|