@roadlittledawn/docs-design-system-react 0.10.0 → 0.11.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/USAGE.md +141 -0
- package/dist/components/Icon.d.ts +52 -0
- package/dist/components/Icon.js +49 -0
- package/dist/components/Icon.stories.d.ts +31 -0
- package/dist/components/Icon.stories.js +141 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/styles.css +11 -0
- package/package.json +1 -1
package/USAGE.md
CHANGED
|
@@ -927,3 +927,144 @@ import {
|
|
|
927
927
|
</TableBody>
|
|
928
928
|
</Table>
|
|
929
929
|
```
|
|
930
|
+
|
|
931
|
+
---
|
|
932
|
+
|
|
933
|
+
## Breadcrumb
|
|
934
|
+
|
|
935
|
+
Breadcrumb navigation component. Renders a `<nav aria-label="Breadcrumb">` with an ordered list of segments. The last item receives `aria-current="page"`. Delimiters are marked `aria-hidden` so screen readers skip them.
|
|
936
|
+
|
|
937
|
+
### Import
|
|
938
|
+
|
|
939
|
+
```tsx
|
|
940
|
+
import { Breadcrumb } from '@roadlittledawn/docs-design-system-react';
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
### Types
|
|
944
|
+
|
|
945
|
+
```ts
|
|
946
|
+
interface BreadcrumbItem {
|
|
947
|
+
label: string; // Display text for the segment
|
|
948
|
+
href?: string; // Optional URL; omit for the current (last) page
|
|
949
|
+
}
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
### Props
|
|
953
|
+
|
|
954
|
+
| Prop | Type | Default | Description |
|
|
955
|
+
|------|------|---------|-------------|
|
|
956
|
+
| `items` | `BreadcrumbItem[]` | — | Ordered list of path segments, root first |
|
|
957
|
+
| `delimiter` | `ReactNode` | `"/"` | Separator between segments. Accepts a string or any ReactNode |
|
|
958
|
+
| `size` | `"sm" \| "md"` | `"md"` | Size variant controlling font size |
|
|
959
|
+
| `collapseOnMobile` | `boolean` | `false` | Collapse middle segments behind an expandable ellipsis on narrow viewports |
|
|
960
|
+
| `scrollOnMobile` | `boolean` | `false` | Let the full trail scroll horizontally instead of wrapping on narrow viewports |
|
|
961
|
+
| `className` | `string` | `""` | Additional CSS classes |
|
|
962
|
+
|
|
963
|
+
### Examples
|
|
964
|
+
|
|
965
|
+
#### Basic
|
|
966
|
+
|
|
967
|
+
```tsx
|
|
968
|
+
<Breadcrumb
|
|
969
|
+
items={[
|
|
970
|
+
{ label: 'Home', href: '/' },
|
|
971
|
+
{ label: 'Docs', href: '/docs' },
|
|
972
|
+
{ label: 'Getting Started' },
|
|
973
|
+
]}
|
|
974
|
+
/>
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
#### Small size with custom delimiter
|
|
978
|
+
|
|
979
|
+
```tsx
|
|
980
|
+
<Breadcrumb
|
|
981
|
+
size="sm"
|
|
982
|
+
delimiter="›"
|
|
983
|
+
items={[
|
|
984
|
+
{ label: 'Home', href: '/' },
|
|
985
|
+
{ label: 'Reference', href: '/reference' },
|
|
986
|
+
{ label: 'API' },
|
|
987
|
+
]}
|
|
988
|
+
/>
|
|
989
|
+
```
|
|
990
|
+
|
|
991
|
+
#### Collapse middle items on mobile
|
|
992
|
+
|
|
993
|
+
```tsx
|
|
994
|
+
<Breadcrumb
|
|
995
|
+
collapseOnMobile
|
|
996
|
+
items={[
|
|
997
|
+
{ label: 'Home', href: '/' },
|
|
998
|
+
{ label: 'Products', href: '/products' },
|
|
999
|
+
{ label: 'Widgets', href: '/products/widgets' },
|
|
1000
|
+
{ label: 'Details' },
|
|
1001
|
+
]}
|
|
1002
|
+
/>
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
---
|
|
1006
|
+
|
|
1007
|
+
## Icon
|
|
1008
|
+
|
|
1009
|
+
Renders an SVG icon without bundling any specific icon library. Accepts a React SVG component (e.g. imported with SVGR or defined inline) or a raw SVG string, making it easy to use your own icon library.
|
|
1010
|
+
|
|
1011
|
+
### Import
|
|
1012
|
+
|
|
1013
|
+
```tsx
|
|
1014
|
+
import { Icon } from '@roadlittledawn/docs-design-system-react';
|
|
1015
|
+
```
|
|
1016
|
+
|
|
1017
|
+
### Props
|
|
1018
|
+
|
|
1019
|
+
| Prop | Type | Default | Description |
|
|
1020
|
+
|------|------|---------|-------------|
|
|
1021
|
+
| `svg` | `React.ComponentType<React.SVGProps<SVGSVGElement>> \| string` | — | SVG to render — accepts a React SVG component or a raw SVG string |
|
|
1022
|
+
| `size` | `number` | `16` | Width and height in pixels |
|
|
1023
|
+
| `className` | `string` | `""` | Additional CSS class names |
|
|
1024
|
+
| `aria-label` | `string` | — | Accessible label. When provided the icon gets `role="img"` and is announced by screen readers. When omitted the icon is decorative (`aria-hidden="true"`) |
|
|
1025
|
+
|
|
1026
|
+
### Examples
|
|
1027
|
+
|
|
1028
|
+
#### React SVG component (SVGR)
|
|
1029
|
+
|
|
1030
|
+
```tsx
|
|
1031
|
+
import { ReactComponent as ChevronIcon } from './chevron.svg';
|
|
1032
|
+
|
|
1033
|
+
<Icon svg={ChevronIcon} size={20} aria-label="Expand" />
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
#### Inline SVG function (define props to forward size/className/aria-*)
|
|
1037
|
+
|
|
1038
|
+
```tsx
|
|
1039
|
+
const StarIcon = (props: React.SVGProps<SVGSVGElement>) => (
|
|
1040
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" {...props}>
|
|
1041
|
+
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
|
|
1042
|
+
</svg>
|
|
1043
|
+
);
|
|
1044
|
+
|
|
1045
|
+
<Icon svg={StarIcon} size={24} />
|
|
1046
|
+
```
|
|
1047
|
+
|
|
1048
|
+
#### Raw SVG string
|
|
1049
|
+
|
|
1050
|
+
```tsx
|
|
1051
|
+
const closeIconSvg = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>`;
|
|
1052
|
+
|
|
1053
|
+
<Icon svg={closeIconSvg} size={24} aria-label="Close" />
|
|
1054
|
+
```
|
|
1055
|
+
|
|
1056
|
+
#### Decorative vs meaningful icons
|
|
1057
|
+
|
|
1058
|
+
```tsx
|
|
1059
|
+
{/* Decorative — hidden from screen readers */}
|
|
1060
|
+
<Icon svg={StarIcon} size={16} />
|
|
1061
|
+
|
|
1062
|
+
{/* Meaningful — announced as "Favorite" */}
|
|
1063
|
+
<Icon svg={StarIcon} size={16} aria-label="Favorite" />
|
|
1064
|
+
```
|
|
1065
|
+
|
|
1066
|
+
### Accessibility notes
|
|
1067
|
+
|
|
1068
|
+
- Do **not** include `aria-hidden`, `role`, or `aria-label` attributes inside your SVG component. The `Icon` component manages all accessibility attributes.
|
|
1069
|
+
- When passing a raw SVG string, do **not** include accessibility attributes in the string itself.
|
|
1070
|
+
- Do **not** pass untrusted or user-supplied SVG strings — the raw string path uses `dangerouslySetInnerHTML` without sanitization.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface IconProps {
|
|
3
|
+
/**
|
|
4
|
+
* SVG to render. Accepts a React SVG component (e.g. imported with SVGR or
|
|
5
|
+
* defined inline) or a raw SVG string.
|
|
6
|
+
*
|
|
7
|
+
* **Accessibility note:** when passing a React SVG component, do not include
|
|
8
|
+
* `aria-hidden`, `role`, or `aria-label` attributes in the component itself.
|
|
9
|
+
* The `Icon` component applies the correct accessibility attributes based on
|
|
10
|
+
* whether an `aria-label` prop is provided.
|
|
11
|
+
*
|
|
12
|
+
* **Security note:** when passing a raw SVG string, ensure the content is
|
|
13
|
+
* from a trusted source. The string is injected via `dangerouslySetInnerHTML`
|
|
14
|
+
* without sanitization.
|
|
15
|
+
*/
|
|
16
|
+
svg: React.ComponentType<React.SVGProps<SVGSVGElement>> | string;
|
|
17
|
+
/**
|
|
18
|
+
* Width and height in pixels.
|
|
19
|
+
* @default 16
|
|
20
|
+
*/
|
|
21
|
+
size?: number;
|
|
22
|
+
/** Additional CSS class names to apply to the icon element. */
|
|
23
|
+
className?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Accessible label for the icon. When provided the icon is announced by
|
|
26
|
+
* screen readers with `role="img"`. When omitted the icon is treated as
|
|
27
|
+
* decorative and hidden from assistive technology (`aria-hidden="true"`).
|
|
28
|
+
*/
|
|
29
|
+
'aria-label'?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Renders an SVG icon. Accepts either a React SVG component (e.g. imported
|
|
33
|
+
* with SVGR) or a raw SVG string, making it easy to use your own icon library
|
|
34
|
+
* without being tied to a specific icon set.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // React SVG component
|
|
38
|
+
* import { ReactComponent as ChevronIcon } from './chevron.svg';
|
|
39
|
+
* <Icon svg={ChevronIcon} size={20} aria-label="Expand" />
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Inline SVG function
|
|
43
|
+
* const StarIcon = (props: React.SVGProps<SVGSVGElement>) => (
|
|
44
|
+
* <svg viewBox="0 0 24 24" {...props}>...</svg>
|
|
45
|
+
* );
|
|
46
|
+
* <Icon svg={StarIcon} size={16} />
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // Raw SVG string
|
|
50
|
+
* <Icon svg='<svg viewBox="0 0 24 24">...</svg>' size={24} />
|
|
51
|
+
*/
|
|
52
|
+
export declare function Icon({ svg, size, className, 'aria-label': ariaLabel, }: IconProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
/**
|
|
14
|
+
* Renders an SVG icon. Accepts either a React SVG component (e.g. imported
|
|
15
|
+
* with SVGR) or a raw SVG string, making it easy to use your own icon library
|
|
16
|
+
* without being tied to a specific icon set.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // React SVG component
|
|
20
|
+
* import { ReactComponent as ChevronIcon } from './chevron.svg';
|
|
21
|
+
* <Icon svg={ChevronIcon} size={20} aria-label="Expand" />
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Inline SVG function
|
|
25
|
+
* const StarIcon = (props: React.SVGProps<SVGSVGElement>) => (
|
|
26
|
+
* <svg viewBox="0 0 24 24" {...props}>...</svg>
|
|
27
|
+
* );
|
|
28
|
+
* <Icon svg={StarIcon} size={16} />
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Raw SVG string
|
|
32
|
+
* <Icon svg='<svg viewBox="0 0 24 24">...</svg>' size={24} />
|
|
33
|
+
*/
|
|
34
|
+
export function Icon(_a) {
|
|
35
|
+
var svg = _a.svg, _b = _a.size, size = _b === void 0 ? 16 : _b, _c = _a.className, className = _c === void 0 ? '' : _c, ariaLabel = _a["aria-label"];
|
|
36
|
+
var isDecorative = !ariaLabel;
|
|
37
|
+
var classNames = ['dds-icon', className].filter(Boolean).join(' ');
|
|
38
|
+
if (typeof svg === 'string') {
|
|
39
|
+
return (_jsx("span", __assign({ className: classNames, style: { width: size, height: size },
|
|
40
|
+
// eslint-disable-next-line react/no-danger
|
|
41
|
+
dangerouslySetInnerHTML: { __html: svg } }, (isDecorative
|
|
42
|
+
? { 'aria-hidden': true }
|
|
43
|
+
: { role: 'img', 'aria-label': ariaLabel }))));
|
|
44
|
+
}
|
|
45
|
+
var SvgComponent = svg;
|
|
46
|
+
return (_jsx(SvgComponent, __assign({ className: classNames, width: size, height: size }, (isDecorative
|
|
47
|
+
? { 'aria-hidden': true }
|
|
48
|
+
: { role: 'img', 'aria-label': ariaLabel }))));
|
|
49
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Icon } from './Icon';
|
|
3
|
+
declare const meta: Meta<typeof Icon>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Icon>;
|
|
6
|
+
/**
|
|
7
|
+
* Pass any React SVG component to the `svg` prop. The component is rendered
|
|
8
|
+
* directly with the provided `size` applied as `width` and `height`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const WithReactComponent: Story;
|
|
11
|
+
/**
|
|
12
|
+
* Pass a raw SVG string to the `svg` prop. The string is injected using
|
|
13
|
+
* `dangerouslySetInnerHTML` — ensure the content is from a trusted source.
|
|
14
|
+
*/
|
|
15
|
+
export declare const WithSvgString: Story;
|
|
16
|
+
/**
|
|
17
|
+
* When an `aria-label` is provided the icon receives `role="img"` and is
|
|
18
|
+
* announced by screen readers with the given label. Use this when the icon
|
|
19
|
+
* conveys meaning without surrounding text.
|
|
20
|
+
*/
|
|
21
|
+
export declare const WithAriaLabel: Story;
|
|
22
|
+
/**
|
|
23
|
+
* Sizes from small (12 px) to large (48 px). The `size` prop sets both
|
|
24
|
+
* `width` and `height` so the icon is always square.
|
|
25
|
+
*/
|
|
26
|
+
export declare const Sizes: Story;
|
|
27
|
+
/**
|
|
28
|
+
* Icons inherit `currentColor` for their stroke/fill, so they automatically
|
|
29
|
+
* adapt to the surrounding text color.
|
|
30
|
+
*/
|
|
31
|
+
export declare const InheritedColor: Story;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Icon } from './Icon';
|
|
14
|
+
// ─── Sample SVG components used in stories ────────────────────────────────────
|
|
15
|
+
// Note: these sample SVG components intentionally omit accessibility attributes
|
|
16
|
+
// (aria-hidden, role, aria-label). The Icon component applies them based on
|
|
17
|
+
// whether an aria-label prop is provided.
|
|
18
|
+
var StarIcon = function (props) { return (_jsx("svg", __assign({ viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, props, { children: _jsx("polygon", { points: "12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" }) }))); };
|
|
19
|
+
var ChevronIcon = function (props) { return (_jsx("svg", __assign({ viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, props, { children: _jsx("polyline", { points: "6 9 12 15 18 9" }) }))); };
|
|
20
|
+
var ExternalLinkIcon = function (props) { return (_jsxs("svg", __assign({ viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, props, { children: [_jsx("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }), _jsx("polyline", { points: "15 3 21 3 21 9" }), _jsx("line", { x1: "10", y1: "14", x2: "21", y2: "3" })] }))); };
|
|
21
|
+
// Raw SVG string example
|
|
22
|
+
var closeIconSvg = "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\"/><line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\"/></svg>";
|
|
23
|
+
// ─── Meta ─────────────────────────────────────────────────────────────────────
|
|
24
|
+
var meta = {
|
|
25
|
+
title: 'Components/Icon',
|
|
26
|
+
component: Icon,
|
|
27
|
+
tags: ['autodocs'],
|
|
28
|
+
decorators: [
|
|
29
|
+
function (Story) { return (_jsx("div", { style: { color: 'var(--dds-tabs-panel-text)' }, children: _jsx(Story, {}) })); },
|
|
30
|
+
],
|
|
31
|
+
argTypes: {
|
|
32
|
+
svg: {
|
|
33
|
+
description: 'SVG to render — accepts a React SVG component or a raw SVG string.',
|
|
34
|
+
control: false,
|
|
35
|
+
},
|
|
36
|
+
size: {
|
|
37
|
+
control: { type: 'number', min: 8, max: 64, step: 2 },
|
|
38
|
+
description: 'Width and height in pixels.',
|
|
39
|
+
table: { defaultValue: { summary: '16' } },
|
|
40
|
+
},
|
|
41
|
+
className: {
|
|
42
|
+
control: 'text',
|
|
43
|
+
description: 'Additional CSS class names.',
|
|
44
|
+
table: { defaultValue: { summary: '""' } },
|
|
45
|
+
},
|
|
46
|
+
'aria-label': {
|
|
47
|
+
control: 'text',
|
|
48
|
+
description: 'Accessible label. When provided the icon is announced by screen readers. When omitted the icon is treated as decorative and hidden from assistive technology.',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
parameters: {
|
|
52
|
+
docs: {
|
|
53
|
+
description: {
|
|
54
|
+
component: "\nThe `Icon` component renders an SVG icon without bundling any specific icon library.\nYou bring your own SVGs \u2014 as a React component or a raw SVG string \u2014 so you are never\nforced to adopt a particular icon set.\n\n## When to Use\n\n- Rendering icons imported with SVGR (e.g. `import { ReactComponent as Star } from './star.svg'`)\n- Rendering inline SVG components defined directly in your code\n- Rendering a trusted raw SVG string from your project's assets\n\n## When Not to Use\n\n- Do not pass untrusted or user-supplied SVG strings; the raw string path uses\n `dangerouslySetInnerHTML` without sanitization.\n- When you only need a decorative shape that can be achieved with CSS alone.\n\n## Accessibility\n\n- Decorative icons (no `aria-label`) automatically receive `aria-hidden=\"true\"` so\n they are ignored by screen readers.\n- Meaningful icons (e.g. a standalone icon button) should receive a descriptive\n `aria-label` so they are announced correctly.\n ",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
export default meta;
|
|
60
|
+
// ─── Stories ──────────────────────────────────────────────────────────────────
|
|
61
|
+
/**
|
|
62
|
+
* Pass any React SVG component to the `svg` prop. The component is rendered
|
|
63
|
+
* directly with the provided `size` applied as `width` and `height`.
|
|
64
|
+
*/
|
|
65
|
+
export var WithReactComponent = {
|
|
66
|
+
args: {
|
|
67
|
+
svg: StarIcon,
|
|
68
|
+
size: 24,
|
|
69
|
+
},
|
|
70
|
+
parameters: {
|
|
71
|
+
docs: {
|
|
72
|
+
source: {
|
|
73
|
+
code: "const StarIcon = (props: React.SVGProps<SVGSVGElement>) => (\n <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" {...props}>\n <polygon points=\"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2\" />\n </svg>\n);\n\n<Icon svg={StarIcon} size={24} />",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Pass a raw SVG string to the `svg` prop. The string is injected using
|
|
80
|
+
* `dangerouslySetInnerHTML` — ensure the content is from a trusted source.
|
|
81
|
+
*/
|
|
82
|
+
export var WithSvgString = {
|
|
83
|
+
args: {
|
|
84
|
+
svg: closeIconSvg,
|
|
85
|
+
size: 24,
|
|
86
|
+
},
|
|
87
|
+
parameters: {
|
|
88
|
+
docs: {
|
|
89
|
+
source: {
|
|
90
|
+
code: "const closeIconSvg = `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\"/><line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\"/></svg>`;\n\n<Icon svg={closeIconSvg} size={24} />",
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* When an `aria-label` is provided the icon receives `role="img"` and is
|
|
97
|
+
* announced by screen readers with the given label. Use this when the icon
|
|
98
|
+
* conveys meaning without surrounding text.
|
|
99
|
+
*/
|
|
100
|
+
export var WithAriaLabel = {
|
|
101
|
+
args: {
|
|
102
|
+
svg: ExternalLinkIcon,
|
|
103
|
+
size: 20,
|
|
104
|
+
'aria-label': 'Opens in a new tab',
|
|
105
|
+
},
|
|
106
|
+
parameters: {
|
|
107
|
+
docs: {
|
|
108
|
+
source: {
|
|
109
|
+
code: "<Icon svg={ExternalLinkIcon} size={20} aria-label=\"Opens in a new tab\" />",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Sizes from small (12 px) to large (48 px). The `size` prop sets both
|
|
116
|
+
* `width` and `height` so the icon is always square.
|
|
117
|
+
*/
|
|
118
|
+
export var Sizes = {
|
|
119
|
+
parameters: {
|
|
120
|
+
docs: {
|
|
121
|
+
source: {
|
|
122
|
+
code: "<Icon svg={ChevronIcon} size={12} />\n<Icon svg={ChevronIcon} size={16} />\n<Icon svg={ChevronIcon} size={20} />\n<Icon svg={ChevronIcon} size={24} />\n<Icon svg={ChevronIcon} size={32} />\n<Icon svg={ChevronIcon} size={48} />",
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
render: function () { return (_jsx("div", { style: { display: 'flex', gap: '1rem', alignItems: 'center' }, children: [12, 16, 20, 24, 32, 48].map(function (size) { return (_jsx(Icon, { svg: ChevronIcon, size: size }, size)); }) })); },
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Icons inherit `currentColor` for their stroke/fill, so they automatically
|
|
130
|
+
* adapt to the surrounding text color.
|
|
131
|
+
*/
|
|
132
|
+
export var InheritedColor = {
|
|
133
|
+
parameters: {
|
|
134
|
+
docs: {
|
|
135
|
+
source: {
|
|
136
|
+
code: "<p style={{ color: '#3b82f6' }}>\n <Icon svg={StarIcon} size={16} /> Blue text with a blue icon\n</p>\n<p style={{ color: '#ef4444' }}>\n <Icon svg={StarIcon} size={16} /> Red text with a red icon\n</p>",
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
render: function () { return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '0.5rem' }, children: [_jsxs("p", { style: { color: '#3b82f6', margin: 0, display: 'flex', alignItems: 'center', gap: '0.375rem', fontFamily: 'sans-serif' }, children: [_jsx(Icon, { svg: StarIcon, size: 16 }), " Blue text with a blue icon"] }), _jsxs("p", { style: { color: '#ef4444', margin: 0, display: 'flex', alignItems: 'center', gap: '0.375rem', fontFamily: 'sans-serif' }, children: [_jsx(Icon, { svg: StarIcon, size: 16 }), " Red text with a red icon"] })] })); },
|
|
141
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/styles.css
CHANGED
|
@@ -2272,4 +2272,15 @@ a.dds-breadcrumb-link:hover {
|
|
|
2272
2272
|
display: flex;
|
|
2273
2273
|
}
|
|
2274
2274
|
}
|
|
2275
|
+
.dds-icon {
|
|
2276
|
+
display: inline-flex;
|
|
2277
|
+
align-items: center;
|
|
2278
|
+
justify-content: center;
|
|
2279
|
+
flex-shrink: 0;
|
|
2280
|
+
}
|
|
2281
|
+
/* Ensure an SVG injected via a raw string fills the container */
|
|
2282
|
+
.dds-icon svg {
|
|
2283
|
+
width: 100%;
|
|
2284
|
+
height: 100%;
|
|
2285
|
+
}
|
|
2275
2286
|
|