@efolusi/meridian 1.20.0 → 1.21.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.
Files changed (183) hide show
  1. package/README.md +1 -1
  2. package/ai/Bubble.d.ts +16 -0
  3. package/ai/Bubble.js +71 -0
  4. package/ai/ChatMessage.js +2 -5
  5. package/ai/Confirmation.d.ts +0 -7
  6. package/ai/Confirmation.js +3 -6
  7. package/ai/GeneratedImage.d.ts +0 -2
  8. package/ai/GeneratedImage.js +2 -4
  9. package/ai/Marker.d.ts +26 -0
  10. package/ai/Marker.js +67 -0
  11. package/ai/Message.d.ts +13 -0
  12. package/ai/Message.js +68 -0
  13. package/ai/MessageScroller.d.ts +21 -0
  14. package/ai/MessageScroller.js +283 -0
  15. package/ai/ModelSelector.d.ts +2 -2
  16. package/ai/ModelSelector.js +1 -2
  17. package/ai/Player.js +1 -1
  18. package/ai/PromptSteps.js +4 -2
  19. package/ai/Sandbox.d.ts +0 -2
  20. package/ai/Sandbox.js +2 -4
  21. package/ai/Suggestions.d.ts +0 -2
  22. package/ai/Suggestions.js +1 -4
  23. package/ai/WebPreview.d.ts +0 -2
  24. package/ai/WebPreview.js +2 -4
  25. package/code/Console.js +1 -1
  26. package/code/EnvList.d.ts +0 -2
  27. package/code/EnvList.js +2 -3
  28. package/components.css +652 -418
  29. package/data/BarChart.d.ts +0 -2
  30. package/data/BarChart.js +1 -4
  31. package/data/Chart.d.ts +14 -0
  32. package/data/Chart.js +149 -0
  33. package/data/EmptyState.d.ts +8 -13
  34. package/data/EmptyState.js +62 -24
  35. package/data/LineChart.js +7 -4
  36. package/data/Skeleton.d.ts +2 -11
  37. package/data/Skeleton.js +8 -38
  38. package/data/Sparkline.js +4 -1
  39. package/data/StatusDot.d.ts +0 -4
  40. package/data/StatusDot.js +3 -6
  41. package/data/Table.d.ts +11 -4
  42. package/data/Table.js +39 -7
  43. package/dates/Calendar.d.ts +10 -27
  44. package/dates/Calendar.js +250 -184
  45. package/dates/TimePicker.js +2 -2
  46. package/display/Accordion.d.ts +47 -15
  47. package/display/Accordion.js +257 -27
  48. package/display/AspectRatio.d.ts +4 -6
  49. package/display/AspectRatio.js +7 -5
  50. package/display/Avatar.d.ts +17 -14
  51. package/display/Avatar.js +68 -43
  52. package/display/Badge.d.ts +9 -8
  53. package/display/Badge.js +32 -14
  54. package/display/Card.d.ts +11 -13
  55. package/display/Card.js +74 -29
  56. package/display/Carousel.d.ts +23 -15
  57. package/display/Carousel.js +217 -66
  58. package/display/Collapsible.d.ts +19 -9
  59. package/display/Collapsible.js +140 -28
  60. package/display/Direction.d.ts +10 -0
  61. package/display/Direction.js +24 -0
  62. package/display/Item.d.ts +19 -0
  63. package/display/Item.js +152 -0
  64. package/display/Kbd.d.ts +5 -7
  65. package/display/Kbd.js +22 -10
  66. package/display/Link.js +2 -4
  67. package/display/Resizable.d.ts +6 -16
  68. package/display/Resizable.js +141 -58
  69. package/display/ScrollArea.d.ts +3 -1
  70. package/display/ScrollArea.js +30 -5
  71. package/display/Separator.d.ts +9 -0
  72. package/display/Separator.js +18 -0
  73. package/display/Timeline.d.ts +24 -0
  74. package/display/Timeline.js +51 -0
  75. package/display/Toolbar.js +5 -4
  76. package/display/TreeList.d.ts +0 -2
  77. package/display/TreeList.js +2 -5
  78. package/feedback/Alert.d.ts +13 -13
  79. package/feedback/Alert.js +40 -36
  80. package/feedback/AlertDialog.d.ts +30 -0
  81. package/feedback/AlertDialog.js +249 -0
  82. package/feedback/Banner.d.ts +1 -3
  83. package/feedback/Banner.js +1 -5
  84. package/feedback/ConfirmDialog.d.ts +1 -1
  85. package/feedback/ConfirmDialog.js +18 -20
  86. package/feedback/Dialog.d.ts +13 -16
  87. package/feedback/Dialog.js +204 -62
  88. package/feedback/Progress.d.ts +8 -9
  89. package/feedback/Progress.js +42 -24
  90. package/feedback/Sonner.d.ts +8 -0
  91. package/feedback/Sonner.js +238 -0
  92. package/feedback/Spinner.d.ts +2 -9
  93. package/feedback/Spinner.js +19 -28
  94. package/feedback/Tooltip.d.ts +9 -10
  95. package/feedback/Tooltip.js +147 -96
  96. package/files/Attachment.d.ts +27 -0
  97. package/files/Attachment.js +111 -0
  98. package/files/FileDrop.js +3 -1
  99. package/finance/PaymentCard.js +3 -3
  100. package/forms/Button.d.ts +6 -5
  101. package/forms/Button.js +22 -8
  102. package/forms/ButtonGroup.d.ts +11 -3
  103. package/forms/ButtonGroup.js +57 -6
  104. package/forms/Checkbox.d.ts +14 -3
  105. package/forms/Checkbox.js +84 -16
  106. package/forms/Combobox.d.ts +24 -16
  107. package/forms/Combobox.js +466 -135
  108. package/forms/Field.d.ts +14 -0
  109. package/forms/Field.js +99 -0
  110. package/forms/IconButton.d.ts +1 -1
  111. package/forms/IconButton.js +4 -3
  112. package/forms/Input.d.ts +8 -8
  113. package/forms/Input.js +46 -33
  114. package/forms/InputGroup.d.ts +8 -15
  115. package/forms/InputGroup.js +74 -35
  116. package/forms/InputOTP.d.ts +13 -0
  117. package/forms/InputOTP.js +125 -0
  118. package/forms/Label.d.ts +2 -6
  119. package/forms/Label.js +6 -4
  120. package/forms/NativeSelect.d.ts +16 -0
  121. package/forms/NativeSelect.js +35 -0
  122. package/forms/NumberInput.js +2 -2
  123. package/forms/Radio.d.ts +12 -1
  124. package/forms/Radio.js +76 -6
  125. package/forms/Select.d.ts +12 -9
  126. package/forms/Select.js +254 -42
  127. package/forms/Slider.d.ts +10 -17
  128. package/forms/Slider.js +78 -39
  129. package/forms/Switch.d.ts +8 -2
  130. package/forms/Switch.js +46 -15
  131. package/forms/Textarea.d.ts +1 -1
  132. package/forms/Textarea.js +26 -18
  133. package/forms/Toggle.d.ts +18 -15
  134. package/forms/Toggle.js +96 -42
  135. package/icons/_svg.js +2 -0
  136. package/index.d.ts +20 -8
  137. package/index.js +50 -38
  138. package/navigation/Breadcrumbs.d.ts +18 -11
  139. package/navigation/Breadcrumbs.js +99 -26
  140. package/navigation/Menubar.d.ts +52 -10
  141. package/navigation/Menubar.js +191 -146
  142. package/navigation/NavigationMenu.d.ts +15 -0
  143. package/navigation/NavigationMenu.js +296 -0
  144. package/navigation/Pagination.d.ts +10 -9
  145. package/navigation/Pagination.js +94 -51
  146. package/navigation/SideNav.js +4 -3
  147. package/navigation/Sidebar.d.ts +29 -0
  148. package/navigation/Sidebar.js +311 -0
  149. package/navigation/Tabs.d.ts +9 -5
  150. package/navigation/Tabs.js +132 -44
  151. package/overlay/Command.d.ts +32 -0
  152. package/overlay/Command.js +257 -0
  153. package/overlay/ContextMenu.d.ts +40 -8
  154. package/overlay/ContextMenu.js +468 -107
  155. package/overlay/Drawer.d.ts +29 -14
  156. package/overlay/Drawer.js +178 -80
  157. package/overlay/DropdownMenu.d.ts +43 -0
  158. package/overlay/DropdownMenu.js +502 -0
  159. package/overlay/HoverCard.d.ts +21 -12
  160. package/overlay/HoverCard.js +129 -61
  161. package/overlay/Popover.d.ts +11 -13
  162. package/overlay/Popover.js +138 -65
  163. package/overlay/Portal.js +21 -7
  164. package/overlay/Sheet.d.ts +11 -0
  165. package/overlay/Sheet.js +62 -0
  166. package/package.json +4 -1
  167. package/tokens/base.css +1 -1
  168. package/dates/DatePicker.d.ts +0 -14
  169. package/dates/DatePicker.js +0 -111
  170. package/dates/DateRangePicker.d.ts +0 -23
  171. package/dates/DateRangePicker.js +0 -150
  172. package/display/ListItem.d.ts +0 -19
  173. package/display/ListItem.js +0 -50
  174. package/feedback/Toast.d.ts +0 -78
  175. package/feedback/Toast.js +0 -192
  176. package/forms/DigitEntry.d.ts +0 -15
  177. package/forms/DigitEntry.js +0 -79
  178. package/forms/FormField.d.ts +0 -82
  179. package/forms/FormField.js +0 -209
  180. package/overlay/CommandPalette.d.ts +0 -21
  181. package/overlay/CommandPalette.js +0 -148
  182. package/overlay/Menu.d.ts +0 -24
  183. package/overlay/Menu.js +0 -139
package/forms/Slider.js CHANGED
@@ -1,58 +1,97 @@
1
1
  'use client';
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  import React from 'react';
4
- import { useFieldProps } from "./FormField.js";
5
- export function Slider({
6
- label,
7
- showValue,
8
- format,
4
+ import { useFieldProps } from "./Field.js";
5
+ function clamp(value, min, max) {
6
+ return Math.max(min, Math.min(max, value));
7
+ }
8
+ function asArray(value, fallback) {
9
+ return Array.isArray(value) ? value : fallback;
10
+ }
11
+ export const Slider = /*#__PURE__*/React.forwardRef(function Slider({
9
12
  min = 0,
10
13
  max = 100,
11
14
  step = 1,
12
- value,
15
+ value: valueProp,
13
16
  defaultValue,
14
- onChange,
17
+ onValueChange,
18
+ onValueCommit,
15
19
  disabled,
20
+ orientation = 'horizontal',
21
+ minStepsBetweenThumbs = 0,
22
+ inverted = false,
23
+ dir,
16
24
  style,
17
25
  className,
18
26
  ...rest
19
- }) {
20
- // Picks up id / aria wiring when nested in a FormField; standalone this is a no-op.
27
+ }, forwardedRef) {
21
28
  const field = useFieldProps({
22
29
  id: rest.id,
23
30
  'aria-describedby': rest['aria-describedby']
24
31
  });
25
- const [inner, setInner] = React.useState(defaultValue != null ? defaultValue : (min + max) / 2);
26
- const v = value != null ? value : inner;
27
- const pct = (v - min) / (max - min) * 100;
28
- const handle = e => {
29
- const n = +e.target.value;
30
- if (value == null) setInner(n);
31
- if (onChange) onChange(n, e);
32
+ const fallback = [min];
33
+ const [inner, setInner] = React.useState(() => asArray(defaultValue, fallback));
34
+ const values = asArray(valueProp, inner).map(value => clamp(Number(value), min, max));
35
+ const latestRef = React.useRef(values);
36
+ latestRef.current = values;
37
+ const span = max - min || 1;
38
+ const percentages = values.map(value => (value - min) / span * 100);
39
+ const low = values.length > 1 ? Math.min(...percentages) : 0;
40
+ const high = values.length > 1 ? Math.max(...percentages) : percentages[0];
41
+ const update = (index, nextNumber) => {
42
+ const next = [...values];
43
+ const gap = minStepsBetweenThumbs * step;
44
+ const lower = index > 0 ? next[index - 1] + gap : min;
45
+ const upper = index < next.length - 1 ? next[index + 1] - gap : max;
46
+ next[index] = clamp(nextNumber, lower, upper);
47
+ latestRef.current = next;
48
+ if (valueProp === undefined) setInner(next);
49
+ onValueChange?.(next);
32
50
  };
33
- const input = /*#__PURE__*/React.createElement("input", _extends({
51
+ const rangeStyle = orientation === 'vertical' ? {
52
+ bottom: `${low}%`,
53
+ height: `${high - low}%`,
54
+ width: '100%'
55
+ } : {
56
+ insetInlineStart: `${inverted ? 100 - high : low}%`,
57
+ width: `${high - low}%`
58
+ };
59
+ const control = /*#__PURE__*/React.createElement("span", {
60
+ className: "ef-slider__control"
61
+ }, /*#__PURE__*/React.createElement("span", {
62
+ className: "ef-slider__rail",
63
+ "data-slot": "slider-track"
64
+ }, /*#__PURE__*/React.createElement("span", {
65
+ className: "ef-slider__range",
66
+ "data-slot": "slider-range",
67
+ style: rangeStyle
68
+ })), values.map((value, index) => /*#__PURE__*/React.createElement("input", _extends({}, rest, field.controlProps, {
69
+ key: index,
34
70
  type: "range",
35
- className: "ef-slider__input",
36
- style: {
37
- '--ef-fill': pct + '%'
38
- },
39
- min: min,
40
- max: max,
71
+ "data-slot": "slider-thumb",
72
+ "aria-label": rest['aria-label'] ? `${rest['aria-label']}${values.length > 1 ? ` ${index + 1}` : ''}` : undefined,
73
+ min: index > 0 ? values[index - 1] + minStepsBetweenThumbs * step : min,
74
+ max: index < values.length - 1 ? values[index + 1] - minStepsBetweenThumbs * step : max,
41
75
  step: step,
42
- value: v,
43
- onChange: handle,
44
- disabled: disabled
45
- }, rest, field.controlProps));
46
- if (!label && !showValue) return /*#__PURE__*/React.createElement("span", {
47
- className: `ef-slider${className ? ' ' + className : ''}`,
48
- style: style
49
- }, input);
50
- return /*#__PURE__*/React.createElement("label", {
76
+ value: value,
77
+ disabled: disabled,
78
+ dir: inverted ? dir === 'rtl' ? 'ltr' : 'rtl' : dir,
79
+ className: "ef-slider__input",
80
+ onChange: event => update(index, Number(event.target.value)),
81
+ onPointerUp: () => onValueCommit?.(latestRef.current),
82
+ onKeyUp: event => {
83
+ if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(event.key)) onValueCommit?.(latestRef.current);
84
+ }
85
+ }))));
86
+ const rootProps = {
87
+ 'data-slot': 'slider',
88
+ 'data-orientation': orientation,
89
+ 'data-disabled': disabled ? '' : undefined,
90
+ dir,
51
91
  className: `ef-slider${className ? ' ' + className : ''}`,
52
- style: style
53
- }, (label || showValue) && /*#__PURE__*/React.createElement("span", {
54
- className: "ef-slider__label"
55
- }, label, /*#__PURE__*/React.createElement("span", {
56
- className: "ef-slider__val"
57
- }, showValue ? format ? format(v) : v : '')), input);
58
- }
92
+ style
93
+ };
94
+ return /*#__PURE__*/React.createElement("span", _extends({}, rootProps, {
95
+ ref: forwardedRef
96
+ }), control);
97
+ });
package/forms/Switch.d.ts CHANGED
@@ -1,6 +1,12 @@
1
- export interface SwitchProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> {
1
+ export interface SwitchProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'size' | 'value' | 'defaultValue' | 'onChange'> {
2
2
  label?: React.ReactNode;
3
3
  /** @default 'md' */
4
4
  size?: 'sm' | 'md';
5
+ onCheckedChange?: (checked: boolean) => void;
6
+ checked?: boolean;
7
+ defaultChecked?: boolean;
8
+ name?: string;
9
+ value?: string;
10
+ required?: boolean;
5
11
  }
6
- export declare function Switch(props: SwitchProps): React.JSX.Element;
12
+ export declare const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLButtonElement>>;
package/forms/Switch.js CHANGED
@@ -1,31 +1,62 @@
1
1
  'use client';
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  import React from 'react';
4
- import { useFieldProps } from "./FormField.js";
5
- export function Switch({
4
+ import { useFieldProps } from "./Field.js";
5
+ export const Switch = /*#__PURE__*/React.forwardRef(function Switch({
6
6
  label,
7
7
  size = 'md',
8
8
  disabled,
9
+ checked: checkedProp,
10
+ defaultChecked,
11
+ onCheckedChange,
12
+ onClick,
13
+ name,
14
+ value = 'on',
15
+ required,
9
16
  style,
10
17
  className,
11
18
  ...rest
12
- }) {
13
- // Picks up id / aria wiring when nested in a FormField; standalone this is a no-op.
19
+ }, ref) {
20
+ // Picks up id / aria wiring when nested in a Field; standalone this is a no-op.
14
21
  const field = useFieldProps({
15
22
  id: rest.id,
16
23
  'aria-describedby': rest['aria-describedby']
17
24
  });
18
- return /*#__PURE__*/React.createElement("label", {
19
- className: `ef-switch ef-switch--${size}${disabled ? ' ef-switch--disabled' : ''}${className ? ' ' + className : ''}`,
20
- style: style
21
- }, /*#__PURE__*/React.createElement("input", _extends({
22
- type: "checkbox",
25
+ const [inner, setInner] = React.useState(!!defaultChecked);
26
+ const checked = checkedProp !== undefined ? checkedProp : inner;
27
+ const control = /*#__PURE__*/React.createElement("button", _extends({
28
+ ref: ref,
29
+ type: "button",
23
30
  role: "switch",
24
- className: "ef-switch__input",
25
- disabled: disabled
26
- }, rest, field.controlProps)), /*#__PURE__*/React.createElement("span", {
31
+ "aria-checked": checked,
32
+ "aria-required": required || undefined,
33
+ disabled: disabled,
34
+ "data-slot": "switch",
35
+ "data-state": checked ? 'checked' : 'unchecked',
36
+ className: `ef-switch ef-switch--${size}${disabled ? ' ef-switch--disabled' : ''}${className ? ' ' + className : ''}`,
37
+ style: style,
38
+ onClick: e => {
39
+ if (onClick) onClick(e);
40
+ if (!e.defaultPrevented) {
41
+ const next = !checked;
42
+ if (checkedProp === undefined) setInner(next);
43
+ if (onCheckedChange) onCheckedChange(next);
44
+ }
45
+ }
46
+ }, rest, field.controlProps), /*#__PURE__*/React.createElement("span", {
47
+ "data-slot": "switch-thumb",
48
+ "data-state": checked ? 'checked' : 'unchecked',
27
49
  className: "ef-switch__track"
28
- }), label ? /*#__PURE__*/React.createElement("span", {
50
+ }));
51
+ const formValue = name && checked ? /*#__PURE__*/React.createElement("input", {
52
+ type: "hidden",
53
+ name: name,
54
+ value: value
55
+ }) : null;
56
+ if (!label) return /*#__PURE__*/React.createElement(React.Fragment, null, control, formValue);
57
+ return /*#__PURE__*/React.createElement("span", {
58
+ className: "ef-switch-field"
59
+ }, control, /*#__PURE__*/React.createElement("span", {
29
60
  className: "ef-switch__label"
30
- }, label) : null);
31
- }
61
+ }, label), formValue);
62
+ });
@@ -5,4 +5,4 @@ export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextArea
5
5
  error?: string;
6
6
  invalid?: boolean;
7
7
  }
8
- export declare function Textarea(props: TextareaProps): React.JSX.Element;
8
+ export declare const Textarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
package/forms/Textarea.js CHANGED
@@ -2,8 +2,8 @@
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  import React from 'react';
4
4
  import { Icon } from "../icons/Icon.js";
5
- import { useFieldProps } from "./FormField.js";
6
- export function Textarea({
5
+ import { useFieldProps } from "./Field.js";
6
+ export const Textarea = /*#__PURE__*/React.forwardRef(function Textarea({
7
7
  label,
8
8
  hint,
9
9
  error,
@@ -11,8 +11,8 @@ export function Textarea({
11
11
  style,
12
12
  className,
13
13
  ...rest
14
- }) {
15
- // Picks up id / aria wiring when nested in a FormField; standalone this is a no-op.
14
+ }, ref) {
15
+ const uid = React.useId();
16
16
  const field = useFieldProps({
17
17
  invalid,
18
18
  error,
@@ -20,25 +20,33 @@ export function Textarea({
20
20
  'aria-describedby': rest['aria-describedby']
21
21
  });
22
22
  const bad = field.invalid;
23
- const el = /*#__PURE__*/React.createElement("textarea", _extends({
24
- className: `ef-textarea${bad ? ' ef-textarea--invalid' : ''}`,
25
- "aria-invalid": bad || undefined
26
- }, rest, field.controlProps));
27
- if (!label && !hint && !error) return /*#__PURE__*/React.cloneElement(el, {
28
- style,
29
- className: el.props.className + (className ? ' ' + className : '')
30
- });
31
- return /*#__PURE__*/React.createElement("label", {
32
- className: `ef-field${className ? ' ' + className : ''}`,
23
+ const controlId = field.id || rest.id || (label || hint || error ? `${uid}c` : undefined);
24
+ const noteId = hint || error ? `${uid}n` : undefined;
25
+ const describedBy = [...new Set([field.controlProps['aria-describedby'], rest['aria-describedby'], noteId].filter(Boolean))].join(' ') || undefined;
26
+ const control = /*#__PURE__*/React.createElement("textarea", _extends({}, rest, field.controlProps, {
27
+ ref: ref,
28
+ id: controlId,
29
+ "data-slot": "textarea",
30
+ "aria-describedby": describedBy,
31
+ "aria-invalid": bad || rest['aria-invalid'] || undefined,
32
+ className: `ef-textarea${bad ? ' ef-textarea--invalid' : ''}${className ? ' ' + className : ''}`,
33
33
  style: style
34
- }, label ? /*#__PURE__*/React.createElement("span", {
35
- className: "ef-field__label"
36
- }, label) : null, el, error ? /*#__PURE__*/React.createElement("span", {
34
+ }));
35
+ if (!label && !hint && !error) return control;
36
+ return /*#__PURE__*/React.createElement("div", {
37
+ className: "ef-field"
38
+ }, label ? /*#__PURE__*/React.createElement("label", {
39
+ className: "ef-field__label",
40
+ htmlFor: controlId
41
+ }, label) : null, control, error ? /*#__PURE__*/React.createElement("span", {
42
+ id: noteId,
43
+ role: "alert",
37
44
  className: "ef-field__error"
38
45
  }, /*#__PURE__*/React.createElement(Icon, {
39
46
  name: "circle-alert",
40
47
  size: 12
41
48
  }), error) : hint ? /*#__PURE__*/React.createElement("span", {
49
+ id: noteId,
42
50
  className: "ef-field__hint"
43
51
  }, hint) : null);
44
- }
52
+ });
package/forms/Toggle.d.ts CHANGED
@@ -3,24 +3,27 @@ export interface ToggleProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
3
3
  pressed?: boolean;
4
4
  defaultPressed?: boolean;
5
5
  onPressedChange?: (pressed: boolean) => void;
6
- /** Identity when used inside a ToggleGroup */
7
- value?: string;
8
- /** Lucide icon name */
9
- icon?: string;
10
- /** @default 'md' */
11
- size?: 'sm' | 'md';
12
- children?: React.ReactNode;
6
+ /** @default 'default' */
7
+ variant?: 'default' | 'outline';
8
+ /** @default 'default' */
9
+ size?: 'default' | 'sm' | 'lg';
13
10
  }
14
- export interface ToggleGroupProps {
11
+ export interface ToggleGroupProps extends React.HTMLAttributes<HTMLDivElement> {
15
12
  /** @default 'single' */
16
13
  type?: 'single' | 'multiple';
17
- /** Controlled: string (single) or string[] (multiple) */
18
14
  value?: string | string[] | null;
19
15
  defaultValue?: string | string[] | null;
20
- onChange?: (value: string | string[] | null) => void;
21
- children?: React.ReactNode;
22
- style?: React.CSSProperties;
23
- className?: string;
16
+ onValueChange?: (value: string | string[] | null) => void;
17
+ variant?: 'default' | 'outline';
18
+ size?: 'default' | 'sm' | 'lg';
19
+ /** Gap in 4px units. @default 2 */
20
+ spacing?: number;
21
+ orientation?: 'horizontal' | 'vertical';
22
+ disabled?: boolean;
23
+ dir?: 'ltr' | 'rtl';
24
24
  }
25
- export declare function Toggle(props: ToggleProps): React.JSX.Element;
26
- export declare function ToggleGroup(props: ToggleGroupProps): React.JSX.Element;
25
+ export interface ToggleGroupItemProps extends ToggleProps { value: string; }
26
+ export declare function toggleVariants(options?: Pick<ToggleProps, 'variant' | 'size'> & { className?: string }): string;
27
+ export declare const Toggle: React.ForwardRefExoticComponent<ToggleProps & React.RefAttributes<HTMLButtonElement>>;
28
+ export declare const ToggleGroup: React.ForwardRefExoticComponent<ToggleGroupProps & React.RefAttributes<HTMLDivElement>>;
29
+ export declare const ToggleGroupItem: React.ForwardRefExoticComponent<ToggleGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
package/forms/Toggle.js CHANGED
@@ -1,74 +1,128 @@
1
1
  'use client';
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  import React from 'react';
4
- import { Icon } from "../icons/Icon.js";
5
4
  const GroupCtx = /*#__PURE__*/React.createContext(null);
6
- export function Toggle({
5
+ export function toggleVariants({
6
+ variant = 'default',
7
+ size = 'default',
8
+ className = ''
9
+ } = {}) {
10
+ const mappedSize = size === 'default' ? 'default' : size;
11
+ return `ef-toggle ef-toggle--${variant} ef-toggle--${mappedSize}${className ? ' ' + className : ''}`;
12
+ }
13
+ export const Toggle = /*#__PURE__*/React.forwardRef(function Toggle({
7
14
  pressed,
8
15
  defaultPressed,
9
16
  onPressedChange,
17
+ onClick,
10
18
  value,
11
- icon,
12
- size = 'md',
19
+ variant = 'default',
20
+ size = 'default',
13
21
  disabled,
14
22
  children,
15
- style,
16
23
  className,
24
+ _groupItem = false,
17
25
  ...rest
18
- }) {
19
- const ctx = React.useContext(GroupCtx);
20
- const [un, setUn] = React.useState(!!defaultPressed);
21
- const isOn = ctx ? ctx.isOn(value) : pressed !== undefined ? pressed : un;
22
- const press = () => {
23
- if (ctx) {
24
- ctx.toggle(value);
25
- return;
26
+ }, ref) {
27
+ const groupContext = React.useContext(GroupCtx);
28
+ const context = _groupItem ? groupContext : null;
29
+ const [uncontrolled, setUncontrolled] = React.useState(!!defaultPressed);
30
+ const isOn = context ? context.isOn(value) : pressed !== undefined ? pressed : uncontrolled;
31
+ const press = event => {
32
+ onClick?.(event);
33
+ if (event.defaultPrevented) return;
34
+ if (context) context.toggle(value);else {
35
+ if (pressed === undefined) setUncontrolled(!isOn);
36
+ onPressedChange?.(!isOn);
26
37
  }
27
- if (pressed === undefined) setUn(!isOn);
28
- if (onPressedChange) onPressedChange(!isOn);
29
38
  };
30
- return /*#__PURE__*/React.createElement("button", _extends({
39
+ const actualVariant = context?.variant ?? variant;
40
+ const actualSize = context?.size ?? size;
41
+ return /*#__PURE__*/React.createElement("button", _extends({}, rest, {
42
+ ref: ref,
31
43
  type: "button",
44
+ "data-slot": context ? 'toggle-group-item' : 'toggle',
45
+ "data-state": isOn ? 'on' : 'off',
32
46
  "aria-pressed": isOn,
33
- disabled: disabled,
47
+ disabled: disabled || context?.disabled,
34
48
  onClick: press,
35
- style: style,
36
- className: `ef-toggle ef-toggle--${size}${isOn ? ' ef-toggle--on' : ''}${className ? ' ' + className : ''}`
37
- }, rest), icon ? /*#__PURE__*/React.createElement(Icon, {
38
- name: icon,
39
- size: size === 'sm' ? 14 : 16
40
- }) : null, children);
41
- }
42
- export function ToggleGroup({
49
+ className: `${toggleVariants({
50
+ variant: actualVariant,
51
+ size: actualSize,
52
+ className
53
+ })}${isOn ? ' ef-toggle--on' : ''}`
54
+ }), children);
55
+ });
56
+ export const ToggleGroup = /*#__PURE__*/React.forwardRef(function ToggleGroup({
43
57
  type = 'single',
44
58
  value,
45
59
  defaultValue,
46
- onChange,
60
+ onValueChange,
61
+ variant = 'default',
62
+ size = 'default',
63
+ spacing = 2,
64
+ orientation = 'horizontal',
65
+ disabled = false,
66
+ dir,
47
67
  children,
48
68
  style,
49
69
  className,
70
+ onKeyDown,
50
71
  ...rest
51
- }) {
52
- const [un, setUn] = React.useState(defaultValue !== undefined ? defaultValue : type === 'multiple' ? [] : null);
53
- const cur = value !== undefined ? value : un;
54
- const isOn = v => type === 'multiple' ? (cur || []).includes(v) : cur === v;
55
- const toggle = v => {
72
+ }, ref) {
73
+ const [uncontrolled, setUncontrolled] = React.useState(defaultValue !== undefined ? defaultValue : type === 'multiple' ? [] : null);
74
+ const current = value !== undefined ? value : uncontrolled;
75
+ const isOn = itemValue => type === 'multiple' ? (current || []).includes(itemValue) : current === itemValue;
76
+ const toggle = itemValue => {
56
77
  let next;
57
78
  if (type === 'multiple') {
58
- const c = cur || [];
59
- next = c.includes(v) ? c.filter(x => x !== v) : [...c, v];
60
- } else next = cur === v ? null : v;
61
- if (value === undefined) setUn(next);
62
- if (onChange) onChange(next);
79
+ const selected = current || [];
80
+ next = selected.includes(itemValue) ? selected.filter(item => item !== itemValue) : [...selected, itemValue];
81
+ } else next = current === itemValue ? null : itemValue;
82
+ if (value === undefined) setUncontrolled(next);
83
+ onValueChange?.(next);
63
84
  };
85
+ const keyNav = event => {
86
+ onKeyDown?.(event);
87
+ if (event.defaultPrevented) return;
88
+ const rtl = (dir || document.documentElement.dir) === 'rtl';
89
+ const previous = orientation === 'vertical' ? event.key === 'ArrowUp' : event.key === (rtl ? 'ArrowRight' : 'ArrowLeft');
90
+ const next = orientation === 'vertical' ? event.key === 'ArrowDown' : event.key === (rtl ? 'ArrowLeft' : 'ArrowRight');
91
+ if (!previous && !next && event.key !== 'Home' && event.key !== 'End') return;
92
+ const items = [...event.currentTarget.querySelectorAll('[data-slot="toggle-group-item"]:not(:disabled)')];
93
+ if (!items.length) return;
94
+ event.preventDefault();
95
+ const index = items.indexOf(document.activeElement);
96
+ const target = event.key === 'Home' ? items[0] : event.key === 'End' ? items.at(-1) : items[(index + (previous ? -1 : 1) + items.length) % items.length];
97
+ target?.focus();
98
+ };
99
+ const ctx = React.useMemo(() => ({
100
+ isOn,
101
+ toggle,
102
+ variant,
103
+ size,
104
+ disabled
105
+ }), [current, type, variant, size, disabled]);
64
106
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
107
+ ref: ref,
65
108
  role: "group",
109
+ "data-slot": "toggle-group",
110
+ "data-orientation": orientation,
111
+ dir: dir,
66
112
  className: `ef-toggle-group${className ? ' ' + className : ''}`,
67
- style: style
113
+ style: {
114
+ '--ef-toggle-gap': `${spacing * 4}px`,
115
+ ...style
116
+ },
117
+ onKeyDown: keyNav
68
118
  }), /*#__PURE__*/React.createElement(GroupCtx.Provider, {
69
- value: {
70
- isOn,
71
- toggle
72
- }
119
+ value: ctx
73
120
  }, children));
74
- }
121
+ });
122
+ export const ToggleGroupItem = /*#__PURE__*/React.forwardRef(function ToggleGroupItem(props, ref) {
123
+ return /*#__PURE__*/React.createElement(Toggle, _extends({}, props, {
124
+ ref: ref,
125
+ _groupItem: true,
126
+ "data-slot": "toggle-group-item"
127
+ }));
128
+ });
package/icons/_svg.js CHANGED
@@ -24,6 +24,7 @@ export const SVGS = {
24
24
  "chevron-up": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"m18 15-6-6-6 6\"></path>\n</svg>",
25
25
  "circle-alert": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\"></circle>\n <line x1=\"12\" x2=\"12\" y1=\"8\" y2=\"12\"></line>\n <line x1=\"12\" x2=\"12.01\" y1=\"16\" y2=\"16\"></line>\n</svg>",
26
26
  "circle-check": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\"></circle>\n <path d=\"m9 12 2 2 4-4\"></path>\n</svg>",
27
+ "circle": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\"></circle>\n</svg>",
27
28
  "clock": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\"></circle>\n <path d=\"M12 6v6l4 2\"></path>\n</svg>",
28
29
  "cloud": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z\"></path>\n</svg>",
29
30
  "code": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"m16 18 6-6-6-6\"></path>\n <path d=\"m8 6-6 6 6 6\"></path>\n</svg>",
@@ -67,6 +68,7 @@ export const SVGS = {
67
68
  "menu": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M4 5h16\"></path>\n <path d=\"M4 12h16\"></path>\n <path d=\"M4 19h16\"></path>\n</svg>",
68
69
  "message-square": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z\"></path>\n</svg>",
69
70
  "mic": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M12 19v3\"></path>\n <path d=\"M19 10v2a7 7 0 0 1-14 0v-2\"></path>\n <rect x=\"9\" y=\"2\" width=\"6\" height=\"13\" rx=\"3\"></rect>\n</svg>",
71
+ "minus": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M5 12h14\"></path>\n</svg>",
70
72
  "monitor": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <rect width=\"20\" height=\"14\" x=\"2\" y=\"3\" rx=\"2\"></rect>\n <line x1=\"8\" x2=\"16\" y1=\"21\" y2=\"21\"></line>\n <line x1=\"12\" x2=\"12\" y1=\"17\" y2=\"21\"></line>\n</svg>",
71
73
  "moon": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z\"></path>\n</svg>",
72
74
  "music": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M9 18V5l12-2v13\"></path>\n <circle cx=\"6\" cy=\"18\" r=\"3\"></circle>\n <circle cx=\"18\" cy=\"16\" r=\"3\"></circle>\n</svg>",