|
| 1 | +import React, { forwardRef, ReactNode } from 'react' |
| 2 | +import clsx from 'clsx' |
| 3 | +import { twMerge } from 'tailwind-merge' |
| 4 | + |
| 5 | +import { |
| 6 | + IComponentBaseProps, |
| 7 | + ComponentColor, |
| 8 | + ComponentSize, |
| 9 | +} from '../types' |
| 10 | + |
| 11 | +export type LoadingProps = |
| 12 | + React.HTMLAttributes<HTMLSpanElement> |
| 13 | + & IComponentBaseProps |
| 14 | + & { |
| 15 | + size?: ComponentSize |
| 16 | + color?: ComponentColor |
| 17 | + variant?: 'spinner' | 'dots' | 'ring' | 'ball' | 'bars' | 'infinity' |
| 18 | + } |
| 19 | + |
| 20 | +const Loading = forwardRef<HTMLSpanElement, LoadingProps>( |
| 21 | + ( |
| 22 | + { |
| 23 | + size, |
| 24 | + variant = 'spinner', |
| 25 | + color, |
| 26 | + dataTheme, |
| 27 | + className, |
| 28 | + style, |
| 29 | + ...props |
| 30 | + }, |
| 31 | + ref |
| 32 | + ): JSX.Element => { |
| 33 | + const classes = twMerge( |
| 34 | + 'loading', |
| 35 | + className, |
| 36 | + clsx({ |
| 37 | + 'loading-lg': size === 'lg', |
| 38 | + 'loading-md': size === 'md', |
| 39 | + 'loading-sm': size === 'sm', |
| 40 | + 'loading-xs': size === 'xs', |
| 41 | + 'loading-spinner': variant === 'spinner', |
| 42 | + 'loading-dots': variant === 'dots', |
| 43 | + 'loading-ring': variant === 'ring', |
| 44 | + 'loading-ball': variant === 'ball', |
| 45 | + 'loading-bars': variant === 'bars', |
| 46 | + 'loading-infinity': variant === 'infinity', |
| 47 | + 'text-primary': color === 'primary', |
| 48 | + 'text-secondary': color === 'secondary', |
| 49 | + 'text-accent': color === 'accent', |
| 50 | + 'text-info': color === 'info', |
| 51 | + 'text-success': color === 'success', |
| 52 | + 'text-warning': color === 'warning', |
| 53 | + 'text-error': color === 'error', |
| 54 | + 'text-ghost': color === 'ghost', |
| 55 | + }) |
| 56 | + ) |
| 57 | + |
| 58 | + return ( |
| 59 | + <span |
| 60 | + {...props} |
| 61 | + ref={ref} |
| 62 | + data-theme={dataTheme} |
| 63 | + className={classes} |
| 64 | + style={style} |
| 65 | + /> |
| 66 | + ) |
| 67 | + } |
| 68 | +) |
| 69 | + |
| 70 | +Loading.displayName = 'Loading' |
| 71 | + |
| 72 | +export default Loading |
0 commit comments