@appdirect/design-system 0.0.22 → 0.0.25
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/README.md +1 -1
- package/dist/Combobox/ADMultiselect.js +91 -0
- package/dist/Combobox/ADMultiselect.tsx +237 -0
- package/dist/Combobox/AutocompleteClearable.js +33 -35
- package/dist/Combobox/AutocompleteClearable.tsx +56 -121
- package/dist/Combobox/SearchableSelect.js +23 -42
- package/dist/Combobox/SearchableSelect.tsx +33 -129
- package/dist/Combobox/Select.js +13 -19
- package/dist/Combobox/Select.tsx +15 -44
- package/dist/Combobox/index.js +1 -1
- package/dist/Combobox/index.ts +2 -2
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +1 -24
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +2 -5
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +15 -22
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +1 -2
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.module.css +2 -9
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +4 -5
- package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +2 -6
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +1 -1
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +1 -1
- package/dist/ComplexComponents/Utilities/CopyButton.js +15 -27
- package/dist/ComplexComponents/Utilities/CopyButton.tsx +35 -49
- package/dist/DESIGN.md +7 -7
- package/dist/DataDisplay/Avatar.js +26 -81
- package/dist/DataDisplay/Avatar.tsx +35 -93
- package/dist/DataDisplay/Pill.js +21 -79
- package/dist/DataDisplay/Pill.tsx +34 -116
- package/dist/Inputs/ColorInput.js +12 -18
- package/dist/Inputs/ColorInput.tsx +13 -41
- package/dist/Inputs/NumberInput.js +15 -50
- package/dist/Inputs/NumberInput.tsx +18 -117
- package/dist/Inputs/Radio.js +1 -1
- package/dist/Inputs/Radio.tsx +1 -1
- package/dist/Inputs/RadioGroup.js +1 -1
- package/dist/Inputs/RadioGroup.tsx +1 -1
- package/dist/Inputs/TextArea.js +12 -18
- package/dist/Inputs/TextArea.tsx +13 -41
- package/dist/Inputs/TextInput.js +12 -18
- package/dist/Inputs/TextInput.tsx +13 -41
- package/dist/Inputs/inputLabel.js +35 -0
- package/dist/Inputs/inputLabel.tsx +83 -0
- package/dist/Layout/Inline.js +5 -42
- package/dist/Layout/Inline.tsx +6 -79
- package/dist/Overlays/Tooltip.js +2 -2
- package/dist/Overlays/Tooltip.tsx +4 -1
- package/dist/contracts/index.json +1 -1
- package/dist/css/foundations.css +44 -2
- package/dist/css/mantine.css +236 -43
- package/dist/css/tokens.css +58 -26
- package/dist/index.js +3 -3
- package/dist/index.ts +4 -4
- package/dist/stories/Combobox/{Multiselect.stories.tsx → ADMultiselect.stories.tsx} +159 -53
- package/dist/stories/Combobox/SearchableSelect.stories.tsx +3 -3
- package/dist/stories/Combobox/Select.stories.tsx +1 -1
- package/dist/stories/ComplexComponents/Utilities/CopyButton.stories.tsx +4 -14
- package/dist/stories/Inputs/ColorInput.stories.tsx +12 -0
- package/dist/stories/Inputs/NumberInput.stories.tsx +12 -0
- package/dist/stories/Inputs/Radio.stories.tsx +10 -5
- package/dist/stories/Inputs/RadioGroup.stories.tsx +122 -80
- package/dist/stories/Inputs/TextArea.stories.tsx +12 -0
- package/dist/stories/Inputs/TextInput.stories.tsx +12 -0
- package/dist/stories/index.json +42 -35
- package/package.json +10 -6
- package/dist/Combobox/Multiselect.js +0 -31
- package/dist/Combobox/Multiselect.tsx +0 -158
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React
|
|
4
|
-
import { ActionIcon } from '@mantine/core';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { ActionIcon, CopyButton as MantineCopyButton } from '@mantine/core';
|
|
5
5
|
import { Tooltip } from '../../Overlays/Tooltip';
|
|
6
6
|
import { RiFileCopyLine } from '@remixicon/react';
|
|
7
7
|
|
|
@@ -10,36 +10,30 @@ export interface CopyButtonProps {
|
|
|
10
10
|
value: string;
|
|
11
11
|
/** Label for accessibility and tooltip context */
|
|
12
12
|
label: string;
|
|
13
|
-
/**
|
|
13
|
+
/** Called with the value after it has been copied (for analytics or toasts; copying is already done) */
|
|
14
14
|
onCopy?: (value: string) => void;
|
|
15
15
|
/** Size of the copy icon */
|
|
16
16
|
iconSize?: number;
|
|
17
|
+
/** Time in ms the "Copied" state stays visible */
|
|
18
|
+
timeout?: number;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* CopyButton Component
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
*
|
|
24
|
+
* Built on Mantine's `CopyButton`: clicking writes `value` to the clipboard and the
|
|
25
|
+
* tooltip switches from "Copy" to "Copied" for `timeout` ms.
|
|
26
|
+
*
|
|
25
27
|
* @example
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* value="Production"
|
|
29
|
-
* label="Environment"
|
|
30
|
-
* onCopy={(value) => navigator.clipboard.writeText(value)}
|
|
31
|
-
* />
|
|
32
|
-
*
|
|
28
|
+
* <CopyButton value="Production" label="Environment" />
|
|
29
|
+
*
|
|
33
30
|
* @example
|
|
34
|
-
* // With custom icon size
|
|
31
|
+
* // With custom icon size and a callback
|
|
35
32
|
* <CopyButton
|
|
36
33
|
* value="sk-1234567890abcdef"
|
|
37
34
|
* label="API Key"
|
|
38
35
|
* iconSize={16}
|
|
39
|
-
* onCopy={(
|
|
40
|
-
* navigator.clipboard.writeText(value);
|
|
41
|
-
* console.log('API Key copied');
|
|
42
|
-
* }}
|
|
36
|
+
* onCopy={() => console.log('API Key copied')}
|
|
43
37
|
* />
|
|
44
38
|
*/
|
|
45
39
|
export function CopyButton({
|
|
@@ -47,36 +41,28 @@ export function CopyButton({
|
|
|
47
41
|
label,
|
|
48
42
|
onCopy,
|
|
49
43
|
iconSize = 24,
|
|
44
|
+
timeout = 1500,
|
|
50
45
|
}: CopyButtonProps) {
|
|
51
|
-
const [isCopied, setIsCopied] = useState(false);
|
|
52
|
-
|
|
53
|
-
const handleCopy = () => {
|
|
54
|
-
if (onCopy) {
|
|
55
|
-
onCopy(value);
|
|
56
|
-
setIsCopied(true);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const handleMouseLeave = () => {
|
|
61
|
-
setIsCopied(false);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
46
|
return (
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
47
|
+
<MantineCopyButton value={value} timeout={timeout}>
|
|
48
|
+
{({ copied, copy }) => (
|
|
49
|
+
<Tooltip label={copied ? 'Copied' : 'Copy'} position="top" withArrow>
|
|
50
|
+
<ActionIcon
|
|
51
|
+
variant="subtle"
|
|
52
|
+
// Numeric size on purpose: t-shirt sizes get a token rule that pins the svg size,
|
|
53
|
+
// which would override `iconSize`. The button is the icon plus 4px padding per side.
|
|
54
|
+
size={iconSize + 8}
|
|
55
|
+
c="blue"
|
|
56
|
+
onClick={() => {
|
|
57
|
+
copy();
|
|
58
|
+
onCopy?.(value);
|
|
59
|
+
}}
|
|
60
|
+
aria-label={`Copy ${label}`}
|
|
61
|
+
>
|
|
62
|
+
<RiFileCopyLine size={iconSize} />
|
|
63
|
+
</ActionIcon>
|
|
64
|
+
</Tooltip>
|
|
65
|
+
)}
|
|
66
|
+
</MantineCopyButton>
|
|
81
67
|
);
|
|
82
|
-
}
|
|
68
|
+
}
|
package/dist/DESIGN.md
CHANGED
|
@@ -353,9 +353,9 @@ All inputs default to `radius="sm"` and `size="sm"` matching the button default.
|
|
|
353
353
|
|
|
354
354
|
### Combobox
|
|
355
355
|
|
|
356
|
-
`Select` · `SearchableSelect` · `AutocompleteClearable` · `
|
|
356
|
+
`Select` · `SearchableSelect` · `AutocompleteClearable` · `ADMultiselect` · `Combobox`
|
|
357
357
|
|
|
358
|
-
`SearchableSelect` and `AutocompleteClearable` are opinionated wrappers with built-in clear affordance. Use `
|
|
358
|
+
`SearchableSelect` and `AutocompleteClearable` are opinionated wrappers with built-in clear affordance. Use `ADMultiselect` for tag-style multi-value selection.
|
|
359
359
|
|
|
360
360
|
**Toolbar vs tag-editor chips** — in dense table toolbars, multi-select values belong in the **chip row above the table**, with a **count** in the control (see **DataTable patterns**). Do not pile chips inside the combobox there; it breaks horizontal layouts. Standalone tag editors (e.g. form fields that edit a list of tags) may keep chips in the field.
|
|
361
361
|
|
|
@@ -640,11 +640,11 @@ Do **not** import `tokens.css` in Mantine apps (duplicates foundations; unused b
|
|
|
640
640
|
|
|
641
641
|
| Package | Version | Role |
|
|
642
642
|
|---|---|---|
|
|
643
|
-
| `@mantine/core` | `^9.
|
|
644
|
-
| `@mantine/hooks` | `^9.
|
|
645
|
-
| `@mantine/dates` | `^9.
|
|
646
|
-
| `@mantine/notifications` | `^9.
|
|
647
|
-
| `@mantine/dropzone` | `^9.
|
|
643
|
+
| `@mantine/core` | `^9.8.2` | Base component library (peer of `@appdirect/design-system`) |
|
|
644
|
+
| `@mantine/hooks` | `^9.8.2` | Utility hooks (useDisclosure, etc.) |
|
|
645
|
+
| `@mantine/dates` | `^9.8.2` | Date/time inputs |
|
|
646
|
+
| `@mantine/notifications` | `^9.8.2` | Do not use in apps — prefer micro-container `ad-toast` (see Alert vs Notification) |
|
|
647
|
+
| `@mantine/dropzone` | `^9.8.2` | File drag-and-drop |
|
|
648
648
|
| `@appdirect/design-tokens` | `^0.0.6` | AppDirect token CSS variables (`--ad-*`) |
|
|
649
649
|
| `@tabler/icons-react` | `^3.33.0` | Icon library (supplementary) |
|
|
650
650
|
| `@remixicon/react` | `^4.6.0` | Primary icon library; default avatar icon |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import React, { forwardRef,
|
|
3
|
+
import React, { forwardRef, useEffect } from 'react';
|
|
4
4
|
import { Avatar as MantineAvatar } from '@mantine/core';
|
|
5
5
|
import { RiUser3Fill } from '@remixicon/react';
|
|
6
6
|
// ========================== CONSTANTS ==========================
|
|
@@ -24,7 +24,8 @@ const ICON_SIZES = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Avatar Component
|
|
26
26
|
*
|
|
27
|
-
* Built on top of Mantine's Avatar component with design system styling.
|
|
27
|
+
* Built on top of Mantine's Avatar component with design system styling. Image load
|
|
28
|
+
* failures fall back to the placeholder content (icon or initials) via Mantine core.
|
|
28
29
|
* Supports three variants: icon, image, and initials with all Mantine t-shirt sizes.
|
|
29
30
|
*
|
|
30
31
|
* @example
|
|
@@ -59,52 +60,19 @@ const ICON_SIZES = {
|
|
|
59
60
|
* />
|
|
60
61
|
*/
|
|
61
62
|
export const Avatar = forwardRef(({ variant, size = 'md', src, alt, initials, icon, fallback = 'icon', fallbackInitials, ...props }, ref) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return true;
|
|
68
|
-
try {
|
|
69
|
-
const hostname = new URL(url, 'https://local.invalid').hostname;
|
|
70
|
-
if (hostname === 'example.com' || hostname.endsWith('.example.com'))
|
|
71
|
-
return true;
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (process.env.NODE_ENV !== 'development')
|
|
65
|
+
return;
|
|
66
|
+
if (variant === 'image' && !src) {
|
|
67
|
+
console.warn('Avatar: src is required when variant is "image"');
|
|
72
68
|
}
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
if (variant === 'initials' && !initials) {
|
|
70
|
+
console.warn('Avatar: initials is required when variant is "initials"');
|
|
75
71
|
}
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
return false;
|
|
79
|
-
};
|
|
80
|
-
// Reset image error when src changes
|
|
81
|
-
React.useEffect(() => {
|
|
82
|
-
if (src && isInvalidUrl(src)) {
|
|
83
|
-
setImageError(true);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
setImageError(false);
|
|
72
|
+
if (variant === 'initials' && initials && initials.length !== 2) {
|
|
73
|
+
console.warn('Avatar: initials should be exactly 2 characters');
|
|
87
74
|
}
|
|
88
|
-
}, [src]);
|
|
89
|
-
// Handle image load error
|
|
90
|
-
const handleImageError = useCallback(() => {
|
|
91
|
-
setImageError(true);
|
|
92
|
-
}, []);
|
|
93
|
-
if (process.env.NODE_ENV === 'development') {
|
|
94
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
95
|
-
React.useEffect(() => {
|
|
96
|
-
if (variant === 'image' && !src) {
|
|
97
|
-
console.warn('Avatar: src is required when variant is "image"');
|
|
98
|
-
}
|
|
99
|
-
if (variant === 'initials' && !initials) {
|
|
100
|
-
console.warn('Avatar: initials is required when variant is "initials"');
|
|
101
|
-
}
|
|
102
|
-
if (variant === 'initials' && initials && initials.length !== 2) {
|
|
103
|
-
console.warn('Avatar: initials should be exactly 2 characters');
|
|
104
|
-
}
|
|
105
|
-
}, [variant, src, initials]);
|
|
106
|
-
}
|
|
107
|
-
// Render icon content
|
|
75
|
+
}, [variant, src, initials]);
|
|
108
76
|
const renderIcon = () => {
|
|
109
77
|
const iconSize = ICON_SIZES[size];
|
|
110
78
|
if (icon) {
|
|
@@ -117,41 +85,18 @@ export const Avatar = forwardRef(({ variant, size = 'md', src, alt, initials, ic
|
|
|
117
85
|
}
|
|
118
86
|
return _jsx(RiUser3Fill, { size: iconSize, color: "var(--ad-color-text-default)" });
|
|
119
87
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
? renderInitials(fallbackInitials)
|
|
134
|
-
: renderIcon(),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
// Only try to load image if we have src and no error yet
|
|
138
|
-
return {
|
|
139
|
-
src: src,
|
|
140
|
-
alt: alt,
|
|
141
|
-
onError: handleImageError,
|
|
142
|
-
};
|
|
143
|
-
case 'initials':
|
|
144
|
-
return {
|
|
145
|
-
children: initials ? renderInitials(initials) : '??',
|
|
146
|
-
};
|
|
147
|
-
case 'icon':
|
|
148
|
-
default:
|
|
149
|
-
return {
|
|
150
|
-
children: renderIcon(),
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
const avatarContent = getAvatarContent();
|
|
155
|
-
return (_jsx(MantineAvatar, { ref: ref, size: AVATAR_SIZES[size], radius: 1000, ...avatarContent, ...props }));
|
|
88
|
+
const renderInitials = (text) => text.substring(0, 2).toUpperCase();
|
|
89
|
+
// Mantine renders `children` whenever there is no `src` or the image fails to load.
|
|
90
|
+
let placeholder;
|
|
91
|
+
if (variant === 'initials') {
|
|
92
|
+
placeholder = initials ? renderInitials(initials) : '??';
|
|
93
|
+
}
|
|
94
|
+
else if (variant === 'image' && fallback === 'initials' && fallbackInitials) {
|
|
95
|
+
placeholder = renderInitials(fallbackInitials);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
placeholder = renderIcon();
|
|
99
|
+
}
|
|
100
|
+
return (_jsx(MantineAvatar, { ref: ref, size: AVATAR_SIZES[size], radius: 1000, src: variant === 'image' ? src : undefined, alt: alt, ...props, children: placeholder }));
|
|
156
101
|
});
|
|
157
102
|
Avatar.displayName = 'Avatar';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { forwardRef,
|
|
3
|
+
import React, { forwardRef, useEffect } from 'react';
|
|
4
4
|
import { Avatar as MantineAvatar, AvatarProps as MantineAvatarProps } from '@mantine/core';
|
|
5
5
|
import { RiUser3Fill } from '@remixicon/react';
|
|
6
6
|
|
|
@@ -53,7 +53,8 @@ const ICON_SIZES = {
|
|
|
53
53
|
/**
|
|
54
54
|
* Avatar Component
|
|
55
55
|
*
|
|
56
|
-
* Built on top of Mantine's Avatar component with design system styling.
|
|
56
|
+
* Built on top of Mantine's Avatar component with design system styling. Image load
|
|
57
|
+
* failures fall back to the placeholder content (icon or initials) via Mantine core.
|
|
57
58
|
* Supports three variants: icon, image, and initials with all Mantine t-shirt sizes.
|
|
58
59
|
*
|
|
59
60
|
* @example
|
|
@@ -88,7 +89,7 @@ const ICON_SIZES = {
|
|
|
88
89
|
* />
|
|
89
90
|
*/
|
|
90
91
|
export const Avatar = forwardRef<HTMLDivElement, DSAvatarProps>(
|
|
91
|
-
({
|
|
92
|
+
({
|
|
92
93
|
variant,
|
|
93
94
|
size = 'md',
|
|
94
95
|
src,
|
|
@@ -97,120 +98,61 @@ export const Avatar = forwardRef<HTMLDivElement, DSAvatarProps>(
|
|
|
97
98
|
icon,
|
|
98
99
|
fallback = 'icon',
|
|
99
100
|
fallbackInitials,
|
|
100
|
-
...props
|
|
101
|
+
...props
|
|
101
102
|
}, ref) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// Check if URL is obviously invalid
|
|
107
|
-
const isInvalidUrl = (url: string) => {
|
|
108
|
-
if (!url || url.trim() === '') return true;
|
|
109
|
-
try {
|
|
110
|
-
const hostname = new URL(url, 'https://local.invalid').hostname;
|
|
111
|
-
if (hostname === 'example.com' || hostname.endsWith('.example.com')) return true;
|
|
112
|
-
} catch {
|
|
113
|
-
return true;
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (process.env.NODE_ENV !== 'development') return;
|
|
105
|
+
if (variant === 'image' && !src) {
|
|
106
|
+
console.warn('Avatar: src is required when variant is "image"');
|
|
114
107
|
}
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// Reset image error when src changes
|
|
120
|
-
React.useEffect(() => {
|
|
121
|
-
if (src && isInvalidUrl(src)) {
|
|
122
|
-
setImageError(true);
|
|
123
|
-
} else {
|
|
124
|
-
setImageError(false);
|
|
108
|
+
if (variant === 'initials' && !initials) {
|
|
109
|
+
console.warn('Avatar: initials is required when variant is "initials"');
|
|
125
110
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
setImageError(true);
|
|
131
|
-
}, []);
|
|
132
|
-
|
|
133
|
-
if (process.env.NODE_ENV === 'development') {
|
|
134
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
135
|
-
React.useEffect(() => {
|
|
136
|
-
if (variant === 'image' && !src) {
|
|
137
|
-
console.warn('Avatar: src is required when variant is "image"');
|
|
138
|
-
}
|
|
139
|
-
if (variant === 'initials' && !initials) {
|
|
140
|
-
console.warn('Avatar: initials is required when variant is "initials"');
|
|
141
|
-
}
|
|
142
|
-
if (variant === 'initials' && initials && initials.length !== 2) {
|
|
143
|
-
console.warn('Avatar: initials should be exactly 2 characters');
|
|
144
|
-
}
|
|
145
|
-
}, [variant, src, initials]);
|
|
146
|
-
}
|
|
111
|
+
if (variant === 'initials' && initials && initials.length !== 2) {
|
|
112
|
+
console.warn('Avatar: initials should be exactly 2 characters');
|
|
113
|
+
}
|
|
114
|
+
}, [variant, src, initials]);
|
|
147
115
|
|
|
148
|
-
// Render icon content
|
|
149
116
|
const renderIcon = () => {
|
|
150
117
|
const iconSize = ICON_SIZES[size];
|
|
151
|
-
|
|
118
|
+
|
|
152
119
|
if (icon) {
|
|
153
|
-
return React.isValidElement(icon)
|
|
154
|
-
? React.cloneElement(icon as React.ReactElement
|
|
120
|
+
return React.isValidElement(icon)
|
|
121
|
+
? React.cloneElement(icon as React.ReactElement<{ size?: number; color?: string }>, {
|
|
155
122
|
size: iconSize,
|
|
156
123
|
color: 'var(--ad-color-text-default)',
|
|
157
124
|
})
|
|
158
125
|
: icon;
|
|
159
126
|
}
|
|
160
|
-
|
|
161
|
-
return <RiUser3Fill size={iconSize} color="var(--ad-color-text-default)" />;
|
|
162
|
-
};
|
|
163
127
|
|
|
164
|
-
|
|
165
|
-
const renderInitials = (text: string) => {
|
|
166
|
-
return text.substring(0, 2).toUpperCase();
|
|
128
|
+
return <RiUser3Fill size={iconSize} color="var(--ad-color-text-default)" />;
|
|
167
129
|
};
|
|
168
130
|
|
|
169
|
-
|
|
170
|
-
const getAvatarContent = () => {
|
|
171
|
-
switch (variant) {
|
|
172
|
-
case 'image':
|
|
173
|
-
// For image variant, always check if we should show fallback first
|
|
174
|
-
if (!src || imageError) {
|
|
175
|
-
// Show fallback content instead of trying to load image
|
|
176
|
-
return {
|
|
177
|
-
children: fallback === 'initials' && fallbackInitials
|
|
178
|
-
? renderInitials(fallbackInitials)
|
|
179
|
-
: renderIcon(),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
// Only try to load image if we have src and no error yet
|
|
183
|
-
return {
|
|
184
|
-
src: src,
|
|
185
|
-
alt: alt,
|
|
186
|
-
onError: handleImageError,
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
case 'initials':
|
|
190
|
-
return {
|
|
191
|
-
children: initials ? renderInitials(initials) : '??',
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
case 'icon':
|
|
195
|
-
default:
|
|
196
|
-
return {
|
|
197
|
-
children: renderIcon(),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
};
|
|
131
|
+
const renderInitials = (text: string) => text.substring(0, 2).toUpperCase();
|
|
201
132
|
|
|
202
|
-
|
|
133
|
+
// Mantine renders `children` whenever there is no `src` or the image fails to load.
|
|
134
|
+
let placeholder: React.ReactNode;
|
|
135
|
+
if (variant === 'initials') {
|
|
136
|
+
placeholder = initials ? renderInitials(initials) : '??';
|
|
137
|
+
} else if (variant === 'image' && fallback === 'initials' && fallbackInitials) {
|
|
138
|
+
placeholder = renderInitials(fallbackInitials);
|
|
139
|
+
} else {
|
|
140
|
+
placeholder = renderIcon();
|
|
141
|
+
}
|
|
203
142
|
|
|
204
143
|
return (
|
|
205
144
|
<MantineAvatar
|
|
206
145
|
ref={ref}
|
|
207
146
|
size={AVATAR_SIZES[size]}
|
|
208
147
|
radius={1000} // Perfect circle - large enough radius to ensure circular shape at all sizes
|
|
209
|
-
{
|
|
148
|
+
src={variant === 'image' ? src : undefined}
|
|
149
|
+
alt={alt}
|
|
210
150
|
{...props}
|
|
211
|
-
|
|
151
|
+
>
|
|
152
|
+
{placeholder}
|
|
153
|
+
</MantineAvatar>
|
|
212
154
|
);
|
|
213
155
|
}
|
|
214
156
|
);
|
|
215
157
|
|
|
216
|
-
Avatar.displayName = 'Avatar';
|
|
158
|
+
Avatar.displayName = 'Avatar';
|
package/dist/DataDisplay/Pill.js
CHANGED
|
@@ -1,81 +1,23 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx
|
|
3
|
-
import { forwardRef } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
gap: 6,
|
|
24
|
-
closeSize: 14,
|
|
25
|
-
},
|
|
26
|
-
md: {
|
|
27
|
-
height: 25,
|
|
28
|
-
fontSize: 14,
|
|
29
|
-
lineHeight: 14,
|
|
30
|
-
letterSpacing: 0.2184,
|
|
31
|
-
px: 11.2,
|
|
32
|
-
gap: 8,
|
|
33
|
-
closeSize: 25,
|
|
34
|
-
},
|
|
35
|
-
lg: {
|
|
36
|
-
height: 32,
|
|
37
|
-
fontSize: 13,
|
|
38
|
-
lineHeight: 14,
|
|
39
|
-
letterSpacing: 0.2,
|
|
40
|
-
px: 12,
|
|
41
|
-
gap: 8,
|
|
42
|
-
closeSize: 18,
|
|
43
|
-
},
|
|
44
|
-
xl: {
|
|
45
|
-
height: 36,
|
|
46
|
-
fontSize: 14,
|
|
47
|
-
lineHeight: 16,
|
|
48
|
-
letterSpacing: 0.22,
|
|
49
|
-
px: 14,
|
|
50
|
-
gap: 8,
|
|
51
|
-
closeSize: 20,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
export const Pill = forwardRef(({ children, size = 'md', withRemoveButton = false, onRemove, style, ...others }, ref) => {
|
|
55
|
-
const config = sizeConfig[size];
|
|
56
|
-
const colors = {
|
|
57
|
-
backgroundColor: 'var(--ad-color-bg-subtle)',
|
|
58
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
59
|
-
border: 'none',
|
|
60
|
-
};
|
|
61
|
-
return (_jsx(Box, { ref: ref, style: {
|
|
62
|
-
display: 'inline-flex',
|
|
63
|
-
alignItems: 'center',
|
|
64
|
-
height: config.height,
|
|
65
|
-
paddingLeft: config.px,
|
|
66
|
-
paddingRight: withRemoveButton ? 0 : config.px,
|
|
67
|
-
borderRadius: config.height / 2,
|
|
68
|
-
fontSize: config.fontSize,
|
|
69
|
-
fontWeight: 400,
|
|
70
|
-
lineHeight: `${config.lineHeight}px`,
|
|
71
|
-
letterSpacing: config.letterSpacing,
|
|
72
|
-
userSelect: 'none',
|
|
73
|
-
...colors,
|
|
74
|
-
...style,
|
|
75
|
-
}, ...others, children: _jsxs(Inline, { gap: config.gap, wrap: "nowrap", children: [_jsx("span", { children: children }), withRemoveButton && (_jsx(CloseButton, { size: config.closeSize, onClick: onRemove, variant: "transparent", style: {
|
|
76
|
-
color: 'currentColor',
|
|
77
|
-
minWidth: config.closeSize,
|
|
78
|
-
minHeight: config.closeSize,
|
|
79
|
-
}, "aria-label": "Remove" }))] }) }));
|
|
80
|
-
});
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { Pill as MantinePill } from '@mantine/core';
|
|
5
|
+
// ========================== COMPONENT ==========================
|
|
6
|
+
/**
|
|
7
|
+
* AppDirect Design System Pill Component
|
|
8
|
+
*
|
|
9
|
+
* A thin wrapper over Mantine's Pill. Colors, radius, height and font size
|
|
10
|
+
* come from the `pill` / `multiselect.pill` component tokens, not from this file.
|
|
11
|
+
*
|
|
12
|
+
* Inside a `PillsInput` / `MultiSelect`, pass `size` explicitly so the pill
|
|
13
|
+
* matches the field: the DS default of `md` takes precedence over the size
|
|
14
|
+
* Mantine would otherwise inherit from the field.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <Pill>Design</Pill>
|
|
19
|
+
* <Pill withRemoveButton onRemove={() => remove('design')}>Design</Pill>
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const Pill = forwardRef(({ size = 'md', removeButtonProps, ...props }, ref) => (_jsx(MantinePill, { ref: ref, size: size, removeButtonProps: { 'aria-label': 'Remove', ...removeButtonProps }, ...props })));
|
|
81
23
|
Pill.displayName = 'Pill';
|