@appdirect/design-system 0.0.22 → 0.0.24

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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/Combobox/ADMultiselect.js +91 -0
  3. package/dist/Combobox/ADMultiselect.tsx +237 -0
  4. package/dist/Combobox/Select.js +13 -19
  5. package/dist/Combobox/Select.tsx +15 -44
  6. package/dist/Combobox/index.js +1 -1
  7. package/dist/Combobox/index.ts +2 -2
  8. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +1 -24
  9. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +2 -5
  10. package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +15 -22
  11. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +1 -2
  12. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.module.css +2 -9
  13. package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +4 -5
  14. package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +2 -6
  15. package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +1 -1
  16. package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +1 -1
  17. package/dist/DESIGN.md +7 -7
  18. package/dist/DataDisplay/Pill.js +21 -79
  19. package/dist/DataDisplay/Pill.tsx +34 -116
  20. package/dist/Inputs/ColorInput.js +12 -18
  21. package/dist/Inputs/ColorInput.tsx +13 -41
  22. package/dist/Inputs/NumberInput.js +15 -50
  23. package/dist/Inputs/NumberInput.tsx +18 -117
  24. package/dist/Inputs/Radio.js +1 -1
  25. package/dist/Inputs/Radio.tsx +1 -1
  26. package/dist/Inputs/RadioGroup.js +1 -1
  27. package/dist/Inputs/RadioGroup.tsx +1 -1
  28. package/dist/Inputs/TextArea.js +12 -18
  29. package/dist/Inputs/TextArea.tsx +13 -41
  30. package/dist/Inputs/TextInput.js +12 -18
  31. package/dist/Inputs/TextInput.tsx +13 -41
  32. package/dist/Inputs/inputLabel.js +35 -0
  33. package/dist/Inputs/inputLabel.tsx +83 -0
  34. package/dist/Overlays/Tooltip.js +2 -2
  35. package/dist/Overlays/Tooltip.tsx +4 -1
  36. package/dist/contracts/index.json +1 -1
  37. package/dist/css/foundations.css +44 -2
  38. package/dist/css/mantine.css +236 -43
  39. package/dist/css/tokens.css +58 -26
  40. package/dist/index.js +3 -3
  41. package/dist/index.ts +4 -4
  42. package/dist/stories/Combobox/{Multiselect.stories.tsx → ADMultiselect.stories.tsx} +159 -53
  43. package/dist/stories/Combobox/Select.stories.tsx +1 -1
  44. package/dist/stories/Inputs/ColorInput.stories.tsx +12 -0
  45. package/dist/stories/Inputs/NumberInput.stories.tsx +12 -0
  46. package/dist/stories/Inputs/Radio.stories.tsx +10 -5
  47. package/dist/stories/Inputs/RadioGroup.stories.tsx +122 -80
  48. package/dist/stories/Inputs/TextArea.stories.tsx +12 -0
  49. package/dist/stories/Inputs/TextInput.stories.tsx +12 -0
  50. package/dist/stories/index.json +40 -32
  51. package/package.json +10 -6
  52. package/dist/Combobox/Multiselect.js +0 -31
  53. package/dist/Combobox/Multiselect.tsx +0 -158
@@ -1,18 +1,12 @@
1
1
  'use client';
2
2
 
3
- import React, { forwardRef, useRef } from 'react';
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 { Text } from '../Typography/Text';
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 in the right section */
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 use Remix +/- icons (not Mantine chevrons).
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 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
- })();
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
- readOnly={readOnly}
177
- disabled={disabled}
178
- handlersRef={setHandlersRef}
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';
@@ -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 = 'md', label, ...props }, ref) => {
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)
@@ -53,7 +53,7 @@ export interface DSRadioProps extends Omit<MantineRadioProps, 'size'> {
53
53
  export const Radio = forwardRef<HTMLInputElement, DSRadioProps>(
54
54
  (
55
55
  {
56
- size = 'md',
56
+ size = 'sm',
57
57
  label,
58
58
  ...props
59
59
  },
@@ -44,7 +44,7 @@ import { Radio as MantineRadio } from '@mantine/core';
44
44
  * </RadioGroup>
45
45
  * ```
46
46
  */
47
- export const RadioGroup = forwardRef(({ size = 'md', label, ...props }, ref) => {
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)
@@ -57,7 +57,7 @@ export interface DSRadioGroupProps extends Omit<React.ComponentPropsWithoutRef<t
57
57
  export const RadioGroup = forwardRef<HTMLDivElement, DSRadioGroupProps>(
58
58
  (
59
59
  {
60
- size = 'md',
60
+ size = 'sm',
61
61
  label,
62
62
  ...props
63
63
  },
@@ -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 { Textarea as MantineTextarea, 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 { 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 enhancedLabel = React.useMemo(() => {
37
- if (!label)
38
- return label;
39
- if (showOptional && !required) {
40
- return (_jsxs(_Fragment, { children: [label, " ", _jsx(Text, { span: true, c: "dimmed", fw: "normal", children: "(Optional)" })] }));
41
- }
42
- return label;
43
- }, [label, showOptional, required]);
44
- 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;
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';
@@ -1,11 +1,9 @@
1
1
  'use client';
2
2
 
3
3
  import React, { forwardRef } from 'react';
4
- import { Textarea as MantineTextarea, TextareaProps as MantineTextareaProps, ActionIcon, Group } from '@mantine/core';
5
- import { IconInfoCircle } from '@tabler/icons-react';
4
+ import { Textarea as MantineTextarea, TextareaProps as MantineTextareaProps } 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 DSTextAreaProps extends Omit<MantineTextareaProps, 'size' | 'ra
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;
@@ -73,40 +71,14 @@ export const TextArea = forwardRef<HTMLTextAreaElement, DSTextAreaProps>(
73
71
  ) => {
74
72
  const effectiveError = error === true ? (errorCaption ?? true) : error;
75
73
 
76
- const enhancedLabel = React.useMemo(() => {
77
- if (!label) return label;
78
- if (showOptional && !required) {
79
- return (
80
- <>
81
- {label} <Text span c="dimmed" fw="normal">(Optional)</Text>
82
- </>
83
- );
84
- }
85
- return label;
86
- }, [label, showOptional, required]);
87
-
88
- const helpIconElement = hasHelpIcon ? (
89
- <Tooltip
90
- label={helpIconLabel ?? 'Help'}
91
- position="top"
92
- withArrow
93
- >
94
- <ActionIcon
95
- variant="transparent"
96
- size="xs"
97
- aria-label={helpIconLabel ?? 'Help'}
98
- onClick={onHelpIconClick}
99
- color="gray"
100
- style={{ cursor: onHelpIconClick ? 'pointer' : 'default' }}
101
- >
102
- <IconInfoCircle size={14} aria-hidden />
103
- </ActionIcon>
104
- </Tooltip>
105
- ) : null;
106
-
107
- const composedRightSection = (helpIconElement && rightSection)
108
- ? <Group gap={4} wrap="nowrap">{rightSection}{helpIconElement}</Group>
109
- : helpIconElement || rightSection;
74
+ const labelProps = getInputLabelProps({
75
+ label,
76
+ required,
77
+ showOptional,
78
+ hasHelpIcon,
79
+ helpIconLabel,
80
+ onHelpIconClick,
81
+ });
110
82
 
111
83
  return (
112
84
  <MantineTextarea
@@ -114,8 +86,8 @@ export const TextArea = forwardRef<HTMLTextAreaElement, DSTextAreaProps>(
114
86
  size={size}
115
87
  radius="sm"
116
88
  required={required}
117
- label={enhancedLabel}
118
- rightSection={composedRightSection}
89
+ rightSection={rightSection}
90
+ {...labelProps}
119
91
  error={effectiveError}
120
92
  {...props}
121
93
  />
@@ -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 { TextInput as MantineTextInput, 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 { TextInput as MantineTextInput } from '@mantine/core';
5
+ import { getInputLabelProps } from './inputLabel.js';
8
6
  /**
9
7
  * AppDirect Design System TextInput Component
10
8
  *
@@ -70,18 +68,14 @@ import { Tooltip } from '../Overlays/Tooltip.js';
70
68
  */
71
69
  export const TextInput = forwardRef(({ size = 'md', leftSection, rightSection, showOptional = false, required, label, hasHelpIcon = false, helpIconLabel, onHelpIconClick, error, errorCaption, ...props }, ref) => {
72
70
  const effectiveError = error === true ? (errorCaption ?? true) : error;
73
- const enhancedLabel = React.useMemo(() => {
74
- if (!label)
75
- return label;
76
- if (showOptional && !required) {
77
- return (_jsxs(_Fragment, { children: [label, " ", _jsx(Text, { span: true, c: "dimmed", fw: "normal", children: "(Optional)" })] }));
78
- }
79
- return label;
80
- }, [label, showOptional, required]);
81
- 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;
82
- const composedRightSection = (helpIconElement && rightSection)
83
- ? _jsxs(Group, { gap: 4, wrap: "nowrap", children: [rightSection, helpIconElement] })
84
- : helpIconElement || rightSection;
85
- return (_jsx(MantineTextInput, { ref: ref, size: size, radius: "sm", required: required, leftSection: leftSection, rightSection: composedRightSection, label: enhancedLabel, error: effectiveError, ...props }));
71
+ const labelProps = getInputLabelProps({
72
+ label,
73
+ required,
74
+ showOptional,
75
+ hasHelpIcon,
76
+ helpIconLabel,
77
+ onHelpIconClick,
78
+ });
79
+ return (_jsx(MantineTextInput, { ref: ref, size: size, radius: "sm", required: required, leftSection: leftSection, rightSection: rightSection, ...labelProps, error: effectiveError, ...props }));
86
80
  });
87
81
  TextInput.displayName = 'TextInput';
@@ -1,11 +1,9 @@
1
1
  'use client';
2
2
 
3
3
  import React, { forwardRef } from 'react';
4
- import { TextInput as MantineTextInput, TextInputProps as MantineTextInputProps, ActionIcon, Group } from '@mantine/core';
5
- import { IconInfoCircle } from '@tabler/icons-react';
4
+ import { TextInput as MantineTextInput, TextInputProps as MantineTextInputProps } 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
  /**
11
9
  * Enhanced TextInput props extending Mantine's TextInputProps
@@ -17,7 +15,7 @@ export interface DSTextInputProps extends Omit<MantineTextInputProps, 'size' | '
17
15
  required?: boolean;
18
16
  /** Whether to show "(Optional)" text after label */
19
17
  showOptional?: boolean;
20
- /** Whether to show a help icon with a tooltip in the right section */
18
+ /** Whether to show a (?) help icon with a tooltip to the right of the label */
21
19
  hasHelpIcon?: boolean;
22
20
  /** Tooltip label shown when hovering the help icon. Also used as aria-label for a11y */
23
21
  helpIconLabel?: string;
@@ -113,40 +111,14 @@ export const TextInput = forwardRef<HTMLInputElement, DSTextInputProps>(
113
111
  ) => {
114
112
  const effectiveError = error === true ? (errorCaption ?? true) : error;
115
113
 
116
- const enhancedLabel = React.useMemo(() => {
117
- if (!label) return label;
118
- if (showOptional && !required) {
119
- return (
120
- <>
121
- {label} <Text span c="dimmed" fw="normal">(Optional)</Text>
122
- </>
123
- );
124
- }
125
- return label;
126
- }, [label, showOptional, required]);
127
-
128
- const helpIconElement = hasHelpIcon ? (
129
- <Tooltip
130
- label={helpIconLabel ?? 'Help'}
131
- position="top"
132
- withArrow
133
- >
134
- <ActionIcon
135
- variant="transparent"
136
- size="xs"
137
- aria-label={helpIconLabel ?? 'Help'}
138
- onClick={onHelpIconClick}
139
- color="gray"
140
- style={{ cursor: onHelpIconClick ? 'pointer' : 'default' }}
141
- >
142
- <IconInfoCircle size={14} aria-hidden />
143
- </ActionIcon>
144
- </Tooltip>
145
- ) : null;
146
-
147
- const composedRightSection = (helpIconElement && rightSection)
148
- ? <Group gap={4} wrap="nowrap">{rightSection}{helpIconElement}</Group>
149
- : helpIconElement || rightSection;
114
+ const labelProps = getInputLabelProps({
115
+ label,
116
+ required,
117
+ showOptional,
118
+ hasHelpIcon,
119
+ helpIconLabel,
120
+ onHelpIconClick,
121
+ });
150
122
 
151
123
  return (
152
124
  <MantineTextInput
@@ -155,8 +127,8 @@ export const TextInput = forwardRef<HTMLInputElement, DSTextInputProps>(
155
127
  radius="sm"
156
128
  required={required}
157
129
  leftSection={leftSection}
158
- rightSection={composedRightSection}
159
- label={enhancedLabel}
130
+ rightSection={rightSection}
131
+ {...labelProps}
160
132
  error={effectiveError}
161
133
  {...props}
162
134
  />
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { ActionIcon } from '@mantine/core';
4
+ import { IconHelp } from '@tabler/icons-react';
5
+ import { Text } from '../Typography/Text.js';
6
+ import { Tooltip } from '../Overlays/Tooltip.js';
7
+ /**
8
+ * Shared label for DS form inputs: label, required asterisk or "(Optional)", then
9
+ * the (?) help icon, the order used by the Figma input label.
10
+ *
11
+ * Returns the props to spread onto the Mantine input. `withAsterisk` is only set
12
+ * when a help icon is shown: Mantine renders its asterisk inside the label after
13
+ * the content, which would put it behind the icon, so in that case the asterisk is
14
+ * rendered here instead. The help icon needs a label to attach to.
15
+ *
16
+ * Sizing follows Mantine core: the label font-size tracks the field `size`, set by the
17
+ * input tokens (`input.label.sizes`) on `.mantine-InputWrapper-label[data-size]`. The
18
+ * "(Optional)" text inherits it and the (?) icon is sized by the same tokens.
19
+ */
20
+ export function getInputLabelProps({ label, required, showOptional, hasHelpIcon, helpIconLabel, onHelpIconClick, }) {
21
+ if (!label)
22
+ return { label };
23
+ const optional = showOptional && !required && (_jsxs(_Fragment, { children: [' ', _jsx(Text, { span: true, fz: "inherit", c: "dimmed", fw: "normal", children: "(Optional)" })] }));
24
+ if (!hasHelpIcon) {
25
+ return optional ? { label: _jsxs(_Fragment, { children: [label, optional] }) } : { label };
26
+ }
27
+ return {
28
+ withAsterisk: false,
29
+ label: (_jsxs(_Fragment, { children: [label, required && (_jsx("span", { className: "mantine-InputWrapper-required", "aria-hidden": true, children: ' *' })), optional, ' ', _jsx(Tooltip, { label: helpIconLabel ?? 'Help', position: "top", withArrow: true, children: _jsx(ActionIcon, { variant: "transparent", size: "xs", color: "gray", "aria-label": helpIconLabel ?? 'Help', onClick: (event) => {
30
+ // The icon lives inside the <label>; don't let the click focus the field.
31
+ event.preventDefault();
32
+ onHelpIconClick?.(event);
33
+ }, children: _jsx(IconHelp, { size: 16, "aria-hidden": true }) }) })] })),
34
+ };
35
+ }
@@ -0,0 +1,83 @@
1
+ import React from 'react';
2
+ import { ActionIcon } from '@mantine/core';
3
+ import { IconHelp } from '@tabler/icons-react';
4
+ import { Text } from '../Typography/Text';
5
+ import { Tooltip } from '../Overlays/Tooltip';
6
+
7
+ export interface InputLabelOptions {
8
+ label?: React.ReactNode;
9
+ required?: boolean;
10
+ /** Show "(Optional)" after the label when the field is not required */
11
+ showOptional?: boolean;
12
+ /** Show a (?) help icon with a tooltip to the right of the label */
13
+ hasHelpIcon?: boolean;
14
+ /** Tooltip text for the help icon; also its aria-label */
15
+ helpIconLabel?: string;
16
+ /** Click handler for the help icon */
17
+ onHelpIconClick?: React.MouseEventHandler<HTMLButtonElement>;
18
+ }
19
+
20
+ /**
21
+ * Shared label for DS form inputs: label, required asterisk or "(Optional)", then
22
+ * the (?) help icon, the order used by the Figma input label.
23
+ *
24
+ * Returns the props to spread onto the Mantine input. `withAsterisk` is only set
25
+ * when a help icon is shown: Mantine renders its asterisk inside the label after
26
+ * the content, which would put it behind the icon, so in that case the asterisk is
27
+ * rendered here instead. The help icon needs a label to attach to.
28
+ *
29
+ * Sizing follows Mantine core: the label font-size tracks the field `size`, set by the
30
+ * input tokens (`input.label.sizes`) on `.mantine-InputWrapper-label[data-size]`. The
31
+ * "(Optional)" text inherits it and the (?) icon is sized by the same tokens.
32
+ */
33
+ export function getInputLabelProps({
34
+ label,
35
+ required,
36
+ showOptional,
37
+ hasHelpIcon,
38
+ helpIconLabel,
39
+ onHelpIconClick,
40
+ }: InputLabelOptions): { label: React.ReactNode; withAsterisk?: boolean } {
41
+ if (!label) return { label };
42
+
43
+ const optional = showOptional && !required && (
44
+ <>
45
+ {' '}
46
+ <Text span fz="inherit" c="dimmed" fw="normal">(Optional)</Text>
47
+ </>
48
+ );
49
+
50
+ if (!hasHelpIcon) {
51
+ return optional ? { label: <>{label}{optional}</> } : { label };
52
+ }
53
+
54
+ return {
55
+ withAsterisk: false,
56
+ label: (
57
+ <>
58
+ {label}
59
+ {required && (
60
+ <span className="mantine-InputWrapper-required" aria-hidden>
61
+ {' *'}
62
+ </span>
63
+ )}
64
+ {optional}{' '}
65
+ <Tooltip label={helpIconLabel ?? 'Help'} position="top" withArrow>
66
+ <ActionIcon
67
+ variant="transparent"
68
+ size="xs"
69
+ color="gray"
70
+ aria-label={helpIconLabel ?? 'Help'}
71
+ onClick={(event) => {
72
+ // The icon lives inside the <label>; don't let the click focus the field.
73
+ event.preventDefault();
74
+ onHelpIconClick?.(event);
75
+ }}
76
+ >
77
+ <IconHelp size={16} aria-hidden />
78
+ </ActionIcon>
79
+ </Tooltip>
80
+ </>
81
+ ),
82
+ };
83
+ }
@@ -41,7 +41,7 @@ import { Tooltip as MantineTooltip } from '@mantine/core';
41
41
  * <Button>Delayed</Button>
42
42
  * </Tooltip>
43
43
  */
44
- export const Tooltip = forwardRef(({ label, children, position = 'top', disabled = false, openDelay = 0, closeDelay = 0, keepMounted = false, width = 'auto', withArrow = true, arrowSize = 6, ...props }, ref) => {
44
+ export const Tooltip = forwardRef(({ label, children, position = 'top', disabled = false, openDelay = 0, closeDelay = 0, keepMounted = false, width = 'auto', maxWidth = 300, withArrow = true, arrowSize = 6, ...props }, ref) => {
45
45
  return (_jsx(MantineTooltip, { ref: ref, label: label, position: position, disabled: disabled, openDelay: openDelay, closeDelay: closeDelay, keepMounted: keepMounted, withArrow: withArrow, arrowSize: arrowSize,
46
46
  // Design system styling from Figma
47
47
  color: "dark", radius: "sm",
@@ -58,7 +58,7 @@ export const Tooltip = forwardRef(({ label, children, position = 'top', disabled
58
58
  borderRadius: '4px',
59
59
  border: 'none',
60
60
  width: width !== 'auto' ? width : undefined,
61
- maxWidth: width === 'auto' ? '300px' : undefined,
61
+ maxWidth: width === 'auto' ? `${maxWidth}px` : undefined,
62
62
  },
63
63
  arrow: {
64
64
  backgroundColor: '#212529',
@@ -22,6 +22,8 @@ export interface DSTooltipProps extends Omit<MantineTooltipProps, 'color' | 'rad
22
22
  keepMounted?: boolean;
23
23
  /** Custom width for tooltip */
24
24
  width?: number | 'auto';
25
+ /** Maximum width in px when `width` is 'auto' (default 300) */
26
+ maxWidth?: number;
25
27
  /** Whether to show arrow pointer */
26
28
  withArrow?: boolean;
27
29
  /** Size of arrow pointer */
@@ -78,6 +80,7 @@ export const Tooltip = forwardRef<HTMLDivElement, DSTooltipProps>(
78
80
  closeDelay = 0,
79
81
  keepMounted = false,
80
82
  width = 'auto',
83
+ maxWidth = 300,
81
84
  withArrow = true,
82
85
  arrowSize = 6,
83
86
  ...props
@@ -110,7 +113,7 @@ export const Tooltip = forwardRef<HTMLDivElement, DSTooltipProps>(
110
113
  borderRadius: '4px',
111
114
  border: 'none',
112
115
  width: width !== 'auto' ? width : undefined,
113
- maxWidth: width === 'auto' ? '300px' : undefined,
116
+ maxWidth: width === 'auto' ? `${maxWidth}px` : undefined,
114
117
  },
115
118
  arrow: {
116
119
  backgroundColor: '#212529',
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.22",
2
+ "version": "0.0.24",
3
3
  "contracts": [
4
4
  {
5
5
  "id": "Alert",