@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,125 +1,43 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { forwardRef } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { Pill as MantinePill, PillProps as MantinePillProps } from '@mantine/core';
|
|
5
|
+
import { ComponentSize } from '../config';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
size?:
|
|
12
|
-
/** Whether the pill can be removed */
|
|
13
|
-
withRemoveButton?: boolean;
|
|
14
|
-
/** Called when remove button is clicked */
|
|
15
|
-
onRemove?: () => void;
|
|
7
|
+
// ========================== TYPES ==========================
|
|
8
|
+
|
|
9
|
+
export interface DSPillProps extends Omit<MantinePillProps, 'size'> {
|
|
10
|
+
/** Pill size from design system scale */
|
|
11
|
+
size?: ComponentSize;
|
|
16
12
|
}
|
|
17
13
|
|
|
18
|
-
//
|
|
19
|
-
const sizeConfig = {
|
|
20
|
-
xs: {
|
|
21
|
-
height: 18,
|
|
22
|
-
fontSize: 10,
|
|
23
|
-
lineHeight: 10,
|
|
24
|
-
letterSpacing: 0.1563,
|
|
25
|
-
px: 8,
|
|
26
|
-
gap: 0,
|
|
27
|
-
closeSize: 18,
|
|
28
|
-
},
|
|
29
|
-
sm: {
|
|
30
|
-
height: 24,
|
|
31
|
-
fontSize: 11,
|
|
32
|
-
lineHeight: 12,
|
|
33
|
-
letterSpacing: 0.17,
|
|
34
|
-
px: 8,
|
|
35
|
-
gap: 6,
|
|
36
|
-
closeSize: 14,
|
|
37
|
-
},
|
|
38
|
-
md: {
|
|
39
|
-
height: 25,
|
|
40
|
-
fontSize: 14,
|
|
41
|
-
lineHeight: 14,
|
|
42
|
-
letterSpacing: 0.2184,
|
|
43
|
-
px: 11.2,
|
|
44
|
-
gap: 8,
|
|
45
|
-
closeSize: 25,
|
|
46
|
-
},
|
|
47
|
-
lg: {
|
|
48
|
-
height: 32,
|
|
49
|
-
fontSize: 13,
|
|
50
|
-
lineHeight: 14,
|
|
51
|
-
letterSpacing: 0.2,
|
|
52
|
-
px: 12,
|
|
53
|
-
gap: 8,
|
|
54
|
-
closeSize: 18,
|
|
55
|
-
},
|
|
56
|
-
xl: {
|
|
57
|
-
height: 36,
|
|
58
|
-
fontSize: 14,
|
|
59
|
-
lineHeight: 16,
|
|
60
|
-
letterSpacing: 0.22,
|
|
61
|
-
px: 14,
|
|
62
|
-
gap: 8,
|
|
63
|
-
closeSize: 20,
|
|
64
|
-
},
|
|
65
|
-
};
|
|
14
|
+
// ========================== COMPONENT ==========================
|
|
66
15
|
|
|
16
|
+
/**
|
|
17
|
+
* AppDirect Design System Pill Component
|
|
18
|
+
*
|
|
19
|
+
* A thin wrapper over Mantine's Pill. Colors, radius, height and font size
|
|
20
|
+
* come from the `pill` / `multiselect.pill` component tokens, not from this file.
|
|
21
|
+
*
|
|
22
|
+
* Inside a `PillsInput` / `MultiSelect`, pass `size` explicitly so the pill
|
|
23
|
+
* matches the field: the DS default of `md` takes precedence over the size
|
|
24
|
+
* Mantine would otherwise inherit from the field.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <Pill>Design</Pill>
|
|
29
|
+
* <Pill withRemoveButton onRemove={() => remove('design')}>Design</Pill>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
67
32
|
export const Pill = forwardRef<HTMLDivElement, DSPillProps>(
|
|
68
|
-
({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const config = sizeConfig[size];
|
|
77
|
-
|
|
78
|
-
const colors = {
|
|
79
|
-
backgroundColor: 'var(--ad-color-bg-subtle)',
|
|
80
|
-
color: 'var(--ad-color-text-dimmed)',
|
|
81
|
-
border: 'none',
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<Box
|
|
86
|
-
ref={ref}
|
|
87
|
-
style={{
|
|
88
|
-
display: 'inline-flex',
|
|
89
|
-
alignItems: 'center',
|
|
90
|
-
height: config.height,
|
|
91
|
-
paddingLeft: config.px,
|
|
92
|
-
paddingRight: withRemoveButton ? 0 : config.px,
|
|
93
|
-
borderRadius: config.height / 2,
|
|
94
|
-
fontSize: config.fontSize,
|
|
95
|
-
fontWeight: 400,
|
|
96
|
-
lineHeight: `${config.lineHeight}px`,
|
|
97
|
-
letterSpacing: config.letterSpacing,
|
|
98
|
-
userSelect: 'none',
|
|
99
|
-
...colors,
|
|
100
|
-
...style,
|
|
101
|
-
}}
|
|
102
|
-
{...others}
|
|
103
|
-
>
|
|
104
|
-
<Inline gap={config.gap} wrap="nowrap">
|
|
105
|
-
<span>{children}</span>
|
|
106
|
-
{withRemoveButton && (
|
|
107
|
-
<CloseButton
|
|
108
|
-
size={config.closeSize}
|
|
109
|
-
onClick={onRemove}
|
|
110
|
-
variant="transparent"
|
|
111
|
-
style={{
|
|
112
|
-
color: 'currentColor',
|
|
113
|
-
minWidth: config.closeSize,
|
|
114
|
-
minHeight: config.closeSize,
|
|
115
|
-
}}
|
|
116
|
-
aria-label="Remove"
|
|
117
|
-
/>
|
|
118
|
-
)}
|
|
119
|
-
</Inline>
|
|
120
|
-
</Box>
|
|
121
|
-
);
|
|
122
|
-
}
|
|
33
|
+
({ size = 'md', removeButtonProps, ...props }, ref) => (
|
|
34
|
+
<MantinePill
|
|
35
|
+
ref={ref}
|
|
36
|
+
size={size}
|
|
37
|
+
removeButtonProps={{ 'aria-label': 'Remove', ...removeButtonProps }}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
)
|
|
123
41
|
);
|
|
124
42
|
|
|
125
|
-
Pill.displayName = 'Pill';
|
|
43
|
+
Pill.displayName = 'Pill';
|
|
@@ -1,10 +1,8 @@
|
|
|
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 { ColorInput as MantineColorInput
|
|
5
|
-
import {
|
|
6
|
-
import { Text } from '../Typography/Text.js';
|
|
7
|
-
import { Tooltip } from '../Overlays/Tooltip.js';
|
|
4
|
+
import { ColorInput as MantineColorInput } from '@mantine/core';
|
|
5
|
+
import { getInputLabelProps } from './inputLabel.js';
|
|
8
6
|
// ========================== COMPONENT ==========================
|
|
9
7
|
/**
|
|
10
8
|
* AppDirect Design System ColorInput Component
|
|
@@ -31,18 +29,14 @@ import { Tooltip } from '../Overlays/Tooltip.js';
|
|
|
31
29
|
*/
|
|
32
30
|
export const ColorInput = forwardRef(({ size = 'md', showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, rightSection, error, errorCaption, ...props }, ref) => {
|
|
33
31
|
const effectiveError = error === true ? (errorCaption ?? true) : error;
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const composedRightSection = (helpIconElement && rightSection)
|
|
44
|
-
? _jsxs(Group, { gap: 4, wrap: "nowrap", children: [rightSection, helpIconElement] })
|
|
45
|
-
: helpIconElement || rightSection;
|
|
46
|
-
return (_jsx(MantineColorInput, { ref: ref, size: size, radius: "sm", required: required, label: enhancedLabel, rightSection: composedRightSection, error: effectiveError, ...props }));
|
|
32
|
+
const labelProps = getInputLabelProps({
|
|
33
|
+
label,
|
|
34
|
+
required,
|
|
35
|
+
showOptional,
|
|
36
|
+
hasHelpIcon,
|
|
37
|
+
helpIconLabel,
|
|
38
|
+
onHelpIconClick,
|
|
39
|
+
});
|
|
40
|
+
return (_jsx(MantineColorInput, { ref: ref, size: size, radius: "sm", required: required, rightSection: rightSection, ...labelProps, error: effectiveError, ...props }));
|
|
47
41
|
});
|
|
48
42
|
ColorInput.displayName = 'ColorInput';
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import React, { forwardRef } from 'react';
|
|
4
|
-
import { ColorInput as MantineColorInput, ColorInputProps as MantineColorInputProps
|
|
5
|
-
import { IconInfoCircle } from '@tabler/icons-react';
|
|
4
|
+
import { ColorInput as MantineColorInput, ColorInputProps as MantineColorInputProps } from '@mantine/core';
|
|
6
5
|
import { ComponentSize } from '../config';
|
|
7
|
-
import {
|
|
8
|
-
import { Tooltip } from '../Overlays/Tooltip';
|
|
6
|
+
import { getInputLabelProps } from './inputLabel';
|
|
9
7
|
|
|
10
8
|
// ========================== TYPES ==========================
|
|
11
9
|
|
|
@@ -14,7 +12,7 @@ export interface DSColorInputProps extends Omit<MantineColorInputProps, 'size' |
|
|
|
14
12
|
size?: ComponentSize;
|
|
15
13
|
/** Whether to show "(Optional)" text after label */
|
|
16
14
|
showOptional?: boolean;
|
|
17
|
-
/** Whether to show a help icon with a tooltip
|
|
15
|
+
/** Whether to show a (?) help icon with a tooltip to the right of the label */
|
|
18
16
|
hasHelpIcon?: boolean;
|
|
19
17
|
/** Tooltip label shown when hovering the help icon. Also used as aria-label for a11y */
|
|
20
18
|
helpIconLabel?: string;
|
|
@@ -71,40 +69,14 @@ export const ColorInput = forwardRef<HTMLInputElement, DSColorInputProps>(
|
|
|
71
69
|
) => {
|
|
72
70
|
const effectiveError = error === true ? (errorCaption ?? true) : error;
|
|
73
71
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
return label;
|
|
84
|
-
}, [label, showOptional, required]);
|
|
85
|
-
|
|
86
|
-
const helpIconElement = hasHelpIcon ? (
|
|
87
|
-
<Tooltip
|
|
88
|
-
label={helpIconLabel ?? 'Help'}
|
|
89
|
-
position="top"
|
|
90
|
-
withArrow
|
|
91
|
-
>
|
|
92
|
-
<ActionIcon
|
|
93
|
-
variant="transparent"
|
|
94
|
-
size="xs"
|
|
95
|
-
aria-label={helpIconLabel ?? 'Help'}
|
|
96
|
-
onClick={onHelpIconClick}
|
|
97
|
-
color="gray"
|
|
98
|
-
style={{ cursor: onHelpIconClick ? 'pointer' : 'default' }}
|
|
99
|
-
>
|
|
100
|
-
<IconInfoCircle size={14} aria-hidden />
|
|
101
|
-
</ActionIcon>
|
|
102
|
-
</Tooltip>
|
|
103
|
-
) : null;
|
|
104
|
-
|
|
105
|
-
const composedRightSection = (helpIconElement && rightSection)
|
|
106
|
-
? <Group gap={4} wrap="nowrap">{rightSection}{helpIconElement}</Group>
|
|
107
|
-
: helpIconElement || rightSection;
|
|
72
|
+
const labelProps = getInputLabelProps({
|
|
73
|
+
label,
|
|
74
|
+
required,
|
|
75
|
+
showOptional,
|
|
76
|
+
hasHelpIcon,
|
|
77
|
+
helpIconLabel,
|
|
78
|
+
onHelpIconClick,
|
|
79
|
+
});
|
|
108
80
|
|
|
109
81
|
return (
|
|
110
82
|
<MantineColorInput
|
|
@@ -112,8 +84,8 @@ export const ColorInput = forwardRef<HTMLInputElement, DSColorInputProps>(
|
|
|
112
84
|
size={size}
|
|
113
85
|
radius="sm"
|
|
114
86
|
required={required}
|
|
115
|
-
|
|
116
|
-
|
|
87
|
+
rightSection={rightSection}
|
|
88
|
+
{...labelProps}
|
|
117
89
|
error={effectiveError}
|
|
118
90
|
{...props}
|
|
119
91
|
/>
|
|
@@ -1,61 +1,26 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx
|
|
3
|
-
import React, { forwardRef
|
|
4
|
-
import { NumberInput as MantineNumberInput,
|
|
5
|
-
import {
|
|
6
|
-
import { Text } from '../Typography/Text.js';
|
|
7
|
-
import { Tooltip } from '../Overlays/Tooltip.js';
|
|
8
|
-
const CONTROL_ICON_SIZE = {
|
|
9
|
-
xs: 10,
|
|
10
|
-
sm: 12,
|
|
11
|
-
md: 14,
|
|
12
|
-
lg: 16,
|
|
13
|
-
xl: 18,
|
|
14
|
-
};
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { NumberInput as MantineNumberInput, } from '@mantine/core';
|
|
5
|
+
import { getInputLabelProps } from './inputLabel.js';
|
|
15
6
|
// ========================== COMPONENT ==========================
|
|
16
7
|
/**
|
|
17
8
|
* AppDirect Design System NumberInput Component
|
|
18
9
|
*
|
|
19
10
|
* A numeric input built on top of Mantine's NumberInput with
|
|
20
11
|
* consistent design system styling and enforced radius.
|
|
21
|
-
* Increment/decrement
|
|
12
|
+
* Increment/decrement uses Mantine's native stacked chevron controls (styled via mantine.css).
|
|
22
13
|
*/
|
|
23
|
-
export const NumberInput = forwardRef(({ size = 'md', showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, rightSection, error, errorCaption, hideControls,
|
|
14
|
+
export const NumberInput = forwardRef(({ size = 'md', showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, leftSection, rightSection, error, errorCaption, hideControls, ...props }, ref) => {
|
|
24
15
|
const effectiveError = error === true ? (errorCaption ?? true) : error;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
handlersRefProp.current =
|
|
35
|
-
handlers;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const enhancedLabel = React.useMemo(() => {
|
|
39
|
-
if (!label)
|
|
40
|
-
return label;
|
|
41
|
-
if (showOptional && !required) {
|
|
42
|
-
return (_jsxs(_Fragment, { children: [label, ' ', _jsx(Text, { span: true, c: "dimmed", fw: "normal", children: "(Optional)" })] }));
|
|
43
|
-
}
|
|
44
|
-
return label;
|
|
45
|
-
}, [label, showOptional, required]);
|
|
46
|
-
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(RiInformationLine, { size: 14, "aria-hidden": true }) }) })) : null;
|
|
47
|
-
const iconSize = CONTROL_ICON_SIZE[size] ?? 14;
|
|
48
|
-
const showDsControls = !hideControls && !readOnly && !disabled && rightSection == null;
|
|
49
|
-
const dsControls = showDsControls ? (_jsxs(Stack, { gap: 0, justify: "center", children: [_jsx(ActionIcon, { variant: "transparent", size: "xs", tabIndex: -1, "aria-hidden": true, onMouseDown: (event) => event.preventDefault(), onClick: () => internalHandlersRef.current?.increment(), children: _jsx(RiAddLine, { size: iconSize, "aria-hidden": true }) }), _jsx(ActionIcon, { variant: "transparent", size: "xs", tabIndex: -1, "aria-hidden": true, onMouseDown: (event) => event.preventDefault(), onClick: () => internalHandlersRef.current?.decrement(), children: _jsx(RiSubtractLine, { size: iconSize, "aria-hidden": true }) })] })) : null;
|
|
50
|
-
const composedRightSection = (() => {
|
|
51
|
-
if (rightSection && helpIconElement) {
|
|
52
|
-
return (_jsxs(Group, { gap: 4, wrap: "nowrap", children: [rightSection, helpIconElement] }));
|
|
53
|
-
}
|
|
54
|
-
if (dsControls && helpIconElement) {
|
|
55
|
-
return (_jsxs(Group, { gap: 4, wrap: "nowrap", children: [dsControls, helpIconElement] }));
|
|
56
|
-
}
|
|
57
|
-
return helpIconElement || rightSection || dsControls;
|
|
58
|
-
})();
|
|
59
|
-
return (_jsx(MantineNumberInput, { ref: ref, size: size, radius: "sm", required: required, label: enhancedLabel, error: effectiveError, hideControls: true, readOnly: readOnly, disabled: disabled, handlersRef: setHandlersRef, rightSection: composedRightSection, ...props }));
|
|
16
|
+
const labelProps = getInputLabelProps({
|
|
17
|
+
label,
|
|
18
|
+
required,
|
|
19
|
+
showOptional,
|
|
20
|
+
hasHelpIcon,
|
|
21
|
+
helpIconLabel,
|
|
22
|
+
onHelpIconClick,
|
|
23
|
+
});
|
|
24
|
+
return (_jsx(MantineNumberInput, { ref: ref, size: size, radius: "sm", required: required, error: effectiveError, hideControls: hideControls, leftSection: leftSection, rightSection: rightSection, ...labelProps, ...props }));
|
|
60
25
|
});
|
|
61
26
|
NumberInput.displayName = 'NumberInput';
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { forwardRef
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
4
|
import {
|
|
5
5
|
NumberInput as MantineNumberInput,
|
|
6
6
|
NumberInputProps as MantineNumberInputProps,
|
|
7
|
-
NumberInputHandlers,
|
|
8
|
-
ActionIcon,
|
|
9
|
-
Group,
|
|
10
|
-
Stack,
|
|
11
7
|
} from '@mantine/core';
|
|
12
|
-
import { RiAddLine, RiInformationLine, RiSubtractLine } from '@remixicon/react';
|
|
13
8
|
import { ComponentSize } from '../config';
|
|
14
|
-
import {
|
|
15
|
-
import { Tooltip } from '../Overlays/Tooltip';
|
|
9
|
+
import { getInputLabelProps } from './inputLabel';
|
|
16
10
|
|
|
17
11
|
// ========================== TYPES ==========================
|
|
18
12
|
|
|
@@ -21,7 +15,7 @@ export interface DSNumberInputProps extends Omit<MantineNumberInputProps, 'size'
|
|
|
21
15
|
size?: ComponentSize;
|
|
22
16
|
/** Whether to show "(Optional)" text after label */
|
|
23
17
|
showOptional?: boolean;
|
|
24
|
-
/** Whether to show a help icon with a tooltip
|
|
18
|
+
/** Whether to show a (?) help icon with a tooltip to the right of the label */
|
|
25
19
|
hasHelpIcon?: boolean;
|
|
26
20
|
/** Tooltip label shown when hovering the help icon. Also used as aria-label for a11y */
|
|
27
21
|
helpIconLabel?: string;
|
|
@@ -34,14 +28,6 @@ export interface DSNumberInputProps extends Omit<MantineNumberInputProps, 'size'
|
|
|
34
28
|
errorCaption?: string;
|
|
35
29
|
}
|
|
36
30
|
|
|
37
|
-
const CONTROL_ICON_SIZE: Record<ComponentSize, number> = {
|
|
38
|
-
xs: 10,
|
|
39
|
-
sm: 12,
|
|
40
|
-
md: 14,
|
|
41
|
-
lg: 16,
|
|
42
|
-
xl: 18,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
31
|
// ========================== COMPONENT ==========================
|
|
46
32
|
|
|
47
33
|
/**
|
|
@@ -49,7 +35,7 @@ const CONTROL_ICON_SIZE: Record<ComponentSize, number> = {
|
|
|
49
35
|
*
|
|
50
36
|
* A numeric input built on top of Mantine's NumberInput with
|
|
51
37
|
* consistent design system styling and enforced radius.
|
|
52
|
-
* Increment/decrement
|
|
38
|
+
* Increment/decrement uses Mantine's native stacked chevron controls (styled via mantine.css).
|
|
53
39
|
*/
|
|
54
40
|
export const NumberInput = forwardRef<HTMLInputElement, DSNumberInputProps>(
|
|
55
41
|
(
|
|
@@ -61,108 +47,25 @@ export const NumberInput = forwardRef<HTMLInputElement, DSNumberInputProps>(
|
|
|
61
47
|
hasHelpIcon = false,
|
|
62
48
|
helpIconLabel,
|
|
63
49
|
onHelpIconClick,
|
|
50
|
+
leftSection,
|
|
64
51
|
rightSection,
|
|
65
52
|
error,
|
|
66
53
|
errorCaption,
|
|
67
54
|
hideControls,
|
|
68
|
-
readOnly,
|
|
69
|
-
disabled,
|
|
70
|
-
handlersRef: handlersRefProp,
|
|
71
55
|
...props
|
|
72
56
|
},
|
|
73
57
|
ref
|
|
74
58
|
) => {
|
|
75
59
|
const effectiveError = error === true ? (errorCaption ?? true) : error;
|
|
76
|
-
const internalHandlersRef = useRef<NumberInputHandlers | null>(null);
|
|
77
|
-
|
|
78
|
-
const setHandlersRef = (handlers: NumberInputHandlers | undefined) => {
|
|
79
|
-
internalHandlersRef.current = handlers ?? null;
|
|
80
|
-
if (!handlersRefProp) return;
|
|
81
|
-
if (typeof handlersRefProp === 'function') {
|
|
82
|
-
handlersRefProp(handlers);
|
|
83
|
-
} else {
|
|
84
|
-
(handlersRefProp as React.MutableRefObject<NumberInputHandlers | undefined>).current =
|
|
85
|
-
handlers;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const enhancedLabel = React.useMemo(() => {
|
|
90
|
-
if (!label) return label;
|
|
91
|
-
if (showOptional && !required) {
|
|
92
|
-
return (
|
|
93
|
-
<>
|
|
94
|
-
{label}{' '}
|
|
95
|
-
<Text span c="dimmed" fw="normal">
|
|
96
|
-
(Optional)
|
|
97
|
-
</Text>
|
|
98
|
-
</>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
return label;
|
|
102
|
-
}, [label, showOptional, required]);
|
|
103
|
-
|
|
104
|
-
const helpIconElement = hasHelpIcon ? (
|
|
105
|
-
<Tooltip label={helpIconLabel ?? 'Help'} position="top" withArrow>
|
|
106
|
-
<ActionIcon
|
|
107
|
-
variant="transparent"
|
|
108
|
-
size="xs"
|
|
109
|
-
aria-label={helpIconLabel ?? 'Help'}
|
|
110
|
-
onClick={onHelpIconClick}
|
|
111
|
-
color="gray"
|
|
112
|
-
style={{ cursor: onHelpIconClick ? 'pointer' : 'default' }}
|
|
113
|
-
>
|
|
114
|
-
<RiInformationLine size={14} aria-hidden />
|
|
115
|
-
</ActionIcon>
|
|
116
|
-
</Tooltip>
|
|
117
|
-
) : null;
|
|
118
|
-
|
|
119
|
-
const iconSize = CONTROL_ICON_SIZE[size] ?? 14;
|
|
120
|
-
const showDsControls = !hideControls && !readOnly && !disabled && rightSection == null;
|
|
121
60
|
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
onClick={() => internalHandlersRef.current?.increment()}
|
|
131
|
-
>
|
|
132
|
-
<RiAddLine size={iconSize} aria-hidden />
|
|
133
|
-
</ActionIcon>
|
|
134
|
-
<ActionIcon
|
|
135
|
-
variant="transparent"
|
|
136
|
-
size="xs"
|
|
137
|
-
tabIndex={-1}
|
|
138
|
-
aria-hidden
|
|
139
|
-
onMouseDown={(event) => event.preventDefault()}
|
|
140
|
-
onClick={() => internalHandlersRef.current?.decrement()}
|
|
141
|
-
>
|
|
142
|
-
<RiSubtractLine size={iconSize} aria-hidden />
|
|
143
|
-
</ActionIcon>
|
|
144
|
-
</Stack>
|
|
145
|
-
) : null;
|
|
146
|
-
|
|
147
|
-
const composedRightSection = (() => {
|
|
148
|
-
if (rightSection && helpIconElement) {
|
|
149
|
-
return (
|
|
150
|
-
<Group gap={4} wrap="nowrap">
|
|
151
|
-
{rightSection}
|
|
152
|
-
{helpIconElement}
|
|
153
|
-
</Group>
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
if (dsControls && helpIconElement) {
|
|
157
|
-
return (
|
|
158
|
-
<Group gap={4} wrap="nowrap">
|
|
159
|
-
{dsControls}
|
|
160
|
-
{helpIconElement}
|
|
161
|
-
</Group>
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
return helpIconElement || rightSection || dsControls;
|
|
165
|
-
})();
|
|
61
|
+
const labelProps = getInputLabelProps({
|
|
62
|
+
label,
|
|
63
|
+
required,
|
|
64
|
+
showOptional,
|
|
65
|
+
hasHelpIcon,
|
|
66
|
+
helpIconLabel,
|
|
67
|
+
onHelpIconClick,
|
|
68
|
+
});
|
|
166
69
|
|
|
167
70
|
return (
|
|
168
71
|
<MantineNumberInput
|
|
@@ -170,17 +73,15 @@ export const NumberInput = forwardRef<HTMLInputElement, DSNumberInputProps>(
|
|
|
170
73
|
size={size}
|
|
171
74
|
radius="sm"
|
|
172
75
|
required={required}
|
|
173
|
-
label={enhancedLabel}
|
|
174
76
|
error={effectiveError}
|
|
175
|
-
hideControls
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
rightSection={composedRightSection}
|
|
77
|
+
hideControls={hideControls}
|
|
78
|
+
leftSection={leftSection}
|
|
79
|
+
rightSection={rightSection}
|
|
80
|
+
{...labelProps}
|
|
180
81
|
{...props}
|
|
181
82
|
/>
|
|
182
83
|
);
|
|
183
84
|
}
|
|
184
85
|
);
|
|
185
86
|
|
|
186
|
-
NumberInput.displayName = 'NumberInput';
|
|
87
|
+
NumberInput.displayName = 'NumberInput';
|
package/dist/Inputs/Radio.js
CHANGED
|
@@ -40,7 +40,7 @@ import { Radio as MantineRadio } from '@mantine/core';
|
|
|
40
40
|
* <Radio label="Required radio" value="required" required />
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
export const Radio = forwardRef(({ size = '
|
|
43
|
+
export const Radio = forwardRef(({ size = 'sm', label, ...props }, ref) => {
|
|
44
44
|
// Construct label with required asterisk if needed
|
|
45
45
|
const enhancedLabel = React.useMemo(() => {
|
|
46
46
|
if (!label)
|
package/dist/Inputs/Radio.tsx
CHANGED
|
@@ -44,7 +44,7 @@ import { Radio as MantineRadio } from '@mantine/core';
|
|
|
44
44
|
* </RadioGroup>
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
export const RadioGroup = forwardRef(({ size = '
|
|
47
|
+
export const RadioGroup = forwardRef(({ size = 'sm', label, ...props }, ref) => {
|
|
48
48
|
// Construct label with required asterisk if needed
|
|
49
49
|
const enhancedLabel = React.useMemo(() => {
|
|
50
50
|
if (!label)
|
package/dist/Inputs/TextArea.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
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 { Textarea as MantineTextarea
|
|
5
|
-
import {
|
|
6
|
-
import { Text } from '../Typography/Text.js';
|
|
7
|
-
import { Tooltip } from '../Overlays/Tooltip.js';
|
|
4
|
+
import { Textarea as MantineTextarea } from '@mantine/core';
|
|
5
|
+
import { getInputLabelProps } from './inputLabel.js';
|
|
8
6
|
// ========================== COMPONENT ==========================
|
|
9
7
|
/**
|
|
10
8
|
* AppDirect Design System TextArea Component
|
|
@@ -33,18 +31,14 @@ import { Tooltip } from '../Overlays/Tooltip.js';
|
|
|
33
31
|
*/
|
|
34
32
|
export const TextArea = forwardRef(({ size = 'md', showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, rightSection, error, errorCaption, ...props }, ref) => {
|
|
35
33
|
const effectiveError = error === true ? (errorCaption ?? true) : error;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const composedRightSection = (helpIconElement && rightSection)
|
|
46
|
-
? _jsxs(Group, { gap: 4, wrap: "nowrap", children: [rightSection, helpIconElement] })
|
|
47
|
-
: helpIconElement || rightSection;
|
|
48
|
-
return (_jsx(MantineTextarea, { ref: ref, size: size, radius: "sm", required: required, label: enhancedLabel, rightSection: composedRightSection, error: effectiveError, ...props }));
|
|
34
|
+
const labelProps = getInputLabelProps({
|
|
35
|
+
label,
|
|
36
|
+
required,
|
|
37
|
+
showOptional,
|
|
38
|
+
hasHelpIcon,
|
|
39
|
+
helpIconLabel,
|
|
40
|
+
onHelpIconClick,
|
|
41
|
+
});
|
|
42
|
+
return (_jsx(MantineTextarea, { ref: ref, size: size, radius: "sm", required: required, rightSection: rightSection, ...labelProps, error: effectiveError, ...props }));
|
|
49
43
|
});
|
|
50
44
|
TextArea.displayName = 'TextArea';
|