Skip to content

Commit

Permalink
add suffix icon interface to time-picker
Browse files Browse the repository at this point in the history
  • Loading branch information
HeskeyBaozi authored and afc163 committed Sep 21, 2018
1 parent 844a5a9 commit a1074a6
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 deletions.
35 changes: 35 additions & 0 deletions components/time-picker/__tests__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,41 @@ exports[`renders ./components/time-picker/demo/size.md correctly 1`] = `
</div>
`;

exports[`renders ./components/time-picker/demo/suffix.md correctly 1`] = `
<span
class="ant-time-picker "
>
<input
class="ant-time-picker-input"
id=""
placeholder="Select time"
type="text"
value=""
/>
<span
class="ant-time-picker-icon"
>
<i
class="anticon anticon-smile ant-time-picker-clock-icon"
>
<svg
aria-hidden="true"
class=""
data-icon="smile"
fill="currentColor"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M288 421a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm352 0a48 48 0 1 0 96 0 48 48 0 1 0-96 0zM512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm263 711c-34.2 34.2-74 61-118.3 79.8C611 874.2 562.3 884 512 884c-50.3 0-99-9.8-144.8-29.2A370.4 370.4 0 0 1 248.9 775c-34.2-34.2-61-74-79.8-118.3C149.8 611 140 562.3 140 512s9.8-99 29.2-144.8A370.4 370.4 0 0 1 249 248.9c34.2-34.2 74-61 118.3-79.8C413 149.8 461.7 140 512 140c50.3 0 99 9.8 144.8 29.2A370.4 370.4 0 0 1 775.1 249c34.2 34.2 61 74 79.8 118.3C874.2 413 884 461.7 884 512s-9.8 99-29.2 144.8A368.89 368.89 0 0 1 775 775zM664 533h-48.1c-4.2 0-7.8 3.2-8.1 7.4C604 589.9 562.5 629 512 629s-92.1-39.1-95.8-88.6c-.3-4.2-3.9-7.4-8.1-7.4H360a8 8 0 0 0-8 8.4c4.4 84.3 74.5 151.6 160 151.6s155.6-67.3 160-151.6a8 8 0 0 0-8-8.4z"
/>
</svg>
</i>
</span>
</span>
`;

exports[`renders ./components/time-picker/demo/value.md correctly 1`] = `
<span
class="ant-time-picker "
Expand Down
31 changes: 31 additions & 0 deletions components/time-picker/demo/suffix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
order: 12
debug: true
title:
zh-CN: 后缀图标
en-US: Suffix
---

## zh-CN

点击 TimePicker,然后可以在浮层中选择或者输入某一时间。

## en-US

Click `TimePicker`, and then we could select or input a time in panel.

````jsx
import { TimePicker, Icon } from 'antd';
import moment from 'moment';

function onChange(time, timeString) {
console.log(time, timeString);
}

const icon = <Icon type="smile" />;

ReactDOM.render(
<TimePicker suffix={icon} onChange={onChange} defaultOpenValue={moment('00:00:00', 'HH:mm:ss')} />,
mountNode
);
````
1 change: 1 addition & 0 deletions components/time-picker/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import moment from 'moment';
| placeholder | display when there's no value | string | "Select a time" |
| popupClassName | className of panel | string | '' |
| secondStep | interval between seconds in picker | number | 1 |
| suffix | The custom suffix icon | ReactNode | - |
| use12Hours | display as 12 hours format, with default format `h:mm:ss a` | boolean | false |
| value | to set time | [moment](http://momentjs.com/) | - |
| onChange | a callback function, can be executed when the selected time is changing | function(time: moment, timeString: string): void | - |
Expand Down
24 changes: 20 additions & 4 deletions components/time-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface TimePickerProps {
clearText?: string;
defaultOpenValue?: moment.Moment;
popupClassName?: string;
suffix?: React.ReactNode;
}

export interface TimePickerLocale {
Expand Down Expand Up @@ -153,20 +154,35 @@ class TimePicker extends React.Component<TimePickerProps, any> {
) : null
);

const inputIcon = (
<span className={`${props.prefixCls}-icon`}>
const { suffix, prefixCls } = props;
const clockIcon = suffix && (
React.isValidElement<{ className?: string }>(suffix)
? React.cloneElement(
suffix,
{
className: classNames({
[suffix.props.className!]: suffix.props.className,
[`${prefixCls}-clock-icon`]: true,
}),
},
) : <span className={`${prefixCls}-clock-icon`}>{suffix}</span>) || (
<Icon
type="clock-circle"
className={`${props.prefixCls}-clock-icon`}
className={`${prefixCls}-clock-icon`}
theme="outlined"
/>
);

const inputIcon = (
<span className={`${prefixCls}-icon`}>
{clockIcon}
</span>
);

const clearIcon = (
<Icon
type="close-circle"
className={`${props.prefixCls}-panel-clear-btn-icon`}
className={`${prefixCls}-panel-clear-btn-icon`}
theme="filled"
/>
);
Expand Down
1 change: 1 addition & 0 deletions components/time-picker/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import moment from 'moment';
| placeholder | 没有值的时候显示的内容 | string | "请选择时间" |
| popupClassName | 弹出层类名 | string | '' |
| secondStep | 秒选项间隔 | number | 1 |
| suffix | 自定义的选择框后缀图标 | ReactNode | - |
| use12Hours | 使用 12 小时制,为 true 时 `format` 默认为 `h:mm:ss a` | boolean | false |
| value | 当前时间 | [moment](http://momentjs.com/) ||
| onChange | 时间发生变化的回调 | function(time: moment, timeString: string): void ||
Expand Down

0 comments on commit a1074a6

Please sign in to comment.