Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
feat: RangePicker (#36)
Browse files Browse the repository at this point in the history
* feat: RangePicker

* add unit test
  • Loading branch information
wangkailang authored Jul 31, 2019
1 parent 192e85c commit 6b385fc
Show file tree
Hide file tree
Showing 18 changed files with 671 additions and 24 deletions.
1 change: 1 addition & 0 deletions .storybook/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { configure, addDecorator } from '@storybook/react';
import { withOptions } from '@storybook/addon-options';
import 'bootstrap-sass/assets/stylesheets/_bootstrap.scss';
import './style.scss';

addDecorator (
withOptions ({
Expand Down
3 changes: 3 additions & 0 deletions .storybook/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.sb-show-main {
padding: 25px;
}
56 changes: 56 additions & 0 deletions docs/content/components/range-picker.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: RangePicker 区间时间选择框
date: 2019-07-30
---

选定开始时间和结束时间输出时间区间。

## 使用场景
1. 开始时间小于结束时间。
2. 支持选择日期同时支持选择时间,精确到秒级别。
3. 选择日期默认当天后的日期禁止选择。
4. 支持中文、英文。默认可以根据浏览器的 language 切换。也可以通过 lang 指定。
5. 支持区间(3 小时内、1 天内、1 周内、1 月内、3 月内)选择,选择区间会立即关闭选择面板。

## 代码演示
1. 默认展示
```jsx
() => {
const [ value, setValue ] = React.useState([]);
const handleOk = date => setValue(date);
const [ cValue, setCvalue ] = React.useState([]);
const handleChange = (date, dataStr) => setCvalue(dataStr);
return (
<div>
<div>点击选中区间为:{cValue.join(' - ')}</div>
<div>点击“确定”得到时间:{value.length ? value.map(i => i.format('YYYY-MM-DD HH:mm:ss')).join(' - ') : ''}</div>
<RangePicker onChange={handleChange} onOk={handleOk} />
</div>
)
}
```

2. 设置 `lang``en` 展示为英文
```jsx
() => {
function onChange(date, dateString) {
console.log(date, dateString);
}
return <RangePicker onChange={onChange} lang="en" />;
}
```

3. 设置默认时间区间
```jsx
<RangePicker defaultValue={[moment('2019-02-16 18:01:57'), moment('2019-02-20 18:01:57')]} />
```

4. 设置 `showDuration``false` 隐藏直接选择区间
```jsx
<RangePicker showDuration={false} />
```

## API
```jsx previewOnly
<PropTable of="rangePicker" />
```
2 changes: 2 additions & 0 deletions docs/content/get-started/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Wizard UI 是基于 React 开发的 UI 组件库。
npm install wizard-ui --save
# or
yarn add wizard-ui
# sass dep && loader
yarn add --dev node-sass style-loader css-loader sass-loader
```

在工作场景中,可以在使用 [Create React APP](https://github.com/facebook/create-react-app) 后直接引用:
Expand Down
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lodash": "^4.17.11",
"node-sass": "^4.12.0",
"prop-types": "^15.7.2",
"rc-calendar": "^9.15.4",
"rc-time-picker": "^3.7.1",
"rc-tree": "^2.1.0",
"react": "^16.8.6",
Expand Down
3 changes: 2 additions & 1 deletion docs/src/components/Playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AllIcon from '../Icon';
import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live';
import { Button } from 'react-bootstrap';
import PropTable from '../PropTable';
import moment from 'moment';
import './style.scss';


Expand All @@ -17,7 +18,7 @@ export default ({ isShow, children, previewOnly, noInline }) => {
setShow(!show);
}
return (
<LiveProvider scope={{ ReactDOM, AllIcon, PropTable, ...bs, ...examples, ...libs }} code={children.trim()} noInline={noInline}>
<LiveProvider scope={{ moment, ReactDOM, AllIcon, PropTable, ...bs, ...examples, ...libs }} code={children.trim()} noInline={noInline}>
{ previewOnly ? <LivePreview/> : (
<div className={`Playground ${(show || isShow) ? 'show' : ''}`}>
{isShow ? (
Expand Down
24 changes: 24 additions & 0 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10055,6 +10055,19 @@ rc-animate@2.x, rc-animate@^2.6.0:
raf "^3.4.0"
react-lifecycles-compat "^3.0.4"

rc-calendar@^9.15.4:
version "9.15.4"
resolved "https://registry.yarnpkg.com/rc-calendar/-/rc-calendar-9.15.4.tgz#b8fe1d6b1f9c3963521f4d17c06b43720f052168"
integrity sha512-+3gS00OO6OfNL7R9vI/YOY86oZ1NKRiK74CzVinJ6qm1PhQobr8IfSdli3cdj6vib9i1MKVn7xRSgUpgJ0rKhA==
dependencies:
babel-runtime "6.x"
classnames "2.x"
moment "2.x"
prop-types "^15.5.8"
rc-trigger "^2.2.0"
rc-util "^4.1.1"
react-lifecycles-compat "^3.0.4"

rc-time-picker@^3.7.1:
version "3.7.1"
resolved "https://registry.yarnpkg.com/rc-time-picker/-/rc-time-picker-3.7.1.tgz#35a2c9cbd9758827c1ce57b8817db49472c95cc3"
Expand Down Expand Up @@ -10101,6 +10114,17 @@ rc-util@^4.0.4, rc-util@^4.4.0, rc-util@^4.5.1:
prop-types "^15.5.10"
shallowequal "^0.2.2"

rc-util@^4.1.1:
version "4.8.4"
resolved "https://registry.yarnpkg.com/rc-util/-/rc-util-4.8.4.tgz#e7baa462ed2647bd478745a9aec7353c0944813a"
integrity sha512-1B2h0/pMXfSUBRAgPdoDIKK5XBuzLBuLI9rLwUEW163SPoDvfb9jmg3ymBPtzne2jWgwtdNw4j0vIq/8Yo849A==
dependencies:
add-dom-event-listener "^1.1.0"
babel-runtime "6.x"
prop-types "^15.5.10"
react-lifecycles-compat "^3.0.4"
shallowequal "^0.2.2"

rc@^1.0.1, rc@^1.1.6, rc@^1.2.7:
version "1.2.8"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@types/rc-time-picker": "^3.4.1",
"@types/rc-tree": "^1.11.3",
"bootstrap-sass": "^3.4.1",
"rc-calendar": "^9.15.4",
"rc-time-picker": "^3.7.1",
"rc-tree": "^2.1.0",
"react-bootstrap": "^0.31.1",
Expand Down Expand Up @@ -63,6 +64,7 @@
"@types/react": "16.8.18",
"@types/react-bootstrap": "^0.32.17",
"@types/react-dom": "16.8.4",
"@types/react-test-renderer": "^16.8.3",
"@types/storybook__react": "^4.0.2",
"awesome-typescript-loader": "^5.2.1",
"babel-jest": "^24.8.0",
Expand Down
56 changes: 36 additions & 20 deletions src/components/Icon/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,58 @@ exports[`Loader should render default ui 1`] = `
initialize {
"0": Object {
"attribs": Object {
"aria-hidden": "true",
"class": "undefined icon",
"height": "1em",
"viewBox": "0 0 34 32",
"width": "1em",
"class": "undefined icon icon-os-search-role",
},
"children": Array [
Object {
"attribs": Object {
"d": "M27.337 15.763c-.794-.287-1.65-.443-2.542-.443-4.13 0-7.451 3.34-7.451 7.451 0 3.433 2.318 6.301 5.495 7.148h-18.9c-.854 0-1.547-.692-1.547-1.547V4.465c0-.854.692-1.547 1.547-1.547h21.852c.854 0 1.547.692 1.547 1.547v11.297zm-2.542 1.181c3.2 0 5.827 2.579 5.827 5.779 0 3.248-2.627 5.827-5.827 5.827-3.248 0-5.827-2.579-5.827-5.779s2.579-5.827 5.827-5.827zM5.61 23.679v1.701h8.12v-1.701H5.61zm0-5.413v1.701h11.367v-1.701H5.61zm0-5.413v1.701h14.615v-1.701H5.61zm0-5.413v1.701h16.239V7.44H5.61zm22.003 18.722c.334 0 .621-.287.621-.621 0-.191-.096-.382-.191-.478L26.132 23.2c.239-.382.382-.812.382-1.29 0-1.433-1.146-2.579-2.579-2.579s-2.579 1.146-2.579 2.579a2.568 2.568 0 0 0 2.579 2.579c.478 0 .907-.143 1.29-.382l1.911 1.863c.143.096.287.191.478.191zm-3.677-5.588c.716 0 1.29.573 1.29 1.29s-.573 1.29-1.29 1.29c-.716 0-1.29-.573-1.29-1.29s.573-1.29 1.29-1.29z",
"aria-hidden": "true",
"height": "1em",
"viewBox": "0 0 34 32",
"width": "1em",
},
"children": Array [],
"name": "path",
"children": Array [
Object {
"attribs": Object {
"d": "M27.337 15.763c-.794-.287-1.65-.443-2.542-.443-4.13 0-7.451 3.34-7.451 7.451 0 3.433 2.318 6.301 5.495 7.148h-18.9c-.854 0-1.547-.692-1.547-1.547V4.465c0-.854.692-1.547 1.547-1.547h21.852c.854 0 1.547.692 1.547 1.547v11.297zm-2.542 1.181c3.2 0 5.827 2.579 5.827 5.779 0 3.248-2.627 5.827-5.827 5.827-3.248 0-5.827-2.579-5.827-5.779s2.579-5.827 5.827-5.827zM5.61 23.679v1.701h8.12v-1.701H5.61zm0-5.413v1.701h11.367v-1.701H5.61zm0-5.413v1.701h14.615v-1.701H5.61zm0-5.413v1.701h16.239V7.44H5.61zm22.003 18.722c.334 0 .621-.287.621-.621 0-.191-.096-.382-.191-.478L26.132 23.2c.239-.382.382-.812.382-1.29 0-1.433-1.146-2.579-2.579-2.579s-2.579 1.146-2.579 2.579a2.568 2.568 0 0 0 2.579 2.579c.478 0 .907-.143 1.29-.382l1.911 1.863c.143.096.287.191.478.191zm-3.677-5.588c.716 0 1.29.573 1.29 1.29s-.573 1.29-1.29 1.29c-.716 0-1.29-.573-1.29-1.29s.573-1.29 1.29-1.29z",
},
"children": Array [],
"name": "path",
"namespace": "http://www.w3.org/2000/svg",
"next": null,
"parent": [Circular],
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"d": undefined,
},
"x-attribsPrefix": Object {
"d": undefined,
},
},
],
"name": "svg",
"namespace": "http://www.w3.org/2000/svg",
"next": null,
"parent": [Circular],
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"d": undefined,
"aria-hidden": undefined,
"height": undefined,
"viewBox": undefined,
"width": undefined,
},
"x-attribsPrefix": Object {
"d": undefined,
"aria-hidden": undefined,
"height": undefined,
"viewBox": undefined,
"width": undefined,
},
},
],
"name": "svg",
"namespace": "http://www.w3.org/2000/svg",
"name": "span",
"namespace": "http://www.w3.org/1999/xhtml",
"next": null,
"parent": null,
"prev": null,
Expand All @@ -51,18 +75,10 @@ initialize {
},
"type": "tag",
"x-attribsNamespace": Object {
"aria-hidden": undefined,
"class": undefined,
"height": undefined,
"viewBox": undefined,
"width": undefined,
},
"x-attribsPrefix": Object {
"aria-hidden": undefined,
"class": undefined,
"height": undefined,
"viewBox": undefined,
"width": undefined,
},
},
"_root": [Circular],
Expand Down
8 changes: 6 additions & 2 deletions src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import './style.scss';

const Icon: React.SFC<IconProps> = props => {
const { type, color, ...rest } = props;
const cls = `${color} icon`;
const cls = `${color} icon icon-${type}`;
const name = lodash.upperFirst(lodash.camelCase(type));
const Icon = icons[name];
return <Icon aria-hidden className={cls} {...rest} />;
return (
<span className={cls} {...rest} >
<Icon aria-hidden/>
</span>
);

}

Expand Down
59 changes: 59 additions & 0 deletions src/components/RangePicker/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RangePicker render show primary without props inject 1`] = `
<span
className="RangePicker form-control"
onClick={[Function]}
onKeyDown={[Function]}
onMouseDown={[Function]}
onTouchStart={[Function]}
>
<span
className="glyphicon glyphicon-calendar"
/>
<input
placeholder="开始时间"
readOnly={true}
tabIndex={-1}
value=""
/>
<span>
</span>
<input
placeholder="结束时间"
readOnly={true}
tabIndex={-1}
value=""
/>
</span>
`;

exports[`RangePicker render show with en lang 1`] = `
<span
className="RangePicker form-control"
onClick={[Function]}
onKeyDown={[Function]}
onMouseDown={[Function]}
onTouchStart={[Function]}
>
<span
className="glyphicon glyphicon-calendar"
/>
<input
placeholder="Start time"
readOnly={true}
tabIndex={-1}
value=""
/>
<span>
To
</span>
<input
placeholder="End time"
readOnly={true}
tabIndex={-1}
value=""
/>
</span>
`;
Loading

0 comments on commit 6b385fc

Please sign in to comment.