@zayne-labs/ui-react 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ikedigwe Ebube
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -16,7 +16,7 @@ function AwaitInner(props) {
16
16
  const { asChild, children, promise, render } = props;
17
17
  const result = use(promise);
18
18
  const Component = asChild ? Slot : Fragment;
19
- const componentProps = asChild && { promise, result };
19
+ const slotProps = asChild && { promise, result };
20
20
  let resolvedChildren;
21
21
  switch (true) {
22
22
  case typeof children === "function": {
@@ -32,7 +32,7 @@ function AwaitInner(props) {
32
32
  break;
33
33
  }
34
34
  }
35
- return /* @__PURE__ */ React.createElement(Component, { ...componentProps }, resolvedChildren);
35
+ return /* @__PURE__ */ React.createElement(Component, { ...slotProps }, resolvedChildren);
36
36
  }
37
37
 
38
38
  export { Await };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/common/await/await.tsx"],"names":["ReactFragment"],"mappings":";;;;;;AAkBO,SAAS,MAAc,KAA2B,EAAA;AACxD,EAAA,MAAM,EAAE,aAAe,EAAA,QAAA,EAAU,iBAAiB,uBAAyB,EAAA,GAAG,aAAgB,GAAA,KAAA;AAE9F,EAAA,MAAM,iBACL,GAAA,cAAA,KAAmB,eAAmB,IAAA,cAAA,KAAmB,0BACtD,aACA,GAAAA,QAAA;AAEJ,EAAA,MAAM,YACL,GAAA,cAAA,KAAmB,eAAmB,IAAA,cAAA,KAAmB,0BACtD,QACA,GAAAA,QAAA;AAEJ,EAAA,MAAM,qBAAqB,OAAQ,CAAA,aAAa,CAAK,IAAA,EAAE,UAAU,aAAc,EAAA;AAE/E,EAAA,MAAM,aAAgB,GAAA,OAAA,CAAQ,QAAQ,CAAA,IAAK,EAAE,QAAS,EAAA;AAEtD,EAAA,uBACE,KAAA,CAAA,aAAA,CAAA,iBAAA,EAAA,EAAmB,GAAG,kBAAA,EAAA,kBACrB,KAAA,CAAA,aAAA,CAAA,YAAA,EAAA,EAAc,GAAG,aAAA,EAAA,kBAChB,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAY,GAAG,WAAA,EAAa,CAC9B,CACD,CAAA;AAEF;AAOA,SAAS,WAAmB,KAAgC,EAAA;AAC3D,EAAA,MAAM,EAAE,OAAA,EAAS,QAAU,EAAA,OAAA,EAAS,QAAW,GAAA,KAAA;AAE/C,EAAM,MAAA,MAAA,GAAS,IAAI,OAAO,CAAA;AAE1B,EAAM,MAAA,SAAA,GAAY,UAAU,IAAO,GAAAA,QAAA;AAEnC,EAAA,MAAM,cAAiB,GAAA,OAAA,IAAW,EAAE,OAAA,EAAS,MAAO,EAAA;AAEpD,EAAI,IAAA,gBAAA;AAEJ,EAAA,QAAQ,IAAM;AAAA,IACb,KAAK,OAAO,QAAA,KAAa,UAAY,EAAA;AACpC,MAAA,gBAAA,GAAmB,SAAS,MAAM,CAAA;AAClC,MAAA;AAAA;AACD,IACA,KAAK,OAAO,MAAA,KAAW,UAAY,EAAA;AAClC,MAAA,gBAAA,GAAmB,OAAO,MAAM,CAAA;AAChC,MAAA;AAAA;AACD,IACA,SAAS;AACR,MAAA,gBAAA,GAAmB,QAAY,IAAA,MAAA;AAC/B,MAAA;AAAA;AACD;AAGD,EAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,SAAA,EAAA,EAAW,GAAG,cAAA,EAAA,EAAiB,gBAAiB,CAAA;AACzD","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport type { DiscriminatedRenderProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { Fragment as ReactFragment, Suspense, use } from \"react\";\nimport { ErrorBoundary } from \"../error-boundary\";\nimport { Slot } from \"../slot\";\nimport type { SuspenseWithBoundaryProps } from \"../suspense-with-boundary\";\n\ntype RenderPropFn<TValue> = (result: TValue) => React.ReactNode;\n\ntype AwaitProps<TValue> = AwaitInnerProps<TValue>\n\t& Pick<SuspenseWithBoundaryProps, \"errorFallback\" | \"fallback\"> & {\n\t\tasChild?: boolean;\n\t\twrapperVariant?: \"none\" | \"only-boundary\" | \"only-suspense\" | \"suspense-and-boundary\";\n\t};\n\nexport function Await<TValue>(props: AwaitProps<TValue>) {\n\tconst { errorFallback, fallback, wrapperVariant = \"suspense-and-boundary\", ...restOfProps } = props;\n\n\tconst WithErrorBoundary =\n\t\twrapperVariant === \"only-boundary\" || wrapperVariant === \"suspense-and-boundary\"\n\t\t\t? ErrorBoundary\n\t\t\t: ReactFragment;\n\n\tconst WithSuspense =\n\t\twrapperVariant === \"only-suspense\" || wrapperVariant === \"suspense-and-boundary\"\n\t\t\t? Suspense\n\t\t\t: ReactFragment;\n\n\tconst errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };\n\n\tconst suspenseProps = Boolean(fallback) && { fallback };\n\n\treturn (\n\t\t<WithErrorBoundary {...errorBoundaryProps}>\n\t\t\t<WithSuspense {...suspenseProps}>\n\t\t\t\t<AwaitInner {...restOfProps} />\n\t\t\t</WithSuspense>\n\t\t</WithErrorBoundary>\n\t);\n}\n\nexport type AwaitInnerProps<TValue> = DiscriminatedRenderProps<React.ReactNode | RenderPropFn<TValue>> & {\n\tasChild?: boolean;\n\tpromise: Promise<TValue>;\n};\n\nfunction AwaitInner<TValue>(props: AwaitInnerProps<TValue>) {\n\tconst { asChild, children, promise, render } = props;\n\n\tconst result = use(promise);\n\n\tconst Component = asChild ? Slot : ReactFragment;\n\n\tconst componentProps = asChild && { promise, result };\n\n\tlet resolvedChildren: React.ReactNode;\n\n\tswitch (true) {\n\t\tcase typeof children === \"function\": {\n\t\t\tresolvedChildren = children(result);\n\t\t\tbreak;\n\t\t}\n\t\tcase typeof render === \"function\": {\n\t\t\tresolvedChildren = render(result);\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tresolvedChildren = children ?? render;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn <Component {...componentProps}>{resolvedChildren}</Component>;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/components/common/await/await.tsx"],"names":["ReactFragment"],"mappings":";;;;;;AAmBO,SAAS,MAAc,KAA2B,EAAA;AACxD,EAAA,MAAM,EAAE,aAAe,EAAA,QAAA,EAAU,iBAAiB,uBAAyB,EAAA,GAAG,aAAgB,GAAA,KAAA;AAE9F,EAAA,MAAM,iBACL,GAAA,cAAA,KAAmB,eAAmB,IAAA,cAAA,KAAmB,0BACtD,aACA,GAAAA,QAAA;AAEJ,EAAA,MAAM,YACL,GAAA,cAAA,KAAmB,eAAmB,IAAA,cAAA,KAAmB,0BACtD,QACA,GAAAA,QAAA;AAEJ,EAAA,MAAM,qBAAqB,OAAQ,CAAA,aAAa,CAAK,IAAA,EAAE,UAAU,aAAc,EAAA;AAE/E,EAAA,MAAM,aAAgB,GAAA,OAAA,CAAQ,QAAQ,CAAA,IAAK,EAAE,QAAS,EAAA;AAEtD,EAAA,uBACE,KAAA,CAAA,aAAA,CAAA,iBAAA,EAAA,EAAmB,GAAG,kBAAA,EAAA,kBACrB,KAAA,CAAA,aAAA,CAAA,YAAA,EAAA,EAAc,GAAG,aAAA,EAAA,kBAChB,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAY,GAAG,WAAA,EAAa,CAC9B,CACD,CAAA;AAEF;AAOA,SAAS,WAAmB,KAAgC,EAAA;AAC3D,EAAA,MAAM,EAAE,OAAA,EAAS,QAAU,EAAA,OAAA,EAAS,QAAW,GAAA,KAAA;AAE/C,EAAM,MAAA,MAAA,GAAS,IAAI,OAAO,CAAA;AAE1B,EAAM,MAAA,SAAA,GAAY,UAAU,IAAO,GAAAA,QAAA;AAEnC,EAAA,MAAM,SAAY,GAAA,OAAA,IAAW,EAAE,OAAA,EAAS,MAAO,EAAA;AAE/C,EAAI,IAAA,gBAAA;AAEJ,EAAA,QAAQ,IAAM;AAAA,IACb,KAAK,OAAO,QAAA,KAAa,UAAY,EAAA;AACpC,MAAA,gBAAA,GAAmB,SAAS,MAAM,CAAA;AAClC,MAAA;AAAA;AACD,IACA,KAAK,OAAO,MAAA,KAAW,UAAY,EAAA;AAClC,MAAA,gBAAA,GAAmB,OAAO,MAAM,CAAA;AAChC,MAAA;AAAA;AACD,IACA,SAAS;AACR,MAAA,gBAAA,GAAmB,QAAY,IAAA,MAAA;AAC/B,MAAA;AAAA;AACD;AAGD,EAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,SAAA,EAAA,EAAW,GAAG,SAAA,EAAA,EAAY,gBAAiB,CAAA;AACpD","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport type { DiscriminatedRenderProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { Fragment as ReactFragment, Suspense, use } from \"react\";\nimport { ErrorBoundary } from \"../error-boundary\";\nimport { Slot } from \"../slot\";\nimport type { SuspenseWithBoundaryProps } from \"../suspense-with-boundary\";\n\ntype RenderPropFn<TValue> = (result: TValue) => React.ReactNode;\n\ntype AwaitProps<TValue> = AwaitInnerProps<TValue>\n\t& Pick<SuspenseWithBoundaryProps, \"errorFallback\" | \"fallback\"> & {\n\t\tasChild?: boolean;\n\t\twrapperVariant?: \"none\" | \"only-boundary\" | \"only-suspense\" | \"suspense-and-boundary\";\n\t};\n\n// TODO - Add Support for Slot components\nexport function Await<TValue>(props: AwaitProps<TValue>) {\n\tconst { errorFallback, fallback, wrapperVariant = \"suspense-and-boundary\", ...restOfProps } = props;\n\n\tconst WithErrorBoundary =\n\t\twrapperVariant === \"only-boundary\" || wrapperVariant === \"suspense-and-boundary\"\n\t\t\t? ErrorBoundary\n\t\t\t: ReactFragment;\n\n\tconst WithSuspense =\n\t\twrapperVariant === \"only-suspense\" || wrapperVariant === \"suspense-and-boundary\"\n\t\t\t? Suspense\n\t\t\t: ReactFragment;\n\n\tconst errorBoundaryProps = Boolean(errorFallback) && { fallback: errorFallback };\n\n\tconst suspenseProps = Boolean(fallback) && { fallback };\n\n\treturn (\n\t\t<WithErrorBoundary {...errorBoundaryProps}>\n\t\t\t<WithSuspense {...suspenseProps}>\n\t\t\t\t<AwaitInner {...restOfProps} />\n\t\t\t</WithSuspense>\n\t\t</WithErrorBoundary>\n\t);\n}\n\nexport type AwaitInnerProps<TValue> = DiscriminatedRenderProps<React.ReactNode | RenderPropFn<TValue>> & {\n\tasChild?: boolean;\n\tpromise: Promise<TValue>;\n};\n\nfunction AwaitInner<TValue>(props: AwaitInnerProps<TValue>) {\n\tconst { asChild, children, promise, render } = props;\n\n\tconst result = use(promise);\n\n\tconst Component = asChild ? Slot : ReactFragment;\n\n\tconst slotProps = asChild && { promise, result };\n\n\tlet resolvedChildren: React.ReactNode;\n\n\tswitch (true) {\n\t\tcase typeof children === \"function\": {\n\t\t\tresolvedChildren = children(result);\n\t\t\tbreak;\n\t\t}\n\t\tcase typeof render === \"function\": {\n\t\t\tresolvedChildren = render(result);\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tresolvedChildren = children ?? render;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn <Component {...slotProps}>{resolvedChildren}</Component>;\n}\n"]}
@@ -1,11 +1,11 @@
1
1
  import * as react from 'react';
2
2
 
3
3
  type ShowProps<TWhen> = {
4
- children: react.ReactNode | ((whenValue: TWhen) => react.ReactNode);
4
+ children: react.ReactNode | ((value: TWhen) => react.ReactNode);
5
5
  fallback?: react.ReactNode;
6
6
  when: false | TWhen | null | undefined;
7
7
  };
8
- declare function ShowRoot<TWhen>({ children, fallback, when }: ShowProps<TWhen>): react.ReactNode;
8
+ declare function ShowRoot<TWhen>(props: ShowProps<TWhen>): react.ReactNode;
9
9
  declare function ShowContent({ children }: {
10
10
  children: react.ReactNode;
11
11
  }): react.ReactNode;
@@ -1,36 +1,34 @@
1
1
  import { __export } from '../../chunk-PZ5AY32C.js';
2
2
  import 'react';
3
- import { getSingleSlot, getRegularChildren } from '@zayne-labs/toolkit-react/utils';
4
- import { isFunction, AssertionError } from '@zayne-labs/toolkit-type-helpers';
3
+ import { getMultipleSlots } from '@zayne-labs/toolkit-react/utils';
4
+ import { isFunction, assert } from '@zayne-labs/toolkit-type-helpers';
5
5
 
6
- function ShowRoot({ children, fallback, when }) {
7
- if ((when == null || when === false) && !isFunction(children)) {
8
- const fallBackSlot = getSingleSlot(children, ShowFallback, {
9
- errorMessage: "Only one <Show.Fallback> or <Show.OtherWise> component is allowed",
10
- throwOnMultipleSlotMatch: true
11
- });
12
- if (fallBackSlot && fallback) {
13
- throw new AssertionError(`
14
- The fallback prop and <Show.Fallback>/<Show.OtherWise> cannot be used at the same time.
15
- `);
16
- }
17
- return fallBackSlot ?? fallback;
18
- }
19
- if (when == null || when === false) {
20
- return fallback;
21
- }
6
+ function ShowRoot(props) {
7
+ const { children, fallback, when } = props;
22
8
  const resolvedChildren = isFunction(children) ? children(when) : children;
23
- const contentSlot = getSingleSlot(resolvedChildren, ShowContent, {
24
- errorMessage: "Only one <Show.Content> component is allowed",
9
+ const {
10
+ regularChildren,
11
+ slots: [contentSlot, fallBackSlot]
12
+ } = getMultipleSlots(resolvedChildren, [ShowContent, ShowFallback], {
13
+ errorMessage: [
14
+ "Only one <Show.Content> component is allowed",
15
+ "Only one <Show.Fallback> or <Show.OtherWise> component is allowed"
16
+ ],
25
17
  throwOnMultipleSlotMatch: true
26
18
  });
27
- const regularChildren = getRegularChildren(resolvedChildren, [ShowFallback, ShowContent]);
19
+ if (!when) {
20
+ assert(
21
+ !(fallBackSlot && fallback),
22
+ "The fallback prop and <Show.Fallback> cannot be used at the same time."
23
+ );
24
+ return fallBackSlot ?? fallback;
25
+ }
28
26
  return contentSlot ?? regularChildren;
29
27
  }
30
28
  function ShowContent({ children }) {
31
29
  return children;
32
30
  }
33
- ShowContent.slotSymbol = Symbol("content");
31
+ ShowContent.slotSymbol = Symbol("show-content");
34
32
  function ShowFallback({ children }) {
35
33
  return children;
36
34
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/common/show/show.tsx","../../../../src/components/common/show/show-parts.ts"],"names":[],"mappings":";;;;;AAaO,SAAS,QAAgB,CAAA,EAAE,QAAU,EAAA,QAAA,EAAU,MAA0B,EAAA;AAC/E,EAAA,IAAA,CAAK,QAAQ,IAAQ,IAAA,IAAA,KAAS,UAAU,CAAC,UAAA,CAAW,QAAQ,CAAG,EAAA;AAC9D,IAAM,MAAA,YAAA,GAAe,aAAc,CAAA,QAAA,EAAU,YAAc,EAAA;AAAA,MAC1D,YAAc,EAAA,mEAAA;AAAA,MACd,wBAA0B,EAAA;AAAA,KAC1B,CAAA;AAED,IAAA,IAAI,gBAAgB,QAAU,EAAA;AAC7B,MAAA,MAAM,IAAI,cAAe,CAAA;AAAA;AAAA,EAEzB,CAAA,CAAA;AAAA;AAGD,IAAA,OAAO,YAAgB,IAAA,QAAA;AAAA;AAGxB,EAAI,IAAA,IAAA,IAAQ,IAAQ,IAAA,IAAA,KAAS,KAAO,EAAA;AACnC,IAAO,OAAA,QAAA;AAAA;AAGR,EAAA,MAAM,mBAAmB,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,IAAI,CAAI,GAAA,QAAA;AAEjE,EAAM,MAAA,WAAA,GAAc,aAAc,CAAA,gBAAA,EAAkB,WAAa,EAAA;AAAA,IAChE,YAAc,EAAA,8CAAA;AAAA,IACd,wBAA0B,EAAA;AAAA,GAC1B,CAAA;AAED,EAAA,MAAM,kBAAkB,kBAAmB,CAAA,gBAAA,EAAkB,CAAC,YAAA,EAAc,WAAW,CAAC,CAAA;AAExF,EAAA,OAAO,WAAe,IAAA,eAAA;AACvB;AAEO,SAAS,WAAA,CAAY,EAAE,QAAA,EAA2C,EAAA;AACxE,EAAO,OAAA,QAAA;AACR;AACA,WAAY,CAAA,UAAA,GAAa,OAAO,SAAS,CAAA;AAElC,SAAS,YAAA,CAAa,EAAE,QAAA,EAA2C,EAAA;AACzE,EAAO,OAAA,QAAA;AACR;AACA,YAAa,CAAA,UAAA,GAAa,OAAO,eAAe,CAAA;;;ACrDhD,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,WAAA;AAAA,EAAA,QAAA,EAAA,MAAA,YAAA;AAAA,EAAA,SAAA,EAAA,MAAA,YAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getRegularChildren, getSingleSlot } from \"@zayne-labs/toolkit-react/utils\";\nimport { AssertionError, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ShowProps<TWhen> = {\n\tchildren: React.ReactNode | ((whenValue: TWhen) => React.ReactNode);\n\tfallback?: React.ReactNode;\n\twhen: false | TWhen | null | undefined;\n};\n\nexport function ShowRoot<TWhen>({ children, fallback, when }: ShowProps<TWhen>) {\n\tif ((when == null || when === false) && !isFunction(children)) {\n\t\tconst fallBackSlot = getSingleSlot(children, ShowFallback, {\n\t\t\terrorMessage: \"Only one <Show.Fallback> or <Show.OtherWise> component is allowed\",\n\t\t\tthrowOnMultipleSlotMatch: true,\n\t\t});\n\n\t\tif (fallBackSlot && fallback) {\n\t\t\tthrow new AssertionError(`\n\t\t\tThe fallback prop and <Show.Fallback>/<Show.OtherWise> cannot be used at the same time.\n\t\t`);\n\t\t}\n\n\t\treturn fallBackSlot ?? fallback;\n\t}\n\n\tif (when == null || when === false) {\n\t\treturn fallback;\n\t}\n\n\tconst resolvedChildren = isFunction(children) ? children(when) : children;\n\n\tconst contentSlot = getSingleSlot(resolvedChildren, ShowContent, {\n\t\terrorMessage: \"Only one <Show.Content> component is allowed\",\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tconst regularChildren = getRegularChildren(resolvedChildren, [ShowFallback, ShowContent]);\n\n\treturn contentSlot ?? regularChildren;\n}\n\nexport function ShowContent({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nShowContent.slotSymbol = Symbol(\"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"]}
1
+ {"version":3,"sources":["../../../../src/components/common/show/show.tsx","../../../../src/components/common/show/show-parts.ts"],"names":[],"mappings":";;;;;AAaO,SAAS,SAAgB,KAAyB,EAAA;AACxD,EAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,IAAA,EAAS,GAAA,KAAA;AAErC,EAAA,MAAM,mBAAmB,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,IAAa,CAAI,GAAA,QAAA;AAE1E,EAAM,MAAA;AAAA,IACL,eAAA;AAAA,IACA,KAAA,EAAO,CAAC,WAAA,EAAa,YAAY;AAAA,MAC9B,gBAAiB,CAAA,gBAAA,EAAkB,CAAC,WAAA,EAAa,YAAY,CAAG,EAAA;AAAA,IACnE,YAAc,EAAA;AAAA,MACb,8CAAA;AAAA,MACA;AAAA,KACD;AAAA,IACA,wBAA0B,EAAA;AAAA,GAC1B,CAAA;AAED,EAAA,IAAI,CAAC,IAAM,EAAA;AACV,IAAA,MAAA;AAAA,MACC,EAAE,YAAgB,IAAA,QAAA,CAAA;AAAA,MAClB;AAAA,KACD;AAEA,IAAA,OAAO,YAAgB,IAAA,QAAA;AAAA;AAGxB,EAAA,OAAO,WAAe,IAAA,eAAA;AACvB;AAEO,SAAS,WAAA,CAAY,EAAE,QAAA,EAA2C,EAAA;AACxE,EAAO,OAAA,QAAA;AACR;AACA,WAAY,CAAA,UAAA,GAAa,OAAO,cAAc,CAAA;AAEvC,SAAS,YAAA,CAAa,EAAE,QAAA,EAA2C,EAAA;AACzE,EAAO,OAAA,QAAA;AACR;AACA,YAAa,CAAA,UAAA,GAAa,OAAO,eAAe,CAAA;;;ACjDhD,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,WAAA;AAAA,EAAA,QAAA,EAAA,MAAA,YAAA;AAAA,EAAA,SAAA,EAAA,MAAA,YAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getMultipleSlots } from \"@zayne-labs/toolkit-react/utils\";\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, 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"]}
@@ -6,11 +6,11 @@ type SwitchProps<TCondition> = {
6
6
  condition?: TCondition;
7
7
  };
8
8
  type SwitchMatchProps<TWhen = unknown> = {
9
- children: react.ReactNode | ((whenValue: TWhen) => react.ReactNode);
9
+ children: react.ReactNode | ((value: TWhen) => react.ReactNode);
10
10
  when: false | TWhen | null | undefined;
11
11
  };
12
12
  declare function SwitchRoot<TCondition = true>(props: SwitchProps<TCondition>): react.ReactNode;
13
- declare function SwitchMatch<TWhen>({ children, when }: SwitchMatchProps<TWhen>): react.ReactNode;
13
+ declare function SwitchMatch<TWhen>(props: SwitchMatchProps<TWhen>): react.ReactNode;
14
14
  declare function SwitchDefault({ children }: {
15
15
  children: react.ReactNode;
16
16
  }): react.ReactNode;
@@ -16,8 +16,9 @@ function SwitchRoot(props) {
16
16
  );
17
17
  return matchedCase ?? defaultCase;
18
18
  }
19
- function SwitchMatch({ children, when }) {
20
- if (when == null || when === false) {
19
+ function SwitchMatch(props) {
20
+ const { children, when } = props;
21
+ if (!when) {
21
22
  return null;
22
23
  }
23
24
  return isFunction(children) ? children(when) : children;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/common/switch/switch.tsx","../../../../src/components/common/switch/switch-parts.ts"],"names":[],"mappings":";;;;;AAmBA,IAAM,sBAAA,GAAyB,OAAO,mBAAmB,CAAA;AAElD,SAAS,WAA8B,KAAgC,EAAA;AAC7E,EAAA,MAAM,EAAE,QAAA,EAAU,SAAY,GAAA,sBAAA,EAA2B,GAAA,KAAA;AAEzD,EAAM,MAAA,WAAA,GAAc,aAAc,CAAA,QAAA,EAAU,aAAe,EAAA;AAAA,IAC1D,YAAc,EAAA,gDAAA;AAAA,IACd,wBAA0B,EAAA;AAAA,GAC1B,CAAA;AAED,EAAM,MAAA,kBAAA,GAAqB,kBAAmB,CAAA,QAAA,EAAU,aAAa,CAAA;AAErE,EAAA,MAAM,cAAc,kBAAmB,CAAA,IAAA;AAAA,IAAK,CAAC,UAC5C,SAAc,KAAA,sBAAA,GAAyB,MAAM,KAAM,CAAA,IAAA,GAAO,KAAM,CAAA,KAAA,CAAM,IAAS,KAAA;AAAA,GAChF;AAEA,EAAA,OAAO,WAAe,IAAA,WAAA;AACvB;AAEO,SAAS,WAAmB,CAAA,EAAE,QAAU,EAAA,IAAA,EAAiC,EAAA;AAC/E,EAAI,IAAA,IAAA,IAAQ,IAAQ,IAAA,IAAA,KAAS,KAAO,EAAA;AACnC,IAAO,OAAA,IAAA;AAAA;AAGR,EAAA,OAAO,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,IAAI,CAAI,GAAA,QAAA;AAChD;AAEO,SAAS,aAAA,CAAc,EAAE,QAAA,EAA2C,EAAA;AAC1E,EAAO,OAAA,QAAA;AACR;AACA,aAAc,CAAA,UAAA,GAAa,OAAO,gBAAgB,CAAA;;;ACjDlD,IAAA,oBAAA,GAAA;AAAA,QAAA,CAAA,oBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,aAAA;AAAA,EAAA,KAAA,EAAA,MAAA,WAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getRegularChildren, getSingleSlot } from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ValidSwitchComponentType = React.ReactElement<SwitchMatchProps>;\n\ntype SwitchProps<TCondition> = {\n\tchildren: ValidSwitchComponentType | ValidSwitchComponentType[];\n\tcondition?: TCondition;\n};\n\ntype SwitchMatchProps<TWhen = unknown> = {\n\tchildren: React.ReactNode | ((whenValue: TWhen) => React.ReactNode);\n\twhen: false | TWhen | null | undefined;\n};\n\nconst defaultConditionSymbol = Symbol(\"condition-default\");\n\nexport function SwitchRoot<TCondition = true>(props: SwitchProps<TCondition>) {\n\tconst { children, condition = defaultConditionSymbol } = 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);\n\n\tconst matchedCase = childrenCasesArray.find((child) =>\n\t\tcondition === defaultConditionSymbol ? child.props.when : child.props.when === condition\n\t);\n\n\treturn matchedCase ?? defaultCase;\n}\n\nexport function SwitchMatch<TWhen>({ children, when }: SwitchMatchProps<TWhen>) {\n\tif (when == null || when === false) {\n\t\treturn null;\n\t}\n\n\treturn isFunction(children) ? children(when) : children;\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"]}
1
+ {"version":3,"sources":["../../../../src/components/common/switch/switch.tsx","../../../../src/components/common/switch/switch-parts.ts"],"names":[],"mappings":";;;;;AAmBA,IAAM,sBAAA,GAAyB,OAAO,mBAAmB,CAAA;AAElD,SAAS,WAA8B,KAAgC,EAAA;AAC7E,EAAA,MAAM,EAAE,QAAA,EAAU,SAAY,GAAA,sBAAA,EAA2B,GAAA,KAAA;AAEzD,EAAM,MAAA,WAAA,GAAc,aAAc,CAAA,QAAA,EAAU,aAAe,EAAA;AAAA,IAC1D,YAAc,EAAA,gDAAA;AAAA,IACd,wBAA0B,EAAA;AAAA,GAC1B,CAAA;AAED,EAAM,MAAA,kBAAA,GAAqB,kBAAmB,CAAA,QAAA,EAAU,aAAa,CAAA;AAErE,EAAA,MAAM,cAAc,kBAAmB,CAAA,IAAA;AAAA,IAAK,CAAC,UAC5C,SAAc,KAAA,sBAAA,GAAyB,MAAM,KAAM,CAAA,IAAA,GAAO,KAAM,CAAA,KAAA,CAAM,IAAS,KAAA;AAAA,GAChF;AAEA,EAAA,OAAO,WAAe,IAAA,WAAA;AACvB;AAEO,SAAS,YAAmB,KAAgC,EAAA;AAClE,EAAM,MAAA,EAAE,QAAU,EAAA,IAAA,EAAS,GAAA,KAAA;AAE3B,EAAA,IAAI,CAAC,IAAM,EAAA;AACV,IAAO,OAAA,IAAA;AAAA;AAGR,EAAA,OAAO,UAAW,CAAA,QAAQ,CAAI,GAAA,QAAA,CAAS,IAAI,CAAI,GAAA,QAAA;AAChD;AAEO,SAAS,aAAA,CAAc,EAAE,QAAA,EAA2C,EAAA;AAC1E,EAAO,OAAA,QAAA;AACR;AACA,aAAc,CAAA,UAAA,GAAa,OAAO,gBAAgB,CAAA;;;ACnDlD,IAAA,oBAAA,GAAA;AAAA,QAAA,CAAA,oBAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA,aAAA;AAAA,EAAA,KAAA,EAAA,MAAA,WAAA;AAAA,EAAA,IAAA,EAAA,MAAA;AAAA,CAAA,CAAA","file":"index.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getRegularChildren, getSingleSlot } from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ValidSwitchComponentType = React.ReactElement<SwitchMatchProps>;\n\ntype SwitchProps<TCondition> = {\n\tchildren: ValidSwitchComponentType | ValidSwitchComponentType[];\n\tcondition?: TCondition;\n};\n\ntype SwitchMatchProps<TWhen = unknown> = {\n\tchildren: React.ReactNode | ((value: TWhen) => React.ReactNode);\n\twhen: false | TWhen | null | undefined;\n};\n\nconst defaultConditionSymbol = Symbol(\"condition-default\");\n\nexport function SwitchRoot<TCondition = true>(props: SwitchProps<TCondition>) {\n\tconst { children, condition = defaultConditionSymbol } = 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);\n\n\tconst matchedCase = childrenCasesArray.find((child) =>\n\t\tcondition === defaultConditionSymbol ? child.props.when : child.props.when === condition\n\t);\n\n\treturn matchedCase ?? defaultCase;\n}\n\nexport function SwitchMatch<TWhen>(props: SwitchMatchProps<TWhen>) {\n\tconst { children, when } = props;\n\n\tif (!when) {\n\t\treturn null;\n\t}\n\n\treturn isFunction(children) ? children(when) : children;\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"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/ui-react",
3
3
  "type": "module",
4
- "version": "0.7.3",
4
+ "version": "0.7.4",
5
5
  "description": "A composable UI/UI-utilities components library. ",
6
6
  "author": "Ryan Zayne",
7
7
  "license": "MIT",
@@ -45,21 +45,21 @@
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "@zayne-labs/toolkit-core": "^0.9.3",
49
- "@zayne-labs/toolkit-react": "^0.9.3",
50
- "@zayne-labs/toolkit-type-helpers": "^0.9.3"
48
+ "@zayne-labs/toolkit-core": "^0.9.5",
49
+ "@zayne-labs/toolkit-react": "^0.9.5",
50
+ "@zayne-labs/toolkit-type-helpers": "^0.9.5"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@arethetypeswrong/cli": "0.17.4",
54
54
  "@size-limit/esbuild-why": "11.2.0",
55
55
  "@size-limit/preset-small-lib": "11.2.0",
56
56
  "@total-typescript/ts-reset": "0.6.1",
57
- "@types/react": "^19.1.0",
57
+ "@types/react": "^19.1.2",
58
58
  "@types/react-dom": "^19.1.2",
59
- "@zayne-labs/tsconfig": "0.8.0",
59
+ "@zayne-labs/tsconfig": "0.8.1",
60
60
  "concurrently": "^9.1.2",
61
61
  "cross-env": "^7.0.3",
62
- "publint": "^0.3.10",
62
+ "publint": "^0.3.12",
63
63
  "react": "^19.1.0",
64
64
  "react-dom": "^19.1.0",
65
65
  "react-hook-form": "^7.55.0",