|
1 | 1 | import React, { useState } from 'react'; |
2 | 2 | import { ComponentStory, ComponentMeta } from '@storybook/react'; |
3 | | -import { SingleDatetimePicker, DateInputExample } from '@reusejs/react'; |
| 3 | +import { DateInput } from '@reusejs/react'; |
4 | 4 |
|
5 | 5 | export default { |
6 | | - title: 'Molecules/Datetime/Single', |
7 | | - component: SingleDatetimePicker, |
| 6 | + title: 'Molecules/Datetime', |
| 7 | + component: DateInput, |
8 | 8 | argTypes: {}, |
9 | | -} as ComponentMeta<typeof SingleDatetimePicker>; |
| 9 | +} as ComponentMeta<typeof DateInput>; |
10 | 10 |
|
11 | | -const Template: ComponentStory<typeof SingleDatetimePicker> = (args) => ( |
12 | | - <SingleDatetimePicker {...args} /> |
13 | | -); |
| 11 | +const Template: ComponentStory<typeof DateInput> = (args) => { |
| 12 | + const [dateVal, setDateVal] = useState(new Date()); |
14 | 13 |
|
15 | | -const DateInputTemplate: ComponentStory<typeof DateInputExample> = (args) => ( |
16 | | - <DateInputExample /> |
17 | | -); |
| 14 | + return ( |
| 15 | + <DateInput |
| 16 | + {...args} |
| 17 | + defaultValue={dateVal} |
| 18 | + onChangeCallback={(val: any) => { |
| 19 | + setDateVal(val); |
| 20 | + }} |
| 21 | + /> |
| 22 | + ); |
| 23 | +}; |
18 | 24 |
|
19 | 25 | export const Default = Template.bind({}); |
20 | 26 | Default.args = {}; |
21 | 27 |
|
22 | | -let dateVal = '2022-09-10'; |
| 28 | +export const FullScreen = Template.bind({}); |
| 29 | +FullScreen.args = { |
| 30 | + screenRelative: true, |
| 31 | + inputWidthClass: 'w-11/12', |
| 32 | +}; |
23 | 33 |
|
24 | | -export const DateInputEl = DateInputTemplate.bind({}); |
25 | | -DateInputEl.args = {}; |
| 34 | +export const WithCustomErrorRenderer = Template.bind({}); |
| 35 | +WithCustomErrorRenderer.args = { |
| 36 | + errorText: 'Error Detected!!!', |
| 37 | + errorTextRenderer: (text: string) => { |
| 38 | + return <div className='font-extrabold text-red-600'>{text}</div>; |
| 39 | + }, |
| 40 | +}; |
| 41 | + |
| 42 | +export const HelperText = Template.bind({}); |
| 43 | +HelperText.args = { |
| 44 | + helperText: 'Helper Text goes here', |
| 45 | +}; |
| 46 | + |
| 47 | +export const MinMaxDate = Template.bind({}); |
| 48 | +MinMaxDate.args = { |
| 49 | + maxDate: new Date('2023-08-31'), |
| 50 | + minDate: new Date('2022-07-1'), |
| 51 | +}; |
| 52 | + |
| 53 | +export const RedColoured = Template.bind({}); |
| 54 | +RedColoured.args = { |
| 55 | + dateInputStyleClasses: { |
| 56 | + inputStyles: |
| 57 | + 'flex w-full items-center rounded bg-red-400 px-3 py-2 text-sm outline-none focus:border-blue-400 focus:ring-blue-400 dark:bg-gray-900', |
| 58 | + }, |
| 59 | + calendarBaseClasses: { |
| 60 | + calenderWrapper: |
| 61 | + 'z-50 block w-full overflow-auto rounded-lg bg-red-500 shadow-xl shadow-gray-200 hover:shadow-xl dark:bg-gray-900 dark:shadow-gray-800', |
| 62 | + wrapper: 'rounded-lg bg-red-400 dark:bg-gray-900', |
| 63 | + weekDaysWrapperStyles: |
| 64 | + 'mt-3 grid grid-cols-7 bg-red-400 text-xs leading-6 text-gray-500 dark:bg-gray-900 dark:text-gray-300', |
| 65 | + dateButtonsSelectableStyles: |
| 66 | + 'bg-red-400 hover:bg-blue-100 dark:bg-gray-900 dark:hover:bg-gray-800', |
| 67 | + dateButtonsUnSelectableStyles: 'bg-red-500 dark:bg-gray-800', |
| 68 | + todayButNotSelectedStyles: 'text-green-300 dark:text-amber-900', |
| 69 | + selectedTextStyles: 'text-white dark:text-gray-900', |
| 70 | + timeSectionSelectedAndTodayClasses: 'bg-red-900 dark:bg-blue-200', |
| 71 | + }, |
| 72 | +}; |
| 73 | + |
| 74 | +const Template2: ComponentStory<typeof DateInput> = (args) => { |
| 75 | + const [startDateVal, setStartDateVal] = useState(new Date()); |
| 76 | + const [endDateVal, setEndDateVal] = useState(new Date()); |
| 77 | + |
| 78 | + return ( |
| 79 | + <div className='flex flex-col md:flex-row md:justify-evenly'> |
| 80 | + <DateInput |
| 81 | + {...args} |
| 82 | + label='Start Date' |
| 83 | + defaultValue={startDateVal} |
| 84 | + onChangeCallback={(val: any) => { |
| 85 | + setStartDateVal(val); |
| 86 | + }} |
| 87 | + /> |
| 88 | + <DateInput |
| 89 | + {...args} |
| 90 | + label='End Date' |
| 91 | + defaultValue={endDateVal} |
| 92 | + onChangeCallback={(val: any) => { |
| 93 | + setEndDateVal(val); |
| 94 | + }} |
| 95 | + /> |
| 96 | + </div> |
| 97 | + ); |
| 98 | +}; |
| 99 | + |
| 100 | +export const TwoPickers = Template2.bind({}); |
| 101 | +TwoPickers.args = {}; |
0 commit comments