@appdirect/design-system 0.0.21 → 0.0.22
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/Select.js +11 -2
- package/dist/Combobox/Select.module.css +8 -0
- package/dist/Combobox/Select.tsx +16 -3
- package/dist/DESIGN.md +6 -2
- package/dist/DataDisplay/Alert.js +3 -2
- package/dist/DataDisplay/Alert.tsx +4 -1
- package/dist/DataDisplay/Badge.js +37 -12
- package/dist/DataDisplay/Badge.tsx +42 -12
- package/dist/Inputs/NumberInput.js +40 -28
- package/dist/Inputs/NumberInput.tsx +93 -32
- package/dist/Overlays/Modal.js +2 -2
- package/dist/Overlays/Modal.tsx +2 -2
- package/dist/contracts/index.json +1 -1
- package/dist/css/mantine.css +1499 -35
- package/dist/stories/Overlays/Drawer.stories.tsx +2 -2
- package/dist/stories/Overlays/Modal.stories.tsx +2 -2
- package/dist/stories/index.json +1 -1
- package/package.json +2 -2
package/dist/Combobox/Select.js
CHANGED
|
@@ -5,6 +5,7 @@ import { Select as MantineSelect, ActionIcon, Group } from '@mantine/core';
|
|
|
5
5
|
import { IconInfoCircle, IconSelector } from '@tabler/icons-react';
|
|
6
6
|
import { Text } from '../Typography/Text.js';
|
|
7
7
|
import { Tooltip } from '../Overlays/Tooltip.js';
|
|
8
|
+
import styles from './Select.module.css';
|
|
8
9
|
// ========================== COMPONENT ==========================
|
|
9
10
|
/**
|
|
10
11
|
* AppDirect Design System Select Component
|
|
@@ -52,7 +53,7 @@ import { Tooltip } from '../Overlays/Tooltip.js';
|
|
|
52
53
|
* />
|
|
53
54
|
* ```
|
|
54
55
|
*/
|
|
55
|
-
export const Select = forwardRef(({ size = 'sm', borderless = false, showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, error, errorCaption, variant, ...props }, ref) => {
|
|
56
|
+
export const Select = forwardRef(({ size = 'sm', borderless = false, showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, error, errorCaption, variant, classNames, ...props }, ref) => {
|
|
56
57
|
const effectiveError = error === true ? (errorCaption ?? true) : error;
|
|
57
58
|
const enhancedLabel = React.useMemo(() => {
|
|
58
59
|
if (!label)
|
|
@@ -67,6 +68,14 @@ export const Select = forwardRef(({ size = 'sm', borderless = false, showOptiona
|
|
|
67
68
|
const composedRightSection = helpIconElement
|
|
68
69
|
? _jsxs(Group, { gap: 4, wrap: "nowrap", children: [selectorIcon, helpIconElement] })
|
|
69
70
|
: selectorIcon;
|
|
70
|
-
|
|
71
|
+
const mergedClassNames = typeof classNames === 'function'
|
|
72
|
+
? classNames
|
|
73
|
+
: {
|
|
74
|
+
...classNames,
|
|
75
|
+
input: [borderless ? styles.borderless : undefined, classNames?.input]
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.join(' '),
|
|
78
|
+
};
|
|
79
|
+
return (_jsx(MantineSelect, { ...props, ref: ref, size: size, radius: "sm", required: required, label: enhancedLabel, rightSection: composedRightSection, rightSectionPointerEvents: hasHelpIcon || props.clearable ? 'auto' : 'none', variant: variant ?? 'default', classNames: mergedClassNames, error: effectiveError }));
|
|
71
80
|
});
|
|
72
81
|
Select.displayName = 'Select';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* borderless keeps default Input padding; only chrome is removed.
|
|
2
|
+
Do not use Mantine variant="unstyled" — it zeros --input-padding*. */
|
|
3
|
+
.borderless[data-variant]:not([data-error]):not([data-disabled]),
|
|
4
|
+
.borderless[data-variant]:not([data-error]):not([data-disabled]):hover,
|
|
5
|
+
.borderless[data-variant]:not([data-error]):focus {
|
|
6
|
+
background: transparent;
|
|
7
|
+
border-color: transparent;
|
|
8
|
+
}
|
package/dist/Combobox/Select.tsx
CHANGED
|
@@ -6,13 +6,14 @@ import { IconInfoCircle, IconSelector } from '@tabler/icons-react';
|
|
|
6
6
|
import { ComponentSize } from '../config';
|
|
7
7
|
import { Text } from '../Typography/Text';
|
|
8
8
|
import { Tooltip } from '../Overlays/Tooltip';
|
|
9
|
+
import styles from './Select.module.css';
|
|
9
10
|
|
|
10
11
|
// ========================== TYPES ==========================
|
|
11
12
|
|
|
12
13
|
export interface DSSelectProps extends Omit<MantineSelectProps, 'size' | 'radius' | 'rightSection'> {
|
|
13
14
|
/** Input size from design system scale */
|
|
14
15
|
size?: ComponentSize;
|
|
15
|
-
/**
|
|
16
|
+
/** No border/fill; keeps normal field padding (does not use Mantine unstyled) */
|
|
16
17
|
borderless?: boolean;
|
|
17
18
|
/** Whether to show "(Optional)" text after label */
|
|
18
19
|
showOptional?: boolean;
|
|
@@ -91,6 +92,7 @@ export const Select = forwardRef<HTMLInputElement, DSSelectProps>(
|
|
|
91
92
|
error,
|
|
92
93
|
errorCaption,
|
|
93
94
|
variant,
|
|
95
|
+
classNames,
|
|
94
96
|
...props
|
|
95
97
|
},
|
|
96
98
|
ref
|
|
@@ -134,8 +136,19 @@ export const Select = forwardRef<HTMLInputElement, DSSelectProps>(
|
|
|
134
136
|
? <Group gap={4} wrap="nowrap">{selectorIcon}{helpIconElement}</Group>
|
|
135
137
|
: selectorIcon;
|
|
136
138
|
|
|
139
|
+
const mergedClassNames =
|
|
140
|
+
typeof classNames === 'function'
|
|
141
|
+
? classNames
|
|
142
|
+
: {
|
|
143
|
+
...classNames,
|
|
144
|
+
input: [borderless ? styles.borderless : undefined, classNames?.input]
|
|
145
|
+
.filter(Boolean)
|
|
146
|
+
.join(' '),
|
|
147
|
+
};
|
|
148
|
+
|
|
137
149
|
return (
|
|
138
150
|
<MantineSelect
|
|
151
|
+
{...props}
|
|
139
152
|
ref={ref}
|
|
140
153
|
size={size}
|
|
141
154
|
radius="sm"
|
|
@@ -143,9 +156,9 @@ export const Select = forwardRef<HTMLInputElement, DSSelectProps>(
|
|
|
143
156
|
label={enhancedLabel}
|
|
144
157
|
rightSection={composedRightSection}
|
|
145
158
|
rightSectionPointerEvents={hasHelpIcon || props.clearable ? 'auto' : 'none'}
|
|
146
|
-
variant={
|
|
159
|
+
variant={variant ?? 'default'}
|
|
160
|
+
classNames={mergedClassNames}
|
|
147
161
|
error={effectiveError}
|
|
148
|
-
{...props}
|
|
149
162
|
/>
|
|
150
163
|
);
|
|
151
164
|
}
|
package/dist/DESIGN.md
CHANGED
|
@@ -623,12 +623,16 @@ These variables are injected by `@appdirect/design-tokens/css/foundations.css` a
|
|
|
623
623
|
### CSS load order
|
|
624
624
|
|
|
625
625
|
```css
|
|
626
|
-
@mantine/core/styles.css
|
|
626
|
+
@mantine/core/styles.css /* Mantine base — not styles.layer.css */
|
|
627
627
|
@appdirect/design-tokens/css/foundations.css /* --ad-* variables */
|
|
628
|
+
@appdirect/design-tokens/css/open-color.css /* --ad-open-color-* (host always loads this) */
|
|
628
629
|
@appdirect/design-tokens/css/mantine.css /* Mantine component overrides */
|
|
630
|
+
@mantine/dates/styles.css /* when using dates */
|
|
629
631
|
```
|
|
630
632
|
|
|
631
|
-
|
|
633
|
+
Do **not** import `tokens.css` in Mantine apps (duplicates foundations; unused by the adapter).
|
|
634
|
+
|
|
635
|
+
**Platform parity (micro-container + micro-ui-ts):** the host loads `foundations.css` + `open-color.css` and sets `window.mantineTheme` / `data-theme`. The remote loads Mantine component CSS (per-file allowlist) → `mantine.css` → dates, and merges the host theme in `MantineProvider`. Storybook and `app/layout.tsx` must follow the same order and host bridge so previews match remotes. See `packages/tokens/CONSUMING.md` Recipe 1.
|
|
632
636
|
|
|
633
637
|
---
|
|
634
638
|
|
|
@@ -53,8 +53,9 @@ import { ALERT_TO_MANTINE_COLOR } from '../types.js';
|
|
|
53
53
|
* <Alert color="danger" title="Error">Error message with light background</Alert>
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
|
-
export const Alert = forwardRef(({ color
|
|
56
|
+
export const Alert = forwardRef(({ color, type, icon: customIcon, title, withCloseButton = false, onClose, children, ...props }, ref) => {
|
|
57
57
|
// Keep `type` as a deprecated alias while `color` becomes the primary API.
|
|
58
|
+
// Do not default `color` in destructuring — that would shadow `type="info"` etc.
|
|
58
59
|
const semanticColor = color ?? type ?? 'default';
|
|
59
60
|
// Map semantic colors to Mantine colors and default icons
|
|
60
61
|
const getAlertConfig = (alertColor) => {
|
|
@@ -72,6 +73,6 @@ export const Alert = forwardRef(({ color = 'default', type, icon: customIcon, ti
|
|
|
72
73
|
};
|
|
73
74
|
const { color: mantineColor, icon: defaultIcon } = getAlertConfig(semanticColor);
|
|
74
75
|
const alertIcon = customIcon || defaultIcon;
|
|
75
|
-
return (_jsx(MantineAlert, { ref: ref, variant: "light", color: mantineColor, radius: "sm", icon: alertIcon, title: title, withCloseButton: withCloseButton, onClose: onClose, ...props, children: children }));
|
|
76
|
+
return (_jsx(MantineAlert, { ref: ref, variant: "light", color: mantineColor, radius: "sm", icon: alertIcon, title: title, withCloseButton: withCloseButton, onClose: onClose, ...props, "data-color": semanticColor, children: children }));
|
|
76
77
|
});
|
|
77
78
|
Alert.displayName = 'Alert';
|
|
@@ -77,7 +77,7 @@ export interface DSAlertProps extends Omit<MantineAlertProps, 'color' | 'variant
|
|
|
77
77
|
export const Alert = forwardRef<HTMLDivElement, DSAlertProps>(
|
|
78
78
|
(
|
|
79
79
|
{
|
|
80
|
-
color
|
|
80
|
+
color,
|
|
81
81
|
type,
|
|
82
82
|
icon: customIcon,
|
|
83
83
|
title,
|
|
@@ -89,6 +89,7 @@ export const Alert = forwardRef<HTMLDivElement, DSAlertProps>(
|
|
|
89
89
|
ref
|
|
90
90
|
) => {
|
|
91
91
|
// Keep `type` as a deprecated alias while `color` becomes the primary API.
|
|
92
|
+
// Do not default `color` in destructuring — that would shadow `type="info"` etc.
|
|
92
93
|
const semanticColor = color ?? type ?? 'default';
|
|
93
94
|
|
|
94
95
|
// Map semantic colors to Mantine colors and default icons
|
|
@@ -120,6 +121,8 @@ export const Alert = forwardRef<HTMLDivElement, DSAlertProps>(
|
|
|
120
121
|
withCloseButton={withCloseButton}
|
|
121
122
|
onClose={onClose}
|
|
122
123
|
{...props}
|
|
124
|
+
// Semantic name for mantine.css ([data-color=info|…]); must win over props.
|
|
125
|
+
data-color={semanticColor}
|
|
123
126
|
>
|
|
124
127
|
{children}
|
|
125
128
|
</MantineAlert>
|
|
@@ -39,30 +39,54 @@ import { Badge as MantineBadge } from '@mantine/core';
|
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
export const Badge = forwardRef(({ variant = 'filled', size = 'md', color = 'default', children, ...props }, ref) => {
|
|
42
|
-
//
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
// Legacy: variant used as semantic color when color stays default.
|
|
43
|
+
const resolvedColor = color === 'default' &&
|
|
44
|
+
['info', 'success', 'danger', 'pending', 'warning'].includes(variant || '')
|
|
45
|
+
? variant === 'warning'
|
|
46
|
+
? 'pending'
|
|
47
|
+
: variant
|
|
48
|
+
: color;
|
|
49
|
+
// Normalize aliases (blue/green/…) to semantic names for mantine.css [data-color].
|
|
50
|
+
const semanticDataColor = (() => {
|
|
47
51
|
switch (resolvedColor) {
|
|
48
52
|
case 'info':
|
|
49
53
|
case 'blue':
|
|
50
|
-
return '
|
|
54
|
+
return 'info';
|
|
51
55
|
case 'success':
|
|
52
56
|
case 'green':
|
|
53
|
-
return '
|
|
57
|
+
return 'success';
|
|
54
58
|
case 'danger':
|
|
55
59
|
case 'red':
|
|
56
|
-
return '
|
|
60
|
+
return 'danger';
|
|
57
61
|
case 'pending':
|
|
58
62
|
case 'warning':
|
|
59
63
|
case 'yellow':
|
|
60
|
-
return '
|
|
64
|
+
return 'pending';
|
|
61
65
|
case 'default':
|
|
62
66
|
case 'gray':
|
|
67
|
+
return 'default';
|
|
68
|
+
default: {
|
|
69
|
+
const _exhaustive = resolvedColor;
|
|
70
|
+
return _exhaustive;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
const getMantineColor = (semantic) => {
|
|
75
|
+
switch (semantic) {
|
|
76
|
+
case 'info':
|
|
77
|
+
return 'blue';
|
|
78
|
+
case 'success':
|
|
79
|
+
return 'green';
|
|
80
|
+
case 'danger':
|
|
81
|
+
return 'red';
|
|
82
|
+
case 'pending':
|
|
83
|
+
return 'yellow';
|
|
84
|
+
case 'default':
|
|
63
85
|
return 'gray';
|
|
64
|
-
default:
|
|
65
|
-
|
|
86
|
+
default: {
|
|
87
|
+
const _exhaustive = semantic;
|
|
88
|
+
return _exhaustive;
|
|
89
|
+
}
|
|
66
90
|
}
|
|
67
91
|
};
|
|
68
92
|
const getMantineVariant = (dsVariant) => {
|
|
@@ -73,6 +97,7 @@ export const Badge = forwardRef(({ variant = 'filled', size = 'md', color = 'def
|
|
|
73
97
|
return 'filled';
|
|
74
98
|
}
|
|
75
99
|
};
|
|
76
|
-
|
|
100
|
+
const mantineColor = getMantineColor(semanticDataColor);
|
|
101
|
+
return (_jsx(MantineBadge, { ref: ref, variant: getMantineVariant(variant), size: size, color: mantineColor, radius: "sm", ...props, "data-color": semanticDataColor, children: children }));
|
|
77
102
|
});
|
|
78
103
|
Badge.displayName = 'Badge';
|
|
@@ -64,31 +64,57 @@ export const Badge = forwardRef<HTMLDivElement, DSBadgeProps>(
|
|
|
64
64
|
},
|
|
65
65
|
ref
|
|
66
66
|
) => {
|
|
67
|
-
//
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
// Legacy: variant used as semantic color when color stays default.
|
|
68
|
+
const resolvedColor: DSBadgeColor =
|
|
69
|
+
color === 'default' &&
|
|
70
|
+
['info', 'success', 'danger', 'pending', 'warning'].includes(variant || '')
|
|
71
|
+
? variant === 'warning'
|
|
72
|
+
? 'pending'
|
|
73
|
+
: (variant as DSBadgeColor)
|
|
74
|
+
: color;
|
|
72
75
|
|
|
76
|
+
// Normalize aliases (blue/green/…) to semantic names for mantine.css [data-color].
|
|
77
|
+
const semanticDataColor = (() => {
|
|
73
78
|
switch (resolvedColor) {
|
|
74
79
|
case 'info':
|
|
75
80
|
case 'blue':
|
|
76
|
-
return '
|
|
81
|
+
return 'info' as const;
|
|
77
82
|
case 'success':
|
|
78
83
|
case 'green':
|
|
79
|
-
return '
|
|
84
|
+
return 'success' as const;
|
|
80
85
|
case 'danger':
|
|
81
86
|
case 'red':
|
|
82
|
-
return '
|
|
87
|
+
return 'danger' as const;
|
|
83
88
|
case 'pending':
|
|
84
89
|
case 'warning':
|
|
85
90
|
case 'yellow':
|
|
86
|
-
return '
|
|
91
|
+
return 'pending' as const;
|
|
87
92
|
case 'default':
|
|
88
93
|
case 'gray':
|
|
94
|
+
return 'default' as const;
|
|
95
|
+
default: {
|
|
96
|
+
const _exhaustive: never = resolvedColor;
|
|
97
|
+
return _exhaustive;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
|
+
|
|
102
|
+
const getMantineColor = (semantic: typeof semanticDataColor) => {
|
|
103
|
+
switch (semantic) {
|
|
104
|
+
case 'info':
|
|
105
|
+
return 'blue';
|
|
106
|
+
case 'success':
|
|
107
|
+
return 'green';
|
|
108
|
+
case 'danger':
|
|
109
|
+
return 'red';
|
|
110
|
+
case 'pending':
|
|
111
|
+
return 'yellow';
|
|
112
|
+
case 'default':
|
|
89
113
|
return 'gray';
|
|
90
|
-
default:
|
|
91
|
-
|
|
114
|
+
default: {
|
|
115
|
+
const _exhaustive: never = semantic;
|
|
116
|
+
return _exhaustive;
|
|
117
|
+
}
|
|
92
118
|
}
|
|
93
119
|
};
|
|
94
120
|
|
|
@@ -101,14 +127,18 @@ export const Badge = forwardRef<HTMLDivElement, DSBadgeProps>(
|
|
|
101
127
|
}
|
|
102
128
|
};
|
|
103
129
|
|
|
130
|
+
const mantineColor = getMantineColor(semanticDataColor);
|
|
131
|
+
|
|
104
132
|
return (
|
|
105
133
|
<MantineBadge
|
|
106
134
|
ref={ref}
|
|
107
135
|
variant={getMantineVariant(variant)}
|
|
108
136
|
size={size}
|
|
109
|
-
color={
|
|
137
|
+
color={mantineColor}
|
|
110
138
|
radius="sm"
|
|
111
139
|
{...props}
|
|
140
|
+
// Semantic name for mantine.css ([data-color=info|…]); must win over props.
|
|
141
|
+
data-color={semanticDataColor}
|
|
112
142
|
>
|
|
113
143
|
{children}
|
|
114
144
|
</MantineBadge>
|
|
@@ -1,49 +1,61 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import React, { forwardRef } from 'react';
|
|
4
|
-
import { NumberInput as MantineNumberInput, ActionIcon, Group } from '@mantine/core';
|
|
5
|
-
import {
|
|
3
|
+
import React, { forwardRef, useRef } from 'react';
|
|
4
|
+
import { NumberInput as MantineNumberInput, ActionIcon, Group, Stack, } from '@mantine/core';
|
|
5
|
+
import { RiAddLine, RiInformationLine, RiSubtractLine } from '@remixicon/react';
|
|
6
6
|
import { Text } from '../Typography/Text.js';
|
|
7
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
|
+
};
|
|
8
15
|
// ========================== COMPONENT ==========================
|
|
9
16
|
/**
|
|
10
17
|
* AppDirect Design System NumberInput Component
|
|
11
18
|
*
|
|
12
19
|
* A numeric input built on top of Mantine's NumberInput with
|
|
13
20
|
* consistent design system styling and enforced radius.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* <NumberInput label="Quantity" placeholder="Enter a number" />
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```tsx
|
|
22
|
-
* <NumberInput
|
|
23
|
-
* label="Price"
|
|
24
|
-
* prefix="$"
|
|
25
|
-
* decimalScale={2}
|
|
26
|
-
* fixedDecimalScale
|
|
27
|
-
* showOptional
|
|
28
|
-
* hasHelpIcon
|
|
29
|
-
* helpIconLabel="Enter the item price"
|
|
30
|
-
* />
|
|
31
|
-
* ```
|
|
21
|
+
* Increment/decrement use Remix +/- icons (not Mantine chevrons).
|
|
32
22
|
*/
|
|
33
|
-
export const NumberInput = forwardRef(({ size = 'md', showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, rightSection, error, errorCaption, ...props }, ref) => {
|
|
23
|
+
export const NumberInput = forwardRef(({ size = 'md', showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, rightSection, error, errorCaption, hideControls, readOnly, disabled, handlersRef: handlersRefProp, ...props }, ref) => {
|
|
34
24
|
const effectiveError = error === true ? (errorCaption ?? true) : error;
|
|
25
|
+
const internalHandlersRef = useRef(null);
|
|
26
|
+
const setHandlersRef = (handlers) => {
|
|
27
|
+
internalHandlersRef.current = handlers ?? null;
|
|
28
|
+
if (!handlersRefProp)
|
|
29
|
+
return;
|
|
30
|
+
if (typeof handlersRefProp === 'function') {
|
|
31
|
+
handlersRefProp(handlers);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
handlersRefProp.current =
|
|
35
|
+
handlers;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
35
38
|
const enhancedLabel = React.useMemo(() => {
|
|
36
39
|
if (!label)
|
|
37
40
|
return label;
|
|
38
41
|
if (showOptional && !required) {
|
|
39
|
-
return (_jsxs(_Fragment, { children: [label,
|
|
42
|
+
return (_jsxs(_Fragment, { children: [label, ' ', _jsx(Text, { span: true, c: "dimmed", fw: "normal", children: "(Optional)" })] }));
|
|
40
43
|
}
|
|
41
44
|
return label;
|
|
42
45
|
}, [label, showOptional, required]);
|
|
43
|
-
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(
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 }));
|
|
48
60
|
});
|
|
49
61
|
NumberInput.displayName = 'NumberInput';
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { forwardRef } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import React, { forwardRef, useRef } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
NumberInput as MantineNumberInput,
|
|
6
|
+
NumberInputProps as MantineNumberInputProps,
|
|
7
|
+
NumberInputHandlers,
|
|
8
|
+
ActionIcon,
|
|
9
|
+
Group,
|
|
10
|
+
Stack,
|
|
11
|
+
} from '@mantine/core';
|
|
12
|
+
import { RiAddLine, RiInformationLine, RiSubtractLine } from '@remixicon/react';
|
|
6
13
|
import { ComponentSize } from '../config';
|
|
7
14
|
import { Text } from '../Typography/Text';
|
|
8
15
|
import { Tooltip } from '../Overlays/Tooltip';
|
|
@@ -27,6 +34,14 @@ export interface DSNumberInputProps extends Omit<MantineNumberInputProps, 'size'
|
|
|
27
34
|
errorCaption?: string;
|
|
28
35
|
}
|
|
29
36
|
|
|
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
|
+
|
|
30
45
|
// ========================== COMPONENT ==========================
|
|
31
46
|
|
|
32
47
|
/**
|
|
@@ -34,24 +49,7 @@ export interface DSNumberInputProps extends Omit<MantineNumberInputProps, 'size'
|
|
|
34
49
|
*
|
|
35
50
|
* A numeric input built on top of Mantine's NumberInput with
|
|
36
51
|
* consistent design system styling and enforced radius.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```tsx
|
|
40
|
-
* <NumberInput label="Quantity" placeholder="Enter a number" />
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```tsx
|
|
45
|
-
* <NumberInput
|
|
46
|
-
* label="Price"
|
|
47
|
-
* prefix="$"
|
|
48
|
-
* decimalScale={2}
|
|
49
|
-
* fixedDecimalScale
|
|
50
|
-
* showOptional
|
|
51
|
-
* hasHelpIcon
|
|
52
|
-
* helpIconLabel="Enter the item price"
|
|
53
|
-
* />
|
|
54
|
-
* ```
|
|
52
|
+
* Increment/decrement use Remix +/- icons (not Mantine chevrons).
|
|
55
53
|
*/
|
|
56
54
|
export const NumberInput = forwardRef<HTMLInputElement, DSNumberInputProps>(
|
|
57
55
|
(
|
|
@@ -66,18 +64,37 @@ export const NumberInput = forwardRef<HTMLInputElement, DSNumberInputProps>(
|
|
|
66
64
|
rightSection,
|
|
67
65
|
error,
|
|
68
66
|
errorCaption,
|
|
67
|
+
hideControls,
|
|
68
|
+
readOnly,
|
|
69
|
+
disabled,
|
|
70
|
+
handlersRef: handlersRefProp,
|
|
69
71
|
...props
|
|
70
72
|
},
|
|
71
73
|
ref
|
|
72
74
|
) => {
|
|
73
75
|
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
|
+
};
|
|
74
88
|
|
|
75
89
|
const enhancedLabel = React.useMemo(() => {
|
|
76
90
|
if (!label) return label;
|
|
77
91
|
if (showOptional && !required) {
|
|
78
92
|
return (
|
|
79
93
|
<>
|
|
80
|
-
{label}
|
|
94
|
+
{label}{' '}
|
|
95
|
+
<Text span c="dimmed" fw="normal">
|
|
96
|
+
(Optional)
|
|
97
|
+
</Text>
|
|
81
98
|
</>
|
|
82
99
|
);
|
|
83
100
|
}
|
|
@@ -85,11 +102,7 @@ export const NumberInput = forwardRef<HTMLInputElement, DSNumberInputProps>(
|
|
|
85
102
|
}, [label, showOptional, required]);
|
|
86
103
|
|
|
87
104
|
const helpIconElement = hasHelpIcon ? (
|
|
88
|
-
<Tooltip
|
|
89
|
-
label={helpIconLabel ?? 'Help'}
|
|
90
|
-
position="top"
|
|
91
|
-
withArrow
|
|
92
|
-
>
|
|
105
|
+
<Tooltip label={helpIconLabel ?? 'Help'} position="top" withArrow>
|
|
93
106
|
<ActionIcon
|
|
94
107
|
variant="transparent"
|
|
95
108
|
size="xs"
|
|
@@ -98,14 +111,58 @@ export const NumberInput = forwardRef<HTMLInputElement, DSNumberInputProps>(
|
|
|
98
111
|
color="gray"
|
|
99
112
|
style={{ cursor: onHelpIconClick ? 'pointer' : 'default' }}
|
|
100
113
|
>
|
|
101
|
-
<
|
|
114
|
+
<RiInformationLine size={14} aria-hidden />
|
|
102
115
|
</ActionIcon>
|
|
103
116
|
</Tooltip>
|
|
104
117
|
) : null;
|
|
105
118
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
119
|
+
const iconSize = CONTROL_ICON_SIZE[size] ?? 14;
|
|
120
|
+
const showDsControls = !hideControls && !readOnly && !disabled && rightSection == null;
|
|
121
|
+
|
|
122
|
+
const dsControls = showDsControls ? (
|
|
123
|
+
<Stack gap={0} justify="center">
|
|
124
|
+
<ActionIcon
|
|
125
|
+
variant="transparent"
|
|
126
|
+
size="xs"
|
|
127
|
+
tabIndex={-1}
|
|
128
|
+
aria-hidden
|
|
129
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
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
|
+
})();
|
|
109
166
|
|
|
110
167
|
return (
|
|
111
168
|
<MantineNumberInput
|
|
@@ -114,8 +171,12 @@ export const NumberInput = forwardRef<HTMLInputElement, DSNumberInputProps>(
|
|
|
114
171
|
radius="sm"
|
|
115
172
|
required={required}
|
|
116
173
|
label={enhancedLabel}
|
|
117
|
-
rightSection={composedRightSection}
|
|
118
174
|
error={effectiveError}
|
|
175
|
+
hideControls
|
|
176
|
+
readOnly={readOnly}
|
|
177
|
+
disabled={disabled}
|
|
178
|
+
handlersRef={setHandlersRef}
|
|
179
|
+
rightSection={composedRightSection}
|
|
119
180
|
{...props}
|
|
120
181
|
/>
|
|
121
182
|
);
|
package/dist/Overlays/Modal.js
CHANGED
|
@@ -33,7 +33,7 @@ import { Button } from '../Buttons/index.js';
|
|
|
33
33
|
* >
|
|
34
34
|
* <Stack gap="md">
|
|
35
35
|
* <Text>Are you sure you want to perform this action?</Text>
|
|
36
|
-
* <Inline justify="flex-
|
|
36
|
+
* <Inline justify="flex-start" gap="sm">
|
|
37
37
|
* <Button variant="outline">Cancel</Button>
|
|
38
38
|
* <Button variant="primary">Confirm</Button>
|
|
39
39
|
* </Inline>
|
|
@@ -56,6 +56,6 @@ export const ConfirmationModal = forwardRef(({ confirmLabel = 'Confirm', cancelL
|
|
|
56
56
|
onClose();
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
return (_jsx(Modal, { ref: ref, onClose: onClose, ...props, children: _jsxs(Stack, { gap: "md", children: [children, _jsxs(Inline, { justify: "flex-
|
|
59
|
+
return (_jsx(Modal, { ref: ref, onClose: onClose, ...props, children: _jsxs(Stack, { gap: "md", children: [children, _jsxs(Inline, { justify: "flex-start", gap: "sm", children: [_jsx(Button, { variant: "outline", onClick: handleCancel, children: cancelLabel }), _jsx(Button, { variant: confirmVariant, onClick: handleConfirm, loading: confirmLoading, children: confirmLabel })] })] }) }));
|
|
60
60
|
});
|
|
61
61
|
ConfirmationModal.displayName = 'ConfirmationModal';
|
package/dist/Overlays/Modal.tsx
CHANGED
|
@@ -45,7 +45,7 @@ export interface DSModalProps extends Omit<MantineModalProps, 'title'> {
|
|
|
45
45
|
* >
|
|
46
46
|
* <Stack gap="md">
|
|
47
47
|
* <Text>Are you sure you want to perform this action?</Text>
|
|
48
|
-
* <Inline justify="flex-
|
|
48
|
+
* <Inline justify="flex-start" gap="sm">
|
|
49
49
|
* <Button variant="outline">Cancel</Button>
|
|
50
50
|
* <Button variant="primary">Confirm</Button>
|
|
51
51
|
* </Inline>
|
|
@@ -142,7 +142,7 @@ export const ConfirmationModal = forwardRef<HTMLDivElement, ConfirmationModalPro
|
|
|
142
142
|
>
|
|
143
143
|
<Stack gap="md">
|
|
144
144
|
{children}
|
|
145
|
-
<Inline justify="flex-
|
|
145
|
+
<Inline justify="flex-start" gap="sm">
|
|
146
146
|
<Button variant="outline" onClick={handleCancel}>
|
|
147
147
|
{cancelLabel}
|
|
148
148
|
</Button>
|