@appdirect/design-system 0.0.23 → 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/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/Utilities/CopyButton.js +15 -27
- package/dist/ComplexComponents/Utilities/CopyButton.tsx +35 -49
- package/dist/DESIGN.md +2 -2
- 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 +12 -36
- package/dist/Inputs/NumberInput.tsx +13 -72
- 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/mantine.css +193 -29
- package/dist/css/tokens.css +58 -18
- 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/TextArea.stories.tsx +12 -0
- package/dist/stories/Inputs/TextInput.stories.tsx +12 -0
- package/dist/stories/index.json +42 -35
- package/package.json +2 -2
- package/dist/Combobox/Multiselect.js +0 -31
- package/dist/Combobox/Multiselect.tsx +0 -158
|
@@ -1,131 +1,35 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/** Input size */
|
|
37
|
-
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
38
|
-
/** Style object for the component */
|
|
39
|
-
style?: React.CSSProperties;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function SearchableSelect({
|
|
43
|
-
label,
|
|
44
|
-
placeholder = "Search programming languages",
|
|
45
|
-
data = languages,
|
|
46
|
-
description,
|
|
47
|
-
error,
|
|
48
|
-
required = false,
|
|
49
|
-
showOptional = false,
|
|
50
|
-
disabled = false,
|
|
51
|
-
searchable = true,
|
|
52
|
-
size = 'md',
|
|
53
|
-
style,
|
|
54
|
-
...props
|
|
55
|
-
}: DSSearchableSelectProps) {
|
|
56
|
-
const combobox = useCombobox({
|
|
57
|
-
onDropdownClose: () => combobox.resetSelectedOption(),
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const [value, setValue] = useState<string | null>(null);
|
|
61
|
-
const [search, setSearch] = useState('');
|
|
62
|
-
|
|
63
|
-
// Convert data to consistent format
|
|
64
|
-
const normalizedData = data.map(item =>
|
|
65
|
-
typeof item === 'string' ? { value: item, label: item } : item
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const shouldFilterOptions = normalizedData.every((item) => item.value !== search);
|
|
69
|
-
const filteredOptions = shouldFilterOptions && searchable
|
|
70
|
-
? normalizedData.filter((item) =>
|
|
71
|
-
item.label.toLowerCase().includes(search.toLowerCase().trim()) ||
|
|
72
|
-
item.value.toLowerCase().includes(search.toLowerCase().trim())
|
|
73
|
-
)
|
|
74
|
-
: normalizedData;
|
|
75
|
-
|
|
76
|
-
const options = filteredOptions.map((item) => (
|
|
77
|
-
<Combobox.Option value={item.value} key={item.value}>
|
|
78
|
-
{item.label}
|
|
79
|
-
</Combobox.Option>
|
|
80
|
-
));
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<div style={style}>
|
|
84
|
-
<Combobox
|
|
85
|
-
store={combobox}
|
|
86
|
-
withinPortal={false}
|
|
87
|
-
onOptionSubmit={(val) => {
|
|
88
|
-
setValue(val);
|
|
89
|
-
setSearch(val);
|
|
90
|
-
combobox.closeDropdown();
|
|
91
|
-
}}
|
|
92
|
-
>
|
|
93
|
-
<Combobox.Target>
|
|
94
|
-
<InputBase
|
|
95
|
-
label={label}
|
|
96
|
-
description={description}
|
|
97
|
-
error={error}
|
|
98
|
-
required={required}
|
|
99
|
-
size={size}
|
|
100
|
-
disabled={disabled}
|
|
101
|
-
rightSection={<Combobox.Chevron />}
|
|
102
|
-
value={search}
|
|
103
|
-
onChange={(event) => {
|
|
104
|
-
combobox.openDropdown();
|
|
105
|
-
combobox.updateSelectedOptionIndex();
|
|
106
|
-
setSearch(event.currentTarget.value);
|
|
107
|
-
}}
|
|
108
|
-
onClick={() => combobox.openDropdown()}
|
|
109
|
-
onFocus={() => combobox.openDropdown()}
|
|
110
|
-
onBlur={() => {
|
|
111
|
-
combobox.closeDropdown();
|
|
112
|
-
setSearch(value || '');
|
|
113
|
-
}}
|
|
114
|
-
placeholder={placeholder}
|
|
115
|
-
rightSectionPointerEvents="none"
|
|
116
|
-
withAsterisk={required && !showOptional}
|
|
117
|
-
{...(showOptional && !required && {
|
|
118
|
-
label: label ? `${label} (optional)` : undefined
|
|
119
|
-
})}
|
|
120
|
-
/>
|
|
121
|
-
</Combobox.Target>
|
|
122
|
-
|
|
123
|
-
<Combobox.Dropdown>
|
|
124
|
-
<Combobox.Options>
|
|
125
|
-
{options.length > 0 ? options : <Combobox.Empty>Nothing found</Combobox.Empty>}
|
|
126
|
-
</Combobox.Options>
|
|
127
|
-
</Combobox.Dropdown>
|
|
128
|
-
</Combobox>
|
|
129
|
-
</div>
|
|
130
|
-
);
|
|
131
|
-
}
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { Select, DSSelectProps } from './Select';
|
|
5
|
+
|
|
6
|
+
// ========================== TYPES ==========================
|
|
7
|
+
|
|
8
|
+
export type DSSearchableSelectProps = DSSelectProps;
|
|
9
|
+
|
|
10
|
+
// ========================== COMPONENT ==========================
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* AppDirect Design System SearchableSelect
|
|
14
|
+
*
|
|
15
|
+
* The DS `Select` (Mantine's `Select`) with `searchable` on by default, so the
|
|
16
|
+
* field is typeable and filters its options. Search, filtering, controlled and
|
|
17
|
+
* uncontrolled value, clearable, grouping and every other `Select` prop are Mantine
|
|
18
|
+
* core behavior.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <SearchableSelect
|
|
23
|
+
* label="Language"
|
|
24
|
+
* placeholder="Search languages"
|
|
25
|
+
* data={['JavaScript', 'TypeScript', 'Python']}
|
|
26
|
+
* />
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const SearchableSelect = forwardRef<HTMLInputElement, DSSearchableSelectProps>(
|
|
30
|
+
({ searchable = true, size = 'md', ...props }, ref) => (
|
|
31
|
+
<Select ref={ref} searchable={searchable} size={size} {...props} />
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
SearchableSelect.displayName = 'SearchableSelect';
|
package/dist/Combobox/Select.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import React, { forwardRef } from 'react';
|
|
4
|
-
import { Select as MantineSelect
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Tooltip } from '../Overlays/Tooltip.js';
|
|
4
|
+
import { Select as MantineSelect } from '@mantine/core';
|
|
5
|
+
import { IconSelector } from '@tabler/icons-react';
|
|
6
|
+
import { getInputLabelProps } from '../Inputs/inputLabel.js';
|
|
8
7
|
import styles from './Select.module.css';
|
|
9
8
|
// ========================== COMPONENT ==========================
|
|
10
9
|
/**
|
|
@@ -55,19 +54,14 @@ import styles from './Select.module.css';
|
|
|
55
54
|
*/
|
|
56
55
|
export const Select = forwardRef(({ size = 'sm', borderless = false, showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, error, errorCaption, variant, classNames, ...props }, ref) => {
|
|
57
56
|
const effectiveError = error === true ? (errorCaption ?? true) : error;
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
const helpIconElement = hasHelpIcon ? (_jsx(Tooltip, { label: helpIconLabel ?? 'Help', position: "top", withArrow: true, children: _jsx(ActionIcon, { variant: "transparent", size: "xs", "aria-label": helpIconLabel ?? 'Help', onClick: onHelpIconClick, color: "gray", style: { cursor: onHelpIconClick ? 'pointer' : 'default' }, children: _jsx(IconInfoCircle, { size: 14, "aria-hidden": true }) }) })) : null;
|
|
67
|
-
const selectorIcon = _jsx(IconSelector, { size: 14, "aria-hidden": true });
|
|
68
|
-
const composedRightSection = helpIconElement
|
|
69
|
-
? _jsxs(Group, { gap: 4, wrap: "nowrap", children: [selectorIcon, helpIconElement] })
|
|
70
|
-
: selectorIcon;
|
|
57
|
+
const labelProps = getInputLabelProps({
|
|
58
|
+
label,
|
|
59
|
+
required,
|
|
60
|
+
showOptional,
|
|
61
|
+
hasHelpIcon,
|
|
62
|
+
helpIconLabel,
|
|
63
|
+
onHelpIconClick,
|
|
64
|
+
});
|
|
71
65
|
const mergedClassNames = typeof classNames === 'function'
|
|
72
66
|
? classNames
|
|
73
67
|
: {
|
|
@@ -76,6 +70,6 @@ export const Select = forwardRef(({ size = 'sm', borderless = false, showOptiona
|
|
|
76
70
|
.filter(Boolean)
|
|
77
71
|
.join(' '),
|
|
78
72
|
};
|
|
79
|
-
return (_jsx(MantineSelect, { ...props, ref: ref, size: size, radius: "sm", required: required,
|
|
73
|
+
return (_jsx(MantineSelect, { ...props, ref: ref, size: size, radius: "sm", required: required, ...labelProps, rightSection: _jsx(IconSelector, { size: 14, "aria-hidden": true }), rightSectionPointerEvents: props.clearable ? 'auto' : 'none', variant: variant ?? 'default', classNames: mergedClassNames, error: effectiveError }));
|
|
80
74
|
});
|
|
81
75
|
Select.displayName = 'Select';
|
package/dist/Combobox/Select.tsx
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import React, { forwardRef } from 'react';
|
|
4
|
-
import { Select as MantineSelect, SelectProps as MantineSelectProps
|
|
5
|
-
import {
|
|
4
|
+
import { Select as MantineSelect, SelectProps as MantineSelectProps } from '@mantine/core';
|
|
5
|
+
import { IconSelector } from '@tabler/icons-react';
|
|
6
6
|
import { ComponentSize } from '../config';
|
|
7
|
-
import {
|
|
8
|
-
import { Tooltip } from '../Overlays/Tooltip';
|
|
7
|
+
import { getInputLabelProps } from '../Inputs/inputLabel';
|
|
9
8
|
import styles from './Select.module.css';
|
|
10
9
|
|
|
11
10
|
// ========================== TYPES ==========================
|
|
@@ -17,7 +16,7 @@ export interface DSSelectProps extends Omit<MantineSelectProps, 'size' | 'radius
|
|
|
17
16
|
borderless?: boolean;
|
|
18
17
|
/** Whether to show "(Optional)" text after label */
|
|
19
18
|
showOptional?: boolean;
|
|
20
|
-
/** Whether to show a help icon with a tooltip
|
|
19
|
+
/** Whether to show a (?) help icon with a tooltip to the right of the label */
|
|
21
20
|
hasHelpIcon?: boolean;
|
|
22
21
|
/** Tooltip label shown when hovering the help icon. Also used as aria-label for a11y */
|
|
23
22
|
helpIconLabel?: string;
|
|
@@ -99,42 +98,14 @@ export const Select = forwardRef<HTMLInputElement, DSSelectProps>(
|
|
|
99
98
|
) => {
|
|
100
99
|
const effectiveError = error === true ? (errorCaption ?? true) : error;
|
|
101
100
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
return label;
|
|
112
|
-
}, [label, showOptional, required]);
|
|
113
|
-
|
|
114
|
-
const helpIconElement = hasHelpIcon ? (
|
|
115
|
-
<Tooltip
|
|
116
|
-
label={helpIconLabel ?? 'Help'}
|
|
117
|
-
position="top"
|
|
118
|
-
withArrow
|
|
119
|
-
>
|
|
120
|
-
<ActionIcon
|
|
121
|
-
variant="transparent"
|
|
122
|
-
size="xs"
|
|
123
|
-
aria-label={helpIconLabel ?? 'Help'}
|
|
124
|
-
onClick={onHelpIconClick}
|
|
125
|
-
color="gray"
|
|
126
|
-
style={{ cursor: onHelpIconClick ? 'pointer' : 'default' }}
|
|
127
|
-
>
|
|
128
|
-
<IconInfoCircle size={14} aria-hidden />
|
|
129
|
-
</ActionIcon>
|
|
130
|
-
</Tooltip>
|
|
131
|
-
) : null;
|
|
132
|
-
|
|
133
|
-
const selectorIcon = <IconSelector size={14} aria-hidden />;
|
|
134
|
-
|
|
135
|
-
const composedRightSection = helpIconElement
|
|
136
|
-
? <Group gap={4} wrap="nowrap">{selectorIcon}{helpIconElement}</Group>
|
|
137
|
-
: selectorIcon;
|
|
101
|
+
const labelProps = getInputLabelProps({
|
|
102
|
+
label,
|
|
103
|
+
required,
|
|
104
|
+
showOptional,
|
|
105
|
+
hasHelpIcon,
|
|
106
|
+
helpIconLabel,
|
|
107
|
+
onHelpIconClick,
|
|
108
|
+
});
|
|
138
109
|
|
|
139
110
|
const mergedClassNames =
|
|
140
111
|
typeof classNames === 'function'
|
|
@@ -153,9 +124,9 @@ export const Select = forwardRef<HTMLInputElement, DSSelectProps>(
|
|
|
153
124
|
size={size}
|
|
154
125
|
radius="sm"
|
|
155
126
|
required={required}
|
|
156
|
-
|
|
157
|
-
rightSection={
|
|
158
|
-
rightSectionPointerEvents={
|
|
127
|
+
{...labelProps}
|
|
128
|
+
rightSection={<IconSelector size={14} aria-hidden />}
|
|
129
|
+
rightSectionPointerEvents={props.clearable ? 'auto' : 'none'}
|
|
159
130
|
variant={variant ?? 'default'}
|
|
160
131
|
classNames={mergedClassNames}
|
|
161
132
|
error={effectiveError}
|
package/dist/Combobox/index.js
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { SearchableSelect } from './SearchableSelect.js';
|
|
7
7
|
export { AutocompleteClearable } from './AutocompleteClearable.js';
|
|
8
|
-
export {
|
|
8
|
+
export { ADMultiselect } from './ADMultiselect.js';
|
|
9
9
|
export { Select } from './Select.js';
|
|
10
10
|
export { Combobox } from './Combobox.js';
|
package/dist/Combobox/index.ts
CHANGED
|
@@ -10,8 +10,8 @@ export type { DSSearchableSelectProps } from './SearchableSelect';
|
|
|
10
10
|
export { AutocompleteClearable } from './AutocompleteClearable';
|
|
11
11
|
export type { DSAutocompleteClearableProps } from './AutocompleteClearable';
|
|
12
12
|
|
|
13
|
-
export {
|
|
14
|
-
export type {
|
|
13
|
+
export { ADMultiselect } from './ADMultiselect';
|
|
14
|
+
export type { ADMultiselectProps } from './ADMultiselect';
|
|
15
15
|
|
|
16
16
|
export { Select } from './Select';
|
|
17
17
|
export type { DSSelectProps } from './Select';
|
|
@@ -1,45 +1,33 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
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.js';
|
|
6
6
|
import { RiFileCopyLine } from '@remixicon/react';
|
|
7
7
|
/**
|
|
8
8
|
* CopyButton Component
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Built on Mantine's `CopyButton`: clicking writes `value` to the clipboard and the
|
|
11
|
+
* tooltip switches from "Copy" to "Copied" for `timeout` ms.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
*
|
|
15
|
-
* <CopyButton
|
|
16
|
-
* value="Production"
|
|
17
|
-
* label="Environment"
|
|
18
|
-
* onCopy={(value) => navigator.clipboard.writeText(value)}
|
|
19
|
-
* />
|
|
14
|
+
* <CopyButton value="Production" label="Environment" />
|
|
20
15
|
*
|
|
21
16
|
* @example
|
|
22
|
-
* // With custom icon size
|
|
17
|
+
* // With custom icon size and a callback
|
|
23
18
|
* <CopyButton
|
|
24
19
|
* value="sk-1234567890abcdef"
|
|
25
20
|
* label="API Key"
|
|
26
21
|
* iconSize={16}
|
|
27
|
-
* onCopy={(
|
|
28
|
-
* navigator.clipboard.writeText(value);
|
|
29
|
-
* console.log('API Key copied');
|
|
30
|
-
* }}
|
|
22
|
+
* onCopy={() => console.log('API Key copied')}
|
|
31
23
|
* />
|
|
32
24
|
*/
|
|
33
|
-
export function CopyButton({ value, label, onCopy, iconSize = 24, }) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const handleMouseLeave = () => {
|
|
42
|
-
setIsCopied(false);
|
|
43
|
-
};
|
|
44
|
-
return (_jsx(Tooltip, { label: isCopied ? "Copied" : "Copy", position: "top", withArrow: true, children: _jsx(ActionIcon, { variant: "subtle", size: "xs", c: "blue", onClick: handleCopy, onMouseLeave: handleMouseLeave, "aria-label": `Copy ${label}`, children: _jsx(RiFileCopyLine, { size: iconSize }) }) }));
|
|
25
|
+
export function CopyButton({ value, label, onCopy, iconSize = 24, timeout = 1500, }) {
|
|
26
|
+
return (_jsx(MantineCopyButton, { value: value, timeout: timeout, children: ({ copied, copy }) => (_jsx(Tooltip, { label: copied ? 'Copied' : 'Copy', position: "top", withArrow: true, children: _jsx(ActionIcon, { variant: "subtle",
|
|
27
|
+
// Numeric size on purpose: t-shirt sizes get a token rule that pins the svg size,
|
|
28
|
+
// which would override `iconSize`. The button is the icon plus 4px padding per side.
|
|
29
|
+
size: iconSize + 8, c: "blue", onClick: () => {
|
|
30
|
+
copy();
|
|
31
|
+
onCopy?.(value);
|
|
32
|
+
}, "aria-label": `Copy ${label}`, children: _jsx(RiFileCopyLine, { size: iconSize }) }) })) }));
|
|
45
33
|
}
|
|
@@ -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
|
|
|
@@ -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';
|