1- import React , { useState } from 'react' ;
1+ import React from 'react' ;
22import type { Meta , StoryFn } from '@storybook/react' ;
3- import {
4- Button ,
5- CalendarIcon ,
6- DateRangePicker ,
7- Modal ,
8- Popper ,
9- useDisclosure ,
10- type Calendar ,
11- type DatePickerProps ,
12- type DateRange ,
13- type DateRangePickerProps ,
14- } from '@var-meta/ui' ;
15- import dayjs from 'dayjs' ;
3+ import { Button , DateRangePicker , Modal , ModalBody , ModalHeader , type DateRangePickerProps } from '@var-meta/ui' ;
164
175import { View } from '@/components/View' ;
186
197const meta : Meta = {
20- title : 'Components/DatePicker /DateRangePicker' ,
8+ title : 'Components/Calendar /DateRangePicker' ,
219 component : DateRangePicker ,
2210 tags : [ 'autodocs' ] ,
2311 argTypes : { } ,
24- args : {
25- withPreset : true ,
26- } ,
12+ args : { } ,
2713} ;
2814
2915export default meta ;
3016
31- const DefaultTemplate : StoryFn < DateRangePickerProps > = ( { ...args } ) => {
17+ const DefaultTemplate : StoryFn < typeof DateRangePicker > = ( { ...args } ) => {
3218 return (
3319 < View prop = "Default" >
3420 < DateRangePicker { ...args } />
@@ -38,84 +24,30 @@ const DefaultTemplate: StoryFn<DateRangePickerProps> = ({ ...args }) => {
3824
3925export const Default : StoryFn < typeof DateRangePicker > = DefaultTemplate . bind ( { } ) ;
4026
41- const WithPopperTemplate : StoryFn < DatePickerProps > = ( { ...args } ) => {
42- const [ value , setValue ] = useState < DateRange > ( {
43- from : new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ,
44- to : undefined ,
45- } ) ;
46- const [ isOpen , { close, setOpened } ] = useDisclosure ( false ) ;
47-
48- const handleChange = ( date ?: DateRange ) => {
49- setValue ( date ) ;
50- close ( ) ;
51- } ;
27+ const MultipleMonthsTemplate : StoryFn < typeof DateRangePicker > = ( { ...args } ) => {
5228 return (
53- < View prop = "Default" >
54- < Popper
55- onOpenChange = { setOpened }
56- open = { isOpen }
57- trigger = {
58- < Button variant = "link" >
59- < CalendarIcon />
60- { value ?. to
61- ? `${ dayjs ( value . from ) . format ( 'MMM DD, YYYY' ) } - ${ dayjs ( value . to ) . format ( 'MMM DD, YYYY' ) } `
62- : 'Select date' }
63- </ Button >
64- }
65- >
66- < DateRangePicker
67- { ...args }
68- withPreset
69- onCancel = { close }
70- from = { value . from }
71- to = { value . to }
72- onChange = { handleChange }
73- />
74- </ Popper >
29+ < View prop = "MultipleMonths" >
30+ < DateRangePicker calendarProps = { { visibleMonths : 2 } } { ...args } />
7531 </ View >
7632 ) ;
7733} ;
7834
79- export const WithPopper : StoryFn < typeof Calendar > = WithPopperTemplate . bind ( { } ) ;
35+ export const MultipleMonths : StoryFn < typeof DateRangePicker > = MultipleMonthsTemplate . bind ( { } ) ;
8036
81- const WithModalTemplate : StoryFn < DatePickerProps > = ( { ...args } ) => {
82- const [ value , setValue ] = useState < DateRange > ( {
83- from : new Date ( new Date ( ) . setHours ( 0 , 0 , 0 , 0 ) ) ,
84- to : undefined ,
85- } ) ;
86- const [ isOpen , { close, setOpened } ] = useDisclosure ( false ) ;
87-
88- const handleChange = ( date ?: DateRange ) => {
89- setValue ( date ) ;
90- close ( ) ;
91- } ;
37+ const WithModalTemplate : StoryFn < typeof DateRangePicker > = ( { ...args } ) => {
9238 return (
93- < View prop = "Default" >
94- < Modal
95- className = "max-w-fit"
96- onOpenChange = { setOpened }
97- open = { isOpen }
98- fitContent
99- trigger = {
100- < Button variant = "link" >
101- < CalendarIcon />
102- { value ?. to
103- ? `${ dayjs ( value . from ) . format ( 'MMM DD, YYYY' ) } - ${ dayjs ( value . to ) . format ( 'MMM DD, YYYY' ) } `
104- : 'Select date' }
105- </ Button >
106- }
107- >
108- < DateRangePicker
109- { ...args }
110- withPreset
111- onCancel = { close }
112- from = { value . from }
113- to = { value . to }
114- onChange = { handleChange }
39+ < View prop = "WithModal" >
40+ < Modal trigger = { < Button > Show Modal</ Button > } >
41+ < ModalHeader
42+ title = "Blog post published"
43+ description = "This blog post has been published. Team members will be able to edit this post and republish changes."
11544 />
45+ < ModalBody >
46+ < DateRangePicker { ...args } />
47+ </ ModalBody >
11648 </ Modal >
11749 </ View >
11850 ) ;
11951} ;
12052
121- export const WithModal : StoryFn < typeof Calendar > = WithModalTemplate . bind ( { } ) ;
53+ export const WithModal : StoryFn < typeof DateRangePicker > = WithModalTemplate . bind ( { } ) ;
0 commit comments