@carbonid1/design-system 7.0.2 → 7.0.3

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.
@@ -4,6 +4,16 @@ import { cn } from '../helpers/cn/cn';
4
4
  import { mergeStatefulClassName } from '../helpers/mergeStatefulClassName/mergeStatefulClassName';
5
5
  import { Button as ButtonPrimitive } from '@base-ui/react/button';
6
6
  import { Loader2 } from 'lucide-react';
7
+ import { Children, cloneElement, Fragment, isValidElement } from 'react';
7
8
  import { buttonVariants } from './Button.variants';
8
- const Button = ({ className, variant, size, contentSpacing, selected, fullWidth, loading, disabled, children, ...props }) => (_jsxs(ButtonPrimitive, { "data-slot": "button", className: mergeStatefulClassName(cn(buttonVariants({ variant, size, contentSpacing, selected }), fullWidth && 'w-full justify-start'), className), disabled: disabled ?? loading, "aria-busy": loading ?? undefined, ...props, children: [loading && _jsx(Loader2, { className: "size-4 animate-spin", "aria-hidden": "true" }), children] }));
9
+ const wrapLoadingTextNodes = (children) => Children.map(children, child => {
10
+ if (typeof child === 'string' || typeof child === 'number') {
11
+ return _jsx("span", { "data-slot": "button-loading-content", children: child });
12
+ }
13
+ if (isValidElement(child) && child.type === Fragment) {
14
+ return cloneElement(child, undefined, wrapLoadingTextNodes(child.props.children));
15
+ }
16
+ return child;
17
+ });
18
+ const Button = ({ className, variant, size, contentSpacing, selected, fullWidth, loading, disabled, children, ...props }) => (_jsxs(ButtonPrimitive, { "data-slot": "button", className: mergeStatefulClassName(cn(buttonVariants({ variant, size, contentSpacing, selected }), 'relative', fullWidth && 'w-full justify-start', loading && '[&>:not([data-slot=button-loading-indicator])]:opacity-0'), className), disabled: disabled ?? loading, "aria-busy": loading ?? undefined, ...props, children: [loading ? wrapLoadingTextNodes(children) : children, loading && (_jsx(Loader2, { "data-slot": "button-loading-indicator", className: "absolute inset-0 m-auto size-4 animate-spin", "aria-hidden": "true" }))] }));
9
19
  export { Button };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carbonid1/design-system",
3
- "version": "7.0.2",
3
+ "version": "7.0.3",
4
4
  "description": "Shared React UI primitives + design tokens (themes, postcss config)",
5
5
  "repository": {
6
6
  "type": "git",