@choice-ui/react 1.8.7 → 1.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/components/button/dist/index.js +7 -0
  2. package/dist/components/checkbox/dist/index.d.ts +10 -1
  3. package/dist/components/checkbox/dist/index.js +49 -5
  4. package/dist/components/checkbox/src/checkbox-icon.d.ts +8 -0
  5. package/dist/components/checkbox/src/checkbox-icon.js +41 -0
  6. package/dist/components/checkbox/src/checkbox.d.ts +2 -0
  7. package/dist/components/checkbox/src/checkbox.js +18 -5
  8. package/dist/components/checkbox/src/index.d.ts +2 -0
  9. package/dist/components/colors/src/color-image-paint/color-image-paint.js +3 -3
  10. package/dist/components/dropdown/dist/index.d.ts +6 -0
  11. package/dist/components/dropdown/dist/index.js +12 -8
  12. package/dist/components/emoji-picker/dist/index.d.ts +29 -1
  13. package/dist/components/emoji-picker/dist/index.js +144 -42
  14. package/dist/components/form/src/adapters/range-adapter.js +2 -2
  15. package/dist/components/icon-button/dist/index.d.ts +1 -1
  16. package/dist/components/icon-button/dist/index.js +39 -0
  17. package/dist/components/menus/dist/index.d.ts +5 -0
  18. package/dist/components/menus/dist/index.js +18 -1
  19. package/dist/components/radio/dist/index.d.ts +9 -1
  20. package/dist/components/radio/dist/index.js +50 -6
  21. package/dist/components/radio/src/context.d.ts +2 -0
  22. package/dist/components/radio/src/index.d.ts +2 -0
  23. package/dist/components/radio/src/radio-icon.d.ts +7 -0
  24. package/dist/components/radio/src/radio-icon.js +41 -0
  25. package/dist/components/radio/src/radio.d.ts +2 -0
  26. package/dist/components/radio/src/radio.js +19 -6
  27. package/dist/components/range/dist/index.d.ts +276 -20
  28. package/dist/components/range/dist/index.js +1030 -602
  29. package/dist/components/range/src/components/connects.d.ts +26 -0
  30. package/dist/components/range/src/components/connects.js +192 -0
  31. package/dist/components/range/src/components/dot.d.ts +8 -0
  32. package/dist/components/range/src/components/dot.js +148 -0
  33. package/dist/components/range/src/components/thumb.d.ts +14 -0
  34. package/dist/components/range/src/components/thumb.js +159 -0
  35. package/dist/components/range/src/context/index.d.ts +4 -0
  36. package/dist/components/range/src/context/range-context.d.ts +35 -0
  37. package/dist/components/range/src/context/range-context.js +13 -0
  38. package/dist/components/range/src/context/range-tuple-context.d.ts +42 -0
  39. package/dist/components/range/src/context/range-tuple-context.js +15 -0
  40. package/dist/components/range/src/index.d.ts +4 -2
  41. package/dist/components/range/src/range-tuple.d.ts +17 -9
  42. package/dist/components/range/src/range-tuple.js +375 -441
  43. package/dist/components/range/src/range.d.ts +17 -9
  44. package/dist/components/range/src/range.js +164 -154
  45. package/dist/components/range/src/tv.d.ts +15 -3
  46. package/dist/components/range/src/tv.js +10 -7
  47. package/dist/components/textarea/dist/index.js +3 -1
  48. package/dist/components/tooltip/dist/index.d.ts +2 -0
  49. package/dist/components/tooltip/dist/index.js +23 -5
  50. package/dist/components/virtual-select/dist/index.d.ts +48 -0
  51. package/dist/index.js +6 -0
  52. package/package.json +20 -32
@@ -244,6 +244,13 @@ var buttonTv = tcv({
244
244
  loading: false,
245
245
  variant: "dark",
246
246
  class: { button: "active:bg-gray-600" }
247
+ },
248
+ {
249
+ disabled: false,
250
+ loading: false,
251
+ variant: "secondary",
252
+ active: false,
253
+ class: { button: "hover:bg-secondary-background" }
247
254
  }
248
255
  ],
249
256
  defaultVariants: {
@@ -1,6 +1,14 @@
1
1
  import { HTMLProps, ReactNode } from 'react';
2
2
  import * as react from 'react';
3
3
 
4
+ interface CheckboxIconProps extends Omit<HTMLProps<HTMLDivElement>, "children"> {
5
+ children?: ReactNode | ((props: {
6
+ value?: boolean;
7
+ mixed?: boolean;
8
+ }) => ReactNode);
9
+ }
10
+ declare const CheckboxIcon: react.MemoExoticComponent<react.ForwardRefExoticComponent<Omit<CheckboxIconProps, "ref"> & react.RefAttributes<HTMLDivElement>>>;
11
+
4
12
  interface CheckboxLabelProps extends Omit<HTMLProps<HTMLLabelElement>, "htmlFor" | "id" | "disabled"> {
5
13
  children: ReactNode;
6
14
  }
@@ -20,9 +28,10 @@ interface CheckboxType {
20
28
  (props: CheckboxProps & {
21
29
  ref?: React.Ref<HTMLInputElement>;
22
30
  }): JSX.Element;
31
+ Icon: typeof CheckboxIcon;
23
32
  Label: typeof CheckboxLabel;
24
33
  displayName?: string;
25
34
  }
26
35
  declare const Checkbox: CheckboxType;
27
36
 
28
- export { Checkbox, type CheckboxProps };
37
+ export { Checkbox, type CheckboxIconProps, type CheckboxLabelProps, type CheckboxProps };
@@ -1,5 +1,5 @@
1
1
  import { Indeterminate, Check } from "@choiceform/icons-react";
2
- import { memo, forwardRef, useId, createContext, useContext } from "react";
2
+ import { memo, forwardRef, useId, Children, isValidElement, createContext, useContext } from "react";
3
3
  import { useEventCallback } from "usehooks-ts";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  import { tcv, tcx } from "../../../shared/utils/tcx/tcx.js";
@@ -137,6 +137,38 @@ var checkboxTv = tcv({
137
137
  focused: false
138
138
  }
139
139
  });
140
+ var CheckboxIcon = memo(
141
+ forwardRef(function CheckboxIcon2(props, ref) {
142
+ const { className, children, ...rest } = props;
143
+ const { value, mixed, disabled, variant } = useCheckboxContext();
144
+ const tv = checkboxTv({
145
+ type: "checkbox",
146
+ variant,
147
+ disabled,
148
+ checked: value || mixed
149
+ });
150
+ const renderIcon = () => {
151
+ if (typeof children === "function") {
152
+ return children({ value, mixed });
153
+ }
154
+ if (children !== void 0) {
155
+ return children;
156
+ }
157
+ return mixed ? /* @__PURE__ */ jsx(Indeterminate, {}) : value ? /* @__PURE__ */ jsx(Check, {}) : null;
158
+ };
159
+ return /* @__PURE__ */ jsx(
160
+ "div",
161
+ {
162
+ ref,
163
+ className: tcx(tv.box(), className),
164
+ "data-active": value,
165
+ ...rest,
166
+ children: renderIcon()
167
+ }
168
+ );
169
+ })
170
+ );
171
+ CheckboxIcon.displayName = "Checkbox.Icon";
140
172
  var CheckboxLabel = memo(
141
173
  forwardRef(function CheckboxLabel2(props, ref) {
142
174
  const { children, className, ...rest } = props;
@@ -195,12 +227,23 @@ var CheckboxBase = forwardRef(function Checkbox(props, ref) {
195
227
  }
196
228
  onKeyDown == null ? void 0 : onKeyDown(e);
197
229
  });
230
+ const isIconElement = (child) => {
231
+ var _a;
232
+ return isValidElement(child) && (child.type === CheckboxIcon || ((_a = child.type) == null ? void 0 : _a.displayName) === "Checkbox.Icon");
233
+ };
234
+ const childArray = Children.toArray(children);
235
+ const iconChild = childArray.find(isIconElement);
236
+ const otherChildren = childArray.filter((child) => !isIconElement(child));
198
237
  const renderChildren = () => {
199
- if (typeof children === "string" || typeof children === "number") {
200
- return /* @__PURE__ */ jsx(CheckboxLabel, { children });
238
+ if (otherChildren.length === 1) {
239
+ const child = otherChildren[0];
240
+ if (typeof child === "string" || typeof child === "number") {
241
+ return /* @__PURE__ */ jsx(CheckboxLabel, { children: child });
242
+ }
201
243
  }
202
- return children;
244
+ return otherChildren;
203
245
  };
246
+ const renderDefaultIcon = () => /* @__PURE__ */ jsx("div", { className: tv.box(), children: mixed ? /* @__PURE__ */ jsx(Indeterminate, {}) : value ? /* @__PURE__ */ jsx(Check, {}) : null });
204
247
  return /* @__PURE__ */ jsx(
205
248
  CheckboxContext.Provider,
206
249
  {
@@ -234,7 +277,7 @@ var CheckboxBase = forwardRef(function Checkbox(props, ref) {
234
277
  ...rest
235
278
  }
236
279
  ),
237
- /* @__PURE__ */ jsx("div", { className: tv.box(), children: mixed ? /* @__PURE__ */ jsx(Indeterminate, {}) : value ? /* @__PURE__ */ jsx(Check, {}) : null })
280
+ iconChild ?? renderDefaultIcon()
238
281
  ] }),
239
282
  renderChildren()
240
283
  ] })
@@ -243,6 +286,7 @@ var CheckboxBase = forwardRef(function Checkbox(props, ref) {
243
286
  });
244
287
  var MemoizedCheckbox = memo(CheckboxBase);
245
288
  var Checkbox2 = MemoizedCheckbox;
289
+ Checkbox2.Icon = CheckboxIcon;
246
290
  Checkbox2.Label = CheckboxLabel;
247
291
  Checkbox2.displayName = "Checkbox";
248
292
  export {
@@ -0,0 +1,8 @@
1
+ import { HTMLProps, ReactNode } from 'react';
2
+ export interface CheckboxIconProps extends Omit<HTMLProps<HTMLDivElement>, "children"> {
3
+ children?: ReactNode | ((props: {
4
+ value?: boolean;
5
+ mixed?: boolean;
6
+ }) => ReactNode);
7
+ }
8
+ export declare const CheckboxIcon: import('react').MemoExoticComponent<import('react').ForwardRefExoticComponent<Omit<CheckboxIconProps, "ref"> & import('react').RefAttributes<HTMLDivElement>>>;
@@ -0,0 +1,41 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Indeterminate, Check } from "@choiceform/icons-react";
3
+ import { memo, forwardRef } from "react";
4
+ import { useCheckboxContext } from "./context.js";
5
+ import { checkboxTv } from "./tv.js";
6
+ import { tcx } from "../../../shared/utils/tcx/tcx.js";
7
+ const CheckboxIcon = memo(
8
+ forwardRef(function CheckboxIcon2(props, ref) {
9
+ const { className, children, ...rest } = props;
10
+ const { value, mixed, disabled, variant } = useCheckboxContext();
11
+ const tv = checkboxTv({
12
+ type: "checkbox",
13
+ variant,
14
+ disabled,
15
+ checked: value || mixed
16
+ });
17
+ const renderIcon = () => {
18
+ if (typeof children === "function") {
19
+ return children({ value, mixed });
20
+ }
21
+ if (children !== void 0) {
22
+ return children;
23
+ }
24
+ return mixed ? /* @__PURE__ */ jsx(Indeterminate, {}) : value ? /* @__PURE__ */ jsx(Check, {}) : null;
25
+ };
26
+ return /* @__PURE__ */ jsx(
27
+ "div",
28
+ {
29
+ ref,
30
+ className: tcx(tv.box(), className),
31
+ "data-active": value,
32
+ ...rest,
33
+ children: renderIcon()
34
+ }
35
+ );
36
+ })
37
+ );
38
+ CheckboxIcon.displayName = "Checkbox.Icon";
39
+ export {
40
+ CheckboxIcon
41
+ };
@@ -1,4 +1,5 @@
1
1
  import { HTMLProps, ReactNode } from 'react';
2
+ import { CheckboxIcon } from './checkbox-icon';
2
3
  import { CheckboxLabel } from './checkbox-label';
3
4
  export interface CheckboxProps extends Omit<HTMLProps<HTMLInputElement>, "value" | "onChange"> {
4
5
  children?: ReactNode;
@@ -14,6 +15,7 @@ interface CheckboxType {
14
15
  (props: CheckboxProps & {
15
16
  ref?: React.Ref<HTMLInputElement>;
16
17
  }): JSX.Element;
18
+ Icon: typeof CheckboxIcon;
17
19
  Label: typeof CheckboxLabel;
18
20
  displayName?: string;
19
21
  }
@@ -1,7 +1,8 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Indeterminate, Check } from "@choiceform/icons-react";
3
- import { memo, forwardRef, useId } from "react";
3
+ import { memo, forwardRef, useId, Children, isValidElement } from "react";
4
4
  import { useEventCallback } from "usehooks-ts";
5
+ import { CheckboxIcon } from "./checkbox-icon.js";
5
6
  import { CheckboxLabel } from "./checkbox-label.js";
6
7
  import { CheckboxContext } from "./context.js";
7
8
  import { checkboxTv } from "./tv.js";
@@ -45,12 +46,23 @@ const CheckboxBase = forwardRef(function Checkbox2(props, ref) {
45
46
  }
46
47
  onKeyDown == null ? void 0 : onKeyDown(e);
47
48
  });
49
+ const isIconElement = (child) => {
50
+ var _a;
51
+ return isValidElement(child) && (child.type === CheckboxIcon || ((_a = child.type) == null ? void 0 : _a.displayName) === "Checkbox.Icon");
52
+ };
53
+ const childArray = Children.toArray(children);
54
+ const iconChild = childArray.find(isIconElement);
55
+ const otherChildren = childArray.filter((child) => !isIconElement(child));
48
56
  const renderChildren = () => {
49
- if (typeof children === "string" || typeof children === "number") {
50
- return /* @__PURE__ */ jsx(CheckboxLabel, { children });
57
+ if (otherChildren.length === 1) {
58
+ const child = otherChildren[0];
59
+ if (typeof child === "string" || typeof child === "number") {
60
+ return /* @__PURE__ */ jsx(CheckboxLabel, { children: child });
61
+ }
51
62
  }
52
- return children;
63
+ return otherChildren;
53
64
  };
65
+ const renderDefaultIcon = () => /* @__PURE__ */ jsx("div", { className: tv.box(), children: mixed ? /* @__PURE__ */ jsx(Indeterminate, {}) : value ? /* @__PURE__ */ jsx(Check, {}) : null });
54
66
  return /* @__PURE__ */ jsx(
55
67
  CheckboxContext.Provider,
56
68
  {
@@ -84,7 +96,7 @@ const CheckboxBase = forwardRef(function Checkbox2(props, ref) {
84
96
  ...rest
85
97
  }
86
98
  ),
87
- /* @__PURE__ */ jsx("div", { className: tv.box(), children: mixed ? /* @__PURE__ */ jsx(Indeterminate, {}) : value ? /* @__PURE__ */ jsx(Check, {}) : null })
99
+ iconChild ?? renderDefaultIcon()
88
100
  ] }),
89
101
  renderChildren()
90
102
  ] })
@@ -93,6 +105,7 @@ const CheckboxBase = forwardRef(function Checkbox2(props, ref) {
93
105
  });
94
106
  const MemoizedCheckbox = memo(CheckboxBase);
95
107
  const Checkbox = MemoizedCheckbox;
108
+ Checkbox.Icon = CheckboxIcon;
96
109
  Checkbox.Label = CheckboxLabel;
97
110
  Checkbox.displayName = "Checkbox";
98
111
  export {
@@ -1,2 +1,4 @@
1
1
  export { Checkbox } from './checkbox';
2
2
  export type { CheckboxProps } from './checkbox';
3
+ export type { CheckboxIconProps } from './checkbox-icon';
4
+ export type { CheckboxLabelProps } from './checkbox-label';
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
2
  import { Button } from "../../../button/dist/index.js";
3
- import { Range } from "../../../range/dist/index.js";
3
+ import { Range as Range2 } from "../../../range/dist/index.js";
4
4
  import React__default, { memo, useState, useRef, useMemo, useEffect, useCallback } from "react";
5
5
  import { useEventCallback } from "usehooks-ts";
6
6
  import { ColorImageToolbar } from "./color-image-toolbar.js";
@@ -209,12 +209,12 @@ const ColorImagePaint = memo(function ColorImagePaint2(props) {
209
209
  return /* @__PURE__ */ jsxs(React__default.Fragment, { children: [
210
210
  /* @__PURE__ */ jsx("span", { className: styles.adjustLabel(), children: (_a2 = features == null ? void 0 : features.labels) == null ? void 0 : _a2[filterName] }),
211
211
  /* @__PURE__ */ jsx(
212
- Range,
212
+ Range2,
213
213
  {
214
214
  min: -100,
215
215
  max: 100,
216
216
  defaultValue: 0,
217
- trackSize: { width: 128 },
217
+ width: 128,
218
218
  value: filters[filterName],
219
219
  onChange: (value) => setFilters({
220
220
  ...filters,
@@ -7,6 +7,12 @@ interface DropdownProps {
7
7
  * @default true
8
8
  */
9
9
  autoSelectFirstItem?: boolean;
10
+ /**
11
+ * Whether to avoid collisions by flipping or shifting the dropdown position.
12
+ * When false, the dropdown will strictly follow the placement direction.
13
+ * @default true
14
+ */
15
+ avoidCollisions?: boolean;
10
16
  children?: React.ReactNode;
11
17
  disabledNested?: boolean;
12
18
  focusManagerProps?: Partial<FloatingFocusManagerProps>;
@@ -13,6 +13,7 @@ var DropdownComponent = memo(function DropdownComponent2(props) {
13
13
  const {
14
14
  children,
15
15
  autoSelectFirstItem = true,
16
+ avoidCollisions = true,
16
17
  disabledNested = false,
17
18
  offset: offsetDistance = DEFAULT_OFFSET,
18
19
  placement = "bottom-start",
@@ -77,11 +78,14 @@ var DropdownComponent = memo(function DropdownComponent2(props) {
77
78
  });
78
79
  });
79
80
  const lastPositionRef = useRef(null);
80
- const middleware = useMemo(
81
- () => [
82
- offset({ mainAxis: isNested ? 10 : offsetDistance, alignmentAxis: isNested ? -4 : 0 }),
83
- flip(),
84
- shift(),
81
+ const middleware = useMemo(() => {
82
+ const baseMiddleware = [
83
+ offset({ mainAxis: isNested ? 10 : offsetDistance, alignmentAxis: isNested ? -4 : 0 })
84
+ ];
85
+ if (avoidCollisions) {
86
+ baseMiddleware.push(flip(), shift());
87
+ }
88
+ baseMiddleware.push(
85
89
  size({
86
90
  padding: 4,
87
91
  apply({ elements, availableHeight, rects }) {
@@ -104,9 +108,9 @@ var DropdownComponent = memo(function DropdownComponent2(props) {
104
108
  }
105
109
  }
106
110
  })
107
- ],
108
- [isNested, offsetDistance, matchTriggerWidth, scrollRef]
109
- );
111
+ );
112
+ return baseMiddleware;
113
+ }, [isNested, offsetDistance, matchTriggerWidth, scrollRef, avoidCollisions]);
110
114
  const { refs, floatingStyles, context, isPositioned } = useFloating({
111
115
  nodeId,
112
116
  open: isControlledOpen,
@@ -15,12 +15,24 @@ type VirtualItem = {
15
15
  emojis: EmojiData[];
16
16
  type: "emojis";
17
17
  };
18
+ interface CategoryNames {
19
+ activities: string;
20
+ animalsNature: string;
21
+ flags: string;
22
+ foodDrink: string;
23
+ frequentlyUsed: string;
24
+ objects: string;
25
+ smileysPeople: string;
26
+ symbols: string;
27
+ travelPlaces: string;
28
+ }
18
29
  interface UseEmojiDataProps {
30
+ categoryNames?: CategoryNames;
19
31
  columns: number;
20
32
  searchQuery: string;
21
33
  showFrequentlyUsed: boolean;
22
34
  }
23
- declare function useEmojiData({ searchQuery, columns, showFrequentlyUsed }: UseEmojiDataProps): {
35
+ declare function useEmojiData({ searchQuery, columns, showFrequentlyUsed, categoryNames, }: UseEmojiDataProps): {
24
36
  categorizedData: VirtualItem[];
25
37
  categoryIndexMap: Map<EmojiCategory, number>;
26
38
  searchResults: {
@@ -52,6 +64,22 @@ interface EmojiPickerProps {
52
64
  showFooter?: boolean;
53
65
  value?: EmojiData | null;
54
66
  variant?: "default" | "dark" | "light";
67
+ i18n?: {
68
+ noEmojisFoundTitle?: string;
69
+ noEmojisFoundDescription?: string;
70
+ footerPickAnEmoji?: string;
71
+ categories?: {
72
+ frequentlyUsed: string;
73
+ smileysPeople: string;
74
+ animalsNature: string;
75
+ foodDrink: string;
76
+ travelPlaces: string;
77
+ activities: string;
78
+ objects: string;
79
+ symbols: string;
80
+ flags: string;
81
+ };
82
+ };
55
83
  }
56
84
  declare const EmojiPicker: React.NamedExoticComponent<EmojiPickerProps>;
57
85