-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(design system): new spinner component
- Loading branch information
Showing
6 changed files
with
149 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline | |
- **Stack:** NEW Stack element to manage layouts. | ||
- **TransferList:** NEW TransferList component to transfer items between two list, also sortable. | ||
- **Table:** extend Props Interface to accept `bordered` prop to add or remove borders on all sides of the table and cells. Defaults to true. | ||
- **Spinner:** New Spinner component. | ||
|
||
# [1.1.0](https://github.com/IQSS/dataverse-frontend/compare/@iqss/[email protected]...@iqss/[email protected]) (2024-03-12) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/design-system/src/lib/components/spinner/Spinner.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ElementType } from 'react' | ||
import { Spinner as SpinnerBS } from 'react-bootstrap' | ||
|
||
type SpinnerVariant = | ||
| 'primary' | ||
| 'secondary' | ||
| 'success' | ||
| 'danger' | ||
| 'warning' | ||
| 'info' | ||
| 'light' | ||
| 'dark' | ||
type SpinnerAnimations = 'border' | 'grow' | ||
|
||
interface SpinnerProps { | ||
variant?: SpinnerVariant | ||
animation?: SpinnerAnimations | ||
size?: 'sm' | ||
role?: string | ||
as?: ElementType | ||
} | ||
|
||
export const Spinner = ({ | ||
variant = 'primary', | ||
animation, | ||
size, | ||
role = 'status', | ||
as | ||
}: SpinnerProps) => { | ||
return ( | ||
<SpinnerBS variant={variant} animation={animation} size={size} role={role} as={as}> | ||
<span className="visually-hidden">Loading...</span> | ||
</SpinnerBS> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/design-system/src/lib/stories/spinner/Spinner.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { Spinner } from '../../components/spinner/Spinner' | ||
|
||
/** | ||
* ## Description | ||
* The Spinner component is used to indicate a loading state. | ||
*/ | ||
const meta: Meta<typeof Spinner> = { | ||
title: 'Spinner', | ||
component: Spinner, | ||
tags: ['autodocs'], | ||
parameters: { | ||
layout: 'centered' | ||
} | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof Spinner> | ||
|
||
export const Default: Story = { | ||
render: () => <Spinner variant="primary" /> | ||
} | ||
|
||
export const AllBorderVariantsAtAGlance: Story = { | ||
render: () => ( | ||
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}> | ||
<Spinner animation="border" variant="primary" /> | ||
<Spinner animation="border" variant="secondary" /> | ||
<Spinner animation="border" variant="success" /> | ||
<Spinner animation="border" variant="danger" /> | ||
<Spinner animation="border" variant="warning" /> | ||
<Spinner animation="border" variant="info" /> | ||
<Spinner animation="border" variant="light" /> | ||
<Spinner animation="border" variant="dark" /> | ||
</div> | ||
) | ||
} | ||
|
||
export const AllGrowVariantsAtAGlance: Story = { | ||
render: () => ( | ||
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}> | ||
<Spinner animation="grow" variant="primary" /> | ||
<Spinner animation="grow" variant="secondary" /> | ||
<Spinner animation="grow" variant="success" /> | ||
<Spinner animation="grow" variant="danger" /> | ||
<Spinner animation="grow" variant="warning" /> | ||
<Spinner animation="grow" variant="info" /> | ||
<Spinner animation="grow" variant="light" /> | ||
<Spinner animation="grow" variant="dark" /> | ||
</div> | ||
) | ||
} | ||
|
||
export const AllSizesAtAGlance: Story = { | ||
render: () => ( | ||
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}> | ||
<Spinner animation="border" variant="primary" size="sm" /> | ||
<Spinner animation="border" variant="primary" /> | ||
<Spinner animation="grow" variant="primary" size="sm" /> | ||
<Spinner animation="grow" variant="primary" /> | ||
</div> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/design-system/tests/component/spinner/Spinner.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Spinner } from '../../../src/lib/components/spinner/Spinner' | ||
|
||
describe('Spinner', () => { | ||
it('renders correctly', () => { | ||
cy.mount(<Spinner />) | ||
|
||
cy.findAllByRole('status').should('exist') | ||
}) | ||
}) |