Skip to content

Commit

Permalink
feat(spinner): update spinner story and add background visible prop
Browse files Browse the repository at this point in the history
  • Loading branch information
andresz1 committed Apr 4, 2023
1 parent 5d9fb02 commit cc89533
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/components/spinner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"build": "vite build"
},
"dependencies": {
"@spark-ui/visuall-hidden": "1"
"@spark-ui/visually-hidden": "0"
}
}
23 changes: 15 additions & 8 deletions packages/components/spinner/src/Spinner.doc.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ArgsTable, Meta, Story, Canvas } from '@storybook/addon-docs'
import { StoryHeading } from '@docs/helpers/StoryHeading'

import { Spinner } from '.'

Expand All @@ -11,48 +10,56 @@ import * as stories from './Spinner.stories'

Spinners provide a visual cue that an action is processing awaiting a course of change or a result.

<StoryHeading label="Install" />
# Install

```sh
npm install @spark-ui/spinner
```

<StoryHeading label="Import" />
# Import

```tsx
import { Spinner } from '@spark-ui/spinner'
```

<StoryHeading label="Props" />
# Props

<ArgsTable of={Spinner} />

<StoryHeading label="Default" />
# Default

<Canvas>
<Story of={stories.Default} />
</Canvas>

<StoryHeading label="Intent" />
# Intent

Use `intent` prop to set the color of the spinner.

<Canvas>
<Story of={stories.Intents} />
</Canvas>

<StoryHeading label="Size" />
# Size

Use `size` prop to set the size of the spinner.

<Canvas>
<Story of={stories.Sizes} />
</Canvas>

<StoryHeading label="Label" />
# Label

Use `label` prop for accessibility, it is important to add a fallback loading text. This text will be visible to screen readers.

<Canvas>
<Story of={stories.Label} />
</Canvas>

# Background

Set `isBackgroundVisible` prop to `true` to display a background under the spinner.

<Canvas>
<Story of={stories.Background} />
</Canvas>
2 changes: 2 additions & 0 deletions packages/components/spinner/src/Spinner.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ export const Sizes: StoryFn = _args => (
)

export const Label: StoryFn = _args => <Spinner label="Loading" />

export const Background: StoryFn = _args => <Spinner isBackgroundVisible />
10 changes: 7 additions & 3 deletions packages/components/spinner/src/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VisuallyHidden } from '@spark-ui/visuall-hidden'
import { VisuallyHidden } from '@spark-ui/visually-hidden'
import { ComponentPropsWithoutRef, forwardRef, PropsWithChildren } from 'react'

import { spinnerVariants, SpinnerVariantsProps } from './Spinner.variants'
Expand All @@ -8,9 +8,13 @@ export interface SpinnerProps extends ComponentPropsWithoutRef<'div'>, SpinnerVa
}

export const Spinner = forwardRef<HTMLDivElement, PropsWithChildren<SpinnerProps>>(
({ className, size, intent, label, ...others }, ref) => {
({ className, size, intent, label, isBackgroundVisible, ...others }, ref) => {
return (
<div ref={ref} className={spinnerVariants({ className, size, intent })} {...others}>
<div
ref={ref}
className={spinnerVariants({ className, size, intent, isBackgroundVisible })}
{...others}
>
{label && <VisuallyHidden>{label}</VisuallyHidden>}
</div>
)
Expand Down
15 changes: 6 additions & 9 deletions packages/components/spinner/src/Spinner.variants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ import { cva, VariantProps } from 'class-variance-authority'
const defaultVariants = {
intent: 'current',
size: 'small',
isBackgroundVisible: false,
} as const

export const spinnerVariants = cva(
[
'inline-block',
'border-solid',
'rounded-full',
'border-md',
'border-b-neutral-container',
'border-l-neutral-container',
'animate-spin',
],
['inline-block', 'border-solid', 'rounded-full', 'border-md', 'animate-spin'],
{
variants: {
size: {
Expand All @@ -31,6 +24,10 @@ export const spinnerVariants = cva(
info: ['border-info'],
neutral: ['border-neutral'],
},
isBackgroundVisible: {
true: ['border-b-neutral-container', 'border-l-neutral-container'],
false: ['border-b-transparent', 'border-l-transparent'],
},
},
defaultVariants,
}
Expand Down

0 comments on commit cc89533

Please sign in to comment.