Skip to content

Commit

Permalink
feat: add field FRangePicker
Browse files Browse the repository at this point in the history
  • Loading branch information
masb0ymas committed May 28, 2021
1 parent c16e450 commit 283182e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/@nexys/fields/FRangePicker/FRangePicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react'
import { DatePicker } from 'antd'
import { FormikContextType, useField } from 'formik'
import useTitleAndError, {
UseTitleAndErrorProps,
} from '@nexys/fields/useTitleAndError/useTitleAndError'
import { RangePickerProps } from 'antd/lib/date-picker'

const { RangePicker } = DatePicker

export type FRangePickerProps = RangePickerProps &
UseTitleAndErrorProps & {
name: string
/**
* Formik Context
*/
formik?: FormikContextType<any>
}

function FRangePicker(props: FRangePickerProps) {
const [field, , helpers] = useField(props as any)
const [title, error] = useTitleAndError(props)

return (
<React.Fragment>
{title}
<RangePicker
{...field}
{...props}
onBlur={() => {
helpers.setTouched(true)
}}
onChange={(value) => {
helpers.setValue(value)
}}
onOk={(value) => {
helpers.setValue(value)
}}
/>
{error}
</React.Fragment>
)
}

export default FRangePicker

0 comments on commit 283182e

Please sign in to comment.