@remotion/design 4.0.451 → 4.0.452

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/dist/Button.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Slot } from '@radix-ui/react-slot';
1
2
  import React from 'react';
2
3
  type CommonProps = {
3
4
  readonly depth?: number;
@@ -6,10 +7,17 @@ type CommonProps = {
6
7
  };
7
8
  type ButtonAsButton = CommonProps & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'href' | 'disabled'> & {
8
9
  readonly href?: undefined;
10
+ readonly asChild?: false;
9
11
  };
10
12
  type ButtonAsAnchor = CommonProps & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'type'> & {
11
13
  readonly href: string;
14
+ readonly asChild?: false;
12
15
  };
13
- export type ButtonProps = ButtonAsButton | ButtonAsAnchor;
16
+ type ButtonAsChild = CommonProps & Omit<React.ComponentPropsWithoutRef<typeof Slot>, 'children' | 'disabled' | 'href'> & {
17
+ readonly asChild: true;
18
+ readonly href?: never;
19
+ readonly children: React.ReactElement;
20
+ };
21
+ export type ButtonProps = ButtonAsButton | ButtonAsAnchor | ButtonAsChild;
14
22
  export declare const Button: React.FC<ButtonProps>;
15
23
  export {};
package/dist/Button.js CHANGED
@@ -1,10 +1,11 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useRef, useState } from 'react';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Slot, Slottable } from '@radix-ui/react-slot';
3
+ import React, { useCallback, useRef, useState } from 'react';
3
4
  import { cn } from './helpers/cn';
4
5
  import { useHoverTransforms } from './helpers/hover-transforms';
5
6
  import { Outer } from './helpers/Outer';
6
7
  import { Spinner } from './Spinner';
7
- export const Button = ({ children, className, disabled, depth, loading, ...rest }) => {
8
+ export const Button = ({ asChild = false, children, className, disabled, depth, loading, ...rest }) => {
8
9
  const [dimensions, setDimensions] = useState(null);
9
10
  const ref = useRef(null);
10
11
  const { isActive, progress } = useHoverTransforms(ref, Boolean(disabled || loading));
@@ -45,14 +46,20 @@ export const Button = ({ children, className, disabled, depth, loading, ...rest
45
46
  });
46
47
  }, []);
47
48
  const isDisabled = disabled || loading;
49
+ const isAnchor = !asChild && 'href' in rest && rest.href !== undefined;
48
50
  const sharedClasses = cn('text-text', 'inline-flex', 'justify-center', 'bg-button-bg', 'items-center', 'font-brand', 'border-solid', 'text-[1em]', 'rounded-lg', 'border-black', 'border-2', 'border-b-4', 'cursor-pointer', 'px-4', 'h-12', 'flex-row', 'items-center', 'relative', 'overflow-hidden', isDisabled && 'cursor-default opacity-50', className);
49
- const innerContent = (_jsxs(_Fragment, { children: [
50
- _jsx("div", { className: cn(loading && 'invisible', 'inline-flex items-center'), children: children }), loading ? (_jsx("div", { className: cn('absolute w-full h-full flex inset-0 items-center justify-center text-inherit bg-inherit'), children: _jsx(Spinner, { size: 20, duration: 1 }) })) : null] }));
51
- const isAnchor = 'href' in rest && rest.href !== undefined;
52
- const content = isAnchor ? (_jsx("a", { ...rest, className: cn('no-underline text-inherit', sharedClasses), "aria-disabled": isDisabled || undefined, tabIndex: isDisabled ? -1 : undefined, onClick: isDisabled
53
- ? (e) => {
54
- e.preventDefault();
55
- }
56
- : rest.onClick, children: innerContent })) : (_jsx("button", { type: "button", disabled: isDisabled, className: sharedClasses, ...rest, children: innerContent }));
51
+ const preventInteraction = useCallback((e) => {
52
+ e.preventDefault();
53
+ e.stopPropagation();
54
+ }, []);
55
+ const spinnerOverlay = loading ? (_jsx("div", { "data-button-spinner": true, className: cn('absolute w-full h-full flex inset-0 items-center justify-center text-inherit bg-inherit'), children: _jsx(Spinner, { size: 20, duration: 1 }) })) : null;
56
+ const slottableChild = asChild
57
+ ? React.cloneElement(children, undefined, _jsx("span", { className: cn(loading && 'invisible', 'inline-flex items-center'), children: children.props
58
+ .children }))
59
+ : null;
60
+ const content = asChild ? (_jsxs(Slot, { ...rest, className: cn('no-underline text-inherit', sharedClasses), "aria-disabled": isDisabled || undefined, tabIndex: isDisabled ? -1 : undefined, onClickCapture: isDisabled ? preventInteraction : undefined, children: [
61
+ _jsx(Slottable, { children: slottableChild }), spinnerOverlay] })) : isAnchor ? (_jsxs("a", { ...rest, className: cn('no-underline text-inherit', sharedClasses), "aria-disabled": isDisabled || undefined, tabIndex: isDisabled ? -1 : undefined, onClickCapture: isDisabled ? preventInteraction : undefined, children: [
62
+ _jsx("div", { className: cn(loading && 'invisible', 'inline-flex items-center'), children: children }), spinnerOverlay] })) : (_jsxs("button", { type: "button", disabled: isDisabled, className: sharedClasses, ...rest, children: [
63
+ _jsx("div", { className: cn(loading && 'invisible', 'inline-flex items-center'), children: children }), spinnerOverlay] }));
57
64
  return (_jsx("div", { ref: ref, className: "contents", onPointerEnter: onPointerEnter, children: dimensions && (isActive || progress > 0) ? (_jsx(Outer, { parentRef: ref, width: dimensions.width, height: dimensions.height, cornerRadius: dimensions.borderRadius, hoverTransform: progress, depthFactor: depth ?? 1, children: content })) : (content) }));
58
65
  };