@trackunit/react-form-components 1.0.50 → 1.0.57
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/index.cjs.js +82 -93
- package/index.esm.js +82 -93
- package/package.json +8 -6
- package/src/components/BaseInput/BaseInput.d.ts +0 -4
- package/src/components/BaseInput/BaseInput.variants.d.ts +11 -11
- package/src/components/BaseInput/components/AddonRenderer.d.ts +16 -0
- package/src/components/BaseInput/components/PrefixRenderer.d.ts +4 -3
- package/src/components/BaseInput/components/SuffixRenderer.d.ts +1 -3
- package/src/components/BaseInput/components/index.d.ts +1 -2
- package/src/components/BaseInput/components/AddonAfterRenderer.d.ts +0 -7
- package/src/components/BaseInput/components/AddonBeforeRenderer.d.ts +0 -7
package/index.cjs.js
CHANGED
|
@@ -5,7 +5,9 @@ var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
|
5
5
|
var reactComponents = require('@trackunit/react-components');
|
|
6
6
|
var usehooksTs = require('usehooks-ts');
|
|
7
7
|
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
8
|
+
var uiDesignTokens = require('@trackunit/ui-design-tokens');
|
|
8
9
|
var React = require('react');
|
|
10
|
+
var stringTs = require('string-ts');
|
|
9
11
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
10
12
|
var polyfill = require('@js-temporal/polyfill');
|
|
11
13
|
var parsePhoneNumberFromString = require('libphonenumber-js');
|
|
@@ -134,7 +136,7 @@ const cvaActionContainer = cssClassVarianceUtilities.cvaMerge(["flex", "items-ce
|
|
|
134
136
|
//might need tweaking in the future
|
|
135
137
|
small: ["m-[1px]"],
|
|
136
138
|
medium: ["m-[3px]"],
|
|
137
|
-
large: ["m-[
|
|
139
|
+
large: ["m-[7px]"],
|
|
138
140
|
},
|
|
139
141
|
},
|
|
140
142
|
defaultVariants: {
|
|
@@ -182,7 +184,8 @@ const ActionButton = ({ type, value, dataTestId, size, disabled, className }) =>
|
|
|
182
184
|
return null;
|
|
183
185
|
}
|
|
184
186
|
};
|
|
185
|
-
|
|
187
|
+
const adjustedIconSize = size === "large" ? "medium" : size;
|
|
188
|
+
return (jsxRuntime.jsx("div", { className: cvaActionContainer({ className, size }), children: jsxRuntime.jsx(reactComponents.IconButton, { className: cvaActionButton({ size: adjustedIconSize }), dataTestId: dataTestId || "testIconButtonId", disabled: disabled, icon: jsxRuntime.jsx(reactComponents.Icon, { name: getIconName(), size: adjustedIconSize }), onClick: buttonAction, size: "small", variant: "secondary" }) }));
|
|
186
189
|
};
|
|
187
190
|
|
|
188
191
|
const cvaInputBase = cssClassVarianceUtilities.cvaMerge([
|
|
@@ -196,7 +199,17 @@ const cvaInputBase = cssClassVarianceUtilities.cvaMerge([
|
|
|
196
199
|
]);
|
|
197
200
|
const cvaInputBaseDisabled = cssClassVarianceUtilities.cvaMerge(["bg-slate-100", "hover:bg-slate-100", "hover:border-slate-300"]);
|
|
198
201
|
const cvaInputBaseInvalid = cssClassVarianceUtilities.cvaMerge(["border-danger-600"]);
|
|
199
|
-
const cvaInput = cssClassVarianceUtilities.cvaMerge([
|
|
202
|
+
const cvaInput = cssClassVarianceUtilities.cvaMerge([
|
|
203
|
+
"overflow-hidden",
|
|
204
|
+
"grid",
|
|
205
|
+
// ! The layout of the grid is critical to the functioning of the cvaInputItemPlacementManager 👇
|
|
206
|
+
// The min restriction of the middle column (--spacing-20) is
|
|
207
|
+
// effectively the minimum width available for the text input
|
|
208
|
+
"grid-cols-[min-content,minmax(var(--spacing-20),1fr),min-content]",
|
|
209
|
+
"grid-rows-1",
|
|
210
|
+
cvaInputBase(),
|
|
211
|
+
"focus-within:outline-native",
|
|
212
|
+
], {
|
|
200
213
|
variants: {
|
|
201
214
|
size: {
|
|
202
215
|
small: ["h-7"],
|
|
@@ -225,19 +238,30 @@ const cvaInput = cssClassVarianceUtilities.cvaMerge(["relative", "flex", "h-10",
|
|
|
225
238
|
],
|
|
226
239
|
defaultVariants: {
|
|
227
240
|
size: "medium",
|
|
241
|
+
disabled: false,
|
|
242
|
+
invalid: false,
|
|
243
|
+
isWarning: false,
|
|
228
244
|
},
|
|
229
245
|
});
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
],
|
|
246
|
+
/**
|
|
247
|
+
* Used for placing items in the grid, using a grid z-stack trick.
|
|
248
|
+
* The span position is used for the input field, which spans the entire grid.
|
|
249
|
+
*! Relies on the specific grid layout of cvaInput ☝️
|
|
250
|
+
*/
|
|
251
|
+
const cvaInputItemPlacementManager = cssClassVarianceUtilities.cvaMerge([], {
|
|
252
|
+
variants: {
|
|
253
|
+
position: {
|
|
254
|
+
before: ["col-start-1", "col-end-2", "row-start-1", "row-end-1"],
|
|
255
|
+
after: ["col-start-3", "col-end-4", "row-start-1", "row-end-1"],
|
|
256
|
+
span: ["col-start-1", "col-end-4", "row-start-1", "row-end-1"],
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
defaultVariants: {
|
|
260
|
+
position: "span",
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
const cvaAccessoriesContainer = cssClassVarianceUtilities.cvaMerge(["grid", "h-full", "w-min", "auto-cols-min", "grid-flow-col"]);
|
|
264
|
+
const cvaInputField = cssClassVarianceUtilities.cvaMerge(["w-full", "px-3", "border-0", "bg-transparent", "text-slate-900", "placeholder-slate-400", "text-sm", "truncate"], {
|
|
241
265
|
variants: {
|
|
242
266
|
size: {
|
|
243
267
|
small: ["py-0.5", "text-xs"],
|
|
@@ -252,31 +276,19 @@ const cvaInputField = cssClassVarianceUtilities.cvaMerge([
|
|
|
252
276
|
true: ["text-slate-500"],
|
|
253
277
|
false: [""],
|
|
254
278
|
},
|
|
255
|
-
autoFocus: {
|
|
256
|
-
true: [""],
|
|
257
|
-
false: ["focus-visible:outline-none"],
|
|
258
|
-
},
|
|
259
|
-
addonBefore: {
|
|
260
|
-
true: [""],
|
|
261
|
-
false: [""],
|
|
262
|
-
},
|
|
263
|
-
prefix: {
|
|
264
|
-
true: ["ps-10"],
|
|
265
|
-
false: [""],
|
|
266
|
-
},
|
|
267
279
|
},
|
|
268
280
|
compoundVariants: [
|
|
269
|
-
{
|
|
270
|
-
addonBefore: true,
|
|
271
|
-
prefix: true,
|
|
272
|
-
className: ["ps-4"],
|
|
273
|
-
},
|
|
274
281
|
{
|
|
275
282
|
disabled: true,
|
|
276
283
|
readOnly: true,
|
|
277
284
|
className: "text-slate-400",
|
|
278
285
|
},
|
|
279
286
|
],
|
|
287
|
+
defaultVariants: {
|
|
288
|
+
size: "medium",
|
|
289
|
+
disabled: false,
|
|
290
|
+
readOnly: false,
|
|
291
|
+
},
|
|
280
292
|
});
|
|
281
293
|
const cvaInputAddon = cssClassVarianceUtilities.cvaMerge([
|
|
282
294
|
"flex",
|
|
@@ -286,14 +298,21 @@ const cvaInputAddon = cssClassVarianceUtilities.cvaMerge([
|
|
|
286
298
|
"border-slate-300",
|
|
287
299
|
"text-slate-500",
|
|
288
300
|
"bg-slate-50",
|
|
289
|
-
|
|
290
|
-
|
|
301
|
+
"text-nowrap",
|
|
302
|
+
], {
|
|
291
303
|
variants: {
|
|
292
304
|
size: {
|
|
293
305
|
small: ["text-xs"],
|
|
294
306
|
medium: ["text-sm"],
|
|
295
307
|
large: ["text-sm"],
|
|
296
308
|
},
|
|
309
|
+
position: {
|
|
310
|
+
before: ["border-e", "rounded-s-lg"],
|
|
311
|
+
after: ["border-s", "rounded-e-lg"],
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
defaultVariants: {
|
|
315
|
+
size: "medium",
|
|
297
316
|
},
|
|
298
317
|
});
|
|
299
318
|
const cvaInputPrefix = cssClassVarianceUtilities.cvaMerge([
|
|
@@ -304,68 +323,38 @@ const cvaInputPrefix = cssClassVarianceUtilities.cvaMerge([
|
|
|
304
323
|
"hover:component-search-prefix",
|
|
305
324
|
"component-baseInput-prefix",
|
|
306
325
|
"component-search-borderless",
|
|
307
|
-
"pl-
|
|
308
|
-
"absolute",
|
|
309
|
-
"inset-y-0",
|
|
326
|
+
"pl-2",
|
|
310
327
|
], {
|
|
311
328
|
variants: {
|
|
312
329
|
disabled: {
|
|
313
330
|
true: ["text-slate-500"],
|
|
314
331
|
false: [""],
|
|
315
332
|
},
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
},
|
|
333
|
+
},
|
|
334
|
+
defaultVariants: {
|
|
335
|
+
disabled: false,
|
|
320
336
|
},
|
|
321
337
|
});
|
|
322
|
-
const cvaInputSuffix = cssClassVarianceUtilities.cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "
|
|
338
|
+
const cvaInputSuffix = cssClassVarianceUtilities.cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "pr-2"], {
|
|
323
339
|
variants: {
|
|
324
340
|
disabled: {
|
|
325
341
|
true: ["text-slate-500"],
|
|
326
342
|
false: [""],
|
|
327
343
|
},
|
|
328
|
-
addonAfter: {
|
|
329
|
-
true: ["relative"],
|
|
330
|
-
false: [""],
|
|
331
|
-
},
|
|
332
|
-
actions: {
|
|
333
|
-
true: ["right-6"],
|
|
334
|
-
false: [""],
|
|
335
|
-
},
|
|
336
344
|
},
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
addonAfter: true,
|
|
340
|
-
actions: true,
|
|
341
|
-
className: ["right-0"],
|
|
342
|
-
},
|
|
343
|
-
],
|
|
344
|
-
});
|
|
345
|
-
const cvaInputAddonAfter = cssClassVarianceUtilities.cvaMerge([cvaInputAddon(), "border-l", "rounded-r-lg", "ml-[1px]"], {
|
|
346
|
-
variants: {
|
|
347
|
-
size: {
|
|
348
|
-
small: ["text-xs"],
|
|
349
|
-
medium: ["text-sm"],
|
|
350
|
-
large: ["text-sm"],
|
|
351
|
-
},
|
|
345
|
+
defaultVariants: {
|
|
346
|
+
disabled: false,
|
|
352
347
|
},
|
|
353
348
|
});
|
|
354
349
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
return (jsxRuntime.jsx("div", { className: cvaInputAddonAfter({ size: fieldSize }), "data-testid": dataTestId ? `${dataTestId}-addonAfter` : null, children: addonAfter }));
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
// Renders the "addonBefore" element if provided
|
|
364
|
-
const AddonBeforeRenderer = ({ addonBefore, addonBeforeClassName, dataTestId, fieldSize, }) => {
|
|
365
|
-
if (!addonBefore) {
|
|
350
|
+
/**
|
|
351
|
+
* Renders the addon element if provided
|
|
352
|
+
*/
|
|
353
|
+
const AddonRenderer = ({ addon, dataTestId, className, fieldSize, position }) => {
|
|
354
|
+
if (!addon) {
|
|
366
355
|
return null;
|
|
367
356
|
}
|
|
368
|
-
return (jsxRuntime.jsx("div", { className:
|
|
357
|
+
return (jsxRuntime.jsx("div", { className: cvaInputAddon({ size: fieldSize, position, className }), "data-testid": dataTestId ? `${dataTestId}-addon${stringTs.titleCase(position)}` : null, children: addon }));
|
|
369
358
|
};
|
|
370
359
|
|
|
371
360
|
// Renders generic actions like "copy" if specified
|
|
@@ -404,7 +393,7 @@ const LockReasonRenderer = ({ lockReason, dataTestId, }) => {
|
|
|
404
393
|
};
|
|
405
394
|
|
|
406
395
|
// Renders the prefix element or falls back to a default prefix for certain types
|
|
407
|
-
const PrefixRenderer = ({ prefix, type,
|
|
396
|
+
const PrefixRenderer = React.forwardRef(({ prefix, type, dataTestId, disabled }, ref) => {
|
|
408
397
|
// Default icons for specific input types
|
|
409
398
|
const defaultPrefixMap = {
|
|
410
399
|
email: jsxRuntime.jsx(reactComponents.Icon, { name: "AtSymbol", size: "small" }),
|
|
@@ -416,25 +405,21 @@ const PrefixRenderer = ({ prefix, type, addonBefore, dataTestId, disabled, }) =>
|
|
|
416
405
|
if (!resolvedPrefix) {
|
|
417
406
|
return null;
|
|
418
407
|
}
|
|
419
|
-
return (jsxRuntime.jsx("div", { className: cvaInputPrefix({ disabled
|
|
420
|
-
};
|
|
408
|
+
return (jsxRuntime.jsx("div", { className: cvaInputPrefix({ disabled }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: ref, children: resolvedPrefix }));
|
|
409
|
+
});
|
|
421
410
|
|
|
422
411
|
// Renders the suffix element or shows an icon if invalid/warning
|
|
423
|
-
const SuffixRenderer = ({ suffix,
|
|
412
|
+
const SuffixRenderer = ({ suffix, isInvalid, isWarning, dataTestId, disabled, }) => {
|
|
424
413
|
// If user provided suffix that's not identical to addonBefore, render it
|
|
425
414
|
if (suffix) {
|
|
426
415
|
return (jsxRuntime.jsx("div", { className: cvaInputSuffix({
|
|
427
416
|
disabled,
|
|
428
|
-
addonAfter: addonAfter !== undefined,
|
|
429
|
-
actions: Boolean(actions),
|
|
430
417
|
}), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix }));
|
|
431
418
|
}
|
|
432
419
|
// If invalid or warning, render an icon (unless within FormGroup)
|
|
433
420
|
if (isInvalid || isWarning) {
|
|
434
421
|
return (jsxRuntime.jsx("div", { className: cvaInputSuffix({
|
|
435
422
|
disabled,
|
|
436
|
-
addonAfter: addonAfter !== undefined,
|
|
437
|
-
actions: Boolean(actions),
|
|
438
423
|
// Hides the icon if inside a FormGroup
|
|
439
424
|
className: "group-[.form-group]:hidden",
|
|
440
425
|
}), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: jsxRuntime.jsx(reactComponents.Icon, { color: isInvalid ? "danger" : "warning", name: "ExclamationTriangle", size: "small" }) }));
|
|
@@ -450,10 +435,14 @@ const SuffixRenderer = ({ suffix, addonAfter, actions, isInvalid, isWarning, dat
|
|
|
450
435
|
* For specific input types make sure to use the corresponding input component.
|
|
451
436
|
* This is a base used by our other input components such as TextInput, NumberInput, PasswordInput, etc.
|
|
452
437
|
*/
|
|
453
|
-
const BaseInput = React.forwardRef(({ className, isInvalid, dataTestId, prefix, suffix, addonBefore, addonAfter, actions, fieldSize = "medium", nonInteractive = false, inputClassName, placeholder,
|
|
438
|
+
const BaseInput = React.forwardRef(({ className, isInvalid, dataTestId, prefix, suffix, addonBefore, addonAfter, actions, fieldSize = "medium", nonInteractive = false, inputClassName, placeholder, isWarning, type, genericAction, style, ...rest }, ref) => {
|
|
454
439
|
// Derive final flags
|
|
455
440
|
const renderAsDisabled = Boolean(rest.disabled);
|
|
456
441
|
const renderAsReadonly = Boolean(rest.readOnly);
|
|
442
|
+
const beforeContainerRef = React.useRef(null);
|
|
443
|
+
const { width: beforeContainerWidth } = reactComponents.useGeometry(beforeContainerRef);
|
|
444
|
+
const afterContainerRef = React.useRef(null);
|
|
445
|
+
const { width: afterContainerWidth } = reactComponents.useGeometry(afterContainerRef);
|
|
457
446
|
// Keep a reference to the input element
|
|
458
447
|
const innerRef = React.useRef(null);
|
|
459
448
|
React.useImperativeHandle(ref, () => innerRef.current, []);
|
|
@@ -463,15 +452,15 @@ const BaseInput = React.forwardRef(({ className, isInvalid, dataTestId, prefix,
|
|
|
463
452
|
isWarning,
|
|
464
453
|
size: fieldSize,
|
|
465
454
|
className,
|
|
466
|
-
}), "data-testid": dataTestId ? `${dataTestId}-container` :
|
|
467
|
-
autoFocus: rest.autoFocus,
|
|
455
|
+
}), "data-testid": dataTestId ? `${dataTestId}-container` : undefined, style: style, children: [jsxRuntime.jsxs("div", { className: cvaAccessoriesContainer({ className: cvaInputItemPlacementManager({ position: "before" }) }), "data-testid": dataTestId ? `${dataTestId}-before-container` : undefined, ref: beforeContainerRef, children: [jsxRuntime.jsx(AddonRenderer, { addon: addonBefore, dataTestId: dataTestId, fieldSize: fieldSize, position: "before" }), jsxRuntime.jsx(PrefixRenderer, { dataTestId: dataTestId, disabled: renderAsDisabled, prefix: prefix, type: type })] }), jsxRuntime.jsx("input", { "aria-required": rest.required, className: cvaInputField({
|
|
468
456
|
readOnly: renderAsReadonly,
|
|
469
457
|
size: fieldSize,
|
|
470
458
|
disabled: renderAsDisabled,
|
|
471
|
-
className: inputClassName,
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
459
|
+
className: cvaInputItemPlacementManager({ position: "span", className: inputClassName }),
|
|
460
|
+
}), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef, style: {
|
|
461
|
+
paddingLeft: beforeContainerWidth ? `calc(${beforeContainerWidth}px + ${uiDesignTokens.themeSpacing[2]})` : undefined,
|
|
462
|
+
paddingRight: afterContainerWidth ? `calc(${afterContainerWidth}px + ${uiDesignTokens.themeSpacing[2]})` : undefined,
|
|
463
|
+
}, type: type, ...rest, disabled: renderAsDisabled, readOnly: renderAsReadonly || nonInteractive }), jsxRuntime.jsxs("div", { className: cvaAccessoriesContainer({ className: cvaInputItemPlacementManager({ position: "after" }) }), "data-testid": dataTestId ? `${dataTestId}-after-container` : undefined, ref: afterContainerRef, children: [jsxRuntime.jsx(LockReasonRenderer, { dataTestId: dataTestId + "-disabled", lockReason: rest.disabled }), jsxRuntime.jsx(LockReasonRenderer, { dataTestId: dataTestId + "-readonly", lockReason: rest.readOnly && !rest.disabled ? rest.readOnly : undefined }), jsxRuntime.jsx(GenericActionsRenderer, { fieldSize: fieldSize, genericAction: genericAction, innerRef: innerRef }), jsxRuntime.jsx(SuffixRenderer, { dataTestId: dataTestId, disabled: renderAsDisabled, isInvalid: isInvalid, isWarning: isWarning, suffix: suffix }), actions, jsxRuntime.jsx(AddonRenderer, { addon: addonAfter, dataTestId: dataTestId, fieldSize: fieldSize, position: "after" })] })] }));
|
|
475
464
|
});
|
|
476
465
|
BaseInput.displayName = "BaseInput";
|
|
477
466
|
|
|
@@ -2980,16 +2969,16 @@ exports.UrlField = UrlField;
|
|
|
2980
2969
|
exports.UrlInput = UrlInput;
|
|
2981
2970
|
exports.checkIfPhoneNumberHasPlus = checkIfPhoneNumberHasPlus;
|
|
2982
2971
|
exports.countryCodeToFlagEmoji = countryCodeToFlagEmoji;
|
|
2972
|
+
exports.cvaAccessoriesContainer = cvaAccessoriesContainer;
|
|
2983
2973
|
exports.cvaActionButton = cvaActionButton;
|
|
2984
2974
|
exports.cvaActionContainer = cvaActionContainer;
|
|
2985
2975
|
exports.cvaInput = cvaInput;
|
|
2986
2976
|
exports.cvaInputAddon = cvaInputAddon;
|
|
2987
|
-
exports.cvaInputAddonAfter = cvaInputAddonAfter;
|
|
2988
|
-
exports.cvaInputAddonBefore = cvaInputAddonBefore;
|
|
2989
2977
|
exports.cvaInputBase = cvaInputBase;
|
|
2990
2978
|
exports.cvaInputBaseDisabled = cvaInputBaseDisabled;
|
|
2991
2979
|
exports.cvaInputBaseInvalid = cvaInputBaseInvalid;
|
|
2992
2980
|
exports.cvaInputField = cvaInputField;
|
|
2981
|
+
exports.cvaInputItemPlacementManager = cvaInputItemPlacementManager;
|
|
2993
2982
|
exports.cvaInputPrefix = cvaInputPrefix;
|
|
2994
2983
|
exports.cvaInputSuffix = cvaInputSuffix;
|
|
2995
2984
|
exports.cvaSelect = cvaSelect;
|
package/index.esm.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { useNamespaceTranslation, registerTranslations, NamespaceTrans } from '@trackunit/i18n-library-translation';
|
|
3
|
-
import { IconButton, Icon, Tooltip, useIsTextTruncated, Heading, Text, Spinner, MenuItem, Tag, useIsFirstRender } from '@trackunit/react-components';
|
|
3
|
+
import { IconButton, Icon, Tooltip, useGeometry, useIsTextTruncated, Heading, Text, Spinner, MenuItem, Tag, useIsFirstRender } from '@trackunit/react-components';
|
|
4
4
|
import { useCopyToClipboard } from 'usehooks-ts';
|
|
5
5
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
6
|
+
import { themeSpacing } from '@trackunit/ui-design-tokens';
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
import React__default, { forwardRef, useRef, useImperativeHandle, useMemo, useState, useCallback, cloneElement, useEffect, useContext } from 'react';
|
|
9
|
+
import { titleCase } from 'string-ts';
|
|
8
10
|
import { uuidv4, nonNullable } from '@trackunit/shared-utils';
|
|
9
11
|
import { Temporal } from '@js-temporal/polyfill';
|
|
10
12
|
import parsePhoneNumberFromString, { isSupportedCountry, getCountries, getCountryCallingCode, AsYouType, parseIncompletePhoneNumber, isValidPhoneNumber } from 'libphonenumber-js';
|
|
@@ -115,7 +117,7 @@ const cvaActionContainer = cvaMerge(["flex", "items-center"], {
|
|
|
115
117
|
//might need tweaking in the future
|
|
116
118
|
small: ["m-[1px]"],
|
|
117
119
|
medium: ["m-[3px]"],
|
|
118
|
-
large: ["m-[
|
|
120
|
+
large: ["m-[7px]"],
|
|
119
121
|
},
|
|
120
122
|
},
|
|
121
123
|
defaultVariants: {
|
|
@@ -163,7 +165,8 @@ const ActionButton = ({ type, value, dataTestId, size, disabled, className }) =>
|
|
|
163
165
|
return null;
|
|
164
166
|
}
|
|
165
167
|
};
|
|
166
|
-
|
|
168
|
+
const adjustedIconSize = size === "large" ? "medium" : size;
|
|
169
|
+
return (jsx("div", { className: cvaActionContainer({ className, size }), children: jsx(IconButton, { className: cvaActionButton({ size: adjustedIconSize }), dataTestId: dataTestId || "testIconButtonId", disabled: disabled, icon: jsx(Icon, { name: getIconName(), size: adjustedIconSize }), onClick: buttonAction, size: "small", variant: "secondary" }) }));
|
|
167
170
|
};
|
|
168
171
|
|
|
169
172
|
const cvaInputBase = cvaMerge([
|
|
@@ -177,7 +180,17 @@ const cvaInputBase = cvaMerge([
|
|
|
177
180
|
]);
|
|
178
181
|
const cvaInputBaseDisabled = cvaMerge(["bg-slate-100", "hover:bg-slate-100", "hover:border-slate-300"]);
|
|
179
182
|
const cvaInputBaseInvalid = cvaMerge(["border-danger-600"]);
|
|
180
|
-
const cvaInput = cvaMerge([
|
|
183
|
+
const cvaInput = cvaMerge([
|
|
184
|
+
"overflow-hidden",
|
|
185
|
+
"grid",
|
|
186
|
+
// ! The layout of the grid is critical to the functioning of the cvaInputItemPlacementManager 👇
|
|
187
|
+
// The min restriction of the middle column (--spacing-20) is
|
|
188
|
+
// effectively the minimum width available for the text input
|
|
189
|
+
"grid-cols-[min-content,minmax(var(--spacing-20),1fr),min-content]",
|
|
190
|
+
"grid-rows-1",
|
|
191
|
+
cvaInputBase(),
|
|
192
|
+
"focus-within:outline-native",
|
|
193
|
+
], {
|
|
181
194
|
variants: {
|
|
182
195
|
size: {
|
|
183
196
|
small: ["h-7"],
|
|
@@ -206,19 +219,30 @@ const cvaInput = cvaMerge(["relative", "flex", "h-10", cvaInputBase()], {
|
|
|
206
219
|
],
|
|
207
220
|
defaultVariants: {
|
|
208
221
|
size: "medium",
|
|
222
|
+
disabled: false,
|
|
223
|
+
invalid: false,
|
|
224
|
+
isWarning: false,
|
|
209
225
|
},
|
|
210
226
|
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
],
|
|
227
|
+
/**
|
|
228
|
+
* Used for placing items in the grid, using a grid z-stack trick.
|
|
229
|
+
* The span position is used for the input field, which spans the entire grid.
|
|
230
|
+
*! Relies on the specific grid layout of cvaInput ☝️
|
|
231
|
+
*/
|
|
232
|
+
const cvaInputItemPlacementManager = cvaMerge([], {
|
|
233
|
+
variants: {
|
|
234
|
+
position: {
|
|
235
|
+
before: ["col-start-1", "col-end-2", "row-start-1", "row-end-1"],
|
|
236
|
+
after: ["col-start-3", "col-end-4", "row-start-1", "row-end-1"],
|
|
237
|
+
span: ["col-start-1", "col-end-4", "row-start-1", "row-end-1"],
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
defaultVariants: {
|
|
241
|
+
position: "span",
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
const cvaAccessoriesContainer = cvaMerge(["grid", "h-full", "w-min", "auto-cols-min", "grid-flow-col"]);
|
|
245
|
+
const cvaInputField = cvaMerge(["w-full", "px-3", "border-0", "bg-transparent", "text-slate-900", "placeholder-slate-400", "text-sm", "truncate"], {
|
|
222
246
|
variants: {
|
|
223
247
|
size: {
|
|
224
248
|
small: ["py-0.5", "text-xs"],
|
|
@@ -233,31 +257,19 @@ const cvaInputField = cvaMerge([
|
|
|
233
257
|
true: ["text-slate-500"],
|
|
234
258
|
false: [""],
|
|
235
259
|
},
|
|
236
|
-
autoFocus: {
|
|
237
|
-
true: [""],
|
|
238
|
-
false: ["focus-visible:outline-none"],
|
|
239
|
-
},
|
|
240
|
-
addonBefore: {
|
|
241
|
-
true: [""],
|
|
242
|
-
false: [""],
|
|
243
|
-
},
|
|
244
|
-
prefix: {
|
|
245
|
-
true: ["ps-10"],
|
|
246
|
-
false: [""],
|
|
247
|
-
},
|
|
248
260
|
},
|
|
249
261
|
compoundVariants: [
|
|
250
|
-
{
|
|
251
|
-
addonBefore: true,
|
|
252
|
-
prefix: true,
|
|
253
|
-
className: ["ps-4"],
|
|
254
|
-
},
|
|
255
262
|
{
|
|
256
263
|
disabled: true,
|
|
257
264
|
readOnly: true,
|
|
258
265
|
className: "text-slate-400",
|
|
259
266
|
},
|
|
260
267
|
],
|
|
268
|
+
defaultVariants: {
|
|
269
|
+
size: "medium",
|
|
270
|
+
disabled: false,
|
|
271
|
+
readOnly: false,
|
|
272
|
+
},
|
|
261
273
|
});
|
|
262
274
|
const cvaInputAddon = cvaMerge([
|
|
263
275
|
"flex",
|
|
@@ -267,14 +279,21 @@ const cvaInputAddon = cvaMerge([
|
|
|
267
279
|
"border-slate-300",
|
|
268
280
|
"text-slate-500",
|
|
269
281
|
"bg-slate-50",
|
|
270
|
-
|
|
271
|
-
|
|
282
|
+
"text-nowrap",
|
|
283
|
+
], {
|
|
272
284
|
variants: {
|
|
273
285
|
size: {
|
|
274
286
|
small: ["text-xs"],
|
|
275
287
|
medium: ["text-sm"],
|
|
276
288
|
large: ["text-sm"],
|
|
277
289
|
},
|
|
290
|
+
position: {
|
|
291
|
+
before: ["border-e", "rounded-s-lg"],
|
|
292
|
+
after: ["border-s", "rounded-e-lg"],
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
defaultVariants: {
|
|
296
|
+
size: "medium",
|
|
278
297
|
},
|
|
279
298
|
});
|
|
280
299
|
const cvaInputPrefix = cvaMerge([
|
|
@@ -285,68 +304,38 @@ const cvaInputPrefix = cvaMerge([
|
|
|
285
304
|
"hover:component-search-prefix",
|
|
286
305
|
"component-baseInput-prefix",
|
|
287
306
|
"component-search-borderless",
|
|
288
|
-
"pl-
|
|
289
|
-
"absolute",
|
|
290
|
-
"inset-y-0",
|
|
307
|
+
"pl-2",
|
|
291
308
|
], {
|
|
292
309
|
variants: {
|
|
293
310
|
disabled: {
|
|
294
311
|
true: ["text-slate-500"],
|
|
295
312
|
false: [""],
|
|
296
313
|
},
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
},
|
|
314
|
+
},
|
|
315
|
+
defaultVariants: {
|
|
316
|
+
disabled: false,
|
|
301
317
|
},
|
|
302
318
|
});
|
|
303
|
-
const cvaInputSuffix = cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "
|
|
319
|
+
const cvaInputSuffix = cvaMerge(["flex", "justify-center", "items-center", "text-slate-400", "pr-2"], {
|
|
304
320
|
variants: {
|
|
305
321
|
disabled: {
|
|
306
322
|
true: ["text-slate-500"],
|
|
307
323
|
false: [""],
|
|
308
324
|
},
|
|
309
|
-
addonAfter: {
|
|
310
|
-
true: ["relative"],
|
|
311
|
-
false: [""],
|
|
312
|
-
},
|
|
313
|
-
actions: {
|
|
314
|
-
true: ["right-6"],
|
|
315
|
-
false: [""],
|
|
316
|
-
},
|
|
317
325
|
},
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
addonAfter: true,
|
|
321
|
-
actions: true,
|
|
322
|
-
className: ["right-0"],
|
|
323
|
-
},
|
|
324
|
-
],
|
|
325
|
-
});
|
|
326
|
-
const cvaInputAddonAfter = cvaMerge([cvaInputAddon(), "border-l", "rounded-r-lg", "ml-[1px]"], {
|
|
327
|
-
variants: {
|
|
328
|
-
size: {
|
|
329
|
-
small: ["text-xs"],
|
|
330
|
-
medium: ["text-sm"],
|
|
331
|
-
large: ["text-sm"],
|
|
332
|
-
},
|
|
326
|
+
defaultVariants: {
|
|
327
|
+
disabled: false,
|
|
333
328
|
},
|
|
334
329
|
});
|
|
335
330
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
return (jsx("div", { className: cvaInputAddonAfter({ size: fieldSize }), "data-testid": dataTestId ? `${dataTestId}-addonAfter` : null, children: addonAfter }));
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
// Renders the "addonBefore" element if provided
|
|
345
|
-
const AddonBeforeRenderer = ({ addonBefore, addonBeforeClassName, dataTestId, fieldSize, }) => {
|
|
346
|
-
if (!addonBefore) {
|
|
331
|
+
/**
|
|
332
|
+
* Renders the addon element if provided
|
|
333
|
+
*/
|
|
334
|
+
const AddonRenderer = ({ addon, dataTestId, className, fieldSize, position }) => {
|
|
335
|
+
if (!addon) {
|
|
347
336
|
return null;
|
|
348
337
|
}
|
|
349
|
-
return (jsx("div", { className:
|
|
338
|
+
return (jsx("div", { className: cvaInputAddon({ size: fieldSize, position, className }), "data-testid": dataTestId ? `${dataTestId}-addon${titleCase(position)}` : null, children: addon }));
|
|
350
339
|
};
|
|
351
340
|
|
|
352
341
|
// Renders generic actions like "copy" if specified
|
|
@@ -385,7 +374,7 @@ const LockReasonRenderer = ({ lockReason, dataTestId, }) => {
|
|
|
385
374
|
};
|
|
386
375
|
|
|
387
376
|
// Renders the prefix element or falls back to a default prefix for certain types
|
|
388
|
-
const PrefixRenderer = ({ prefix, type,
|
|
377
|
+
const PrefixRenderer = forwardRef(({ prefix, type, dataTestId, disabled }, ref) => {
|
|
389
378
|
// Default icons for specific input types
|
|
390
379
|
const defaultPrefixMap = {
|
|
391
380
|
email: jsx(Icon, { name: "AtSymbol", size: "small" }),
|
|
@@ -397,25 +386,21 @@ const PrefixRenderer = ({ prefix, type, addonBefore, dataTestId, disabled, }) =>
|
|
|
397
386
|
if (!resolvedPrefix) {
|
|
398
387
|
return null;
|
|
399
388
|
}
|
|
400
|
-
return (jsx("div", { className: cvaInputPrefix({ disabled
|
|
401
|
-
};
|
|
389
|
+
return (jsx("div", { className: cvaInputPrefix({ disabled }), "data-testid": dataTestId ? `${dataTestId}-prefix` : null, ref: ref, children: resolvedPrefix }));
|
|
390
|
+
});
|
|
402
391
|
|
|
403
392
|
// Renders the suffix element or shows an icon if invalid/warning
|
|
404
|
-
const SuffixRenderer = ({ suffix,
|
|
393
|
+
const SuffixRenderer = ({ suffix, isInvalid, isWarning, dataTestId, disabled, }) => {
|
|
405
394
|
// If user provided suffix that's not identical to addonBefore, render it
|
|
406
395
|
if (suffix) {
|
|
407
396
|
return (jsx("div", { className: cvaInputSuffix({
|
|
408
397
|
disabled,
|
|
409
|
-
addonAfter: addonAfter !== undefined,
|
|
410
|
-
actions: Boolean(actions),
|
|
411
398
|
}), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix }));
|
|
412
399
|
}
|
|
413
400
|
// If invalid or warning, render an icon (unless within FormGroup)
|
|
414
401
|
if (isInvalid || isWarning) {
|
|
415
402
|
return (jsx("div", { className: cvaInputSuffix({
|
|
416
403
|
disabled,
|
|
417
|
-
addonAfter: addonAfter !== undefined,
|
|
418
|
-
actions: Boolean(actions),
|
|
419
404
|
// Hides the icon if inside a FormGroup
|
|
420
405
|
className: "group-[.form-group]:hidden",
|
|
421
406
|
}), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: jsx(Icon, { color: isInvalid ? "danger" : "warning", name: "ExclamationTriangle", size: "small" }) }));
|
|
@@ -431,10 +416,14 @@ const SuffixRenderer = ({ suffix, addonAfter, actions, isInvalid, isWarning, dat
|
|
|
431
416
|
* For specific input types make sure to use the corresponding input component.
|
|
432
417
|
* This is a base used by our other input components such as TextInput, NumberInput, PasswordInput, etc.
|
|
433
418
|
*/
|
|
434
|
-
const BaseInput = forwardRef(({ className, isInvalid, dataTestId, prefix, suffix, addonBefore, addonAfter, actions, fieldSize = "medium", nonInteractive = false, inputClassName, placeholder,
|
|
419
|
+
const BaseInput = forwardRef(({ className, isInvalid, dataTestId, prefix, suffix, addonBefore, addonAfter, actions, fieldSize = "medium", nonInteractive = false, inputClassName, placeholder, isWarning, type, genericAction, style, ...rest }, ref) => {
|
|
435
420
|
// Derive final flags
|
|
436
421
|
const renderAsDisabled = Boolean(rest.disabled);
|
|
437
422
|
const renderAsReadonly = Boolean(rest.readOnly);
|
|
423
|
+
const beforeContainerRef = useRef(null);
|
|
424
|
+
const { width: beforeContainerWidth } = useGeometry(beforeContainerRef);
|
|
425
|
+
const afterContainerRef = useRef(null);
|
|
426
|
+
const { width: afterContainerWidth } = useGeometry(afterContainerRef);
|
|
438
427
|
// Keep a reference to the input element
|
|
439
428
|
const innerRef = useRef(null);
|
|
440
429
|
useImperativeHandle(ref, () => innerRef.current, []);
|
|
@@ -444,15 +433,15 @@ const BaseInput = forwardRef(({ className, isInvalid, dataTestId, prefix, suffix
|
|
|
444
433
|
isWarning,
|
|
445
434
|
size: fieldSize,
|
|
446
435
|
className,
|
|
447
|
-
}), "data-testid": dataTestId ? `${dataTestId}-container` :
|
|
448
|
-
autoFocus: rest.autoFocus,
|
|
436
|
+
}), "data-testid": dataTestId ? `${dataTestId}-container` : undefined, style: style, children: [jsxs("div", { className: cvaAccessoriesContainer({ className: cvaInputItemPlacementManager({ position: "before" }) }), "data-testid": dataTestId ? `${dataTestId}-before-container` : undefined, ref: beforeContainerRef, children: [jsx(AddonRenderer, { addon: addonBefore, dataTestId: dataTestId, fieldSize: fieldSize, position: "before" }), jsx(PrefixRenderer, { dataTestId: dataTestId, disabled: renderAsDisabled, prefix: prefix, type: type })] }), jsx("input", { "aria-required": rest.required, className: cvaInputField({
|
|
449
437
|
readOnly: renderAsReadonly,
|
|
450
438
|
size: fieldSize,
|
|
451
439
|
disabled: renderAsDisabled,
|
|
452
|
-
className: inputClassName,
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
440
|
+
className: cvaInputItemPlacementManager({ position: "span", className: inputClassName }),
|
|
441
|
+
}), "data-testid": dataTestId, placeholder: renderAsDisabled ? undefined : placeholder, ref: innerRef, style: {
|
|
442
|
+
paddingLeft: beforeContainerWidth ? `calc(${beforeContainerWidth}px + ${themeSpacing[2]})` : undefined,
|
|
443
|
+
paddingRight: afterContainerWidth ? `calc(${afterContainerWidth}px + ${themeSpacing[2]})` : undefined,
|
|
444
|
+
}, type: type, ...rest, disabled: renderAsDisabled, readOnly: renderAsReadonly || nonInteractive }), jsxs("div", { className: cvaAccessoriesContainer({ className: cvaInputItemPlacementManager({ position: "after" }) }), "data-testid": dataTestId ? `${dataTestId}-after-container` : undefined, ref: afterContainerRef, children: [jsx(LockReasonRenderer, { dataTestId: dataTestId + "-disabled", lockReason: rest.disabled }), jsx(LockReasonRenderer, { dataTestId: dataTestId + "-readonly", lockReason: rest.readOnly && !rest.disabled ? rest.readOnly : undefined }), jsx(GenericActionsRenderer, { fieldSize: fieldSize, genericAction: genericAction, innerRef: innerRef }), jsx(SuffixRenderer, { dataTestId: dataTestId, disabled: renderAsDisabled, isInvalid: isInvalid, isWarning: isWarning, suffix: suffix }), actions, jsx(AddonRenderer, { addon: addonAfter, dataTestId: dataTestId, fieldSize: fieldSize, position: "after" })] })] }));
|
|
456
445
|
});
|
|
457
446
|
BaseInput.displayName = "BaseInput";
|
|
458
447
|
|
|
@@ -2914,4 +2903,4 @@ const useZodValidators = () => {
|
|
|
2914
2903
|
*/
|
|
2915
2904
|
setupLibraryTranslations();
|
|
2916
2905
|
|
|
2917
|
-
export { ActionButton, BaseInput, Checkbox, CheckboxField, ColorField, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, DropZoneDefaultLabel, EMAIL_REGEX, EmailField, EmailInput, FormFieldSelectAdapter, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneFieldWithController, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaActionButton, cvaActionContainer, cvaInput, cvaInputAddon,
|
|
2906
|
+
export { ActionButton, BaseInput, Checkbox, CheckboxField, ColorField, CreatableSelect, CreatableSelectField, DateField, DateInput, DropZone, DropZoneDefaultLabel, EMAIL_REGEX, EmailField, EmailInput, FormFieldSelectAdapter, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PasswordField, PasswordInput, PhoneField, PhoneFieldWithController, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SelectField, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, UrlField, UrlInput, checkIfPhoneNumberHasPlus, countryCodeToFlagEmoji, cvaAccessoriesContainer, cvaActionButton, cvaActionContainer, cvaInput, cvaInputAddon, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputItemPlacementManager, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectControl, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefixSuffix, cvaSelectXIcon, getCountryAbbreviation, getPhoneNumberWithPlus, isInvalidCountryCode, isInvalidPhoneNumber, isValidHEXColor, parseSchedule, phoneErrorMessage, serializeSchedule, useCustomComponents, useGetPhoneValidationRules, usePhoneInput, useZodValidators, validateEmailAddress, validatePhoneNumber, weekDay };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-form-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.57",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
"zod": "3.22.4",
|
|
18
18
|
"react-hook-form": "7.53.1",
|
|
19
19
|
"tailwind-merge": "^2.0.0",
|
|
20
|
-
"@trackunit/css-class-variance-utilities": "1.0.
|
|
21
|
-
"@trackunit/react-components": "1.1.
|
|
22
|
-
"@trackunit/ui-icons": "1.0.
|
|
23
|
-
"@trackunit/shared-utils": "1.2.
|
|
24
|
-
"@trackunit/
|
|
20
|
+
"@trackunit/css-class-variance-utilities": "1.0.32",
|
|
21
|
+
"@trackunit/react-components": "1.1.38",
|
|
22
|
+
"@trackunit/ui-icons": "1.0.35",
|
|
23
|
+
"@trackunit/shared-utils": "1.2.29",
|
|
24
|
+
"@trackunit/ui-design-tokens": "1.0.33",
|
|
25
|
+
"@trackunit/i18n-library-translation": "1.0.41",
|
|
26
|
+
"string-ts": "^2.0.0"
|
|
25
27
|
},
|
|
26
28
|
"module": "./index.esm.js",
|
|
27
29
|
"main": "./index.cjs.js",
|
|
@@ -46,10 +46,6 @@ export interface BaseInputProps extends FilteredInputProps, CommonProps {
|
|
|
46
46
|
* Custom css classes for the inner Input element.
|
|
47
47
|
*/
|
|
48
48
|
inputClassName?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Custom css classes for the addon before element.
|
|
51
|
-
*/
|
|
52
|
-
addonBeforeClassName?: string;
|
|
53
49
|
/**
|
|
54
50
|
* If true, shows the input in warning state.
|
|
55
51
|
*/
|
|
@@ -7,27 +7,27 @@ export declare const cvaInput: (props?: ({
|
|
|
7
7
|
invalid?: boolean | null | undefined;
|
|
8
8
|
isWarning?: boolean | null | undefined;
|
|
9
9
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Used for placing items in the grid, using a grid z-stack trick.
|
|
12
|
+
* The span position is used for the input field, which spans the entire grid.
|
|
13
|
+
*! Relies on the specific grid layout of cvaInput ☝️
|
|
14
|
+
*/
|
|
15
|
+
export declare const cvaInputItemPlacementManager: (props?: ({
|
|
16
|
+
position?: "before" | "after" | "span" | null | undefined;
|
|
17
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
18
|
+
export declare const cvaAccessoriesContainer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
10
19
|
export declare const cvaInputField: (props?: ({
|
|
11
20
|
size?: "small" | "medium" | "large" | null | undefined;
|
|
12
21
|
disabled?: boolean | null | undefined;
|
|
13
22
|
readOnly?: boolean | null | undefined;
|
|
14
|
-
autoFocus?: boolean | null | undefined;
|
|
15
|
-
addonBefore?: boolean | null | undefined;
|
|
16
|
-
prefix?: boolean | null | undefined;
|
|
17
23
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
18
|
-
export declare const cvaInputAddon: (props?:
|
|
19
|
-
export declare const cvaInputAddonBefore: (props?: ({
|
|
24
|
+
export declare const cvaInputAddon: (props?: ({
|
|
20
25
|
size?: "small" | "medium" | "large" | null | undefined;
|
|
26
|
+
position?: "before" | "after" | null | undefined;
|
|
21
27
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
22
28
|
export declare const cvaInputPrefix: (props?: ({
|
|
23
29
|
disabled?: boolean | null | undefined;
|
|
24
|
-
addonBefore?: boolean | null | undefined;
|
|
25
30
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
26
31
|
export declare const cvaInputSuffix: (props?: ({
|
|
27
32
|
disabled?: boolean | null | undefined;
|
|
28
|
-
addonAfter?: boolean | null | undefined;
|
|
29
|
-
actions?: boolean | null | undefined;
|
|
30
|
-
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
31
|
-
export declare const cvaInputAddonAfter: (props?: ({
|
|
32
|
-
size?: "small" | "medium" | "large" | null | undefined;
|
|
33
33
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { VariantProps } from "@trackunit/css-class-variance-utilities";
|
|
2
|
+
import { CommonProps } from "@trackunit/react-components";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
import { FormComponentSizes } from "../../../types";
|
|
5
|
+
import { cvaInputAddon } from "../BaseInput.variants";
|
|
6
|
+
type Position = NonNullable<VariantProps<typeof cvaInputAddon>["position"]>;
|
|
7
|
+
type AddonRendererProps = {
|
|
8
|
+
addon?: ReactNode;
|
|
9
|
+
fieldSize: FormComponentSizes;
|
|
10
|
+
position: Position;
|
|
11
|
+
} & CommonProps;
|
|
12
|
+
/**
|
|
13
|
+
* Renders the addon element if provided
|
|
14
|
+
*/
|
|
15
|
+
export declare const AddonRenderer: ({ addon, dataTestId, className, fieldSize, position }: AddonRendererProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
16
|
+
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { HTMLInputTypeAttribute, ReactNode } from "react";
|
|
2
|
-
|
|
2
|
+
type PrefixRendererProps = {
|
|
3
3
|
prefix?: ReactNode;
|
|
4
4
|
type?: HTMLInputTypeAttribute;
|
|
5
|
-
addonBefore?: ReactNode;
|
|
6
5
|
dataTestId?: string;
|
|
7
6
|
disabled: boolean;
|
|
8
|
-
}
|
|
7
|
+
};
|
|
8
|
+
export declare const PrefixRenderer: import("react").ForwardRefExoticComponent<PrefixRendererProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
9
|
+
export {};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
-
export declare const SuffixRenderer: ({ suffix,
|
|
2
|
+
export declare const SuffixRenderer: ({ suffix, isInvalid, isWarning, dataTestId, disabled, }: {
|
|
3
3
|
suffix?: ReactNode;
|
|
4
|
-
addonAfter?: ReactNode;
|
|
5
|
-
actions?: ReactNode;
|
|
6
4
|
isInvalid?: boolean;
|
|
7
5
|
isWarning?: boolean;
|
|
8
6
|
dataTestId?: string;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import { FormComponentSizes } from "../../../types";
|
|
3
|
-
export declare const AddonAfterRenderer: ({ addonAfter, dataTestId, fieldSize, }: {
|
|
4
|
-
addonAfter?: ReactNode;
|
|
5
|
-
dataTestId?: string;
|
|
6
|
-
fieldSize: FormComponentSizes;
|
|
7
|
-
}) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FormComponentSizes } from "../../../types";
|
|
2
|
-
export declare const AddonBeforeRenderer: ({ addonBefore, addonBeforeClassName, dataTestId, fieldSize, }: {
|
|
3
|
-
addonBefore?: React.ReactNode;
|
|
4
|
-
addonBeforeClassName?: string;
|
|
5
|
-
dataTestId?: string;
|
|
6
|
-
fieldSize: FormComponentSizes;
|
|
7
|
-
}) => import("react/jsx-runtime").JSX.Element | null;
|