Git Product home page Git Product logo

picker's Introduction

rc-picker

NPM version build status Codecov npm download bundle size

Live Demo

https://react-component.github.io/picker/

Install

rc-picker

Usage

import Picker from 'rc-picker';
import 'rc-picker/assets/index.css';
import { render } from 'react-dom';

render(<Picker />, mountNode);

API

Picker

Property Type Default Description
prefixCls String rc-picker prefixCls of this component
className String '' additional css class of root dom node
style React.CSSProperties additional style of root dom node
dropdownClassName String '' additional className applied to dropdown
dropdownAlign Object:alignConfig of dom-align value will be merged into placement's dropdownAlign config
popupStyle React.CSSProperties customize popup style
transitionName String '' css class for animation
locale Object import from 'rc-picker/lib/locale/en_US' rc-picker locale
inputReadOnly boolean false set input to read only
allowClear boolean | { clearIcon?: ReactNode } false whether show clear button or customize clear button
autoFocus boolean false whether auto focus
showTime boolean | Object showTime options to provide an additional time selection
picker time | date | week | month | year control which kind of panel should be shown
format String | String[] depends on whether you set timePicker and your locale use to format/parse date(without time) value to/from input. When an array is provided, all values are used for parsing and first value for display
use12Hours boolean false 12 hours display mode
value moment current value like input's value
defaultValue moment defaultValue like input's defaultValue
open boolean false current open state of picker. controlled prop
suffixIcon ReactNode The custom suffix icon
prevIcon ReactNode The custom prev icon
nextIcon ReactNode The custom next icon
superPrevIcon ReactNode The custom super prev icon
superNextIcon ReactNode The custom super next icon
disabled boolean false whether the picker is disabled
placeholder String picker input's placeholder
getPopupContainer function(trigger) to set the container of the floating layer, while the default is to create a div element in body
onChange Function(date: moment, dateString: string) a callback function, can be executed when the selected time is changing
onOpenChange Function(open:boolean) called when open/close picker
onFocus (event:React.FocusEvent<HTMLInputElement>) => void called like input's on focus
onBlur (event:React.FocusEvent<HTMLInputElement>) => void called like input's on blur
onKeyDown (event:React.KeyboardEvent<HTMLInputElement>, preventDefault: () => void) => void input on keydown event
direction String: ltr or rtl Layout direction of picker component, it supports RTL direction too.

PickerPanel

Property Type Default Description
prefixCls String rc-picker prefixCls of this component
className String '' additional css class of root dom
style React.CSSProperties additional style of root dom node
locale Object import from 'rc-picker/lib/locale/en_US' rc-picker locale
value moment current value like input's value
defaultValue moment defaultValue like input's defaultValue
defaultPickerValue moment Set default display picker view date
mode time | datetime | date | week | month | year | decade control which kind of panel
picker time | date | week | month | year control which kind of panel
tabIndex Number 0 view tabIndex
showTime boolean | Object showTime options to provide an additional time selection
showToday boolean false whether to show today button
disabledDate Function(date:moment) => boolean whether to disable select of current date
dateRender Function(currentDate:moment, today:moment) => React.Node custom rendering function for date cells
monthCellRender Function(currentDate:moment, locale:Locale) => React.Node Custom month cell render method
renderExtraFooter (mode) => React.Node extra footer
onSelect Function(date: moment) a callback function, can be executed when the selected time
onPanelChange Function(value: moment, mode) callback when picker panel mode is changed
onMouseDown (event:React.MouseEvent<HTMLInputElement>) => void callback when executed onMouseDown event
direction String: ltr or rtl Layout direction of picker component, it supports RTL direction too.

RangePicker

Property Type Default Description
prefixCls String rc-picker prefixCls of this component
className String '' additional css class of root dom
style React.CSSProperties additional style of root dom node
locale Object import from 'rc-picker/lib/locale/en_US' rc-picker locale
value moment current value like input's value
defaultValue moment defaultValue like input's defaultValue
defaultPickerValue moment Set default display picker view date
separator String '~' set separator between inputs
picker time | date | week | month | year control which kind of panel
placeholder [String, String] placeholder of date input
showTime boolean | Object showTime options to provide an additional time selection
showTime.defaultValue [moment, moment] to set default time of selected date
use12Hours boolean false 12 hours display mode
disabledTime Function(date: moment, type:'start'|'end'):Object
ranges { String | [range: string]: moment[] } | { [range: string]: () => moment[] } preseted ranges for quick selection
format String | String[] depends on whether you set timePicker and your locale use to format/parse date(without time) value to/from input. When an array is provided, all values are used for parsing and first value for display
allowEmpty [boolean, boolean] allow range picker clearing text
selectable [boolean, boolean] whether to selected picker
disabled boolean false whether the range picker is disabled
onChange Function(value:[moment], formatString: [string, string]) a callback function, can be executed when the selected time is changing
onCalendarChange Function(value:[moment], formatString: [string, string], info: { range:'start'|'end' }) a callback function, can be executed when the start time or the end time of the range is changing
direction String: ltr or rtl Layout direction of picker component, it supports RTL direction too.
order boolean true (TimeRangePicker only) false to disable auto order

showTime-options

Property Type Default Description
format String moment format
showHour boolean true whether show hour
showMinute boolean true whether show minute
showSecond boolean true whether show second
use12Hours boolean false 12 hours display mode
hourStep Number 1 interval between hours in picker
minuteStep Number 1 interval between minutes in picker
secondStep Number 1 interval between seconds in picker
hideDisabledOptions boolean false whether hide disabled options
defaultValue moment null default initial value

Development

npm install
npm start

License

rc-picker is released under the MIT license.

picker's People

Contributors

07akioni avatar afc163 avatar aix3 avatar alancutflim avatar alicanso avatar boyyangzai avatar branqa avatar dependabot-preview[bot] avatar dependabot[bot] avatar fireairforce avatar hihuz avatar iamkun avatar kerm1it avatar kiner-tang avatar li-jia-nan avatar linxianxi avatar madccc avatar morenyang avatar nodkz avatar poyiding avatar rayliao avatar stivan8 avatar thommeszip avatar tnyo43 avatar wongest avatar wxh16144 avatar xrkffgg avatar yoyo837 avatar yuiai01 avatar zombiej avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

picker's Issues

clone.weekday is not a function

dayjs <= 1.8.30 没有问题
dayjs > 1.8.30 点击日期选择器直接报错

TypeError: clone.weekday is not a function
    in DateBody (created by DatePanel)
    in div (created by DatePanel)
    in DatePanel (created by PickerPanel)
    in div (created by PickerPanel)
    in PickerPanel (created by InnerPicker)
    in div (created by InnerPicker)
    in div (created by PopupInner)
    in PopupInner (created by Align)
    in Align (created by CSSMotion)
    in CSSMotion (created by ForwardRef)
    in ForwardRef (created by Popup)
    in div (created by Popup)
    in Popup (created by Trigger)
    in Portal (created by Trigger)
    in Trigger (created by PickerTrigger)
    in PickerTrigger (created by InnerPicker)
    in InnerPicker (created by Picker)
    in Picker (created by Context.Consumer)
    in LocaleReceiver (created by Picker)
    in Picker (at Header.tsx:35)
    in header (at Header.tsx:33)
    in div (at Header.tsx:32)

Uncaught TypeError: Cannot read property 'getNow' of undefined

Hi, I am getting this error after I installed the package via yarn add rc-picker.
The input is appearing on the screen when I click on the input I get this error.
any idea why is this happening?

Uncaught TypeError: Cannot read property 'getNow' of undefined
    at postState (PickerPanel.js:124)
    at useControlledState (useMergedState.js:28)
    at PickerPanel (PickerPanel.js:120)
    at renderWithHooks (react-dom.development.js:14985)
    at mountIndeterminateComponent (react-dom.development.js:17811)
    at beginWork (react-dom.development.js:19049)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at beginWork$1 (react-dom.development.js:23964)
    at performUnitOfWork (react-dom.development.js:22776)
    at workLoopSync (react-dom.development.js:22707)
    at renderRootSync (react-dom.development.js:22670)
    at performSyncWorkOnRoot (react-dom.development.js:22293)
    at react-dom.development.js:11327
    at unstable_runWithPriority (scheduler.development.js:646)
    at runWithPriority$1 (react-dom.development.js:11276)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11322)
    at flushSyncCallbackQueue (react-dom.development.js:11309)
    at discreteUpdates$1 (react-dom.development.js:22420)
    at discreteUpdates (react-dom.development.js:3756)
    at dispatchDiscreteEvent (react-dom.development.js:5889)

Allow overriding of the color on cell hover

Hi Team,
On cell hover, I wanted to override the color. However, its specified with !important attribute which is not a good practice. Could you please remove it so that it can be overridden ?

file: index.less line 106

   &:hover {
        background: fade(blue, 30%) !important;
      }

Missing getShortWeekdays and getShortMonths for date-fns

I just switched to date-fns and this is what my antd datepicker looks like:
Screen Shot 2020-08-14 at 10 14 17 AM

This is what it looked like before the switch (was using Dayjs):
Screen Shot 2020-08-14 at 10 14 52 AM

This is how I generate the picker:

import generatePicker from 'antd/es/date-picker/generatePicker';
import dateFnsGenerateConfig from 'rc-picker/lib/generate/dateFns';

export default generatePicker<Date>(dateFnsGenerateConfig);

And here's an example of how I render it:

      <DatePicker.RangePicker
        bordered={false}
        onChange={dates => {
          this.setDates(dates || [null, null]);
        }}
        placeholder={['Start', 'End']}
        value={[minDate, maxDate]}
      />

Looks like the config for date-fns that's generated by rc-picker is missing the methods getShortWeekdays and getShortMonths.

I am using date-fns 2.15.0. I tried both rc-picker 1.15.3 and 2.0.5 but both gave the same (broken) results.

NPM install fails

when I try to installl this from npm, I get this error:
npm ERR! Unexpected end of JSON input while parsing near '...mNz\n8oD5xcC77i86DFzj'

And this affects antdesign too, because it is dependent on this.

GenerateConfig is not undefined

Is there anyone find that, Generateconfig is passed in through props, but there is no API description. As a result, the value of generateconfig is undefined and an error will be reported when using it.

Use according to novice guidelines

`export default function IndexPage() {

return (

  <Picker />

);
}`

there will be a error,because Generateconfig is undefined
`TypeError: Cannot read property 'locale' of undefined
formatValue
./node_modules/rc-picker/es/utils/dateUtil.js:126
123 | var generateConfig = _ref.generateConfig,
124 | locale = _ref.locale,
125 | format = _ref.format;

126 | return typeof format === 'function' ? format(value) : generateConfig.locale.format(locale.locale, value, format);
127 | }
128 | export function parseValue(value, _ref2) {
129 | var generateConfig = _ref2.generateConfig,
View compiled`

Is that mean we should give Generateconfig a default value from generate

Support for pickerValue (similar to defaultPickerValue)

Howdy,

It would be nice if the displayed month could be better controlled to prevent situations like below when using the range picker:

  1. Assume the start and end dates are currently 2021-01-01
  2. Open picker to select start date
  3. Click previous month 12 times
  4. Select 2020-01-01
  5. My code sets defaultPickerValue to [2020-01-01, 2020-01-01]
  6. Panel now "focuses" back to 2021-01-01 for choosing the start date

Now I have click previous month 12 times again to select 2020-01-01 as the end date too

Similar issue was logged in Ant Design: ant-design/ant-design#15360

defaultPickerValue is not working

Reproduction link

https://codesandbox.io/s/rc-picker-playground-870j6?file=/src/App.tsx

Steps to reproduce

Pass defaultPickerValue only to Picker component is not working. (not with defaultValue)

What is expected?

Pass defaultPickerValue only to Picker component is working.

What is actually happening?

Pass the same value to defaultPickerValue and defaultValue in Picker component is working.
But pass only defaultPickerValue would not work.

Environment Info
moment 2.29.1
React 16.13.1
rc-picker 2.3.0
rc-utils 5.4.0

基于antd 4.x 封装组件库时报错 Invalid hook call.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Steps to reproduce

  1. 利用lerna管理前端模块
root/
  ├── packages/
      ├── ui/
          ├── package.json
      ├── fe/
          ├── package.json
// root/packages/ui/package.json
{
  ...
  "name": "my-ui",
  "version": "0.0.0",
  "peerDependencies": {
    "react": "^16.9.0",
    "react-dom": "^16.9.0"
  },
  ...
}
// root/packages/fe/package.json
{
  ...
  "dependencies": {
    "my-ui": "^0.0.0",
    "react": "^16.9.0",
    "react-dom": "^16.9.0"
  },
  ...
}
  1. 运行项目时 报错 Invalid hook call.
  2. 通过 npm ls react 发现 react 被 rc-picker 依赖进来
> root/packages/ui $ npm ls react
@gogoal/[email protected] /Users/caoyujian/workspace/lts-probe/packages/lts-probe-ui
└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected] 

What is expected?

rc-picker 中的 react 依赖从 dependencies 移动至 devDependencies

What is actually happening?

运行项目时 报错 Invalid hook call.

Environment Info
antd 4.5.4
React ^16.9.0
System Mac
Browser Chrome latest

Key events on Checkbox component

The onKeyPress and onKeyDown events do not work in the Checkbox component, apart from the onKeyUp event is not found, and is in the native html component

Users can't reset their panel navigations

Use case:
The user opens the picker popup, clicks on the month (switches mode to month panel), clicks some arrows (year changes), the user panics and wants to get back to original calendar view. The user clicks outside of the picker popup, causing the popup to close. Now the user expects to reopen it again in its original state.

Problem:
The picker opens in the state it was left in. It opens the last used panel, not the default "date" panel. If defaultValue is unset, it opens the last year navigated to as well.
This is a usability regression in ant-design 4. It was working fine in ant3.

Expected:
When a user cancels date picking by closing and reopening a panel, all settings should be as they were before the user did anything. Users are easily confused and expect a complete cancel functionality.

Solution:
Picker should create a new PickerPanel (e.g. by generating a new component's key). Alternatively, PickerPanel could expose a 'reset' method to set panel mode and inner view date back to their default values.
The reset should be a side effect of Picker's 'triggerInnerOpen'. Same for RangePicker.

Add onKeyDown event

Hi,

I would like to know if it is possible to add onKeyDown event to the picker ?

[Question/Bug] Defocus click behaviour change between versions 2.5.2 and >2.5.2

Hi,

There's a behaviour change between vs 2.5.2 and beyond.

Demonstrated in https://codesandbox.io/s/gifted-grass-cejvh?file=/src/App.tsx (which allows version toggle of rc-picker).

With the following picker:
image

In 2.5.2:
Change the date from 2021-05-27 to another valid date via keyboard input (e.g. 2021-05-28)
Click outside of picker
Date stays as 2021-05-28

Beyond 2.5.2:
Change the date from 2021-05-27 to another valid date via keyboard input (e.g. 2021-05-28)
Click outside of picker
Date resets to 2021-05-27

Is this change intentional? 2.5.2 behavior is preferable for our use case.

Can I customize the ok button?

When I use the showTime attr, the ok button will appear in any case. Is this a common usage ? Or is there a prop which can customize the ok button?

generateConfig for date-fns throws error for some locales

The generateConfig methods use dealLocal() function to get date-fns specific locale data for the provided language, but the implementation fails in some cases because rc-picker locales names do not exactly match with date-fns ones.

For example Italian:

  • rc-picker use it_IT as locale name;
  • dealLocal() converts it into itIT;
  • generateConfig.getWeekFirstDay() method tries to load date-fns locale data with an itIT key, but it does not exists and this leads to clone constant to be undefined.

The only solution is to replace the current dealLocal() implementation with a static map of locales names and prevent errors with a default value:

const DEFAULT_LOCALE = 'enUS';

const LOCALES_MAP = {
  'en_US': 'enUS',
  'it_IT': 'it',
  'es_ES': 'es',

  // and so on...
}

const dealLocal = (str: string): string => LOCALES_MAP[str] || DEFAULT_LOCALE;

Dayjs is not peer dependency anymore, breaks registration of plugins in client app that has also the dependency

Hi,

We have a design system library we use to support our applications. This library uses ant which uses rc-picker. We re-generate the pickers using ant, with dayjs instead of moment. In this library, we mark dayjs as a peer dependency. We also install it in our main applications where we register multiple plugins on the singleton dayjs instance. This has been made possible through #214.

However, since #270 our workflow has been broken. Since dayjs is included as a dependency here, the build of our design system library causes a dayjs singleton to be created, as does our main app. Therefore we have two singletons, and the plugins are only registered on one of them.

Input customization

Add prop to customize input fields.

Example

<Picker inputRender={field => <div>{field}</div>}  />

Case example: Add mask

Uncaught TypeError: date.localeData is not a function

After upgrading antd from 4.4 to 4.5 which upgrades rc-picker to 1.11, this error shows up whenever I open the RangePicker panel.

It's thrown by getShortMonths and getWeekFirstDay, and even a zero configuration <RangePicker />(no props) throws such error.

I'm using moment included in antd and don't use any other date libraries. There's also no configs related to moment in webpack or babel.
I'm using "antd-dayjs-webpack-plugin": "0.0.8".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.