Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/storybook locale control #38

Merged
merged 2 commits into from May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -30,10 +30,10 @@
"@emotion/react": "^11",
"@emotion/styled": "^11",
"@preconstruct/cli": "^2.1.5",
"@storybook/addon-actions": "^6.3.12",
"@storybook/addon-essentials": "^6.3.12",
"@storybook/addon-links": "^6.3.12",
"@storybook/react": "^6.3.12",
"@storybook/addon-actions": "^6.5.4",
"@storybook/addon-essentials": "^6.5.4",
"@storybook/addon-links": "^6.5.4",
"@storybook/react": "^6.5.4",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@types/jest": "^27.4.0",
Expand Down
19 changes: 16 additions & 3 deletions src/calendar.stories.tsx
Expand Up @@ -14,7 +14,7 @@ import {
useOutsideClick,
VStack,
} from '@chakra-ui/react'
import ptBR from 'date-fns/locale/pt-BR'
import * as locales from 'date-fns/locale'

import { Calendar } from './calendar'
import { CalendarMonth } from './month'
Expand Down Expand Up @@ -55,7 +55,7 @@ export const Basic: ComponentStory<typeof Calendar> = () => {
)
}

export const CustomLocale: ComponentStory<typeof Calendar> = () => {
export const CustomLocale: ComponentStory<typeof Calendar> = ({ locale }) => {
const [dates, setDates] = useState<CalendarValues>({})

const handleSelectDate = (dates: CalendarValues) => setDates(dates)
Expand All @@ -64,7 +64,7 @@ export const CustomLocale: ComponentStory<typeof Calendar> = () => {
<Calendar
value={dates}
onSelectDate={handleSelectDate}
locale={ptBR}
locale={locale}
weekdayFormat="EEEEEE"
>
<CalendarControls>
Expand All @@ -83,6 +83,19 @@ export const CustomLocale: ComponentStory<typeof Calendar> = () => {
)
}

const mapping = Object.fromEntries(Object.entries(locales))

CustomLocale.argTypes = {
locale: {
options: Object.keys(mapping),
mapping,
},
}

CustomLocale.args = {
locale: locales.ptBR,
}

export const DisablePastDates: ComponentStory<typeof Calendar> = () => {
const [dates, setDates] = useState<CalendarValues>({})

Expand Down