Skip to content

Commit 8f2a27e

Browse files
faga295FliPPeDroundAlkaidcc
authored
feat: init date time picker (#38)
* feat: init date time picker * feat: set auto-props-disabled (#30) * feat: date picker component (#31) * feat: init datepicker * feat: init datePicker *feat: set auto-props-disabled on datePicker Co-authored-by: faga <lzc295592@163.com> Co-authored-by: joypeng <70848683+FliPPeDround@users.noreply.github.com> * fix: typo (#32) * feat: init autocomplete component (#13) * feat: init autocomplete component * chore: argument name change * feat: add controls * chore: trigger on focus control * chore: remote search control * feat: set auto-props-disabled Co-authored-by: faga <lzc295592@163.com> Co-authored-by: joypeng <70848683+FliPPeDround@users.noreply.github.com> * chore: layout width change Co-authored-by: faga <lzc295592@163.com> Co-authored-by: joypeng <70848683+FliPPeDround@users.noreply.github.com> Co-authored-by: ZhangZhiChao <54631354+Alkaidcc@users.noreply.github.com>
1 parent 3c8239d commit 8f2a27e

File tree

3 files changed

+192
-1
lines changed

3 files changed

+192
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# 🎉 A Element-plus docs by histoire
2+
3+
24
## Contributors
35

46
This project exists thanks to all the people who contribute.

src/components/Form/datePicker.story.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ const isHoliday = ({ dayjs }: DateCell) => {
109109
</script>
110110

111111
<template>
112-
<Story title="Form/DatePicker" auto-props-disabled>
112+
<Story
113+
title="Form/DatePicker"
114+
auto-props-disabled
115+
:layout="{ type: 'grid', width: 480 }"
116+
>
113117
<Variant title="Basic Usage">
114118
<el-date-picker
115119
v-model="date"
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<script setup lang="ts">
2+
import { logEvent } from 'histoire/client'
3+
import { ref } from 'vue'
4+
5+
const date = ref()
6+
const size = ref<'large' | 'default' | 'small'>('default')
7+
const valueFormat = ref()
8+
const range = ref(false)
9+
const defaultTime = new Date(2000, 1, 1, 12, 0, 0)
10+
const defaultRangeTime: [Date, Date] = [
11+
new Date(2000, 1, 1, 12, 0, 0),
12+
new Date(2000, 2, 1, 8, 0, 0),
13+
]
14+
const shortcuts = [
15+
{
16+
text: 'Today',
17+
value: new Date(),
18+
},
19+
{
20+
text: 'Yesterday',
21+
value: () => {
22+
const date = new Date()
23+
date.setTime(date.getTime() - 3600 * 1000 * 24)
24+
return date
25+
},
26+
},
27+
{
28+
text: 'A week ago',
29+
value: () => {
30+
const date = new Date()
31+
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
32+
return date
33+
},
34+
},
35+
]
36+
const rangeShortcuts = [
37+
{
38+
text: 'Last week',
39+
value: () => {
40+
const end = new Date()
41+
const start = new Date()
42+
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
43+
return [start, end]
44+
},
45+
},
46+
{
47+
text: 'Last month',
48+
value: () => {
49+
const end = new Date()
50+
const start = new Date()
51+
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
52+
return [start, end]
53+
},
54+
},
55+
{
56+
text: 'Last 3 months',
57+
value: () => {
58+
const end = new Date()
59+
const start = new Date()
60+
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
61+
return [start, end]
62+
},
63+
},
64+
]
65+
const sizeList = [
66+
{
67+
label: 'large',
68+
value: 'large',
69+
},
70+
{
71+
label: 'default',
72+
value: 'default',
73+
},
74+
{
75+
label: 'small',
76+
value: 'small',
77+
},
78+
]
79+
const valueFormatList = [
80+
{
81+
label: 'YYYY-MM-DD h:m:s a',
82+
value: 'YYYY-MM-DD h:m:s a',
83+
},
84+
{
85+
label: 'x',
86+
value: 'x',
87+
},
88+
]
89+
const handleChange = (dateTime: any) => {
90+
logEvent('change', { dateTime })
91+
}
92+
</script>
93+
94+
<template>
95+
<Story title="Form/DateTimePicker" :layout="{ type: 'grid', width: 480 }">
96+
<Variant title="Basic Usage">
97+
<el-date-picker
98+
v-model="date"
99+
type="datetime"
100+
placeholder="Select date and time"
101+
:size="size"
102+
@change="handleChange"
103+
/>
104+
<template #controls>
105+
<HstRadio v-model="size" :options="sizeList" title="Size" />
106+
</template>
107+
</Variant>
108+
<Variant title="With shortcuts">
109+
<el-date-picker
110+
v-model="date"
111+
type="datetime"
112+
placeholder="Select date and time"
113+
:shortcuts="shortcuts"
114+
@change="handleChange"
115+
/>
116+
</Variant>
117+
<Variant title="Date time format">
118+
<el-date-picker
119+
v-model="date"
120+
type="datetime"
121+
placeholder="Pick a Date"
122+
format="YYYY/MM/DD HH:mm:ss"
123+
:value-format="valueFormat"
124+
@change="handleChange"
125+
/>
126+
<template #controls>
127+
<HstRadio
128+
v-model="valueFormat"
129+
:options="valueFormatList"
130+
title="Date time format"
131+
/>
132+
</template>
133+
</Variant>
134+
<Variant title="Date and time range">
135+
<el-date-picker
136+
v-model="date"
137+
type="datetimerange"
138+
range-separator="To"
139+
start-placeholder="Start date"
140+
end-placeholder="End date"
141+
:size="size"
142+
:shortcuts="rangeShortcuts"
143+
@change="handleChange"
144+
/>
145+
<template #controls>
146+
<HstRadio v-model="size" :options="sizeList" title="Size" />
147+
</template>
148+
</Variant>
149+
<Variant title="Default time">
150+
<el-date-picker
151+
v-model="date"
152+
:type="`datetime${range ? 'range' : ''}`"
153+
placeholder="Select date"
154+
start-placeholder="Start Date"
155+
end-placeholder="End Date"
156+
:default-time="range ? defaultRangeTime : defaultTime"
157+
@change="handleChange"
158+
/>
159+
<template #controls>
160+
<HstCheckbox v-model="range" title="Range" />
161+
</template>
162+
</Variant>
163+
</Story>
164+
</template>
165+
166+
<docs lang="md">
167+
# DateTimePicker
168+
Select date and time in one picker.
169+
170+
## Basic Usage
171+
You can select date and time in one picker at the same time by setting `type` to `datetime`. The way to use shortcuts is the same as Date Picker.
172+
173+
## Date Time Formats
174+
Use `format` to control displayed text's format in the input box. Use `value-format` to control binding value's format.
175+
176+
By default, the component accepts and emits a `Date` object.
177+
178+
Check the list [here](https://day.js.org/docs/en/display/format#list-of-all-available-formats) of all available formats of Day.js.
179+
180+
## Date and time range
181+
You can select date and time range by setting `type` to `datetimerange`.
182+
183+
## Default time value for start date and end date
184+
When picking date range on the date panel with type `datetimerange`, `00:00:00` will be used as the default time value for start and end date. We can control it with the `default-time` attribute. `default-time` accepts an array of up to two Date objects. The first item controls time value of the start date and the second item controls time value of the end date.
185+
</docs>

0 commit comments

Comments
 (0)