@zayne-labs/ui-react 0.10.5 → 0.10.6

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 (122) hide show
  1. package/css/animation.css +47 -0
  2. package/css/theme.css +10 -4
  3. package/dist/esm/{await-fjas2Q-C.js → await-Da5w2vIc.js} +14 -15
  4. package/dist/esm/await-Da5w2vIc.js.map +1 -0
  5. package/dist/esm/{card-TD60Xux0.js → card-gWNDcZV0.js} +8 -9
  6. package/dist/esm/card-gWNDcZV0.js.map +1 -0
  7. package/dist/esm/{carousel-YXXtZ85s.js → carousel-BY9RvR71.js} +20 -23
  8. package/dist/esm/carousel-BY9RvR71.js.map +1 -0
  9. package/dist/esm/{chunk-Cl8Af3a2.js → chunk-CTAAG5j7.js} +3 -1
  10. package/dist/esm/{cn-_FbtIrlZ.js → cn-s-D7vHW1.js} +1 -1
  11. package/dist/esm/{cn-_FbtIrlZ.js.map → cn-s-D7vHW1.js.map} +1 -1
  12. package/dist/esm/common/await/index.d.ts +4 -0
  13. package/dist/esm/common/await/index.js +8 -0
  14. package/dist/esm/common/client-gate/index.d.ts +33 -0
  15. package/dist/esm/common/client-gate/index.js +35 -0
  16. package/dist/esm/common/client-gate/index.js.map +1 -0
  17. package/dist/esm/{components/common → common}/error-boundary/index.d.ts +1 -1
  18. package/dist/esm/{components/common → common}/error-boundary/index.js +1 -1
  19. package/dist/esm/common/for/index.d.ts +2 -0
  20. package/dist/esm/common/for/index.js +3 -0
  21. package/dist/esm/common/index.d.ts +9 -0
  22. package/dist/esm/common/index.js +11 -0
  23. package/dist/esm/common/presence/index.d.ts +22 -0
  24. package/dist/esm/common/presence/index.js +6 -0
  25. package/dist/esm/{components/common → common}/show/index.d.ts +1 -1
  26. package/dist/esm/{components/common → common}/show/index.js +1 -2
  27. package/dist/esm/{components/common → common}/slot/index.d.ts +1 -1
  28. package/dist/esm/common/slot/index.js +3 -0
  29. package/dist/esm/common/suspense-with-boundary/index.d.ts +3 -0
  30. package/dist/esm/common/suspense-with-boundary/index.js +4 -0
  31. package/dist/esm/{components/common → common}/switch/index.d.ts +1 -1
  32. package/dist/esm/{components/common → common}/switch/index.js +1 -2
  33. package/dist/esm/common/teleport/index.d.ts +2 -0
  34. package/dist/esm/common/teleport/index.js +3 -0
  35. package/dist/esm/{drag-scroll-De6-soln.js → drag-scroll-Bb1SG4On.js} +9 -12
  36. package/dist/esm/{drag-scroll-De6-soln.js.map → drag-scroll-Bb1SG4On.js.map} +1 -1
  37. package/dist/esm/drop-zone-5dDyxv_f.js +987 -0
  38. package/dist/esm/drop-zone-5dDyxv_f.js.map +1 -0
  39. package/dist/esm/{error-boundary-xM9An3gz.js → error-boundary-y9Samt_s.js} +1 -1
  40. package/dist/esm/error-boundary-y9Samt_s.js.map +1 -0
  41. package/dist/esm/{for-DGs2XZ21.js → for-Dfh7e9Z4.js} +2 -3
  42. package/dist/esm/{for-DGs2XZ21.js.map → for-Dfh7e9Z4.js.map} +1 -1
  43. package/dist/esm/{form-BHfmbX32.js → form-DDSlHq5t.js} +61 -73
  44. package/dist/esm/form-DDSlHq5t.js.map +1 -0
  45. package/dist/esm/{index-BBJzo-WC.d.ts → index-B53RIFft.d.ts} +4 -3
  46. package/dist/esm/index-BBHGVe_0.d.ts +336 -0
  47. package/dist/esm/{index-CnvH74ea.d.ts → index-Bra0UlL_.d.ts} +4 -3
  48. package/dist/esm/{index-DVr1tbxh.d.ts → index-BsGxDKlt.d.ts} +10 -9
  49. package/dist/esm/{index-BYhH4Fm0.d.ts → index-C1GPFYKG.d.ts} +1 -1
  50. package/dist/esm/{index-lKxE9WPi.d.ts → index-CJLZEhIo.d.ts} +4 -2
  51. package/dist/esm/{index-CWKQ5V4B.d.ts → index-CZjeBSoQ.d.ts} +1 -1
  52. package/dist/esm/{index-DJjxpXUk.d.ts → index-CffEFE66.d.ts} +1 -1
  53. package/dist/esm/{index-D6o1oxQd.d.ts → index-CvjRPnhb.d.ts} +13 -16
  54. package/dist/esm/{index-Y_2u8pWF.d.ts → index-D259PHNG.d.ts} +5 -4
  55. package/dist/esm/{index-DqutTJQB.d.ts → index-DoRAzdDN.d.ts} +13 -12
  56. package/dist/esm/{index-BeDmH7lX.d.ts → index-GHA8HNcd.d.ts} +10 -9
  57. package/dist/esm/{index-Cbg54Lt4.d.ts → index-RnqeaSJm.d.ts} +21 -20
  58. package/dist/esm/presence-CRZsP1Jk.js +156 -0
  59. package/dist/esm/presence-CRZsP1Jk.js.map +1 -0
  60. package/dist/esm/{show-BabiXbf7.js → show-N1ZXBhoA.js} +18 -9
  61. package/dist/esm/show-N1ZXBhoA.js.map +1 -0
  62. package/dist/esm/{slot-D1062oA5.js → slot-WVWfOlr3.js} +5 -6
  63. package/dist/esm/{slot-D1062oA5.js.map → slot-WVWfOlr3.js.map} +1 -1
  64. package/dist/esm/{suspense-with-boundary-CEVORL8K.js → suspense-with-boundary-D-1NYDV4.js} +2 -2
  65. package/dist/esm/suspense-with-boundary-D-1NYDV4.js.map +1 -0
  66. package/dist/esm/{switch-CCMD01Rs.js → switch-Ch22z21e.js} +7 -11
  67. package/dist/esm/switch-Ch22z21e.js.map +1 -0
  68. package/dist/esm/{teleport-DfuYOzsj.js → teleport-C8TzRm4M.js} +1 -1
  69. package/dist/esm/teleport-C8TzRm4M.js.map +1 -0
  70. package/dist/esm/{components/ui → ui}/card/index.d.ts +1 -1
  71. package/dist/esm/{components/ui → ui}/card/index.js +3 -3
  72. package/dist/esm/ui/carousel/index.d.ts +2 -0
  73. package/dist/esm/ui/carousel/index.js +16 -0
  74. package/dist/esm/ui/drag-scroll/index.d.ts +2 -0
  75. package/dist/esm/ui/drag-scroll/index.js +4 -0
  76. package/dist/esm/ui/drop-zone/index.d.ts +2 -0
  77. package/dist/esm/ui/drop-zone/index.js +17 -0
  78. package/dist/esm/{components/ui → ui}/form/index.d.ts +1 -1
  79. package/dist/esm/{components/ui → ui}/form/index.js +4 -5
  80. package/dist/esm/ui/index.d.ts +6 -0
  81. package/dist/esm/ui/index.js +18 -0
  82. package/dist/style.css +385 -25
  83. package/package.json +20 -17
  84. package/dist/esm/await-fjas2Q-C.js.map +0 -1
  85. package/dist/esm/card-TD60Xux0.js.map +0 -1
  86. package/dist/esm/carousel-YXXtZ85s.js.map +0 -1
  87. package/dist/esm/components/common/await/index.d.ts +0 -5
  88. package/dist/esm/components/common/await/index.js +0 -10
  89. package/dist/esm/components/common/for/index.d.ts +0 -2
  90. package/dist/esm/components/common/for/index.js +0 -3
  91. package/dist/esm/components/common/index.d.ts +0 -10
  92. package/dist/esm/components/common/index.js +0 -13
  93. package/dist/esm/components/common/slot/index.js +0 -3
  94. package/dist/esm/components/common/suspense-with-boundary/index.d.ts +0 -3
  95. package/dist/esm/components/common/suspense-with-boundary/index.js +0 -4
  96. package/dist/esm/components/common/teleport/index.d.ts +0 -2
  97. package/dist/esm/components/common/teleport/index.js +0 -3
  98. package/dist/esm/components/ui/carousel/index.d.ts +0 -2
  99. package/dist/esm/components/ui/carousel/index.js +0 -18
  100. package/dist/esm/components/ui/drag-scroll/index.d.ts +0 -2
  101. package/dist/esm/components/ui/drag-scroll/index.js +0 -4
  102. package/dist/esm/components/ui/drop-zone/index.d.ts +0 -2
  103. package/dist/esm/components/ui/drop-zone/index.js +0 -18
  104. package/dist/esm/components/ui/index.d.ts +0 -6
  105. package/dist/esm/components/ui/index.js +0 -19
  106. package/dist/esm/drop-zone-BPfSu99L.js +0 -381
  107. package/dist/esm/drop-zone-BPfSu99L.js.map +0 -1
  108. package/dist/esm/error-boundary-xM9An3gz.js.map +0 -1
  109. package/dist/esm/form-BHfmbX32.js.map +0 -1
  110. package/dist/esm/getSlot-Cf5ON6lE.js +0 -85
  111. package/dist/esm/getSlot-Cf5ON6lE.js.map +0 -1
  112. package/dist/esm/index-B-NUFudm.d.ts +0 -183
  113. package/dist/esm/index-BNrCAe9Y.d.ts +0 -142
  114. package/dist/esm/lib/utils/index.d.ts +0 -2
  115. package/dist/esm/lib/utils/index.js +0 -4
  116. package/dist/esm/show-BabiXbf7.js.map +0 -1
  117. package/dist/esm/suspense-with-boundary-CEVORL8K.js.map +0 -1
  118. package/dist/esm/switch-CCMD01Rs.js.map +0 -1
  119. package/dist/esm/teleport-DfuYOzsj.js.map +0 -1
  120. package/dist/esm/utils-ChjmDoRe.js +0 -89
  121. package/dist/esm/utils-ChjmDoRe.js.map +0 -1
  122. /package/dist/esm/{common-BYWy8Q78.js → common-PS3X58Pj.js} +0 -0
@@ -1,142 +0,0 @@
1
- import { CallbackFn, EmptyObject, Prettify, UnionToIntersection, UnknownObject } from "@zayne-labs/toolkit-type-helpers";
2
- import * as react8 from "react";
3
-
4
- //#region src/lib/utils/getSlotMap/getSlotMap.d.ts
5
- type GetSlotName<TSlotComponentProps extends GetSlotComponentProps> = string extends TSlotComponentProps["name"] ? never : "default" extends TSlotComponentProps["name"] ? never : TSlotComponentProps["name"];
6
- type GetSpecificSlotsType<TSlotComponentProps extends GetSlotComponentProps> = { [TName in keyof TSlotComponentProps as GetSlotName<TSlotComponentProps>]: Extract<TSlotComponentProps["children"], React.ReactNode> };
7
- /**
8
- * Maps slot names to their corresponding children types
9
- */
10
- type GetSlotMapResult<TSlotComponentProps extends GetSlotComponentProps> = UnionToIntersection<GetSpecificSlotsType<TSlotComponentProps>> & {
11
- default: React.ReactNode[];
12
- };
13
- /**
14
- * Symbol used to identify SlotComponent instances
15
- */
16
- declare const slotComponentSymbol: unique symbol;
17
- /**
18
- * @description Creates a map of named slots from React children. Returns an object mapping slot names to their children,
19
- * with a default slot for unmatched children.
20
- *
21
- * @example
22
- * ```tsx
23
- * import { type GetSlotComponentProps, SlotComponent } from "@zayne-labs/toolkit-react/utils"
24
- *
25
- * type SlotProps = GetSlotComponentProps<"header" | "footer">;
26
- *
27
- * function Parent({ children }: { children: React.ReactNode }) {
28
- * const slots = getSlotMap<SlotProps>(children);
29
- *
30
- * return (
31
- * <div>
32
- * <header>{slots.header}</header>
33
- * <main>{slots.default}</main>
34
- * <footer>{slots.footer}</footer>
35
- * </div>
36
- * );
37
- * }
38
- * ```
39
- *
40
- * Usage:
41
- * ```tsx
42
- * <Parent>
43
- * <SlotComponent name="header">Header Content</SlotComponent>
44
- * <div>Random stuff</div>
45
- * <SlotComponent name="footer">Footer Content</SlotComponent>
46
- * </Parent>
47
- * ```
48
- */
49
- declare const getSlotMap: <TSlotComponentProps extends GetSlotComponentProps>(children: React.ReactNode) => Prettify<GetSlotMapResult<TSlotComponentProps>>;
50
- /**
51
- * @description Produce props for the SlotComponent
52
- *
53
- * @example
54
- * ```ts
55
- * // Pattern One (slot or slots have same children type, which is just React.ReactNode by default)
56
- * type SlotProps = GetSlotComponentProps<"header" | "content" | "footer">;
57
- *
58
- * // Pattern Two (some slots can have different children type)
59
- * type SlotProps = GetSlotComponentProps<"header", React.ReactNode> | GetSlotComponentProps<"header", (renderProp: RenderProp) => React.ReactNode>;
60
- * ```
61
- */
62
- type GetSlotComponentProps<TName extends string = string, TChildren extends CallbackFn<never, React.ReactNode> | React.ReactNode = CallbackFn<never, React.ReactNode> | React.ReactNode> = {
63
- children: TChildren;
64
- /**
65
- * Name of the slot where content should be rendered
66
- */
67
- name: TName;
68
- };
69
- /**
70
- * @description Creates a slot component
71
- */
72
- declare const createSlotComponent: <TSlotComponentProps extends GetSlotComponentProps>() => {
73
- (props: TSlotComponentProps): React.ReactNode;
74
- slotSymbol: typeof slotComponentSymbol;
75
- };
76
- type SlotWithNameAndSymbol<TSlotComponentProps extends GetSlotComponentProps = GetSlotComponentProps, TOtherProps extends UnknownObject = EmptyObject> = {
77
- (props: Pick<TSlotComponentProps, "children"> & TOtherProps): React.ReactNode;
78
- readonly slotName?: TSlotComponentProps["name"];
79
- readonly slotSymbol?: symbol;
80
- };
81
- /**
82
- * @description Adds a slot symbol and name to a slot component passed in
83
- */
84
- declare const withSlotNameAndSymbol: <TSlotComponentProps extends GetSlotComponentProps, TOtherProps extends UnknownObject = EmptyObject>(name: TSlotComponentProps["name"], SlotComponent?: SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps>) => SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps>;
85
- //#endregion
86
- //#region src/lib/utils/getSlot/getSlot.d.ts
87
- type FunctionalComponent<TProps extends UnknownObject = never> = React.FunctionComponent<TProps>;
88
- /**
89
- * @description Checks if a react child (within the children array) matches the provided SlotComponent using multiple matching strategies:
90
- * 1. Matches by slot symbol property
91
- * 2. Matches by component name
92
- */
93
- declare const matchesSlotComponent: (child: React.ReactNode, SlotComponent: FunctionalComponent) => boolean;
94
- /**
95
- * @description Checks if a react child (within the children array) matches any of the provided SlotComponents.
96
- */
97
- declare const matchesAnySlotComponent: (child: React.ReactNode, SlotComponents: FunctionalComponent[]) => boolean;
98
- type SlotOptions = {
99
- /**
100
- * @description The error message to throw when multiple slots are found for a given slot component
101
- */
102
- errorMessage?: string;
103
- /**
104
- * @description When true, an AssertionError will be thrown if multiple slots are found for a given slot component
105
- */
106
- throwOnMultipleSlotMatch?: boolean;
107
- };
108
- /**
109
- * @description Retrieves a single slot element from a collection of React children that matches the provided SlotComponent component.
110
- *
111
- * @throws { AssertionError } when throwOnMultipleSlotMatch is true and multiple slots are found
112
- */
113
- declare const getSingleSlot: (children: React.ReactNode, SlotComponent: FunctionalComponent, options?: SlotOptions) => react8.ReactNode;
114
- type MultipleSlotsOptions = {
115
- /**
116
- * @description The error message to throw when multiple slots are found for a given slot component
117
- * If a string is provided, the same message will be used for all slot components
118
- * If an array is provided, each string in the array will be used as the errorMessage for the corresponding slot component
119
- */
120
- errorMessage?: string | string[];
121
- /**
122
- * @description When true, an AssertionError will be thrown if multiple slots are found for a given slot component
123
- * If a boolean is provided, the same value will be used for all slot components
124
- * If an array is provided, each boolean in the array will be used as the throwOnMultipleSlotMatch value for the corresponding slot component
125
- */
126
- throwOnMultipleSlotMatch?: boolean | boolean[];
127
- };
128
- type GetMultipleSlotsResult<TSlotComponents extends FunctionalComponent[]> = {
129
- regularChildren: React.ReactNode[];
130
- slots: { [Key in keyof TSlotComponents]: ReturnType<TSlotComponents[Key]> };
131
- };
132
- /**
133
- * @description The same as getSingleSlot, but for multiple slot components
134
- */
135
- declare const getMultipleSlots: <const TSlotComponents extends FunctionalComponent[]>(children: React.ReactNode, SlotComponents: TSlotComponents, options?: MultipleSlotsOptions) => Prettify<GetMultipleSlotsResult<TSlotComponents>>;
136
- /**
137
- * @description Returns all children that are not slot elements (i.e., don't match any of the provided slot components)
138
- */
139
- declare const getRegularChildren: (children: React.ReactNode, SlotComponentOrComponents: FunctionalComponent | FunctionalComponent[]) => react8.ReactNode[];
140
- //#endregion
141
- export { FunctionalComponent, GetSlotComponentProps, GetSlotMapResult, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, slotComponentSymbol, withSlotNameAndSymbol };
142
- //# sourceMappingURL=index-BNrCAe9Y.d.ts.map
@@ -1,2 +0,0 @@
1
- import { FunctionalComponent, GetSlotComponentProps, GetSlotMapResult, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, slotComponentSymbol, withSlotNameAndSymbol } from "../../index-BNrCAe9Y.js";
2
- export { FunctionalComponent, GetSlotComponentProps, GetSlotMapResult, createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, slotComponentSymbol, withSlotNameAndSymbol };
@@ -1,4 +0,0 @@
1
- import { createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol } from "../../utils-ChjmDoRe.js";
2
- import { getMultipleSlots, getRegularChildren, getSingleSlot, matchesAnySlotComponent, matchesSlotComponent } from "../../getSlot-Cf5ON6lE.js";
3
-
4
- export { createSlotComponent, getMultipleSlots, getRegularChildren, getSingleSlot, getSlotMap, matchesAnySlotComponent, matchesSlotComponent, slotComponentSymbol, withSlotNameAndSymbol };
@@ -1 +0,0 @@
1
- {"version":3,"file":"show-BabiXbf7.js","names":[],"sources":["../../src/components/common/show/show.tsx","../../src/components/common/show/show-parts.ts"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getMultipleSlots } from \"@/lib/utils/getSlot\";\nimport { assert, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ShowProps<TWhen> = {\n\tchildren: React.ReactNode | ((value: TWhen) => React.ReactNode);\n\tfallback?: React.ReactNode;\n\twhen: false | TWhen | null | undefined;\n};\n\nexport function ShowRoot<TWhen>(props: ShowProps<TWhen>) {\n\tconst { children, fallback = null, when } = props;\n\n\tconst resolvedChildren = isFunction(children) ? children(when as TWhen) : children;\n\n\tconst {\n\t\tregularChildren,\n\t\tslots: [contentSlot, fallBackSlot],\n\t} = getMultipleSlots(resolvedChildren, [ShowContent, ShowFallback], {\n\t\terrorMessage: [\n\t\t\t\"Only one <Show.Content> component is allowed\",\n\t\t\t\"Only one <Show.Fallback> or <Show.OtherWise> component is allowed\",\n\t\t],\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tif (!when) {\n\t\tassert(\n\t\t\t!(fallBackSlot && fallback),\n\t\t\t\"The fallback prop and <Show.Fallback> cannot be used at the same time.\"\n\t\t);\n\n\t\treturn fallBackSlot ?? fallback;\n\t}\n\n\treturn contentSlot ?? regularChildren;\n}\n\nexport function ShowContent({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nShowContent.slotSymbol = Symbol(\"show-content\");\n\nexport function ShowFallback({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nShowFallback.slotSymbol = Symbol(\"show-fallback\");\n","export {\n\tShowContent as Content,\n\tShowFallback as Fallback,\n\tShowFallback as Otherwise,\n\tShowRoot as Root,\n} from \"./show\";\n"],"mappings":";;;;;;AAaA,SAAgB,SAAgB,OAAyB;CACxD,MAAM,EAAE,UAAU,WAAW,MAAM,MAAM,GAAG;CAE5C,MAAM,mBAAmB,WAAW,YAAY,SAAS,QAAiB;CAE1E,MAAM,EACL,iBACA,OAAO,CAAC,aAAa,aAAa,EAClC,GAAG,iBAAiB,kBAAkB,CAAC,aAAa,aAAa,EAAE;EACnE,cAAc,CACb,gDACA,oEACA;EACD,0BAA0B;EAC1B;AAED,KAAI,CAAC,MAAM;AACV,SACC,EAAE,gBAAgB,WAClB;AAGD,SAAO,gBAAgB;CACvB;AAED,QAAO,eAAe;AACtB;AAED,SAAgB,YAAY,EAAE,UAAyC,EAAE;AACxE,QAAO;AACP;AACD,YAAY,aAAa,OAAO;AAEhC,SAAgB,aAAa,EAAE,UAAyC,EAAE;AACzE,QAAO;AACP;AACD,aAAa,aAAa,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"suspense-with-boundary-CEVORL8K.js","names":[],"sources":["../../src/components/common/suspense-with-boundary/suspense-with-boundary.tsx"],"sourcesContent":["import { Suspense } from \"react\";\nimport { ErrorBoundary, type ErrorBoundaryProps } from \"../error-boundary\";\n\nexport type SuspenseWithBoundaryProps = {\n\tchildren: React.ReactNode;\n\terrorFallback?: ErrorBoundaryProps[\"fallback\"];\n\tfallback?: React.ReactNode;\n};\n\nexport function SuspenseWithBoundary(props: SuspenseWithBoundaryProps) {\n\tconst { children, errorFallback, fallback } = props;\n\n\tconst errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };\n\tconst suspenseProps = Boolean(fallback) && { fallback };\n\n\treturn (\n\t\t<ErrorBoundary {...errorBoundaryProps}>\n\t\t\t<Suspense {...suspenseProps}>{children}</Suspense>\n\t\t</ErrorBoundary>\n\t);\n}\n"],"mappings":";;;;;AASA,SAAgB,qBAAqB,OAAkC;CACtE,MAAM,EAAE,UAAU,eAAe,UAAU,GAAG;CAE9C,MAAM,qBAAqB,QAAQ,kBAAkB,EAAE,UAAU,eAAe;CAChF,MAAM,gBAAgB,QAAQ,aAAa,EAAE,UAAU;AAEvD,QACC,oBAAC;EAAc,GAAI;YAClB,oBAAC;GAAS,GAAI;GAAgB;;;AAGhC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"switch-CCMD01Rs.js","names":[],"sources":["../../src/components/common/switch/switch.tsx","../../src/components/common/switch/switch-parts.ts"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getRegularChildren, getSingleSlot } from \"@/lib/utils/getSlot\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ValidSwitchComponentType = React.ReactElement<SwitchMatchProps<unknown>>;\n\ntype SwitchProps = {\n\tchildren: ValidSwitchComponentType | ValidSwitchComponentType[];\n\tvalue?: unknown;\n};\n\nconst defaultValueSymbol = Symbol(\"default-value\");\n\nexport function SwitchRoot(props: SwitchProps) {\n\tconst { children, value = defaultValueSymbol } = props;\n\n\tconst defaultCase = getSingleSlot(children, SwitchDefault, {\n\t\terrorMessage: \"Only one <Switch.Default> component is allowed\",\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tconst childrenCasesArray = getRegularChildren(children, SwitchDefault) as ValidSwitchComponentType[];\n\n\tconst matchedCase = childrenCasesArray.find((child) => {\n\t\t// == If value is defaultValueSymbol, match the cases in order like switch(true)\n\t\tif (value === defaultValueSymbol) {\n\t\t\treturn Boolean(child.props.when);\n\t\t}\n\n\t\t// == Otherwise, match the cases like switch(value)\n\t\treturn child.props.when === value;\n\t});\n\n\treturn matchedCase ?? defaultCase;\n}\n\ntype SwitchMatchProps<TWhen> = {\n\tchildren: React.ReactNode | ((value: TWhen) => React.ReactNode);\n\twhen: false | TWhen | null | undefined;\n};\n\nexport function SwitchMatch<TWhen>(props: SwitchMatchProps<TWhen>) {\n\tconst { children, when } = props;\n\n\tconst resolvedChildren = isFunction(children) ? children(when as TWhen) : children;\n\n\treturn resolvedChildren;\n}\n\nexport function SwitchDefault({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nSwitchDefault.slotSymbol = Symbol(\"switch-default\");\n","export { SwitchDefault as Default, SwitchMatch as Match, SwitchRoot as Root } from \"./switch\";\n"],"mappings":";;;;;;AAcA,MAAM,qBAAqB,OAAO;AAElC,SAAgB,WAAW,OAAoB;CAC9C,MAAM,EAAE,UAAU,QAAQ,oBAAoB,GAAG;CAEjD,MAAM,cAAc,cAAc,UAAU,eAAe;EAC1D,cAAc;EACd,0BAA0B;EAC1B;CAED,MAAM,qBAAqB,mBAAmB,UAAU;CAExD,MAAM,cAAc,mBAAmB,MAAM,UAAU;AAEtD,MAAI,UAAU,mBACb,QAAO,QAAQ,MAAM,MAAM;AAI5B,SAAO,MAAM,MAAM,SAAS;CAC5B;AAED,QAAO,eAAe;AACtB;AAOD,SAAgB,YAAmB,OAAgC;CAClE,MAAM,EAAE,UAAU,MAAM,GAAG;CAE3B,MAAM,mBAAmB,WAAW,YAAY,SAAS,QAAiB;AAE1E,QAAO;AACP;AAED,SAAgB,cAAc,EAAE,UAAyC,EAAE;AAC1E,QAAO;AACP;AACD,cAAc,aAAa,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"teleport-DfuYOzsj.js","names":[],"sources":["../../src/components/common/teleport/teleport.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { type AnyString, isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useEffect, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\n\ntype ValidHtmlTags = keyof HTMLElementTagNameMap;\n\ntype PortalProps = {\n\tchildren: React.ReactNode;\n\tinsertPosition?: InsertPosition;\n\tto: AnyString | HTMLElement | ValidHtmlTags | null;\n};\n\nfunction Teleport(props: PortalProps) {\n\tconst { children, insertPosition, to } = props;\n\n\tconst [portalContainer, setPortalContainer] = useState<HTMLElement | null>(null);\n\n\t/* eslint-disable react-hooks-extra/no-direct-set-state-in-use-effect -- Allow */\n\n\tuseEffect(() => {\n\t\tif (!to) return;\n\n\t\tif (insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tdestination && setPortalContainer(destination);\n\t}, [to, insertPosition]);\n\n\tuseEffect(() => {\n\t\tif (!to) return;\n\n\t\tif (!insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tconst tempWrapper = document.createElement(\"div\");\n\t\ttempWrapper.style.display = \"contents\";\n\n\t\tdestination?.insertAdjacentElement(insertPosition, tempWrapper);\n\n\t\tsetPortalContainer(tempWrapper);\n\n\t\treturn () => {\n\t\t\ttempWrapper.remove();\n\t\t};\n\t}, [to, insertPosition]);\n\n\t/* eslint-enable react-hooks-extra/no-direct-set-state-in-use-effect -- Allow */\n\n\treturn portalContainer && createPortal(children, portalContainer);\n}\n\nexport { Teleport };\n"],"mappings":";;;;;AAgBA,SAAS,SAAS,OAAoB;CACrC,MAAM,EAAE,UAAU,gBAAgB,IAAI,GAAG;CAEzC,MAAM,CAAC,iBAAiB,mBAAmB,GAAG,SAA6B;AAI3E,iBAAgB;AACf,MAAI,CAAC,GAAI;AAET,MAAI,eAAgB;EAEpB,MAAM,cAAc,SAAS,MAAM,SAAS,cAA2B,MAAM;AAE7E,iBAAe,mBAAmB;CAClC,GAAE,CAAC,IAAI,eAAe;AAEvB,iBAAgB;AACf,MAAI,CAAC,GAAI;AAET,MAAI,CAAC,eAAgB;EAErB,MAAM,cAAc,SAAS,MAAM,SAAS,cAA2B,MAAM;EAE7E,MAAM,cAAc,SAAS,cAAc;AAC3C,cAAY,MAAM,UAAU;AAE5B,eAAa,sBAAsB,gBAAgB;AAEnD,qBAAmB;AAEnB,eAAa;AACZ,eAAY;EACZ;CACD,GAAE,CAAC,IAAI,eAAe;AAIvB,QAAO,mBAAmB,aAAa,UAAU;AACjD"}
@@ -1,89 +0,0 @@
1
- import { isFunction } from "@zayne-labs/toolkit-type-helpers";
2
- import { Fragment, isValidElement } from "react";
3
- import { toArray } from "@zayne-labs/toolkit-core";
4
-
5
- //#region src/lib/utils/getSlotMap/getSlotMap.ts
6
- /**
7
- * Symbol used to identify SlotComponent instances
8
- */
9
- const slotComponentSymbol = Symbol("slot-component");
10
- /**
11
- * @description Creates a map of named slots from React children. Returns an object mapping slot names to their children,
12
- * with a default slot for unmatched children.
13
- *
14
- * @example
15
- * ```tsx
16
- * import { type GetSlotComponentProps, SlotComponent } from "@zayne-labs/toolkit-react/utils"
17
- *
18
- * type SlotProps = GetSlotComponentProps<"header" | "footer">;
19
- *
20
- * function Parent({ children }: { children: React.ReactNode }) {
21
- * const slots = getSlotMap<SlotProps>(children);
22
- *
23
- * return (
24
- * <div>
25
- * <header>{slots.header}</header>
26
- * <main>{slots.default}</main>
27
- * <footer>{slots.footer}</footer>
28
- * </div>
29
- * );
30
- * }
31
- * ```
32
- *
33
- * Usage:
34
- * ```tsx
35
- * <Parent>
36
- * <SlotComponent name="header">Header Content</SlotComponent>
37
- * <div>Random stuff</div>
38
- * <SlotComponent name="footer">Footer Content</SlotComponent>
39
- * </Parent>
40
- * ```
41
- */
42
- const getSlotMap = (children) => {
43
- const slots = { default: [] };
44
- const isFragment = isValidElement(children) && children.type === Fragment;
45
- const actualChildren = isFragment ? children.props.children : children;
46
- const childrenArray = toArray(actualChildren);
47
- for (const child of childrenArray) {
48
- if (!isValidElement(child) || !isFunction(child.type)) {
49
- slots.default.push(child);
50
- continue;
51
- }
52
- const childType = child.type;
53
- const isSlotElement = childType.slotSymbol === slotComponentSymbol && Boolean(childType.slotName ?? child.props.name);
54
- if (!isSlotElement) {
55
- slots.default.push(child);
56
- continue;
57
- }
58
- const slotName = childType.slotName ?? child.props.name;
59
- if (slotName === "default") {
60
- slots.default.push(child);
61
- continue;
62
- }
63
- slots[slotName] = child;
64
- }
65
- return slots;
66
- };
67
- /**
68
- * @description Creates a slot component
69
- */
70
- const createSlotComponent = () => {
71
- const SlotComponent = (props) => props.children;
72
- SlotComponent.slotSymbol = slotComponentSymbol;
73
- return SlotComponent;
74
- };
75
- function DefaultSlotComponent(props) {
76
- return props.children;
77
- }
78
- /**
79
- * @description Adds a slot symbol and name to a slot component passed in
80
- */
81
- const withSlotNameAndSymbol = (name, SlotComponent = DefaultSlotComponent) => {
82
- SlotComponent.slotSymbol = slotComponentSymbol;
83
- SlotComponent.slotName = name;
84
- return SlotComponent;
85
- };
86
-
87
- //#endregion
88
- export { createSlotComponent, getSlotMap, slotComponentSymbol, withSlotNameAndSymbol };
89
- //# sourceMappingURL=utils-ChjmDoRe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-ChjmDoRe.js","names":["slots: Record<string, TSlotComponentProps[\"children\"]> & { default: React.ReactNode[] }","ReactFragment"],"sources":["../../src/lib/utils/getSlotMap/getSlotMap.ts"],"sourcesContent":["import { toArray } from \"@zayne-labs/toolkit-core\";\nimport type { InferProps } from \"@zayne-labs/toolkit-react/utils\";\nimport {\n\ttype CallbackFn,\n\ttype EmptyObject,\n\ttype Prettify,\n\ttype UnionToIntersection,\n\ttype UnknownObject,\n\tisFunction,\n} from \"@zayne-labs/toolkit-type-helpers\";\nimport { Fragment as ReactFragment, isValidElement } from \"react\";\n\ntype GetSlotName<TSlotComponentProps extends GetSlotComponentProps> =\n\tstring extends TSlotComponentProps[\"name\"]\n\t\t? never\n\t\t: \"default\" extends TSlotComponentProps[\"name\"]\n\t\t\t? never\n\t\t\t: TSlotComponentProps[\"name\"];\n\ntype GetSpecificSlotsType<TSlotComponentProps extends GetSlotComponentProps> = {\n\t// This conditional before the remapping will prevent an Indexed Record type from showing up if the props are not passed, enhancing type safety\n\t[TName in keyof TSlotComponentProps as GetSlotName<TSlotComponentProps>]: Extract<\n\t\tTSlotComponentProps[\"children\"],\n\t\tReact.ReactNode\n\t>;\n};\n\n/**\n * Maps slot names to their corresponding children types\n */\nexport type GetSlotMapResult<TSlotComponentProps extends GetSlotComponentProps> = UnionToIntersection<\n\tGetSpecificSlotsType<TSlotComponentProps>\n> & { default: React.ReactNode[] };\n\n/**\n * Symbol used to identify SlotComponent instances\n */\nexport const slotComponentSymbol = Symbol(\"slot-component\");\n\n/**\n * @description Creates a map of named slots from React children. Returns an object mapping slot names to their children,\n * with a default slot for unmatched children.\n *\n * @example\n * ```tsx\n * import { type GetSlotComponentProps, SlotComponent } from \"@zayne-labs/toolkit-react/utils\"\n *\n * type SlotProps = GetSlotComponentProps<\"header\" | \"footer\">;\n *\n * function Parent({ children }: { children: React.ReactNode }) {\n * const slots = getSlotMap<SlotProps>(children);\n *\n * return (\n * <div>\n * <header>{slots.header}</header>\n * <main>{slots.default}</main>\n * <footer>{slots.footer}</footer>\n * </div>\n * );\n * }\n * ```\n *\n * Usage:\n * ```tsx\n * <Parent>\n * <SlotComponent name=\"header\">Header Content</SlotComponent>\n * <div>Random stuff</div>\n * <SlotComponent name=\"footer\">Footer Content</SlotComponent>\n * </Parent>\n * ```\n */\nexport const getSlotMap = <TSlotComponentProps extends GetSlotComponentProps>(\n\tchildren: React.ReactNode\n): Prettify<GetSlotMapResult<TSlotComponentProps>> => {\n\tconst slots: Record<string, TSlotComponentProps[\"children\"]> & { default: React.ReactNode[] } = {\n\t\tdefault: [],\n\t};\n\n\tconst isFragment = isValidElement<InferProps<HTMLElement>>(children) && children.type === ReactFragment;\n\n\tconst actualChildren = isFragment ? children.props.children : children;\n\n\tconst childrenArray = toArray<React.ReactNode>(actualChildren);\n\n\tfor (const child of childrenArray) {\n\t\tif (!isValidElement<TSlotComponentProps>(child) || !isFunction(child.type)) {\n\t\t\tslots.default.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst childType = child.type as SlotWithNameAndSymbol;\n\n\t\tconst isSlotElement =\n\t\t\tchildType.slotSymbol === slotComponentSymbol && Boolean(childType.slotName ?? child.props.name);\n\n\t\tif (!isSlotElement) {\n\t\t\tslots.default.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst slotName = childType.slotName ?? child.props.name;\n\n\t\tif (slotName === \"default\") {\n\t\t\tslots.default.push(child);\n\t\t\tcontinue;\n\t\t}\n\n\t\tslots[slotName] = child;\n\t}\n\n\treturn slots as GetSlotMapResult<TSlotComponentProps>;\n};\n\n/**\n * @description Produce props for the SlotComponent\n *\n * @example\n * ```ts\n * // Pattern One (slot or slots have same children type, which is just React.ReactNode by default)\n * type SlotProps = GetSlotComponentProps<\"header\" | \"content\" | \"footer\">;\n *\n * // Pattern Two (some slots can have different children type)\n * type SlotProps = GetSlotComponentProps<\"header\", React.ReactNode> | GetSlotComponentProps<\"header\", (renderProp: RenderProp) => React.ReactNode>;\n * ```\n */\nexport type GetSlotComponentProps<\n\tTName extends string = string,\n\tTChildren extends CallbackFn<never, React.ReactNode> | React.ReactNode =\n\t\t| CallbackFn<never, React.ReactNode>\n\t\t| React.ReactNode,\n> = {\n\tchildren: TChildren;\n\t/**\n\t * Name of the slot where content should be rendered\n\t */\n\tname: TName;\n};\n\n/**\n * @description Creates a slot component\n */\nexport const createSlotComponent = <TSlotComponentProps extends GetSlotComponentProps>() => {\n\tconst SlotComponent = (props: TSlotComponentProps) => props.children as React.ReactNode;\n\n\tSlotComponent.slotSymbol = slotComponentSymbol;\n\n\treturn SlotComponent;\n};\n\ntype SlotWithNameAndSymbol<\n\tTSlotComponentProps extends GetSlotComponentProps = GetSlotComponentProps,\n\tTOtherProps extends UnknownObject = EmptyObject,\n> = {\n\t(props: Pick<TSlotComponentProps, \"children\"> & TOtherProps): React.ReactNode;\n\treadonly slotName?: TSlotComponentProps[\"name\"];\n\treadonly slotSymbol?: symbol;\n};\n\nfunction DefaultSlotComponent(props: Pick<GetSlotComponentProps, \"children\">): React.ReactNode {\n\treturn props.children as React.ReactNode;\n}\n\n/**\n * @description Adds a slot symbol and name to a slot component passed in\n */\nexport const withSlotNameAndSymbol = <\n\tTSlotComponentProps extends GetSlotComponentProps,\n\tTOtherProps extends UnknownObject = EmptyObject,\n>(\n\tname: TSlotComponentProps[\"name\"],\n\tSlotComponent: SlotWithNameAndSymbol<TSlotComponentProps, TOtherProps> = DefaultSlotComponent\n) => {\n\t/* eslint-disable no-param-reassign -- This is necessary */\n\t// @ts-expect-error -- This is necessary for the time being, to prevent type errors and accidental overrides on consumer side\n\tSlotComponent.slotSymbol = slotComponentSymbol;\n\t// @ts-expect-error -- This is necessary for the time being, to prevent type errors and accidental overrides on consumer side\n\tSlotComponent.slotName = name;\n\n\t/* eslint-enable no-param-reassign -- This is necessary */\n\n\treturn SlotComponent;\n};\n"],"mappings":";;;;;;;;AAqCA,MAAa,sBAAsB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkC1C,MAAa,cACZ,aACqD;CACrD,MAAMA,QAA0F,EAC/F,SAAS,EAAE,EACX;CAED,MAAM,aAAa,eAAwC,aAAa,SAAS,SAASC;CAE1F,MAAM,iBAAiB,aAAa,SAAS,MAAM,WAAW;CAE9D,MAAM,gBAAgB,QAAyB;AAE/C,MAAK,MAAM,SAAS,eAAe;AAClC,MAAI,CAAC,eAAoC,UAAU,CAAC,WAAW,MAAM,OAAO;AAC3E,SAAM,QAAQ,KAAK;AACnB;EACA;EAED,MAAM,YAAY,MAAM;EAExB,MAAM,gBACL,UAAU,eAAe,uBAAuB,QAAQ,UAAU,YAAY,MAAM,MAAM;AAE3F,MAAI,CAAC,eAAe;AACnB,SAAM,QAAQ,KAAK;AACnB;EACA;EAED,MAAM,WAAW,UAAU,YAAY,MAAM,MAAM;AAEnD,MAAI,aAAa,WAAW;AAC3B,SAAM,QAAQ,KAAK;AACnB;EACA;AAED,QAAM,YAAY;CAClB;AAED,QAAO;AACP;;;;AA8BD,MAAa,4BAA+E;CAC3F,MAAM,iBAAiB,UAA+B,MAAM;AAE5D,eAAc,aAAa;AAE3B,QAAO;AACP;AAWD,SAAS,qBAAqB,OAAiE;AAC9F,QAAO,MAAM;AACb;;;;AAKD,MAAa,yBAIZ,MACA,gBAAyE,yBACrE;AAGJ,eAAc,aAAa;AAE3B,eAAc,WAAW;AAIzB,QAAO;AACP"}