/** @jsxImportSource react */ import * as React from "react" import { motion } from "framer-motion" import { qwikify$ } from "@builder.io/qwik-react"; import { cn, buttonIcon, buttonVariants, type ButtonVariantProps, type ButtonVariantIconProps } from "@nestri/ui/design"; import {cloneElement,} from "./utils" export interface ButtonRootProps extends React.HTMLAttributes, ButtonVariantProps { class?: string; children?: React.ReactElement; onClick?: () => void | Promise; setIsLoading?: (v: boolean) => void; isLoading: boolean; disabled?: boolean; loadingTime?: number; href?: string; } export interface ButtonIconProps extends React.HTMLAttributes, ButtonVariantIconProps { isLoading: boolean; height?: number; width?: number; class?:string; } export interface ButtonLabelProps extends React.HTMLAttributes, ButtonVariantIconProps { loadingText?: string; class?: string; isLoading: boolean; } export const Icon: React.FC = (({ class:className, children, size = "md", isLoading, type = "leading", height = 20, width = 20, }) => { if (isLoading) { return ( ) // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition } else if (!isLoading && children) { return cloneElement(children as React.ReactElement, buttonIcon({ size, type, className })) } }) export const Label = React.forwardRef(({ class:className, children, loadingText, isLoading, ...props }, forwardedRef) => { return ( {isLoading && loadingText ? loadingText : children} ) }) const Root = React.forwardRef(({ class: className, href, disabled = false, loadingTime, intent = "primary", variant = "solid", size = "md", isLoading, setIsLoading, onClick, children, ...props }, forwardedRef) => { const handleClick = async () => { if (setIsLoading) { if (!isLoading && !disabled) { setIsLoading(true); if (onClick) { await onClick(); } else { // Simulate an async operation await new Promise(resolve => setTimeout(resolve, loadingTime)); } setIsLoading(false); } } }; const Component = href ? 'a' : 'button'; const iconOnly = React.Children.toArray(children).some(child => React.isValidElement(child) && child.type === Icon && child.props.type === 'only' ); const buttonSize = iconOnly ? 'iconOnlyButtonSize' : 'size'; return ( {children} ) }) export type ButtonRoot = typeof Root; export type ButtonIcon = typeof Icon; export type ButtonLabel = typeof Label; Root.displayName = 'Root'; Icon.displayName = "Icon"; Label.displayName = "Label"; export const Button = { Root: qwikify$(Root), Icon: qwikify$(Icon), Label: qwikify$(Label) } //The ✔️ SVG is here: {/* */ }