@brightlocal/ui-components 3.3.0 → 3.5.0
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/AI_USAGE.md +22 -3
- package/README.md +177 -109
- package/component-meta.json +1307 -113
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +13 -2
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +4 -3
- package/dist/banner.cjs +1 -1
- package/dist/banner.d.ts +47 -11
- package/dist/banner.d.ts.map +1 -1
- package/dist/banner.js +156 -79
- package/dist/blocks/empty-state.cjs +1 -1
- package/dist/blocks/empty-state.d.ts +40 -5
- package/dist/blocks/empty-state.d.ts.map +1 -1
- package/dist/blocks/empty-state.js +59 -52
- package/dist/blocks/input-list.cjs +1 -1
- package/dist/blocks/input-list.d.ts +1 -0
- package/dist/blocks/input-list.d.ts.map +1 -1
- package/dist/blocks/input-list.js +39 -39
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +12 -6
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +64 -63
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +47 -43
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +12 -0
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +115 -97
- package/dist/chart.cjs +6 -6
- package/dist/chart.d.ts +6 -10
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +281 -296
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +430 -343
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +23 -2
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +212 -207
- package/dist/count-indicator.cjs +1 -0
- package/dist/count-indicator.d.ts +85 -0
- package/dist/count-indicator.d.ts.map +1 -0
- package/dist/count-indicator.js +72 -0
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +101 -11
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +593 -523
- package/dist/description-list.cjs +1 -0
- package/dist/description-list.d.ts +142 -0
- package/dist/description-list.d.ts.map +1 -0
- package/dist/description-list.js +173 -0
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts +26 -3
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +62 -47
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.d.ts +8 -4
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +37 -38
- package/dist/file-upload.cjs +1 -0
- package/dist/file-upload.d.ts +546 -0
- package/dist/file-upload.d.ts.map +1 -0
- package/dist/file-upload.js +1103 -0
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +7 -2
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +52 -52
- package/dist/hooks/use-file-dropzone.cjs +1 -0
- package/dist/hooks/use-file-dropzone.d.ts +75 -0
- package/dist/hooks/use-file-dropzone.d.ts.map +1 -0
- package/dist/hooks/use-file-dropzone.js +133 -0
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.d.ts +29 -16
- package/dist/hover-card.d.ts.map +1 -1
- package/dist/hover-card.js +153 -36
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +681 -623
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.d.ts +30 -1
- package/dist/input-chip.d.ts.map +1 -1
- package/dist/input-chip.js +131 -115
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +37 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +131 -114
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.js +6 -6
- package/dist/lib/empty-canvas.cjs +1 -1
- package/dist/lib/empty-canvas.d.ts +27 -1
- package/dist/lib/empty-canvas.d.ts.map +1 -1
- package/dist/lib/empty-canvas.js +27 -23
- package/dist/lib/empty-chip.cjs +1 -1
- package/dist/lib/empty-chip.d.ts +19 -2
- package/dist/lib/empty-chip.d.ts.map +1 -1
- package/dist/lib/empty-chip.js +14 -9
- package/dist/lib/field-aria.cjs +1 -1
- package/dist/lib/field-aria.d.ts +4 -4
- package/dist/lib/field-aria.d.ts.map +1 -1
- package/dist/lib/field-aria.js +7 -5
- package/dist/lib/media-viewer-content.cjs +1 -1
- package/dist/lib/media-viewer-content.js +1 -1
- package/dist/lib/motion.cjs +1 -1
- package/dist/lib/motion.js +15 -10
- package/dist/lib/table-internal.cjs +1 -1
- package/dist/lib/table-internal.d.ts +19 -0
- package/dist/lib/table-internal.d.ts.map +1 -1
- package/dist/lib/table-internal.js +22 -7
- package/dist/list.cjs +1 -1
- package/dist/list.d.ts +230 -40
- package/dist/list.d.ts.map +1 -1
- package/dist/list.js +301 -66
- package/dist/logo-mark.cjs +1 -1
- package/dist/logo-mark.d.ts +18 -2
- package/dist/logo-mark.d.ts.map +1 -1
- package/dist/logo-mark.js +159 -79
- package/dist/media-empty.cjs +1 -1
- package/dist/media-empty.d.ts +50 -7
- package/dist/media-empty.d.ts.map +1 -1
- package/dist/media-empty.js +14 -13
- package/dist/media-viewer.cjs +1 -1
- package/dist/media-viewer.js +6 -6
- package/dist/multi-select-filter.cjs +1 -1
- package/dist/multi-select-filter.d.ts.map +1 -1
- package/dist/multi-select-filter.js +92 -101
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +11 -0
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +17 -17
- package/dist/relative-date.d.ts +6 -0
- package/dist/relative-date.d.ts.map +1 -1
- package/dist/resizable.d.ts +1 -1
- package/dist/result-count.cjs +1 -1
- package/dist/result-count.d.ts +13 -16
- package/dist/result-count.d.ts.map +1 -1
- package/dist/result-count.js +24 -33
- package/dist/route-progress.cjs +1 -1
- package/dist/route-progress.js +24 -23
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +22 -3
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +152 -125
- package/dist/single-select-filter.cjs +1 -1
- package/dist/single-select-filter.d.ts.map +1 -1
- package/dist/single-select-filter.js +67 -76
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +77 -76
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +39 -3
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +127 -76
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.d.ts +34 -0
- package/dist/textarea.d.ts.map +1 -1
- package/dist/textarea.js +115 -19
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +137 -131
- package/dist/typography-text.cjs +1 -1
- package/dist/typography-text.d.ts +6 -2
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography-text.js +14 -13
- package/package.json +2 -3
- package/src/blocks/empty-state.tsx +108 -48
- package/src/blocks/input-list.tsx +15 -9
- package/src/blocks/sidebar.tsx +39 -16
- package/src/components/alert-dialog.tsx +18 -2
- package/src/components/banner.tsx +247 -68
- package/src/components/button.tsx +27 -10
- package/src/components/card.tsx +89 -7
- package/src/components/chart.tsx +47 -67
- package/src/components/combobox.tsx +221 -12
- package/src/components/command.tsx +83 -37
- package/src/components/count-indicator.tsx +188 -0
- package/src/components/data-table.tsx +506 -159
- package/src/components/description-list.tsx +445 -0
- package/src/components/dialog.tsx +74 -5
- package/src/components/drawer.tsx +52 -32
- package/src/components/file-upload.tsx +2574 -0
- package/src/components/global-layout.tsx +18 -5
- package/src/components/hover-card.tsx +395 -65
- package/src/components/input-chip.tsx +67 -2
- package/src/components/input-group.tsx +89 -6
- package/src/components/list.tsx +720 -72
- package/src/components/logo-mark.tsx +109 -25
- package/src/components/media-empty.tsx +62 -7
- package/src/components/multi-select-filter.tsx +9 -16
- package/src/components/pagination.tsx +15 -2
- package/src/components/relative-date.tsx +6 -0
- package/src/components/result-count.tsx +27 -54
- package/src/components/sheet.tsx +86 -8
- package/src/components/single-select-filter.tsx +9 -16
- package/src/components/table.tsx +16 -1
- package/src/components/tabs.tsx +223 -41
- package/src/components/textarea.tsx +271 -4
- package/src/components/tooltip.tsx +29 -2
- package/src/components/typography-text.tsx +7 -2
- package/src/hooks/use-file-dropzone.ts +325 -0
- package/src/index.ts +4 -0
- package/src/lib/empty-canvas.tsx +47 -20
- package/src/lib/empty-chip.tsx +38 -3
- package/src/lib/field-aria.tsx +11 -6
- package/src/lib/table-internal.ts +38 -0
|
@@ -5,6 +5,8 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
5
5
|
|
|
6
6
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
7
7
|
import { Chip } from "@brightlocal/ui-components/chip";
|
|
8
|
+
import { useFieldDescribedBy } from "../lib/field-aria";
|
|
9
|
+
import { CountIndicator, type CountIndicatorProps } from "./count-indicator";
|
|
8
10
|
|
|
9
11
|
/* -------------------------------------------------------------------------------------------------
|
|
10
12
|
* InputChip Context
|
|
@@ -79,6 +81,7 @@ function useInputChipInput() {
|
|
|
79
81
|
return context;
|
|
80
82
|
}
|
|
81
83
|
|
|
84
|
+
/** Returns the combined InputChip context (value, dispatch, and input state). */
|
|
82
85
|
function useInputChipContext(): InputChipContextValue {
|
|
83
86
|
const dispatch = useInputChipDispatch();
|
|
84
87
|
const { value, disabled } = useInputChipValue();
|
|
@@ -259,6 +262,10 @@ const inputChipInputVariants = cva(
|
|
|
259
262
|
// Focus-within state (when input inside is focused)
|
|
260
263
|
"has-[:focus-visible]:border-ring has-[:focus-visible]:bg-background",
|
|
261
264
|
"has-[:focus-visible]:shadow-default",
|
|
265
|
+
// Over the count limit: error border (the message stays with the consumer)
|
|
266
|
+
"has-[[data-slot=count-indicator][data-state=over]]:border-destructive-40",
|
|
267
|
+
"has-[[data-slot=count-indicator][data-state=over]]:has-[:focus-visible]:border-destructive-40",
|
|
268
|
+
"has-[[data-slot=count-indicator][data-state=over]]:has-[:focus-visible]:shadow-destructive",
|
|
262
269
|
// Disabled state
|
|
263
270
|
"has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50",
|
|
264
271
|
// Transition
|
|
@@ -389,6 +396,9 @@ const InputChipInput = React.forwardRef<HTMLInputElement, InputChipInputProps>(
|
|
|
389
396
|
useInputChipDispatch();
|
|
390
397
|
const { value, disabled } = useInputChipValue();
|
|
391
398
|
const { inputValue } = useInputChipInput();
|
|
399
|
+
// Inside a Field the textbox also reads the FieldError, the hint and the
|
|
400
|
+
// count (InputChipCount); explicit ids from the consumer are kept.
|
|
401
|
+
const describedBy = useFieldDescribedBy(ariaDescribedby);
|
|
392
402
|
|
|
393
403
|
// Expose the inner text input through the consumer's ref
|
|
394
404
|
React.useImperativeHandle(ref, () => inputRef.current!, [inputRef]);
|
|
@@ -435,7 +445,7 @@ const InputChipInput = React.forwardRef<HTMLInputElement, InputChipInputProps>(
|
|
|
435
445
|
{children}
|
|
436
446
|
<input
|
|
437
447
|
ref={inputRef as React.RefObject<HTMLInputElement>}
|
|
438
|
-
aria-describedby={
|
|
448
|
+
aria-describedby={describedBy || undefined}
|
|
439
449
|
aria-invalid={hasError ? "true" : undefined}
|
|
440
450
|
aria-label={ariaLabel}
|
|
441
451
|
aria-labelledby={ariaLabelledby}
|
|
@@ -634,4 +644,59 @@ function InputChipItems({
|
|
|
634
644
|
* Exports
|
|
635
645
|
* -----------------------------------------------------------------------------------------------*/
|
|
636
646
|
|
|
637
|
-
|
|
647
|
+
/* -------------------------------------------------------------------------------------------------
|
|
648
|
+
* InputChip Count (Items against a limit)
|
|
649
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Props for InputChipCount. `count` is optional: by default the chip field
|
|
653
|
+
* counts its items.
|
|
654
|
+
*/
|
|
655
|
+
export interface InputChipCountProps extends Omit<
|
|
656
|
+
CountIndicatorProps,
|
|
657
|
+
"count"
|
|
658
|
+
> {
|
|
659
|
+
/**
|
|
660
|
+
* Count to show. Omit it to count the items in the chip field.
|
|
661
|
+
*/
|
|
662
|
+
count?: number;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Count of items against a limit at the end of the last row of the chip field,
|
|
667
|
+
* such as `3 / 5`. Place it inside `InputChipInput`, next to `InputChipItems`.
|
|
668
|
+
*
|
|
669
|
+
* It never blocks adding. Over the limit the count turns red and the field
|
|
670
|
+
* takes the error border; show the error message and reject the save yourself
|
|
671
|
+
* (`onBeforeAdd` on `InputChip` can stop the add itself).
|
|
672
|
+
*
|
|
673
|
+
* @example
|
|
674
|
+
* ```tsx
|
|
675
|
+
* <InputChipInput dataHook="emails-input">
|
|
676
|
+
* <InputChipItems />
|
|
677
|
+
* <InputChipCount dataHook="emails-count" limit={5} />
|
|
678
|
+
* </InputChipInput>
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
681
|
+
const InputChipCount = React.forwardRef<HTMLSpanElement, InputChipCountProps>(
|
|
682
|
+
({ className, count, ...props }, ref) => {
|
|
683
|
+
const { value } = useInputChipValue();
|
|
684
|
+
return (
|
|
685
|
+
<CountIndicator
|
|
686
|
+
ref={ref}
|
|
687
|
+
className={cn("order-last ml-auto pl-3", className)}
|
|
688
|
+
count={count ?? value.length}
|
|
689
|
+
{...props}
|
|
690
|
+
/>
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
);
|
|
694
|
+
InputChipCount.displayName = "InputChipCount";
|
|
695
|
+
|
|
696
|
+
export {
|
|
697
|
+
InputChip,
|
|
698
|
+
InputChipCount,
|
|
699
|
+
InputChipInput,
|
|
700
|
+
InputChipItems,
|
|
701
|
+
useInputChipContext,
|
|
702
|
+
};
|
|
@@ -6,11 +6,18 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
6
6
|
import { X } from "@brightlocal/icons";
|
|
7
7
|
|
|
8
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
|
+
import { CountIndicator, type CountIndicatorProps } from "./count-indicator";
|
|
9
10
|
import { Input, type InputProps } from "./input";
|
|
10
11
|
|
|
11
12
|
interface InputGroupContextValue {
|
|
12
13
|
/** Snapshot of the composed input's DOM state, kept fresh by InputGroupInput. */
|
|
13
|
-
inputState: {
|
|
14
|
+
inputState: {
|
|
15
|
+
hasValue: boolean;
|
|
16
|
+
length: number;
|
|
17
|
+
disabled: boolean;
|
|
18
|
+
/** False until the composed input has been read once. */
|
|
19
|
+
ready: boolean;
|
|
20
|
+
};
|
|
14
21
|
/** Re-reads the composed input into `inputState`; cheap and safe to call often. */
|
|
15
22
|
syncInputState: () => void;
|
|
16
23
|
/**
|
|
@@ -36,7 +43,7 @@ const InputGroupContext = React.createContext<InputGroupContextValue | null>(
|
|
|
36
43
|
);
|
|
37
44
|
|
|
38
45
|
const inputGroupVariants = cva(
|
|
39
|
-
"relative flex w-full items-center rounded-sm border border-input bg-background transition-[color,background-color,border-color,box-shadow] duration-fast ease-out has-[input:focus-visible]:border-ring has-[input:focus-visible]:shadow-default has-[:disabled]:opacity-50",
|
|
46
|
+
"relative flex w-full items-center rounded-sm border border-input bg-background transition-[color,background-color,border-color,box-shadow] duration-fast ease-out has-[input:focus-visible]:border-ring has-[input:focus-visible]:shadow-default has-[:disabled]:opacity-50 has-[[data-slot=count-indicator][data-state=over]]:border-destructive-40 has-[[data-slot=count-indicator][data-state=over]]:has-[input:focus-visible]:border-destructive-40 has-[[data-slot=count-indicator][data-state=over]]:has-[input:focus-visible]:shadow-destructive",
|
|
40
47
|
{
|
|
41
48
|
variants: {
|
|
42
49
|
size: {
|
|
@@ -88,7 +95,9 @@ const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
|
|
|
88
95
|
) => {
|
|
89
96
|
const [inputState, setInputState] = React.useState({
|
|
90
97
|
hasValue: false,
|
|
98
|
+
length: 0,
|
|
91
99
|
disabled: false,
|
|
100
|
+
ready: false,
|
|
92
101
|
});
|
|
93
102
|
const inputRef = React.useRef<HTMLInputElement | null>(null);
|
|
94
103
|
const syncInputState = React.useCallback(() => {
|
|
@@ -97,10 +106,15 @@ const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
|
|
|
97
106
|
// not offer a clear affordance either.
|
|
98
107
|
const next = {
|
|
99
108
|
hasValue: !!input && input.value.length > 0,
|
|
109
|
+
length: input ? input.value.length : 0,
|
|
100
110
|
disabled: !!input && (input.disabled || input.readOnly),
|
|
111
|
+
ready: true,
|
|
101
112
|
};
|
|
102
113
|
setInputState((prev) =>
|
|
103
|
-
prev.hasValue === next.hasValue &&
|
|
114
|
+
prev.hasValue === next.hasValue &&
|
|
115
|
+
prev.length === next.length &&
|
|
116
|
+
prev.disabled === next.disabled &&
|
|
117
|
+
prev.ready === next.ready
|
|
104
118
|
? prev
|
|
105
119
|
: next
|
|
106
120
|
);
|
|
@@ -248,9 +262,23 @@ const inputGroupAddonVariants = cva(
|
|
|
248
262
|
"flex shrink-0 items-center text-muted-foreground",
|
|
249
263
|
{
|
|
250
264
|
variants: {
|
|
265
|
+
// The inner side (next to the group's border) is inset 12px so an icon
|
|
266
|
+
// or prefix never sits on the border. An addon holding a button keeps
|
|
267
|
+
// 4px: the button's own box centres its icon, which lands it on the
|
|
268
|
+
// same 12px line as a bare icon (icon-sm: 4px + 8px). The button case
|
|
269
|
+
// matches InputGroupButton by data-slot too, so an `asChild` link
|
|
270
|
+
// counts. The inset is a variable read by a plain padding utility, so
|
|
271
|
+
// a consumer's pl-*/pr-* replaces it through twMerge instead of losing
|
|
272
|
+
// to the more specific :has() selector.
|
|
251
273
|
align: {
|
|
252
|
-
"inline-start":
|
|
253
|
-
|
|
274
|
+
"inline-start": [
|
|
275
|
+
"pl-(--input-group-addon-inset) [--input-group-addon-inset:--spacing(3)]",
|
|
276
|
+
"has-[>button,>[data-slot=input-group-button]]:[--input-group-addon-inset:--spacing(1)]",
|
|
277
|
+
],
|
|
278
|
+
"inline-end": [
|
|
279
|
+
"ml-auto pr-(--input-group-addon-inset) [--input-group-addon-inset:--spacing(3)]",
|
|
280
|
+
"has-[>button,>[data-slot=input-group-button]]:[--input-group-addon-inset:--spacing(1)]",
|
|
281
|
+
],
|
|
254
282
|
"block-start": "self-start",
|
|
255
283
|
"block-end": "self-end",
|
|
256
284
|
},
|
|
@@ -264,7 +292,15 @@ const inputGroupAddonVariants = cva(
|
|
|
264
292
|
interface InputGroupAddonProps
|
|
265
293
|
extends
|
|
266
294
|
React.HTMLAttributes<HTMLDivElement>,
|
|
267
|
-
VariantProps<typeof inputGroupAddonVariants> {
|
|
295
|
+
VariantProps<typeof inputGroupAddonVariants> {
|
|
296
|
+
/**
|
|
297
|
+
* Which side of the input the addon sits on. Inline addons are inset 12px
|
|
298
|
+
* on their inner side (4px when the addon holds an `InputGroupButton`, so
|
|
299
|
+
* the button's icon lands on the same line), so no padding is needed.
|
|
300
|
+
* @default "inline-start"
|
|
301
|
+
*/
|
|
302
|
+
align?: "inline-start" | "inline-end" | "block-start" | "block-end" | null;
|
|
303
|
+
}
|
|
268
304
|
|
|
269
305
|
const InputGroupAddon = React.forwardRef<HTMLDivElement, InputGroupAddonProps>(
|
|
270
306
|
({ className, align, ...props }, ref) => {
|
|
@@ -280,6 +316,51 @@ const InputGroupAddon = React.forwardRef<HTMLDivElement, InputGroupAddonProps>(
|
|
|
280
316
|
);
|
|
281
317
|
InputGroupAddon.displayName = "InputGroupAddon";
|
|
282
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Props for InputGroupCount. `count` is optional: by default the group counts
|
|
321
|
+
* the characters in its input.
|
|
322
|
+
*/
|
|
323
|
+
interface InputGroupCountProps extends Omit<CountIndicatorProps, "count"> {
|
|
324
|
+
/**
|
|
325
|
+
* Count to show. Omit it to count the characters in the group's input; pass
|
|
326
|
+
* it when the group counts something else.
|
|
327
|
+
*/
|
|
328
|
+
count?: number;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Count against a limit at the end of the group, such as `12 / 125`. Place it
|
|
333
|
+
* last, after the input (and before a clear button, if there is one).
|
|
334
|
+
*
|
|
335
|
+
* It never blocks typing. Over the limit the count turns red and the group
|
|
336
|
+
* takes the error border; show the error message and stop the save yourself.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```tsx
|
|
340
|
+
* <InputGroup dataHook="alt-group">
|
|
341
|
+
* <InputGroupInput value={alt} onChange={...} />
|
|
342
|
+
* <InputGroupCount dataHook="alt-count" limit={125} />
|
|
343
|
+
* </InputGroup>
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
const InputGroupCount = React.forwardRef<HTMLSpanElement, InputGroupCountProps>(
|
|
347
|
+
({ className, count, ...props }, ref) => {
|
|
348
|
+
const context = React.useContext(InputGroupContext);
|
|
349
|
+
return (
|
|
350
|
+
<CountIndicator
|
|
351
|
+
ref={ref}
|
|
352
|
+
className={cn("pr-3", className)}
|
|
353
|
+
count={count ?? context?.inputState.length ?? 0}
|
|
354
|
+
// A saved value already over the limit is read on mount; that first
|
|
355
|
+
// read is not a crossing, so it stays silent.
|
|
356
|
+
ready={count !== undefined || (context?.inputState.ready ?? true)}
|
|
357
|
+
{...props}
|
|
358
|
+
/>
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
InputGroupCount.displayName = "InputGroupCount";
|
|
363
|
+
|
|
283
364
|
const inputGroupButtonVariants = cva(
|
|
284
365
|
[
|
|
285
366
|
"inline-flex items-center justify-center gap-2",
|
|
@@ -434,6 +515,7 @@ export {
|
|
|
434
515
|
InputGroupAddon,
|
|
435
516
|
InputGroupButton,
|
|
436
517
|
InputGroupClear,
|
|
518
|
+
InputGroupCount,
|
|
437
519
|
inputGroupVariants,
|
|
438
520
|
inputGroupButtonVariants,
|
|
439
521
|
};
|
|
@@ -443,4 +525,5 @@ export type {
|
|
|
443
525
|
InputGroupAddonProps,
|
|
444
526
|
InputGroupButtonProps,
|
|
445
527
|
InputGroupClearProps,
|
|
528
|
+
InputGroupCountProps,
|
|
446
529
|
};
|