@dmsi/wedgekit-react 0.0.2
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 +35 -0
- package/dist/chunk-27KIIUAR.js +59 -0
- package/dist/chunk-2G2E2JMA.js +123 -0
- package/dist/chunk-4C66DLIJ.js +51 -0
- package/dist/chunk-4RD5ZF2V.js +55 -0
- package/dist/chunk-4RJKB7LC.js +14 -0
- package/dist/chunk-4T7F5BZZ.js +26 -0
- package/dist/chunk-5GOBP2JS.js +53 -0
- package/dist/chunk-6ZY524ID.js +42 -0
- package/dist/chunk-AWQSSKCK.js +32 -0
- package/dist/chunk-BNHSAFMP.js +93 -0
- package/dist/chunk-BWRHL2AG.js +439 -0
- package/dist/chunk-DKKYR6DS.js +132 -0
- package/dist/chunk-E5ALT5W7.js +182 -0
- package/dist/chunk-FY7PTP6E.js +322 -0
- package/dist/chunk-GTCSRHPF.js +119 -0
- package/dist/chunk-I2UVVKQI.js +12 -0
- package/dist/chunk-IGQVA7SC.js +41 -0
- package/dist/chunk-K3IKUSZW.js +59 -0
- package/dist/chunk-KENSVWOY.js +151 -0
- package/dist/chunk-KX3O6GJ6.js +138 -0
- package/dist/chunk-L4UM372R.js +253 -0
- package/dist/chunk-ORMEWXMH.js +37 -0
- package/dist/chunk-Q3FKEKIN.js +23 -0
- package/dist/chunk-SEKKGFM6.js +28 -0
- package/dist/chunk-SY3HT54E.js +91 -0
- package/dist/chunk-TAW5ZZ4Z.js +346 -0
- package/dist/chunk-TRUPPHBQ.js +109 -0
- package/dist/chunk-TU55CHXU.js +30 -0
- package/dist/chunk-TWZZB4WO.js +114 -0
- package/dist/chunk-TYI74BSP.js +62 -0
- package/dist/chunk-U42SKNR6.js +104 -0
- package/dist/chunk-UU3FA6LV.js +72 -0
- package/dist/chunk-WVUIIBRR.js +51 -0
- package/dist/chunk-XUIPGYP5.js +39 -0
- package/dist/chunk-Z4UCFUF7.js +299 -0
- package/dist/components/Breadcrumbs.cjs +376 -0
- package/dist/components/Breadcrumbs.js +90 -0
- package/dist/components/Button.cjs +319 -0
- package/dist/components/Button.js +8 -0
- package/dist/components/CalendarRange.cjs +520 -0
- package/dist/components/CalendarRange.js +13 -0
- package/dist/components/Caption.cjs +283 -0
- package/dist/components/Caption.js +80 -0
- package/dist/components/Checkbox.cjs +378 -0
- package/dist/components/Checkbox.js +11 -0
- package/dist/components/ContentTab.cjs +382 -0
- package/dist/components/ContentTab.js +10 -0
- package/dist/components/ContentTabs.cjs +472 -0
- package/dist/components/ContentTabs.js +98 -0
- package/dist/components/DMSiLogo.cjs +79 -0
- package/dist/components/DMSiLogo.js +56 -0
- package/dist/components/DataGrid.cjs +3113 -0
- package/dist/components/DataGrid.js +758 -0
- package/dist/components/DataGridCell.cjs +1907 -0
- package/dist/components/DataGridCell.js +24 -0
- package/dist/components/DataTable.cjs +791 -0
- package/dist/components/DataTable.js +720 -0
- package/dist/components/DateInput.cjs +1130 -0
- package/dist/components/DateInput.js +170 -0
- package/dist/components/DateRangeInput.cjs +1131 -0
- package/dist/components/DateRangeInput.js +171 -0
- package/dist/components/DebugJson.cjs +50 -0
- package/dist/components/DebugJson.js +27 -0
- package/dist/components/Display.cjs +234 -0
- package/dist/components/Display.js +12 -0
- package/dist/components/EditingContext.cjs +73 -0
- package/dist/components/EditingContext.js +35 -0
- package/dist/components/FilterGroup.cjs +1431 -0
- package/dist/components/FilterGroup.js +231 -0
- package/dist/components/FullViewportBox.cjs +35 -0
- package/dist/components/FullViewportBox.js +12 -0
- package/dist/components/Grid.cjs +69 -0
- package/dist/components/Grid.js +36 -0
- package/dist/components/GridContainer.cjs +125 -0
- package/dist/components/GridContainer.js +92 -0
- package/dist/components/Heading.cjs +238 -0
- package/dist/components/Heading.js +14 -0
- package/dist/components/HorizontalDivider.cjs +33 -0
- package/dist/components/HorizontalDivider.js +10 -0
- package/dist/components/Icon.cjs +98 -0
- package/dist/components/Icon.js +7 -0
- package/dist/components/Input.cjs +672 -0
- package/dist/components/Input.js +21 -0
- package/dist/components/InputGroup.cjs +270 -0
- package/dist/components/InputGroup.js +60 -0
- package/dist/components/Label.cjs +223 -0
- package/dist/components/Label.js +8 -0
- package/dist/components/Link.cjs +262 -0
- package/dist/components/Link.js +8 -0
- package/dist/components/List.cjs +37 -0
- package/dist/components/List.js +14 -0
- package/dist/components/LiveChatComponent.cjs +63 -0
- package/dist/components/LiveChatComponent.js +40 -0
- package/dist/components/LogoAgilityTopBar.cjs +115 -0
- package/dist/components/LogoAgilityTopBar.js +92 -0
- package/dist/components/LogoDMSiTopBar.cjs +79 -0
- package/dist/components/LogoDMSiTopBar.js +7 -0
- package/dist/components/LogoMillworkTopBar.cjs +221 -0
- package/dist/components/LogoMillworkTopBar.js +198 -0
- package/dist/components/MainBar.cjs +211 -0
- package/dist/components/MainBar.js +65 -0
- package/dist/components/Menu.cjs +437 -0
- package/dist/components/Menu.js +11 -0
- package/dist/components/MenuOption.cjs +483 -0
- package/dist/components/MenuOption.js +13 -0
- package/dist/components/MobileDataGrid.cjs +658 -0
- package/dist/components/MobileDataGrid.js +125 -0
- package/dist/components/Modal.cjs +783 -0
- package/dist/components/Modal.js +245 -0
- package/dist/components/ModalButtons.cjs +385 -0
- package/dist/components/ModalButtons.js +10 -0
- package/dist/components/ModalContent.cjs +57 -0
- package/dist/components/ModalContent.js +7 -0
- package/dist/components/ModalHeader.cjs +426 -0
- package/dist/components/ModalHeader.js +11 -0
- package/dist/components/ModalScrim.cjs +64 -0
- package/dist/components/ModalScrim.js +7 -0
- package/dist/components/NavigationTab.cjs +431 -0
- package/dist/components/NavigationTab.js +10 -0
- package/dist/components/NavigationTabs.cjs +477 -0
- package/dist/components/NavigationTabs.js +56 -0
- package/dist/components/Notification.cjs +640 -0
- package/dist/components/Notification.js +117 -0
- package/dist/components/OptionPill.cjs +478 -0
- package/dist/components/OptionPill.js +11 -0
- package/dist/components/Paragraph.cjs +231 -0
- package/dist/components/Paragraph.js +8 -0
- package/dist/components/Password.cjs +700 -0
- package/dist/components/Password.js +53 -0
- package/dist/components/ProjectBar.cjs +242 -0
- package/dist/components/ProjectBar.js +63 -0
- package/dist/components/Radio.cjs +349 -0
- package/dist/components/Radio.js +131 -0
- package/dist/components/Search.cjs +767 -0
- package/dist/components/Search.js +12 -0
- package/dist/components/Select.cjs +758 -0
- package/dist/components/Select.js +12 -0
- package/dist/components/SideMenu.cjs +54 -0
- package/dist/components/SideMenu.js +21 -0
- package/dist/components/SideMenuGroup.cjs +422 -0
- package/dist/components/SideMenuGroup.js +83 -0
- package/dist/components/SideMenuItem.cjs +388 -0
- package/dist/components/SideMenuItem.js +70 -0
- package/dist/components/Stack.cjs +138 -0
- package/dist/components/Stack.js +7 -0
- package/dist/components/StatusPill.cjs +265 -0
- package/dist/components/StatusPill.js +52 -0
- package/dist/components/Stepper.cjs +885 -0
- package/dist/components/Stepper.js +105 -0
- package/dist/components/Subheader.cjs +226 -0
- package/dist/components/Subheader.js +8 -0
- package/dist/components/Surface.cjs +98 -0
- package/dist/components/Surface.js +40 -0
- package/dist/components/Swatch.cjs +1728 -0
- package/dist/components/Swatch.js +1319 -0
- package/dist/components/Textarea.cjs +269 -0
- package/dist/components/Textarea.js +96 -0
- package/dist/components/Theme.cjs +36 -0
- package/dist/components/Theme.js +7 -0
- package/dist/components/Time.cjs +1118 -0
- package/dist/components/Time.js +353 -0
- package/dist/components/Toast.cjs +644 -0
- package/dist/components/Toast.js +218 -0
- package/dist/components/Tooltip.cjs +273 -0
- package/dist/components/Tooltip.js +9 -0
- package/dist/components/TopBar.cjs +352 -0
- package/dist/components/TopBar.js +132 -0
- package/dist/components/useInfiniteScroll.cjs +57 -0
- package/dist/components/useInfiniteScroll.js +8 -0
- package/dist/components/useMatchesMedia.cjs +53 -0
- package/dist/components/useMatchesMedia.js +9 -0
- package/dist/components/useMenuSystem.cjs +358 -0
- package/dist/components/useMenuSystem.js +11 -0
- package/dist/components/useMounted.cjs +39 -0
- package/dist/components/useMounted.js +8 -0
- package/dist/fonts.css +21 -0
- package/dist/icons-light[FILL]-PPZXOLWS.woff2 +0 -0
- package/dist/icons-normal[FILL]-PPZXOLWS.woff2 +0 -0
- package/dist/index.css +4401 -0
- package/dist/open-sans-55T6A4JE.woff2 +0 -0
- package/dist/types.cjs +18 -0
- package/dist/types.js +0 -0
- package/package.json +66 -0
- package/src/brand.css +125 -0
- package/src/classNames.ts +144 -0
- package/src/components/Breadcrumbs.tsx +116 -0
- package/src/components/Button.tsx +210 -0
- package/src/components/CalendarRange.tsx +429 -0
- package/src/components/Caption.tsx +101 -0
- package/src/components/Checkbox.tsx +196 -0
- package/src/components/ContentTab.tsx +66 -0
- package/src/components/ContentTabs.tsx +103 -0
- package/src/components/DMSiLogo.tsx +32 -0
- package/src/components/DataGrid.tsx +948 -0
- package/src/components/DataGridCell.tsx +384 -0
- package/src/components/DataTable.tsx +835 -0
- package/src/components/DateInput.tsx +188 -0
- package/src/components/DateRangeInput.tsx +179 -0
- package/src/components/DebugJson.tsx +24 -0
- package/src/components/Display.tsx +60 -0
- package/src/components/EditingContext.tsx +40 -0
- package/src/components/FilterGroup.tsx +234 -0
- package/src/components/FullViewportBox.tsx +11 -0
- package/src/components/Grid.tsx +75 -0
- package/src/components/GridContainer.tsx +124 -0
- package/src/components/Heading.tsx +66 -0
- package/src/components/HorizontalDivider.tsx +3 -0
- package/src/components/Icon.tsx +36 -0
- package/src/components/Input.tsx +511 -0
- package/src/components/InputGroup.tsx +51 -0
- package/src/components/Label.tsx +40 -0
- package/src/components/Link.tsx +106 -0
- package/src/components/List.tsx +10 -0
- package/src/components/LiveChatComponent.tsx +56 -0
- package/src/components/LogoAgilityTopBar.tsx +53 -0
- package/src/components/LogoDMSiTopBar.tsx +32 -0
- package/src/components/LogoMillworkTopBar.tsx +118 -0
- package/src/components/MainBar.tsx +83 -0
- package/src/components/Menu.tsx +286 -0
- package/src/components/MenuOption.tsx +275 -0
- package/src/components/MobileDataGrid.tsx +135 -0
- package/src/components/Modal.tsx +271 -0
- package/src/components/ModalButtons.tsx +44 -0
- package/src/components/ModalContent.tsx +23 -0
- package/src/components/ModalHeader.tsx +41 -0
- package/src/components/ModalScrim.tsx +35 -0
- package/src/components/NavigationTab.tsx +89 -0
- package/src/components/NavigationTabs.tsx +63 -0
- package/src/components/Notification.tsx +120 -0
- package/src/components/OptionPill.tsx +114 -0
- package/src/components/Paragraph.tsx +49 -0
- package/src/components/Password.tsx +46 -0
- package/src/components/ProjectBar.tsx +76 -0
- package/src/components/Radio.tsx +140 -0
- package/src/components/Search.tsx +129 -0
- package/src/components/Select.tsx +104 -0
- package/src/components/SideMenu.tsx +21 -0
- package/src/components/SideMenuGroup.tsx +81 -0
- package/src/components/SideMenuItem.tsx +90 -0
- package/src/components/Stack.tsx +179 -0
- package/src/components/StatusPill.tsx +51 -0
- package/src/components/Stepper.tsx +91 -0
- package/src/components/Subheader.tsx +44 -0
- package/src/components/Surface.tsx +34 -0
- package/src/components/Swatch.tsx +1066 -0
- package/src/components/Textarea.tsx +101 -0
- package/src/components/Theme.tsx +13 -0
- package/src/components/Time.tsx +438 -0
- package/src/components/Toast.tsx +244 -0
- package/src/components/Tooltip.tsx +137 -0
- package/src/components/TopBar.tsx +124 -0
- package/src/components/useInfiniteScroll.tsx +40 -0
- package/src/components/useMatchesMedia.tsx +28 -0
- package/src/components/useMenuSystem.tsx +367 -0
- package/src/components/useMounted.tsx +14 -0
- package/src/darkmode.css +140 -0
- package/src/fonts.css +23 -0
- package/src/index.css +509 -0
- package/src/index.tsx +2 -0
- package/src/types.ts +149 -0
- package/src/utils/formatting.tsx +81 -0
- package/src/utils.ts +23 -0
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
ComponentProps,
|
|
4
|
+
ReactNode,
|
|
5
|
+
RefObject,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
|
|
11
|
+
import clsx from "clsx";
|
|
12
|
+
import {
|
|
13
|
+
baseTransition,
|
|
14
|
+
componentGap,
|
|
15
|
+
componentPaddingMinusBorder,
|
|
16
|
+
componentPaddingXUsingComponentGap,
|
|
17
|
+
typography,
|
|
18
|
+
} from "../classNames";
|
|
19
|
+
import { Label } from "./Label";
|
|
20
|
+
import { Icon } from "./Icon";
|
|
21
|
+
import {
|
|
22
|
+
getDecimalPlaceholder,
|
|
23
|
+
formatDecimalValue,
|
|
24
|
+
formatCurrencyDisplay,
|
|
25
|
+
} from "../utils/formatting";
|
|
26
|
+
import { TextAlign } from "../types";
|
|
27
|
+
|
|
28
|
+
export type InputVariant =
|
|
29
|
+
| "default"
|
|
30
|
+
| "search"
|
|
31
|
+
| "finder"
|
|
32
|
+
| "currency"
|
|
33
|
+
| "percentage"
|
|
34
|
+
| "uom";
|
|
35
|
+
|
|
36
|
+
export type InputFormatting = {
|
|
37
|
+
variant?: InputVariant;
|
|
38
|
+
decimals?: number;
|
|
39
|
+
uom?: string;
|
|
40
|
+
removeSearchIcon?: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type InputBaseProps = {
|
|
44
|
+
after?: ReactNode;
|
|
45
|
+
before?: ReactNode;
|
|
46
|
+
label?: string;
|
|
47
|
+
error?: boolean;
|
|
48
|
+
align?: TextAlign;
|
|
49
|
+
caption?: ReactNode;
|
|
50
|
+
required?: boolean;
|
|
51
|
+
selectOnFocus?: boolean;
|
|
52
|
+
inputContainerRef?: RefObject<HTMLLabelElement | null>;
|
|
53
|
+
removeRoundness?: boolean;
|
|
54
|
+
removeBorder?: boolean;
|
|
55
|
+
wrapperClassName?: string;
|
|
56
|
+
focus?: boolean;
|
|
57
|
+
} & InputFormatting &
|
|
58
|
+
Omit<ComponentProps<"input">, "align">;
|
|
59
|
+
|
|
60
|
+
export const InputBase = ({
|
|
61
|
+
before,
|
|
62
|
+
after,
|
|
63
|
+
type,
|
|
64
|
+
label,
|
|
65
|
+
error,
|
|
66
|
+
className,
|
|
67
|
+
align = "left",
|
|
68
|
+
caption,
|
|
69
|
+
required,
|
|
70
|
+
selectOnFocus,
|
|
71
|
+
removeRoundness,
|
|
72
|
+
inputContainerRef,
|
|
73
|
+
removeBorder,
|
|
74
|
+
wrapperClassName,
|
|
75
|
+
focus,
|
|
76
|
+
...props
|
|
77
|
+
}: InputBaseProps) => {
|
|
78
|
+
const attributes = {
|
|
79
|
+
"data-error": (error && !focus) || null,
|
|
80
|
+
"data-focus": focus || null,
|
|
81
|
+
};
|
|
82
|
+
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const input = inputRef.current;
|
|
86
|
+
const focusHandler = () => {
|
|
87
|
+
input?.select();
|
|
88
|
+
};
|
|
89
|
+
if (selectOnFocus) {
|
|
90
|
+
inputRef.current?.addEventListener("focus", focusHandler);
|
|
91
|
+
|
|
92
|
+
return () => {
|
|
93
|
+
input?.removeEventListener("focus", focusHandler);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}, [selectOnFocus]);
|
|
97
|
+
|
|
98
|
+
const inputBaseClass = clsx(
|
|
99
|
+
"w-full",
|
|
100
|
+
"flex flex-row items-center",
|
|
101
|
+
"bg-background-action-secondary-normal caret-icon-on-action-secondary-normal",
|
|
102
|
+
componentGap,
|
|
103
|
+
baseTransition,
|
|
104
|
+
"outline-transparent outline-2 -outline-offset-2",
|
|
105
|
+
componentPaddingMinusBorder,
|
|
106
|
+
!removeRoundness && "rounded-base",
|
|
107
|
+
!removeBorder && "border border-border-primary-normal",
|
|
108
|
+
"relative",
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const inputFocusClass = clsx(
|
|
112
|
+
"has-[[data-focus]]:border-transparent has-[[data-focus]]:outline-border-primary-focus focus-within:border-transparent focus-within:outline-border-primary-focus",
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const inputDisabledClass = clsx(
|
|
116
|
+
"has-disabled:bg-background-action-secondary-disabled",
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const inputReadOnlyClass = clsx(
|
|
120
|
+
"has-[input:not(:disabled):read-only]:outline-none has-[input:not(:disabled):read-only]:bg-transparent has-[input:not(:disabled):read-only]:border-transparent has-[input:not(:disabled):read-only]:pl-0",
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const inputInvalidClass = clsx(
|
|
124
|
+
"has-[[data-error]]:border-transparent has-[[data-error]]:not-focus-within:outline-border-primary-error has-[[data-error]]:not-focus-within:outline-1",
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<label
|
|
129
|
+
ref={inputContainerRef}
|
|
130
|
+
className={clsx(
|
|
131
|
+
"w-full flex flex-col",
|
|
132
|
+
"block",
|
|
133
|
+
"text-text-primary-normal has-disabled:text-text-primary-disabled",
|
|
134
|
+
componentGap,
|
|
135
|
+
)}
|
|
136
|
+
style={{
|
|
137
|
+
...props.style,
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
{label && (
|
|
141
|
+
<div className={clsx("flex items-center", componentGap)}>
|
|
142
|
+
<Label
|
|
143
|
+
className={clsx(
|
|
144
|
+
props.disabled || props.readOnly
|
|
145
|
+
? "cursor-default"
|
|
146
|
+
: "cursor-pointer",
|
|
147
|
+
)}
|
|
148
|
+
>
|
|
149
|
+
{label}
|
|
150
|
+
</Label>
|
|
151
|
+
|
|
152
|
+
{required && (
|
|
153
|
+
<span
|
|
154
|
+
className={clsx(typography.label, "text-text-critical-normal")}
|
|
155
|
+
>
|
|
156
|
+
*
|
|
157
|
+
</span>
|
|
158
|
+
)}
|
|
159
|
+
</div>
|
|
160
|
+
)}
|
|
161
|
+
|
|
162
|
+
<div
|
|
163
|
+
className={clsx(
|
|
164
|
+
inputBaseClass,
|
|
165
|
+
!props.disabled && inputInvalidClass,
|
|
166
|
+
inputFocusClass,
|
|
167
|
+
inputDisabledClass,
|
|
168
|
+
inputReadOnlyClass,
|
|
169
|
+
wrapperClassName,
|
|
170
|
+
)}
|
|
171
|
+
>
|
|
172
|
+
{before}
|
|
173
|
+
|
|
174
|
+
<input
|
|
175
|
+
ref={(el) => {
|
|
176
|
+
inputRef.current = el;
|
|
177
|
+
}}
|
|
178
|
+
type={type}
|
|
179
|
+
required={required}
|
|
180
|
+
{...props}
|
|
181
|
+
{...attributes}
|
|
182
|
+
id={props.id}
|
|
183
|
+
className={clsx(
|
|
184
|
+
"flex-1 outline-none w-full max-w-full min-h-6 min-w-0",
|
|
185
|
+
"[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
186
|
+
"placeholder:text-text-secondary-normal disabled:text-text-secondary-disabled",
|
|
187
|
+
align === "right" && "text-right",
|
|
188
|
+
align === "center" && "text-center",
|
|
189
|
+
componentPaddingXUsingComponentGap,
|
|
190
|
+
typography.paragraph,
|
|
191
|
+
className,
|
|
192
|
+
props.readOnly && !props.disabled && "!px-0",
|
|
193
|
+
)}
|
|
194
|
+
/>
|
|
195
|
+
|
|
196
|
+
{after}
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
{caption}
|
|
200
|
+
</label>
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export const Input = ({
|
|
205
|
+
variant = "default",
|
|
206
|
+
decimals,
|
|
207
|
+
uom,
|
|
208
|
+
removeSearchIcon,
|
|
209
|
+
value: propValue,
|
|
210
|
+
onChange,
|
|
211
|
+
onBlur,
|
|
212
|
+
onClear,
|
|
213
|
+
...props
|
|
214
|
+
}: Omit<ComponentProps<"input">, "value" | "onChange" | "align" | "children"> &
|
|
215
|
+
InputBaseProps & {
|
|
216
|
+
value?: string | number;
|
|
217
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
218
|
+
onClear?: () => void;
|
|
219
|
+
}) => {
|
|
220
|
+
const [internalValue, setInternalValue] = useState("");
|
|
221
|
+
const [displayValue, setDisplayValue] = useState("");
|
|
222
|
+
|
|
223
|
+
// Initialize values based on variant
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
const stringValue = propValue?.toString() ?? "";
|
|
226
|
+
|
|
227
|
+
if (variant === "currency") {
|
|
228
|
+
if (
|
|
229
|
+
propValue === undefined ||
|
|
230
|
+
propValue === "" ||
|
|
231
|
+
(typeof propValue === "number" && isNaN(propValue))
|
|
232
|
+
) {
|
|
233
|
+
setInternalValue("");
|
|
234
|
+
setDisplayValue("");
|
|
235
|
+
} else {
|
|
236
|
+
const numValue =
|
|
237
|
+
typeof propValue === "string" ? parseFloat(propValue) : propValue;
|
|
238
|
+
if (!isNaN(numValue)) {
|
|
239
|
+
const formatted = numValue.toFixed(decimals ?? 2);
|
|
240
|
+
setInternalValue(formatted);
|
|
241
|
+
setDisplayValue(formatCurrencyDisplay(formatted));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
setInternalValue(stringValue);
|
|
246
|
+
setDisplayValue(stringValue);
|
|
247
|
+
}
|
|
248
|
+
}, [propValue, decimals, variant]);
|
|
249
|
+
|
|
250
|
+
const getInputProps = () => {
|
|
251
|
+
const baseProps = {
|
|
252
|
+
...props,
|
|
253
|
+
...getDecimalPlaceholder(decimals),
|
|
254
|
+
value: propValue
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
switch (variant) {
|
|
258
|
+
case "search":
|
|
259
|
+
return {
|
|
260
|
+
...baseProps,
|
|
261
|
+
placeholder: props.placeholder ?? "Search",
|
|
262
|
+
className: "!mr-6",
|
|
263
|
+
value: displayValue,
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
case "finder":
|
|
267
|
+
return baseProps;
|
|
268
|
+
|
|
269
|
+
case "currency":
|
|
270
|
+
return {
|
|
271
|
+
...baseProps,
|
|
272
|
+
align: "right" as const,
|
|
273
|
+
type: "text" as const,
|
|
274
|
+
value: displayValue,
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
case "percentage":
|
|
278
|
+
case "uom":
|
|
279
|
+
return {
|
|
280
|
+
...baseProps,
|
|
281
|
+
type: "number" as const,
|
|
282
|
+
align: "right" as const,
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
default:
|
|
286
|
+
return baseProps;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const getBeforeElement = () => {
|
|
291
|
+
if (props.before) return props.before;
|
|
292
|
+
|
|
293
|
+
switch (variant) {
|
|
294
|
+
case "search":
|
|
295
|
+
return !removeSearchIcon ? (
|
|
296
|
+
<span className="text-icon-primary-normal contents">
|
|
297
|
+
<Icon name="search" />
|
|
298
|
+
</span>
|
|
299
|
+
) : null;
|
|
300
|
+
|
|
301
|
+
case "currency":
|
|
302
|
+
return (
|
|
303
|
+
<span className="text-icon-primary-normal contents">
|
|
304
|
+
<Icon name="attach_money" />
|
|
305
|
+
</span>
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
default:
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const getAfterElement = () => {
|
|
314
|
+
if (props.after) return props.after;
|
|
315
|
+
|
|
316
|
+
switch (variant) {
|
|
317
|
+
case "search": {
|
|
318
|
+
const hasValue = displayValue.length > 0;
|
|
319
|
+
return hasValue && !props.readOnly ? (
|
|
320
|
+
<Icon
|
|
321
|
+
name="close"
|
|
322
|
+
onClick={handleSearchReset}
|
|
323
|
+
className="cursor-pointer absolute right-2 bottom-2/4 translate-y-2/4"
|
|
324
|
+
/>
|
|
325
|
+
) : null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
case "finder":
|
|
329
|
+
return <Icon name="search" />;
|
|
330
|
+
|
|
331
|
+
case "uom":
|
|
332
|
+
return uom ? (
|
|
333
|
+
<span className="text-text-secondary-normal uppercase">
|
|
334
|
+
{uom.slice(0, 4)}
|
|
335
|
+
</span>
|
|
336
|
+
) : null;
|
|
337
|
+
|
|
338
|
+
case "percentage":
|
|
339
|
+
return (
|
|
340
|
+
<span className="text-icon-primary-normal contents">
|
|
341
|
+
<Icon name="percent" />
|
|
342
|
+
</span>
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
default:
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const handleSearchReset = () => {
|
|
351
|
+
setInternalValue("");
|
|
352
|
+
setDisplayValue("");
|
|
353
|
+
|
|
354
|
+
if (onChange) {
|
|
355
|
+
const syntheticEvent = {
|
|
356
|
+
target: { value: "" },
|
|
357
|
+
} as React.ChangeEvent<HTMLInputElement>;
|
|
358
|
+
|
|
359
|
+
if (typeof onChange === "function") {
|
|
360
|
+
onChange(syntheticEvent);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
onClear?.();
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
368
|
+
const rawValue = e.target.value;
|
|
369
|
+
|
|
370
|
+
if (variant === "search") {
|
|
371
|
+
setInternalValue(rawValue);
|
|
372
|
+
setDisplayValue(rawValue);
|
|
373
|
+
if (typeof onChange === "function") {
|
|
374
|
+
onChange(e);
|
|
375
|
+
}
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (variant === "currency") {
|
|
380
|
+
const raw = rawValue.replace(/,/g, ""); // Remove commas for processing
|
|
381
|
+
|
|
382
|
+
if (raw === "") {
|
|
383
|
+
setInternalValue("");
|
|
384
|
+
setDisplayValue("");
|
|
385
|
+
if (onChange) {
|
|
386
|
+
const syntheticEvent = {
|
|
387
|
+
...e,
|
|
388
|
+
target: { ...e.target, value: "" },
|
|
389
|
+
};
|
|
390
|
+
onChange(syntheticEvent);
|
|
391
|
+
}
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const regex = /^\d*\.?\d*$/;
|
|
396
|
+
if (!regex.test(raw)) return;
|
|
397
|
+
|
|
398
|
+
const parts = raw.split(".");
|
|
399
|
+
const currentDecimals = decimals ?? 2;
|
|
400
|
+
if (parts.length === 2 && parts[1].length > currentDecimals) return;
|
|
401
|
+
|
|
402
|
+
setInternalValue(raw);
|
|
403
|
+
setDisplayValue(formatCurrencyDisplay(raw));
|
|
404
|
+
|
|
405
|
+
const asNumber = Number(raw);
|
|
406
|
+
if (!isNaN(asNumber) && onChange) {
|
|
407
|
+
const syntheticEvent = {
|
|
408
|
+
...e,
|
|
409
|
+
target: { ...e.target, value: asNumber.toString() },
|
|
410
|
+
};
|
|
411
|
+
onChange(syntheticEvent);
|
|
412
|
+
}
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Default behavior for other variants
|
|
417
|
+
setInternalValue(rawValue);
|
|
418
|
+
setDisplayValue(rawValue);
|
|
419
|
+
if (typeof onChange === "function") {
|
|
420
|
+
onChange(e);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
|
|
425
|
+
if (variant === "currency") {
|
|
426
|
+
const formatted = formatDecimalValue(internalValue, decimals ?? 2);
|
|
427
|
+
setInternalValue(formatted);
|
|
428
|
+
setDisplayValue(formatCurrencyDisplay(formatted));
|
|
429
|
+
|
|
430
|
+
const asNumber = Number(formatted);
|
|
431
|
+
if (!isNaN(asNumber) && onChange) {
|
|
432
|
+
const syntheticEvent = {
|
|
433
|
+
...e,
|
|
434
|
+
target: { ...e.target, value: asNumber.toString() },
|
|
435
|
+
} as React.ChangeEvent<HTMLInputElement>;
|
|
436
|
+
onChange(syntheticEvent);
|
|
437
|
+
}
|
|
438
|
+
} else if (variant === "uom" || variant === "percentage") {
|
|
439
|
+
const formattedValue = formatDecimalValue(e.target.value, decimals);
|
|
440
|
+
e.target.value = formattedValue;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
onBlur?.(e);
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
const inputProps = getInputProps();
|
|
447
|
+
|
|
448
|
+
return (
|
|
449
|
+
<InputBase
|
|
450
|
+
{...inputProps}
|
|
451
|
+
before={getBeforeElement()}
|
|
452
|
+
after={getAfterElement()}
|
|
453
|
+
onChange={handleChange}
|
|
454
|
+
onBlur={handleBlur}
|
|
455
|
+
/>
|
|
456
|
+
);
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
Input.displayName = "Input";
|
|
460
|
+
|
|
461
|
+
// Legacy component exports for backward compatibility
|
|
462
|
+
export const Finder = (
|
|
463
|
+
props: Omit<ComponentProps<"input">, "value" | "align" | "children"> &
|
|
464
|
+
InputBaseProps & { value?: string | number },
|
|
465
|
+
) => <Input {...props} variant="finder" />;
|
|
466
|
+
|
|
467
|
+
export const UOM = (
|
|
468
|
+
props: Omit<ComponentProps<"input">, "value" | "align" | "children"> &
|
|
469
|
+
InputBaseProps & {
|
|
470
|
+
uom: string;
|
|
471
|
+
value?: string | number;
|
|
472
|
+
},
|
|
473
|
+
) => <Input {...props} variant="uom" />;
|
|
474
|
+
|
|
475
|
+
export const Currency = (
|
|
476
|
+
props: Omit<
|
|
477
|
+
ComponentProps<"input">,
|
|
478
|
+
"value" | "onChange" | "align" | "children"
|
|
479
|
+
> &
|
|
480
|
+
InputBaseProps & {
|
|
481
|
+
value?: number;
|
|
482
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
483
|
+
},
|
|
484
|
+
) => {
|
|
485
|
+
const handleCurrencyChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
486
|
+
// For currency, we want to pass the numeric value but maintain the string interface
|
|
487
|
+
props.onChange?.(e);
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
return (
|
|
491
|
+
<Input
|
|
492
|
+
{...props}
|
|
493
|
+
variant="currency"
|
|
494
|
+
decimals={props.decimals ?? 2}
|
|
495
|
+
onChange={handleCurrencyChange}
|
|
496
|
+
/>
|
|
497
|
+
);
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
export const Percentage = (
|
|
501
|
+
props: Omit<ComponentProps<"input">, "value" | "align" | "children"> &
|
|
502
|
+
InputBaseProps & {
|
|
503
|
+
value?: string | number;
|
|
504
|
+
},
|
|
505
|
+
) => <Input {...props} variant="percentage" />;
|
|
506
|
+
|
|
507
|
+
// Set display names for legacy components
|
|
508
|
+
Finder.displayName = "Finder";
|
|
509
|
+
UOM.displayName = "UOM";
|
|
510
|
+
Currency.displayName = "Currency";
|
|
511
|
+
Percentage.displayName = "Percentage";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ComponentProps, ReactNode } from "react";
|
|
3
|
+
import { Label } from "./Label";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import { useId } from "react";
|
|
6
|
+
import { componentGap, layoutGap } from "../classNames";
|
|
7
|
+
|
|
8
|
+
type InputGroupProps = {
|
|
9
|
+
label: string;
|
|
10
|
+
orientation?: "vertical" | "horizontal";
|
|
11
|
+
error?: boolean;
|
|
12
|
+
caption?: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const InputGroup = ({
|
|
16
|
+
label,
|
|
17
|
+
orientation = "horizontal",
|
|
18
|
+
error = false,
|
|
19
|
+
children,
|
|
20
|
+
caption,
|
|
21
|
+
...props
|
|
22
|
+
}: ComponentProps<"div"> & InputGroupProps) => {
|
|
23
|
+
const id = useId();
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div {...props} className={clsx("flex flex-col", componentGap)}>
|
|
27
|
+
<Label
|
|
28
|
+
as="label"
|
|
29
|
+
className={clsx({ "!text-text-primary-error": error })}
|
|
30
|
+
htmlFor={id}
|
|
31
|
+
>
|
|
32
|
+
{label}
|
|
33
|
+
</Label>
|
|
34
|
+
|
|
35
|
+
<div
|
|
36
|
+
className={clsx(
|
|
37
|
+
"flex *:py-mobile-component-padding desktop:*:py-desktop-component-padding compact:*:py-desktop-compact-component-padding",
|
|
38
|
+
orientation === "vertical"
|
|
39
|
+
? "flex-col"
|
|
40
|
+
: clsx("items-center", layoutGap),
|
|
41
|
+
)}
|
|
42
|
+
>
|
|
43
|
+
{children}
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
{caption}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
InputGroup.displayName = "InputGroup";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import { AsProps, TextAttributes, TypographyProps } from "../types";
|
|
3
|
+
import { componentPaddingXUsingComponentGap, typography } from "../classNames";
|
|
4
|
+
export type Tags = "span" | "label" | "p" | "a";
|
|
5
|
+
|
|
6
|
+
type LabelProps = {
|
|
7
|
+
as?: Tags;
|
|
8
|
+
} & AsProps<Tags> &
|
|
9
|
+
TextAttributes &
|
|
10
|
+
TypographyProps;
|
|
11
|
+
|
|
12
|
+
export const Label = ({
|
|
13
|
+
as = "span",
|
|
14
|
+
padded,
|
|
15
|
+
className,
|
|
16
|
+
color,
|
|
17
|
+
align,
|
|
18
|
+
...props
|
|
19
|
+
}: LabelProps) => {
|
|
20
|
+
const Element = as;
|
|
21
|
+
return (
|
|
22
|
+
<Element
|
|
23
|
+
className={clsx(
|
|
24
|
+
typography.label,
|
|
25
|
+
align === "left" && "text-left",
|
|
26
|
+
align === "center" && "text-center",
|
|
27
|
+
align === "right" && "text-right",
|
|
28
|
+
className,
|
|
29
|
+
padded && componentPaddingXUsingComponentGap,
|
|
30
|
+
)}
|
|
31
|
+
{...props}
|
|
32
|
+
style={{
|
|
33
|
+
...props.style,
|
|
34
|
+
color: color ? `var(--color-${color})` : undefined,
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Label.displayName = "Label";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import { MouseEvent } from "react";
|
|
3
|
+
|
|
4
|
+
import { AsProps, TextAttributes, TypographyProps } from "../types";
|
|
5
|
+
import { baseTransition, componentPaddingY, typography } from "../classNames";
|
|
6
|
+
|
|
7
|
+
export type LinkProps = AsProps &
|
|
8
|
+
TextAttributes &
|
|
9
|
+
TypographyProps & {
|
|
10
|
+
variant?: "primary" | "secondary" | "critical";
|
|
11
|
+
typographyStyle?: "paragraph" | "caption";
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
paddedY?: boolean;
|
|
14
|
+
onClick?: (event: MouseEvent<HTMLElement>) => void;
|
|
15
|
+
underline?: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const Link = ({
|
|
19
|
+
as = "a",
|
|
20
|
+
className,
|
|
21
|
+
variant = "primary",
|
|
22
|
+
typographyStyle = "paragraph",
|
|
23
|
+
disabled = false,
|
|
24
|
+
color,
|
|
25
|
+
paddedY,
|
|
26
|
+
align,
|
|
27
|
+
underline = false,
|
|
28
|
+
...props
|
|
29
|
+
}: LinkProps) => {
|
|
30
|
+
const Component = as;
|
|
31
|
+
|
|
32
|
+
const primaryStateStyles =
|
|
33
|
+
variant === "primary" &&
|
|
34
|
+
!disabled &&
|
|
35
|
+
clsx(
|
|
36
|
+
"text-text-link-normal hover:text-text-link-hover active:text-text-link-active",
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const secondaryStateStyles =
|
|
40
|
+
variant === "secondary" &&
|
|
41
|
+
!disabled &&
|
|
42
|
+
clsx(
|
|
43
|
+
"text-text-primary-normal hover:text-text-link-hover active:text-text-link-active",
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const criticalStateStyles =
|
|
47
|
+
variant === "critical" &&
|
|
48
|
+
!disabled &&
|
|
49
|
+
clsx(
|
|
50
|
+
"text-text-action-critical-normal hover:text-text-action-critical-hover active:text-text-action-critical-active",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const criticalStateDisabledStyles =
|
|
54
|
+
disabled &&
|
|
55
|
+
variant === "critical" &&
|
|
56
|
+
clsx("text-text-action-critical-disabled");
|
|
57
|
+
|
|
58
|
+
const disabledStateStyles =
|
|
59
|
+
disabled &&
|
|
60
|
+
["primary", "secondary"].includes(variant) &&
|
|
61
|
+
clsx("text-text-link-disabled");
|
|
62
|
+
|
|
63
|
+
const disabledStyles = disabled && clsx("pointer-events-none cursor-default");
|
|
64
|
+
const underlineStyles = underline
|
|
65
|
+
? "decoration-current"
|
|
66
|
+
: "decoration-transparent";
|
|
67
|
+
|
|
68
|
+
const paddingY = paddedY && componentPaddingY;
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<Component
|
|
72
|
+
className={clsx(
|
|
73
|
+
"inline",
|
|
74
|
+
disabled ? "cursor-default" : "cursor-pointer",
|
|
75
|
+
"underline decoration-[10%] underline-offset-[32%]",
|
|
76
|
+
!disabled && "hover:decoration-current",
|
|
77
|
+
!disabled && "active:decoration-transparent",
|
|
78
|
+
"flex flex-col items-center justify-center",
|
|
79
|
+
baseTransition,
|
|
80
|
+
primaryStateStyles,
|
|
81
|
+
secondaryStateStyles,
|
|
82
|
+
criticalStateStyles,
|
|
83
|
+
criticalStateDisabledStyles,
|
|
84
|
+
disabledStateStyles,
|
|
85
|
+
disabledStyles,
|
|
86
|
+
underlineStyles,
|
|
87
|
+
typographyStyle === "caption" && typography.caption,
|
|
88
|
+
typographyStyle === "paragraph" && typography.paragraph,
|
|
89
|
+
align === "left" && "text-left",
|
|
90
|
+
align === "center" && "text-center",
|
|
91
|
+
align === "right" && "text-right",
|
|
92
|
+
paddingY,
|
|
93
|
+
className,
|
|
94
|
+
)}
|
|
95
|
+
{...props}
|
|
96
|
+
style={{
|
|
97
|
+
...props.style,
|
|
98
|
+
color: color ? `var(--color-${color})` : undefined,
|
|
99
|
+
}}
|
|
100
|
+
aria-disabled={disabled}
|
|
101
|
+
tabIndex={disabled ? -1 : undefined}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
Link.displayName = "Link";
|