Skip to content

Commit

Permalink
Replace CustomDateTimePicker & remove CustomDatePicker using react-da…
Browse files Browse the repository at this point in the history
…tepicker.
  • Loading branch information
samuraikun committed Feb 24, 2024
1 parent 943ca77 commit 696293f
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 143 deletions.
24 changes: 20 additions & 4 deletions app/activity/components/activity-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Input
} from '@chakra-ui/react'
import { PrimaryButton } from '@/components/button'
import { CustomDateTimePicker } from '@/components/customDateTimePicker'
import { CustomDateTimePicker } from '@/components/date'
import { InputForm, TextareaForm } from '@/components/input'
import { getDateObj } from '@/libs/utils'
import { useActivityCreate, useActivityUpdate } from '../hooks'
Expand Down Expand Up @@ -114,23 +114,39 @@ export const ActivityForm = ({
name="timeFrom"
control={control}
render={({ field: { onChange, value } }) => (
<CustomDateTimePicker onChange={onChange} value={value} />
<CustomDateTimePicker
onChange={onChange}
selectedDate={value}
placeholderText="2024-01-01 10:00"
dateFormat="yyyy-MM-dd HH:mm"
/>
)}
/>
{errors.timeFrom && (
<FormErrorMessage>{errors.timeFrom.message}</FormErrorMessage>
)}
</FormControl>

<FormControl mt={{ base: '30px', md: '40px' }}>
<FormControl
isInvalid={!!errors.timeTo}
mt={{ base: '30px', md: '40px' }}
>
<FormLabel>Time To</FormLabel>
<Controller
name="timeTo"
control={control}
render={({ field: { onChange, value } }) => (
<CustomDateTimePicker onChange={onChange} value={value} />
<CustomDateTimePicker
onChange={onChange}
selectedDate={value}
placeholderText="2024-01-01 12:00"
dateFormat="yyyy-MM-dd HH:mm"
/>
)}
/>
{errors.timeTo && (
<FormErrorMessage>{errors.timeTo.message}</FormErrorMessage>
)}
</FormControl>

<FormControl
Expand Down
117 changes: 0 additions & 117 deletions app/components/customDateTimePicker/dateTimePickerWrapper.tsx

This file was deleted.

1 change: 0 additions & 1 deletion app/components/customDateTimePicker/index.ts

This file was deleted.

This file was deleted.

110 changes: 110 additions & 0 deletions app/components/date/custom-date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,113 @@ export const CustomDatePicker = ({
</Box>
)
}

export const CustomDateTimePicker = ({
selectedDate,
onChange,
placeholderText,
dateFormat
}: DatePickerProps) => {
const { colorMode } = useColorMode()

const dateTimePickerStyles = {
'.react-datepicker-wrapper': {
width: '100%'
},
'.react-datepicker-popper': {
right: { base: 0, md: 'unset' }
},
'.react-datepicker ': {
width: '100%',
border: 'none',
boxShadow: '0px 2px 16px 0px rgba(0,0,0,.25);',
fontSize: 'sm'
},
'.react-datepicker__month-container': {
backgroundColor: colorMode === 'dark' ? 'gray.700' : 'white',
width: { base: '100%', md: '400px' }
},
'.react-datepicker__triangle': {
display: 'none'
},
'.react-datepicker__header': {
backgroundColor: colorMode === 'dark' ? 'gray.700' : 'white',
borderBottomColor: colorMode === 'dark' ? 'gray.500' : 'gray.300'
},
'.react-datepicker__current-month': {
color: colorMode === 'dark' ? 'primary.700' : 'primary.800',
paddingY: '8px',
fontSize: 'lg'
},
'.react-datepicker__navigation': {
top: '11px'
},
'.react-datepicker__navigation--previous': {
left: '32px'
},
'.react-datepicker__navigation--next': {
right: '32px'
},
'.react-datepicker__navigation-icon': {
'&::before': {
borderColor: colorMode === 'dark' ? 'gray.500' : 'gray.400'
}
},
'.react-datepicker__month': {
margin: '1rem'
},
'.react-datepicker__day-names': {
paddingY: '4px'
},
'.react-datepicker__day-name': {
width: { base: '2.4rem', md: '2.8rem' },
lineHeight: { base: '2.4rem', md: '2.8rem' },
color: colorMode === 'dark' ? 'gray.300' : 'black'
},
'.react-datepicker__day': {
width: { base: '2.4rem', md: '2.8rem' },
lineHeight: { base: '2.2rem', md: '2.4rem' },
':hover': {
backgroundColor: colorMode === 'dark' ? 'gray.600' : 'gray.100'
},
color: colorMode === 'dark' ? 'gray.300' : 'black'
},
'.react-datepicker__day--selected': {
fontWeight: 'bold',
color: 'white',
backgroundColor: colorMode === 'dark' ? 'primary.700' : 'primary.500'
},
'.react-datepicker__day--keyboard-selected': {
background: 'none'
},
'.react-datepicker__time-container': {
backgroundColor: colorMode === 'dark' ? 'gray.700' : 'white'
},
'.react-datepicker-time__header': {
backgroundColor: colorMode === 'dark' ? 'gray.700' : 'white',
borderBottomColor: colorMode === 'dark' ? 'gray.500' : 'gray.300',
color: colorMode === 'dark' ? 'gray.300' : 'black'
},
'.react-datepicker__time-box': {
backgroundColor: colorMode === 'dark' ? 'gray.700' : 'white',
color: colorMode === 'dark' ? 'gray.300' : 'black'
}
}

return (
<Box sx={dateTimePickerStyles}>
<DatePicker
selected={selectedDate}
placeholderText={placeholderText}
onChange={onChange}
dateFormat={dateFormat}
showTimeSelect
timeFormat="HH:mm"
timeIntervals={15}
timeCaption="time"
popperPlacement="bottom-start"
customInput={<InputForm rightIcon={FiCalendar} />}
/>
</Box>
)
}
2 changes: 1 addition & 1 deletion app/components/date/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { CustomDatePicker } from './custom-date-picker'
export { CustomDatePicker, CustomDateTimePicker } from './custom-date-picker'
16 changes: 14 additions & 2 deletions app/components/date/stories/custom-date-picker.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react'
import { Meta } from '@storybook/react'
import { CustomDatePicker } from '@/components/date'
import { Meta, StoryFn } from '@storybook/react'
import { CustomDatePicker, CustomDateTimePicker } from '@/components/date'

const meta: Meta<typeof CustomDatePicker> = {
title: 'CustomDatePicker',
Expand All @@ -18,3 +18,15 @@ export const Default = () => {
/>
)
}

export const DateTimePicker: StoryFn = () => {
const [selectedDate, setSelectedDate] = useState<Date | null>(new Date())
return (
<CustomDateTimePicker
selectedDate={selectedDate}
onChange={(date) => setSelectedDate(date)}
placeholderText="Select Date"
dateFormat="yyyy/MM/dd HH:mm"
/>
)
}

0 comments on commit 696293f

Please sign in to comment.