@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.
Files changed (48) hide show
  1. package/dist/Combobox/ADMultiselect.js +91 -0
  2. package/dist/Combobox/ADMultiselect.tsx +237 -0
  3. package/dist/Combobox/AutocompleteClearable.js +33 -35
  4. package/dist/Combobox/AutocompleteClearable.tsx +56 -121
  5. package/dist/Combobox/SearchableSelect.js +23 -42
  6. package/dist/Combobox/SearchableSelect.tsx +33 -129
  7. package/dist/Combobox/Select.js +13 -19
  8. package/dist/Combobox/Select.tsx +15 -44
  9. package/dist/Combobox/index.js +1 -1
  10. package/dist/Combobox/index.ts +2 -2
  11. package/dist/ComplexComponents/Utilities/CopyButton.js +15 -27
  12. package/dist/ComplexComponents/Utilities/CopyButton.tsx +35 -49
  13. package/dist/DESIGN.md +2 -2
  14. package/dist/DataDisplay/Avatar.js +26 -81
  15. package/dist/DataDisplay/Avatar.tsx +35 -93
  16. package/dist/DataDisplay/Pill.js +21 -79
  17. package/dist/DataDisplay/Pill.tsx +34 -116
  18. package/dist/Inputs/ColorInput.js +12 -18
  19. package/dist/Inputs/ColorInput.tsx +13 -41
  20. package/dist/Inputs/NumberInput.js +12 -36
  21. package/dist/Inputs/NumberInput.tsx +13 -72
  22. package/dist/Inputs/TextArea.js +12 -18
  23. package/dist/Inputs/TextArea.tsx +13 -41
  24. package/dist/Inputs/TextInput.js +12 -18
  25. package/dist/Inputs/TextInput.tsx +13 -41
  26. package/dist/Inputs/inputLabel.js +35 -0
  27. package/dist/Inputs/inputLabel.tsx +83 -0
  28. package/dist/Layout/Inline.js +5 -42
  29. package/dist/Layout/Inline.tsx +6 -79
  30. package/dist/Overlays/Tooltip.js +2 -2
  31. package/dist/Overlays/Tooltip.tsx +4 -1
  32. package/dist/contracts/index.json +1 -1
  33. package/dist/css/mantine.css +193 -29
  34. package/dist/css/tokens.css +58 -18
  35. package/dist/index.js +3 -3
  36. package/dist/index.ts +4 -4
  37. package/dist/stories/Combobox/{Multiselect.stories.tsx → ADMultiselect.stories.tsx} +159 -53
  38. package/dist/stories/Combobox/SearchableSelect.stories.tsx +3 -3
  39. package/dist/stories/Combobox/Select.stories.tsx +1 -1
  40. package/dist/stories/ComplexComponents/Utilities/CopyButton.stories.tsx +4 -14
  41. package/dist/stories/Inputs/ColorInput.stories.tsx +12 -0
  42. package/dist/stories/Inputs/NumberInput.stories.tsx +12 -0
  43. package/dist/stories/Inputs/TextArea.stories.tsx +12 -0
  44. package/dist/stories/Inputs/TextInput.stories.tsx +12 -0
  45. package/dist/stories/index.json +42 -35
  46. package/package.json +2 -2
  47. package/dist/Combobox/Multiselect.js +0 -31
  48. package/dist/Combobox/Multiselect.tsx +0 -158
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import React, { forwardRef, useState, useCallback } from 'react';
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
- // Track image loading state
104
- const [imageError, setImageError] = useState(false);
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 (url.includes('broken-image')) return true;
116
- return false;
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
- }, [src]);
127
-
128
- // Handle image load error
129
- const handleImageError = useCallback(() => {
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
- // Render initials content
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
- // Handle different variants
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
- const avatarContent = getAvatarContent();
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
- {...avatarContent}
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';
@@ -1,81 +1,23 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { forwardRef } from 'react';
4
- import { Box, CloseButton } from '@mantine/core';
5
- import { Inline } from '../Layout/index.js';
6
- // Size configurations
7
- const sizeConfig = {
8
- xs: {
9
- height: 18,
10
- fontSize: 10,
11
- lineHeight: 10,
12
- letterSpacing: 0.1563,
13
- px: 8,
14
- gap: 0,
15
- closeSize: 18,
16
- },
17
- sm: {
18
- height: 24,
19
- fontSize: 11,
20
- lineHeight: 12,
21
- letterSpacing: 0.17,
22
- px: 8,
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';
@@ -1,125 +1,43 @@
1
1
  'use client';
2
2
 
3
- import { forwardRef } from 'react';
4
- import { Box, CloseButton } from '@mantine/core';
5
- import { Inline } from '../Layout';
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
- export interface DSPillProps extends React.ComponentPropsWithoutRef<'div'> {
8
- /** Pill content */
9
- children: React.ReactNode;
10
- /** Size of the pill */
11
- size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
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
- // Size configurations
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
- children,
70
- size = 'md',
71
- withRemoveButton = false,
72
- onRemove,
73
- style,
74
- ...others
75
- }, ref) => {
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, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import React, { forwardRef } from 'react';
4
- import { ColorInput as MantineColorInput, ActionIcon, Group } from '@mantine/core';
5
- import { IconInfoCircle } from '@tabler/icons-react';
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 enhancedLabel = React.useMemo(() => {
35
- if (!label)
36
- return label;
37
- if (showOptional && !required) {
38
- return (_jsxs(_Fragment, { children: [label, " ", _jsx(Text, { span: true, c: "dimmed", fw: "normal", children: "(Optional)" })] }));
39
- }
40
- return label;
41
- }, [label, showOptional, required]);
42
- 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;
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, ActionIcon, Group } from '@mantine/core';
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 { Text } from '../Typography/Text';
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 in the right section */
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 enhancedLabel = React.useMemo(() => {
75
- if (!label) return label;
76
- if (showOptional && !required) {
77
- return (
78
- <>
79
- {label} <Text span c="dimmed" fw="normal">(Optional)</Text>
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
- label={enhancedLabel}
116
- rightSection={composedRightSection}
87
+ rightSection={rightSection}
88
+ {...labelProps}
117
89
  error={effectiveError}
118
90
  {...props}
119
91
  />
@@ -1,10 +1,8 @@
1
1
  'use client';
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import React, { forwardRef } from 'react';
4
- import { NumberInput as MantineNumberInput, ActionIcon, Group, } from '@mantine/core';
5
- import { RiInformationLine } from '@remixicon/react';
6
- import { Text } from '../Typography/Text.js';
7
- import { Tooltip } from '../Overlays/Tooltip.js';
4
+ import { NumberInput as MantineNumberInput, } from '@mantine/core';
5
+ import { getInputLabelProps } from './inputLabel.js';
8
6
  // ========================== COMPONENT ==========================
9
7
  /**
10
8
  * AppDirect Design System NumberInput Component
@@ -15,36 +13,14 @@ import { Tooltip } from '../Overlays/Tooltip.js';
15
13
  */
16
14
  export const NumberInput = forwardRef(({ size = 'md', showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, leftSection, rightSection, error, errorCaption, hideControls, ...props }, ref) => {
17
15
  const effectiveError = error === true ? (errorCaption ?? true) : error;
18
- const enhancedLabel = React.useMemo(() => {
19
- if (!label)
20
- return label;
21
- if (showOptional && !required) {
22
- return (_jsxs(_Fragment, { children: [label, ' ', _jsx(Text, { span: true, c: "dimmed", fw: "normal", children: "(Optional)" })] }));
23
- }
24
- return label;
25
- }, [label, showOptional, required]);
26
- 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;
27
- const nativeControlsVisible = !hideControls && !props.readOnly && !props.disabled;
28
- const composedLeftSection = React.useMemo(() => {
29
- if (!helpIconElement)
30
- return leftSection;
31
- if (nativeControlsVisible) {
32
- if (leftSection) {
33
- return (_jsxs(Group, { gap: 4, wrap: "nowrap", children: [helpIconElement, leftSection] }));
34
- }
35
- return helpIconElement;
36
- }
37
- return leftSection;
38
- }, [helpIconElement, leftSection, nativeControlsVisible]);
39
- const composedRightSection = React.useMemo(() => {
40
- if (!helpIconElement || nativeControlsVisible) {
41
- return rightSection;
42
- }
43
- if (rightSection) {
44
- return (_jsxs(Group, { gap: 4, wrap: "nowrap", children: [rightSection, helpIconElement] }));
45
- }
46
- return helpIconElement;
47
- }, [helpIconElement, nativeControlsVisible, rightSection]);
48
- return (_jsx(MantineNumberInput, { ref: ref, size: size, radius: "sm", required: required, label: enhancedLabel, error: effectiveError, hideControls: hideControls, leftSection: composedLeftSection, 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 }));
49
25
  });
50
26
  NumberInput.displayName = 'NumberInput';