diff --git a/packages/core/lib/components/Spinner.tsx b/packages/core/lib/components/Spinner.tsx new file mode 100644 index 0000000..d47704e --- /dev/null +++ b/packages/core/lib/components/Spinner.tsx @@ -0,0 +1,69 @@ +import { Color, getTextColorClassname } from '../colors/color.type'; + +export type SpinnerProps = { + size?: 'x-small' | 'small' | 'medium' | 'large' | 'x-large'; + color?: Color; + className?: string; +}; + +export const Spinner = ({ + size = 'medium', + color, + className = '', +}: SpinnerProps) => { + const sizeStyles: { style: string; fontSize: 'l' | 'm' | 's' | 'xs' } = { + 'x-small': { + style: 'w-4 h-4', + fontSize: 's' as const, + }, + small: { + style: 'w-5 h-5', + fontSize: 'm' as const, + }, + medium: { + style: 'w-6 h-6', + fontSize: 'm' as const, + }, + large: { + style: 'w-7 h-7', + fontSize: 'l' as const, + }, + 'x-large': { + style: 'w-8 h-8', + fontSize: 'l' as const, + }, + }[size]; + + const colorStyles = color ? getTextColorClassname(color) : ''; + + const spinnerStyles = ` + ${sizeStyles.style} + ${colorStyles} + ${className} + `; + + return ( +
+ ); +}; diff --git a/packages/core/lib/index.ts b/packages/core/lib/index.ts index ec1ea34..0186fe0 100644 --- a/packages/core/lib/index.ts +++ b/packages/core/lib/index.ts @@ -11,6 +11,7 @@ import { colors } from './colors/color'; import { Button } from './components/Button'; import { LinkButton } from './components/LinkButton'; import { Tag } from './components/Tag'; +import { Spinner } from './components/Spinner'; export { Display, Heading, Title, Body, Detail, Label, Link, colors }; -export { Button, LinkButton, Tag }; +export { Button, LinkButton, Tag, Spinner }; diff --git a/stories/core/Spinner.stories.ts b/stories/core/Spinner.stories.ts new file mode 100644 index 0000000..7bd0184 --- /dev/null +++ b/stories/core/Spinner.stories.ts @@ -0,0 +1,71 @@ +import type { Meta, StoryObj } from '@storybook/react'; +import { fn } from '@storybook/test'; +import { Spinner } from '../../packages/core/lib'; + +const meta = { + title: 'Components/Spinner', + component: Spinner, + parameters: { + layout: 'centered', + }, + tags: ['autodocs'], + argTypes: { + size: { + control: { + type: 'select', + options: ['x-small', 'small', 'medium', 'large', 'x-large'], + }, + }, + }, +} satisfies Meta