Skip to content

Commit

Permalink
refactor(TimePicker2): convert to TypeScript, impove docs and tests, c…
Browse files Browse the repository at this point in the history
  • Loading branch information
FairyYang committed Oct 17, 2024
1 parent d93eda1 commit 30e2760
Show file tree
Hide file tree
Showing 24 changed files with 1,308 additions and 1,115 deletions.
8 changes: 7 additions & 1 deletion components/time-picker2/__docs__/demo/disabled/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const disabledHours = [1, 2, 3, 4, 5];
const disabledMinutes = [10, 20, 30, 40, 50];
const disabledSeconds = [10, 20, 30, 40, 50];

const disabledItems = list => index => {
const disabledItems = (list: number[]) => (index: number) => {
return list.indexOf(index) >= 0;
};

Expand All @@ -20,6 +20,12 @@ ReactDOM.render(
disabledMinutes={disabledItems(disabledMinutes)}
disabledSeconds={disabledItems(disabledSeconds)}
/>
<p>RangePicker Disable Hours/Minutes/Seconds</p>
<TimePicker2.RangePicker
disabledHours={() => disabledHours}
disabledMinutes={() => disabledMinutes}
disabledSeconds={() => disabledSeconds}
/>
</div>,
mountNode
);
6 changes: 3 additions & 3 deletions components/time-picker2/__docs__/demo/field/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { TimePicker2, Field, Button } from '@alifd/next';
import dayjs from 'dayjs';
import dayjs, { type Dayjs } from 'dayjs';

class Demo extends React.Component {
field = new Field(this);

onClick = () => {
const value = this.field.getValue('time-picker');
console.log(value.format('HH:mm:ss'));
const value: Dayjs | undefined = this.field.getValue('time-picker');
console.log(value!.format('HH:mm:ss'));
};

render() {
Expand Down
5 changes: 3 additions & 2 deletions components/time-picker2/__docs__/demo/preset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import ReactDOM from 'react-dom';
import React, { useState } from 'react';
import dayjs from 'dayjs';
import { TimePicker2 } from '@alifd/next';
import type { TimePickerProps, ValueType } from '@alifd/next/types/time-picker2';

const nowTime = dayjs(new Date());
const currentHour = dayjs().hour(nowTime.hour()).minute(0).second(0);
const nextHour = currentHour.hour(currentHour.hour() + 1);

const preset = [
const preset: TimePickerProps['preset'] = [
{
label: '此刻',
value: () => nowTime,
Expand All @@ -23,7 +24,7 @@ const presetRange = [
];

function Picker() {
const [value, onChange] = useState(dayjs('12:00:00', 'HH:mm:ss', true));
const [value, onChange] = useState<ValueType>(dayjs('12:00:00', 'HH:mm:ss', true));

return (
<div>
Expand Down
5 changes: 3 additions & 2 deletions components/time-picker2/__docs__/demo/render-menu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { TimePicker2 } from '@alifd/next';
import type { TimePickerProps } from '@alifd/next/types/time-picker2';

const renderTimeMenuItems = list => {
return list.map(({ label, value }) => {
const renderTimeMenuItems: TimePickerProps['renderTimeMenuItems'] = list => {
return list.map(({ value }) => {
return {
value,
label: value > 9 ? String(value) : `0${value}`,
Expand Down
3 changes: 2 additions & 1 deletion components/time-picker2/__docs__/demo/step/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { TimePicker2 } from '@alifd/next';
import type { Dayjs } from 'dayjs';

ReactDOM.render(
<TimePicker2
onChange={val => console.log(val.format('HH:mm:ss'))}
onChange={(val: Dayjs) => console.log(val.format('HH:mm:ss'))}
hourStep={2}
minuteStep={5}
secondStep={5}
Expand Down
22 changes: 16 additions & 6 deletions components/time-picker2/__docs__/demo/value/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { TimePicker2 } from '@alifd/next';
import dayjs from 'dayjs';
import dayjs, { type Dayjs } from 'dayjs';
import type { TimePickerProps, ValueType } from '@alifd/next/types/time-picker2';

class ControlledTimePicker2 extends React.Component {
constructor(props, context) {
super(props, context);
interface ControlledTimePicker2Props {
onChange: (value: ValueType) => void;
}
class ControlledTimePicker2 extends React.Component<
ControlledTimePicker2Props,
{
value: Dayjs | null;
rangeValue: (Dayjs | null)[] | null;
}
> {
constructor(props: ControlledTimePicker2Props) {
super(props);
this.state = {
value: dayjs('12:00:00', 'HH:mm:ss', true),
rangeValue: [dayjs('14:00:00', 'HH:mm:ss'), dayjs('16:00:00', 'HH:mm:ss')],
};
}

onSelect = value => {
onSelect: TimePickerProps['onChange'] = (value: Dayjs | null) => {
this.setState({ value });
this.props.onChange(value);
};

onRangeSelect = rangeValue => {
onRangeSelect: TimePickerProps['onChange'] = (rangeValue: (Dayjs | null)[] | null) => {
this.setState({ rangeValue });
this.props.onChange(rangeValue);
};
Expand Down
106 changes: 60 additions & 46 deletions components/time-picker2/__docs__/index.en-us.md

Large diffs are not rendered by default.

118 changes: 56 additions & 62 deletions components/time-picker2/__docs__/index.md

Large diffs are not rendered by default.

Loading

0 comments on commit 30e2760

Please sign in to comment.