@enigmax/primitives 0.16.0 → 0.18.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 (89) hide show
  1. package/dist/button-CaXaqG_K.d.ts +63 -0
  2. package/dist/chunk-2QFTRNAZ.js +88 -0
  3. package/dist/chunk-6BGBYUSZ.js +114 -0
  4. package/dist/chunk-AU3H5WIY.js +107 -0
  5. package/dist/chunk-F25CGNQC.js +19 -0
  6. package/dist/chunk-HC2ME5PU.js +168 -0
  7. package/dist/chunk-HS3X3XCW.js +43 -0
  8. package/dist/chunk-IIT6U7LM.js +249 -0
  9. package/dist/chunk-IXVMRVD4.js +96 -0
  10. package/dist/chunk-KJINGUQN.js +188 -0
  11. package/dist/chunk-LKA2UG4P.js +542 -0
  12. package/dist/chunk-MMQPZGSU.js +161 -0
  13. package/dist/chunk-OCMI7R6H.js +79 -0
  14. package/dist/chunk-QYMUIW5I.js +28 -0
  15. package/dist/chunk-S653GLSF.js +17 -0
  16. package/dist/chunk-SNYUBXWQ.js +149 -0
  17. package/dist/chunk-U3V4EHOB.js +41 -0
  18. package/dist/chunk-UOSSNUSC.js +309 -0
  19. package/dist/chunk-WSB655JB.js +47 -0
  20. package/dist/chunk-XNNQRA35.js +31 -0
  21. package/dist/chunk-XQHCZAPJ.js +102 -0
  22. package/dist/chunk-ZCUFYBPB.js +154 -0
  23. package/dist/chunk-ZWR2EXHQ.js +55 -0
  24. package/dist/flags-BBJc9unY.d.ts +133 -0
  25. package/dist/index-D-ARvWpQ.d.ts +306 -0
  26. package/dist/index-DNXPtY9X.d.ts +144 -0
  27. package/dist/index.d.ts +16 -496
  28. package/dist/index.js +9 -1
  29. package/dist/input-BwXjFenq.d.ts +77 -0
  30. package/dist/marquee-CJ3Uwy3E.d.ts +81 -0
  31. package/dist/network-D2LsBG_k.d.ts +39 -0
  32. package/dist/next/index.d.ts +20 -3
  33. package/dist/next/index.js +23 -3
  34. package/dist/notifications-BpVV6sel.d.ts +70 -0
  35. package/dist/password-3DRQYAYQ.js +2 -0
  36. package/dist/password-C8lG4Zm9.d.ts +71 -0
  37. package/dist/password-FB2CUEKJ.js +1 -0
  38. package/dist/react/button.d.ts +75 -0
  39. package/dist/react/button.js +4 -0
  40. package/dist/react/flag.d.ts +37 -0
  41. package/dist/react/flag.js +3 -0
  42. package/dist/react/index.d.ts +28 -286
  43. package/dist/react/index.js +22 -2
  44. package/dist/react/input.d.ts +4 -0
  45. package/dist/react/input.js +3 -0
  46. package/dist/react/marquee.d.ts +44 -0
  47. package/dist/react/marquee.js +3 -0
  48. package/dist/react/network.d.ts +20 -0
  49. package/dist/react/network.js +3 -0
  50. package/dist/react/notifications.d.ts +17 -0
  51. package/dist/react/notifications.js +3 -0
  52. package/dist/react/palette.d.ts +3 -0
  53. package/dist/react/palette.js +4 -0
  54. package/dist/react/relative-time.d.ts +21 -0
  55. package/dist/react/relative-time.js +3 -0
  56. package/dist/react/search.d.ts +30 -0
  57. package/dist/react/search.js +3 -0
  58. package/dist/react/slot.d.ts +47 -0
  59. package/dist/react/slot.js +2 -0
  60. package/dist/react/toast.d.ts +40 -0
  61. package/dist/react/toast.js +4 -0
  62. package/dist/react-router/index.d.ts +20 -3
  63. package/dist/react-router/index.js +23 -3
  64. package/dist/relative-time-YpRTG7YH.d.ts +106 -0
  65. package/dist/search-P4OHCRXD.js +50 -0
  66. package/package.json +53 -1
  67. package/registry.json +235 -16
  68. package/src/core/flags.ts +266 -0
  69. package/src/core/input-icons.ts +34 -0
  70. package/src/core/input.ts +5 -21
  71. package/src/core/palette.ts +0 -0
  72. package/src/index.ts +18 -0
  73. package/src/react/button.tsx +70 -4
  74. package/src/react/flag.tsx +70 -0
  75. package/src/react/index.ts +52 -5
  76. package/src/react/input/icon.tsx +17 -0
  77. package/src/react/input/index.tsx +307 -0
  78. package/src/react/input/password.tsx +174 -0
  79. package/src/react/input/search.tsx +82 -0
  80. package/src/react/input/types.ts +146 -0
  81. package/src/react/input/write-value.ts +18 -0
  82. package/src/react/palette/context.ts +60 -0
  83. package/src/react/palette/index.tsx +66 -0
  84. package/src/react/palette/root.tsx +621 -0
  85. package/src/react/slot.tsx +91 -0
  86. package/src/react/use-button.ts +3 -1
  87. package/dist/chunk-53DQY6LP.js +0 -1164
  88. package/dist/chunk-U2KYYMBJ.js +0 -724
  89. package/src/react/input.tsx +0 -429
@@ -0,0 +1,91 @@
1
+ "use client";
2
+
3
+ import { Children, cloneElement, forwardRef, isValidElement, type ReactNode } from "react";
4
+
5
+ /**
6
+ * `asChild`: render the behaviour onto YOUR element instead of ours.
7
+ *
8
+ * This is the escape hatch that decides whether a headless package is usable at scale. A
9
+ * component that always renders its own `<button>` forces every consumer who needs a link,
10
+ * a `motion.button`, a router's `Link` or their own design-system button to reimplement the
11
+ * behaviour - and that is the moment a team stops using the package. With `asChild` the
12
+ * component contributes props, refs and handlers, and the consumer owns the element:
13
+ *
14
+ * ```tsx
15
+ * <Button asChild shortcut="s">
16
+ * <motion.a href="/save" whileTap={{ scale: 0.98 }}>Save</motion.a>
17
+ * </Button>
18
+ * ```
19
+ *
20
+ * Radix's Slot, deliberately: the semantics are the ones a React developer already knows.
21
+ * Its rules, and why each is the way round it is:
22
+ *
23
+ * - The CHILD's props win, because the child is what the author wrote by hand at this call
24
+ * site, while ours are the defaults a component supplied.
25
+ * - EVENT HANDLERS are chained rather than replaced, ours first: dropping ours would take
26
+ * the behaviour with it silently, which is the failure `onClick` on the Button already
27
+ * cost once. The child's handler still runs even if ours called `preventDefault`, so a
28
+ * handler that wants to bail checks `event.defaultPrevented` itself.
29
+ * - `className` and `style` are MERGED, child last, because both are additive by nature and
30
+ * an overwritten className is the single most confusing thing a wrapper can do.
31
+ * - Refs are composed, so both sides keep the node.
32
+ */
33
+
34
+ type Props = Record<string, unknown>;
35
+
36
+ function composeRefs<T>(...refs: React.Ref<T>[]): (node: T | null) => void {
37
+ return (node) => {
38
+ for (const ref of refs) {
39
+ if (typeof ref === "function") ref(node);
40
+ else if (ref) (ref as React.MutableRefObject<T | null>).current = node;
41
+ }
42
+ };
43
+ }
44
+
45
+ /** Merge the slot's props into the child's, by the rules above. */
46
+ export function mergeSlotProps(slotProps: Props, childProps: Props): Props {
47
+ const merged: Props = { ...slotProps, ...childProps };
48
+
49
+ for (const key of Object.keys(slotProps)) {
50
+ const slotValue = slotProps[key];
51
+ const childValue = childProps[key];
52
+ const isHandler = /^on[A-Z]/.test(key);
53
+
54
+ if (isHandler && typeof slotValue === "function" && typeof childValue === "function") {
55
+ merged[key] = (...args: unknown[]) => {
56
+ (slotValue as (...a: unknown[]) => unknown)(...args);
57
+ return (childValue as (...a: unknown[]) => unknown)(...args);
58
+ };
59
+ } else if (isHandler && typeof slotValue === "function" && childValue === undefined) {
60
+ merged[key] = slotValue;
61
+ } else if (key === "style") {
62
+ merged[key] = { ...(slotValue as object), ...(childValue as object) };
63
+ } else if (key === "className") {
64
+ merged[key] = [slotValue, childValue].filter(Boolean).join(" ");
65
+ }
66
+ }
67
+ return merged;
68
+ }
69
+
70
+ export interface SlotProps extends Props {
71
+ children?: ReactNode;
72
+ }
73
+
74
+ /**
75
+ * Clones its single child with the props it was given.
76
+ *
77
+ * A child that is not a single element is a mistake worth failing on rather than
78
+ * papering over: `asChild` with two children has no answer to "which one gets the
79
+ * behaviour", and rendering nothing would be a blank space nobody can debug.
80
+ */
81
+ export const Slot = forwardRef<HTMLElement, SlotProps>(function Slot({ children, ...slotProps }, forwardedRef) {
82
+ const child = Children.only(children);
83
+ if (!isValidElement(child)) return null;
84
+
85
+ const childProps = child.props as Props;
86
+ const childRef = (child as unknown as { ref?: React.Ref<unknown>; }).ref;
87
+ const merged = mergeSlotProps(slotProps, childProps);
88
+ if (forwardedRef || childRef) merged.ref = composeRefs(forwardedRef as React.Ref<unknown>, childRef ?? null);
89
+
90
+ return cloneElement(child, merged);
91
+ });
@@ -13,6 +13,8 @@ export interface UseButtonResult extends ButtonState {
13
13
  disabled?: boolean;
14
14
  href?: string;
15
15
  title?: string;
16
+ /** The ARIA way to announce the key. `title` is the pointer half of the same fact. */
17
+ "aria-keyshortcuts"?: string;
16
18
  };
17
19
  press: () => void;
18
20
  reset: () => void;
@@ -85,7 +87,7 @@ export function useButton(options: ButtonOptions = {}): UseButtonResult {
85
87
  ...(state.loading ? { "data-loading": "" as const } : {}),
86
88
  ...(state.cooldown > 0 ? { "data-cooldown": "" as const } : {}),
87
89
  ...(state.element === "button" ? { disabled: state.disabled } : { href: options.href }),
88
- ...(state.shortcut ? { title: `Shortcut: ${state.shortcut.toUpperCase()}` } : {})
90
+ ...(state.shortcut ? { title: `Shortcut: ${state.shortcut.toUpperCase()}`, "aria-keyshortcuts": state.shortcut } : {})
89
91
  }
90
92
  };
91
93
  }