forked from phc/orario
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
996 B
JavaScript
34 lines
996 B
JavaScript
import { useRef } from 'preact/hooks'
|
|
import { Icon } from './Icon.jsx'
|
|
|
|
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
|
|
|
|
export const DatePicker = ({ date, setDate }) => {
|
|
const input = useRef()
|
|
|
|
const [year, month, day] = date.split('T')[0].split('-')
|
|
return (
|
|
<div
|
|
class="date-picker"
|
|
onClick={() =>
|
|
isSafari ? input.current.focus() : input.current.showPicker()
|
|
}
|
|
>
|
|
<input
|
|
ref={input}
|
|
type="date"
|
|
value={`${year}-${month}-${day}`}
|
|
onChange={e => setDate(new Date(e.target.value).toISOString())}
|
|
/>
|
|
<div class="date-picker-render">
|
|
<div class="date">
|
|
{day}/{month}/{year}
|
|
</div>
|
|
<div class="calendar">
|
|
<Icon name="calendar_month" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|