Skip to content

Commit

Permalink
feat: export useDatePickerHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
tangxuezhi committed Dec 1, 2020
1 parent 7708282 commit 727b823
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
3 changes: 3 additions & 0 deletions components/date-picker/generate-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import PickerTag from '../picker-tag'
import generateSinglePicker from './generate-single-picker'
import generateRangePicker from './generate-range-picker'
import { InputColors, InputVariantTypes, NormalSizes } from '../../utils/prop-types'
import useDatePickerHandle from './../use-date-picker-handle'

export const Components = { button: PickerButton, rangeItem: PickerTag }

Expand Down Expand Up @@ -143,6 +144,7 @@ function generatePicker<DateType>(generateConfig: GenerateConfig<DateType>) {
RangePicker: React.FC<RangePickerProps<DateType>>
TimePicker: typeof TimePicker
QuarterPicker: typeof QuarterPicker
useDatePickerHandle: typeof useDatePickerHandle
}

const MergedDatePicker = DatePicker as MergedDatePicker
Expand All @@ -152,6 +154,7 @@ function generatePicker<DateType>(generateConfig: GenerateConfig<DateType>) {
MergedDatePicker.RangePicker = RangePicker as React.FC<RangePickerProps<DateType>>
MergedDatePicker.TimePicker = TimePicker
MergedDatePicker.QuarterPicker = QuarterPicker
MergedDatePicker.useDatePickerHandle = useDatePickerHandle

return MergedDatePicker
}
Expand Down
5 changes: 4 additions & 1 deletion components/date-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export type RangePickerProps = BaseRangePickerProps<Dayjs>
// It's acceptable now, but the experience is not excellent.
// Think about `<input type="date/time" />`

export const DatePicker = generatePicker<Dayjs>(generateConfig)
const DatePicker = generatePicker<Dayjs>(generateConfig)
DatePicker.useDatePickerHandle = useDatePickerHandle

export { DatePicker }

export default DatePicker

Expand Down
7 changes: 3 additions & 4 deletions pages/en-us/components/date-picker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import dayjs from 'dayjs'
import { useState } from 'react'
import { Layout, Playground, Attributes } from 'lib/components'
import { Link, Text, Code, Spacer, DatePicker, Divider, Button } from 'components'
import { useDatePickerHandle } from 'components/date-picker'
import NextLink from 'next/link'

export const meta = {
Expand Down Expand Up @@ -685,12 +684,12 @@ Select or input a date or time.
<Playground
title="With `UseDatePickerHandle`"
desc="Use `hooks` to capture changes."
scope={{ DatePicker, Spacer, Button, dayjs, Divider, useDatePickerHandle }}
scope={{ DatePicker, Spacer, Button, dayjs, Divider }}
code={`
() => {
const { RangePicker } = DatePicker
const { ref, setValue, getValue, focus, blur } = useDatePickerHandle()
const { ref: ref2, setValue: setValue2, getValue: getValue2, focus: focus2, blur: blur2 } = useDatePickerHandle()
const { ref, setValue, getValue, focus, blur } = DatePicker.useDatePickerHandle()
const { ref: ref2, setValue: setValue2, getValue: getValue2, focus: focus2, blur: blur2 } = DatePicker.useDatePickerHandle()
const setChange = () => {
console.log(ref)
setValue(dayjs())
Expand Down
19 changes: 9 additions & 10 deletions pages/zh-cn/components/date-picker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import dayjs from 'dayjs'
import { useState } from 'react'
import { Layout, Playground, Attributes } from 'lib/components'
import { Link, Text, Code, Spacer, DatePicker, Divider, Button } from 'components'
import { useDatePickerHandle } from 'components/date-picker'
import NextLink from 'next/link'

export const meta = {
Expand Down Expand Up @@ -703,12 +702,12 @@ export const meta = {
<Playground
title="使用 `UseDatePickerHandle`"
desc="使用 `hooks` 捕获日期选择框的变化。"
scope={{ DatePicker, Spacer, Button, dayjs, Divider, useDatePickerHandle }}
scope={{ DatePicker, Spacer, Button, dayjs, Divider }}
code={`
() => {
const { RangePicker } = DatePicker
const { ref, setValue, getValue, focus, blur } = useDatePickerHandle()
const { ref: ref2, setValue: setValue2, getValue: getValue2, focus: focus2, blur: blur2 } = useDatePickerHandle()
const { ref, setValue, getValue, focus, blur } = DatePicker.useDatePickerHandle()
const { ref: ref2, setValue: setValue2, getValue: getValue2, focus: focus2, blur: blur2 } = DatePicker.useDatePickerHandle()
const setChange = () => {
console.log(ref)
setValue(dayjs())
Expand Down Expand Up @@ -892,12 +891,12 @@ export const meta = {

<Attributes.Title>共同的方法</Attributes.Title>

| 名称 | 描述 | 参数 | 返回值 |
| -------------- | -------- | -------------------- | -------------------- |
| **blur()** | 移除焦点 | - | - |
| **focus()** | 获取焦点 | - | - |
| **setValue()** | 设置值 | `dayjs` \| `dayjs[]` \| `null` | - |
| **getValue()** | 获取值 | - | `dayjs` \| `dayjs[]` \| `null` |
| 名称 | 描述 | 参数 | 返回值 |
| -------------- | -------- | ------------------------------ | ------------------------------ |
| **blur()** | 移除焦点 | - | - |
| **focus()** | 获取焦点 | - | - |
| **setValue()** | 设置值 | `dayjs` \| `dayjs[]` \| `null` | - |
| **getValue()** | 获取值 | - | `dayjs` \| `dayjs[]` \| `null` |

<Attributes.Title>useDatePickerHandle</Attributes.Title>

Expand Down

0 comments on commit 727b823

Please sign in to comment.