Skip to content

Commit

Permalink
feat(spinner): add sizes spinner component (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILLIPS71 authored Apr 21, 2024
1 parent 4240d35 commit 1c07d7a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/react/src/components/spinner/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type * as Polymophic from '@/utilities/polymorphic'
import type { SpinnerVariantProps } from '@giantnodes/theme'

import { spinner } from '@giantnodes/theme'
import React from 'react'

const __ELEMENT_TYPE__ = 'svg'

type ComponentOwnProps = {}
type ComponentOwnProps = SpinnerVariantProps

type ComponentProps<T extends React.ElementType> = Polymophic.ComponentPropsWithRef<T, ComponentOwnProps>

Expand All @@ -15,11 +16,11 @@ type ComponentType = <T extends React.ElementType = typeof __ELEMENT_TYPE__>(

const Component: ComponentType = React.forwardRef(
<T extends React.ElementType = typeof __ELEMENT_TYPE__>(props: ComponentProps<T>) => {
const { as, children, className, size, status, variant, ...rest } = props
const { as, children, className, size, ...rest } = props

const Element = as ?? __ELEMENT_TYPE__

const slots = React.useMemo(() => spinner({}), [])
const slots = React.useMemo(() => spinner({ size }), [size])

const component = React.useMemo<React.ComponentPropsWithoutRef<typeof __ELEMENT_TYPE__>>(
() => ({
Expand Down
3 changes: 0 additions & 3 deletions packages/theme/src/components/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ export const button = tv({
},
},
size: {
none: {
button: ['text-xs'],
},
xs: {
button: ['text-xs', 'px-2.5', 'py-1'],
},
Expand Down
25 changes: 23 additions & 2 deletions packages/theme/src/components/spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,32 @@ import { tv } from 'tailwind-variants'

export const spinner = tv({
slots: {
svg: ['animate-spin', 'text-inherit', 'size-4'],
svg: ['animate-spin', 'text-inherit'],
circle: ['opacity-25'],
path: ['opacity-75'],
},
variants: {},
variants: {
size: {
xs: {
svg: ['size-2'],
},
sm: {
svg: ['size-3'],
},
md: {
svg: ['size-4'],
},
lg: {
svg: ['size-5'],
},
xl: {
svg: ['size-6'],
},
},
},
defaultVariants: {
size: 'sm',
},
})

export type SpinnerVariantProps = VariantProps<typeof spinner>

0 comments on commit 1c07d7a

Please sign in to comment.