Skip to content

Commit

Permalink
chore(react): add storybook (#768)
Browse files Browse the repository at this point in the history
Co-authored-by: Segun Adebayo <joseshegs@gmail.com>
  • Loading branch information
TylerAPfledderer and segunadebayo committed Apr 26, 2023
1 parent 52aba16 commit 3dc2063
Show file tree
Hide file tree
Showing 41 changed files with 6,322 additions and 1,755 deletions.
14 changes: 14 additions & 0 deletions packages/react/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { StorybookConfig } from '@storybook/react-vite'
const config: StorybookConfig = {
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
],
framework: {
name: '@storybook/react-vite',
options: {},
},
}
export default config
16 changes: 16 additions & 0 deletions packages/react/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Preview } from '@storybook/react'

const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
layout: 'centered',
},
}

export default preview
15 changes: 13 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"prepack": "clean-package",
"postpack": "clean-package restore",
"typedocs": "ts-node ../../scripts/generate-type-docs.ts",
"storydocs": "ts-node ../../scripts/generate-stories.ts"
"storydocs": "ts-node ../../scripts/generate-stories.ts",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"dependencies": {
"@polymorphic-factory/react": "0.4.1",
Expand Down Expand Up @@ -96,7 +98,16 @@
"typescript": "5.0.4",
"vite": "4.3.3",
"vite-plugin-dts": "2.3.0",
"vitest": "0.30.1"
"vitest": "0.30.1",
"storybook": "^7.0.5",
"@storybook/react": "^7.0.5",
"@storybook/react-vite": "^7.0.5",
"@storybook/addon-links": "^7.0.5",
"@storybook/addon-essentials": "^7.0.5",
"@storybook/blocks": "^7.0.5",
"@storybook/addon-interactions": "^7.0.5",
"@storybook/testing-library": "^0.0.14-next.2",
"prop-types": "^15.8.1"
},
"peerDependencies": {
"react": ">=18.0.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/accordion/accordion.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import type { Meta } from '@storybook/react'
import { useState } from 'react'
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '.'

type AccordionType = typeof Accordion

const meta: Meta<AccordionType> = {
title: 'Accordion',
component: Accordion,
}

export default meta

export const Basic = () => {
const items = ['panel-1', 'panel-2', 'panel-3']
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Meta } from '@storybook/react'
import {
Carousel,
CarouselNextSlideTrigger,
Expand All @@ -8,6 +9,15 @@ import {
} from './'
import './carousel.css'

type CarouselType = typeof Carousel

const meta: Meta<CarouselType> = {
title: 'Carousel',
component: Carousel,
}

export default meta

export const images = [
'https://tinyurl.com/5b6ka8jd',
'https://tinyurl.com/7rmccdn5',
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/carousel/docs/carousel.stories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Basic": "const Basic = () => (\n <Carousel>\n <CarouselPrevSlideTrigger>\n <button>Prev</button>\n </CarouselPrevSlideTrigger>\n <CarouselNextSlideTrigger>\n <button>Next</button>\n </CarouselNextSlideTrigger>\n <CarouselViewport>\n <CarouselSlideGroup>\n {images.map((image, index) => (\n <CarouselSlide key={index} index={index}>\n <img\n src={image}\n alt=\"\"\n style={{ height: '300px', width: '100%', objectFit: 'cover' }}\n />\n </CarouselSlide>\n ))}\n </CarouselSlideGroup>\n </CarouselViewport>\n </Carousel>\n)"
}
6 changes: 3 additions & 3 deletions packages/react/src/checkbox/checkbox.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[data-part='root'] {
[data-scope='checkbox'][data-part='root'] {
display: flex;
flex-direction: row;
cursor: pointer;
gap: 8px;
}

[data-part='control'] {
[data-scope='checkbox'][data-part='control'] {
border: 2px solid;
border-radius: 9999px;
display: flex;
Expand All @@ -15,7 +15,7 @@
height: 16px;
}

[data-part='control'][data-checked] {
[data-scope='checkbox'][data-part='control'][data-checked] {
background: black;
color: white;
}
10 changes: 10 additions & 0 deletions packages/react/src/checkbox/checkbox.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import type { Meta } from '@storybook/react'
import { useState } from 'react'
import { Checkbox, CheckboxControl, CheckboxInput, CheckboxLabel } from '.'
import './checkbox.css'

type CheckboxType = typeof Checkbox

const meta: Meta<CheckboxType> = {
title: 'Checkbox',
component: Checkbox,
}

export default meta

export const Basic = () => (
<Checkbox>
<CheckboxLabel>Checkbox</CheckboxLabel>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/combobox/combobox.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[data-part='option'][data-highlighted] {
[data-scope='combobox'][data-part='option'][data-highlighted] {
background-color: greenyellow;
}

[data-part='content'] {
[data-scope='combobox'][data-part='content'] {
list-style-type: none;
max-width: 240px;
padding: 0;
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/combobox/combobox.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Meta } from '@storybook/react'
import { useState } from 'react'
import { Portal } from '..'
import {
Expand All @@ -14,6 +15,15 @@ import {
} from './'
import './combobox.css'

type ComboboxType = typeof Combobox

const meta: Meta<ComboboxType> = {
title: 'Combobox',
component: Combobox,
}

export default meta

const comboboxData: Pick<ComboboxOptionProps, 'label' | 'value' | 'disabled'>[] = [
{ label: 'ReactJS', value: 'react' },
{ label: 'SolidJS', value: 'solid' },
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/dialog/dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Meta } from '@storybook/react'
import { Portal } from '@zag-js/react'
import { useState } from 'react'
import {
Expand All @@ -11,6 +12,15 @@ import {
DialogTrigger,
} from './'

type DialogType = typeof Dialog

const meta: Meta<DialogType> = {
title: 'Dialog',
component: Dialog,
}

export default meta

export const Basic = () => {
return (
<Dialog>
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/editable/editable.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Meta } from '@storybook/react'
import {
Editable,
EditableArea,
Expand All @@ -10,6 +11,15 @@ import {
EditableSubmitTrigger,
} from './'

type EditableType = typeof Editable

const meta: Meta<EditableType> = {
title: 'Editable',
component: Editable,
}

export default meta

export const Basic = () => (
<Editable placeholder="Placeholder" activationMode="dblclick">
<EditableLabel>Label</EditableLabel>
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/environment/environment.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import type { Meta } from '@storybook/react'
import { useEffect } from 'react'
import Frame from 'react-frame-component'
import { Environment } from './environment'
import { useEnvironmentContext } from './environment-context'

type EnvironmentType = typeof Environment

const meta: Meta<EnvironmentType> = {
title: 'Environment',
component: Environment,
}

export default meta

const PrintEnvironment = () => {
const getRootNode = useEnvironmentContext()
useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/hover-card/hover-card.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[data-part='trigger'] {
[data-scope='hover-card'][data-part='trigger'] {
text-decoration: none;
}

[data-part='content'] {
[data-scope='hover-card'][data-part='content'] {
padding: 0.5rem;
border: 1px solid lightgray;
background: white;
filter: drop-shadow(0px 4px 6px rgba(0, 0, 0, 0.15));
}

[data-part='arrow'] {
[data-scope='hover-card'][data-part='arrow'] {
--arrow-background: white;
--arrow-size: 8px;
}
10 changes: 10 additions & 0 deletions packages/react/src/hover-card/hover-card.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Meta } from '@storybook/react'
import { Portal } from '@zag-js/react'
import { useState } from 'react'
import {
Expand All @@ -10,6 +11,15 @@ import {
} from '.'
import './hover-card.css'

type HoverCardType = typeof HoverCard

const meta: Meta<HoverCardType> = {
title: 'HoverCard',
component: HoverCard,
}

export default meta

export const Basic = () => (
<HoverCard>
<HoverCardTrigger>
Expand Down
12 changes: 6 additions & 6 deletions packages/react/src/menu/menu.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[data-part='content'] {
[data-scope='menu'][data-part='content'] {
margin: 0;
width: 160px;
background-color: white;
Expand All @@ -8,7 +8,7 @@
list-style-type: none;
}

[data-part*='item'] {
[data-scope='menu'][data-part*='item'] {
all: unset;
cursor: pointer;
font-size: 1rem;
Expand All @@ -23,23 +23,23 @@
padding: 0 0.25rem 0 1rem;
}

[data-part*='item'][data-focus] {
[data-scope='menu'][data-part*='item'][data-focus] {
outline: none;
background-color: rebeccapurple;
color: white;
}

[data-part*='item'][data-disabled] {
[data-scope='menu'][data-part*='item'][data-disabled] {
opacity: 0.4;
}

[data-part='separator'] {
[data-scope='menu'][data-part='separator'] {
width: 100%;
border: 0;
border-top: 1px solid rgb(189, 189, 189);
}

[data-part='label'] {
[data-scope='menu'][data-part='label'] {
display: block;
padding-inline: 1rem;
padding-block: 0.5rem;
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/menu/menu.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Meta } from '@storybook/react'
import { Portal } from '@zag-js/react'
import { useState } from 'react'
import {
Expand All @@ -14,6 +15,15 @@ import {
} from '.'
import './menu.css'

type MenuType = typeof Menu

const meta: Meta<MenuType> = {
title: 'Menu',
component: Menu,
}

export default meta

export const Basic = () => (
<Menu>
<MenuTrigger>
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/number-input/number-input.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[data-part='scrubber'] {
[data-scope='number-input'][data-part='scrubber'] {
width: 16px;
height: 16px;
background-color: red;
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/number-input/number-input.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Meta } from '@storybook/react'
import {
NumberInput,
NumberInputControl,
Expand All @@ -9,6 +10,15 @@ import {
} from './'
import './number-input.css'

type NumberInputType = typeof NumberInput

const meta: Meta<NumberInputType> = {
title: 'NumberInput',
component: NumberInput,
}

export default meta

export const Basic = () => (
<NumberInput min={-50} max={50} clampValueOnBlur>
<NumberInputScrubber />
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/pagination/pagination.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[data-part='item'][data-selected] {
[data-scope='pagination'][data-part='item'][data-selected] {
background-color: aqua;
}

[data-part='prev-item'][data-disabled],
[data-part='next-item'][data-disabled] {
[data-scope='pagination'][data-part='prev-item'][data-disabled],
[data-scope='pagination'][data-part='next-item'][data-disabled] {
cursor: not-allowed;
opacity: 0.4;
}
Loading

1 comment on commit 3dc2063

@vercel
Copy link

@vercel vercel bot commented on 3dc2063 Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.