Skip to content

Commit 9a2f00f

Browse files
jevin98sleeprite
authored andcommitted
!479 feat(datePicker): 新增static(面板)模式
* chore: 统一borderColor变量 * feat(datePicker): 新增static(面板)模式
1 parent 719d42e commit 9a2f00f

File tree

6 files changed

+95
-43
lines changed

6 files changed

+95
-43
lines changed

docs/src/document/zh-CN/components/datePicker.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,32 @@ const shortcuts2 = [
527527

528528
:::
529529

530+
::: title 静态面板
531+
:::
532+
533+
::: demo 通过 `static` 开启静态面板模式
534+
535+
<template>
536+
<lay-space direction="vertical">
537+
modelValue: {{value11}}
538+
<lay-date-picker v-model="value11" static type="date" placeholder="format"></lay-date-picker>
539+
</lay-space>
540+
<lay-space style="margin-top: 10px" direction="vertical">
541+
modelValue: {{value12}}
542+
<lay-date-picker v-model="value12" static type="date" range placeholder="范围"></lay-date-picker>
543+
</lay-space>
544+
</template>
545+
546+
<script setup>
547+
import { ref } from 'vue'
548+
549+
const value11 = ref(null);
550+
const value12 = ref([]);
551+
552+
</script>
553+
554+
:::
555+
530556
::: title Date Picker 属性
531557
:::
532558

@@ -559,6 +585,8 @@ const shortcuts2 = [
559585
| content-class | 内容自定义 Class | `string` `Array<string \| object>` `object` | -- | -- | -- |
560586
| year-page | 年份选择器每页年份的个数 | `number` | `15` | --| `2.19.0` |
561587
| shortcuts | 设置快捷选项,需要传入数组对象 | `Array<Shortcuts>` | -- | --| `2.19.0` |
588+
| static | 静态日期面板模式 | `boolean` | `false` | --| `2.22.1` |
589+
| teleportProps | 继承至 dropdown 组件,下拉面板 `传递` 属性 | `object` | `{to: 'body', disabled: false}` | -- | `2.22.1` |
562590

563591

564592
:::

packages/component/component/datePicker/__tests__/datePicker.test.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,45 @@ describe("LayDatePicker date type", () => {
262262
}
263263
});
264264
});
265+
266+
test("static model > modelValue", async () => {
267+
const wrapper = mount(LayDatePicker, {
268+
props: {
269+
modelValue: "2025/11/12 10:00:00",
270+
static: true
271+
},
272+
});
273+
274+
await nextTick()
275+
276+
const component = wrapper.findComponent(LayDatePicker);
277+
const DateInstance = wrapper.findComponent(DateComponent);
278+
279+
const [YearSpan, MonthSpan] = DateInstance.findAll(
280+
".layui-laydate-header .laydate-set-ym span"
281+
);
282+
283+
expect((component.props() as any).modelValue).toBe("2025/11/12 10:00:00");
284+
285+
expect(YearSpan.text()).toContain("2025");
286+
expect(MonthSpan.text()).toContain("11");
287+
288+
const dateCurrent = DateInstance.find(".layui-laydate-content .layui-this");
289+
290+
expect(dateCurrent.exists()).toBeTruthy();
291+
expect(dateCurrent.text()).toBe("12");
292+
293+
await YearSpan.trigger("click");
294+
await sleep();
295+
296+
const YearInstance = wrapper.findComponent(Year);
297+
298+
expect((YearInstance.vm as any).currentYear).toBe(2025);
299+
300+
const YearCurrent = YearInstance.find(".layui-laydate-content .layui-this");
301+
302+
expect(YearCurrent.exists()).toBeTruthy();
303+
expect(YearCurrent.text()).toBe("2025");
304+
});
305+
265306
});

packages/component/component/datePicker/component/common/InputBlock.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import LayInput from "../../../input/index.vue";
1111
import { DATE_PICKER_CONTEXT } from "../../interface";
1212
import { checkRangeValue, dayjsToString } from "../../util";
1313
14-
const props = withDefaults(defineProps<DatePickerProps>(), {});
14+
const props = defineProps<DatePickerProps>();
1515
const emits = defineEmits([
1616
"update:modelValue",
1717
"change",
@@ -29,7 +29,7 @@ const classes = computed(() => {
2929
"layui-date-picker",
3030
{
3131
"layui-date-range-picker": props.range,
32-
// "layui-date-picker-static": props.static,
32+
"layui-date-picker-static": props.static,
3333
},
3434
];
3535
});
@@ -255,12 +255,14 @@ function onPick(dates: Dayjs | Array<Dayjs>) {
255255
<template>
256256
<div :class="classes" :size="size">
257257
<LayDropdown
258+
v-if="!static"
258259
ref="dropdownRef"
259260
:disabled="disabled"
260261
:auto-fit-min-width="false"
261262
:click-to-close="false"
262263
:content-class="contentClass"
263264
:content-style="contentStyle"
265+
:teleport-props="teleportProps"
264266
>
265267
<LayInput
266268
v-if="!range"
@@ -314,5 +316,7 @@ function onPick(dates: Dayjs | Array<Dayjs>) {
314316
<slot :on-pick="onPick" />
315317
</template>
316318
</LayDropdown>
319+
320+
<slot v-else :on-pick="onPick" />
317321
</div>
318322
</template>

packages/component/component/datePicker/index.less

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ html #layuicss-laydate {
7575
z-index: 66666666;
7676
border-radius: var(--global-border-radius);
7777
font-size: 14px;
78-
-webkit-animation-duration: 0.2s;
79-
animation-duration: 0.2s;
80-
-webkit-animation-fill-mode: both;
81-
animation-fill-mode: both;
8278

8379
.layui-laydate-year-control {
8480
padding: 4px;
@@ -94,30 +90,6 @@ html #layuicss-laydate {
9490
-webkit-transition-duration: 0.3s;
9591
}
9692

97-
/* 微微往下滑入 */
98-
@keyframes laydate-downbit {
99-
0% {
100-
opacity: 0.3;
101-
transform: translate3d(0, -5px, 0);
102-
}
103-
100% {
104-
opacity: 1;
105-
transform: translate3d(0, 0, 0);
106-
}
107-
}
108-
109-
.layui-laydate {
110-
animation-name: laydate-downbit;
111-
}
112-
// .layui-laydate-static {
113-
// position: relative;
114-
// z-index: 0;
115-
// display: inline-block;
116-
// margin: 0;
117-
// -webkit-animation: none;
118-
// animation: none;
119-
// }
120-
12193
/* 展开年月列表时 */
12294
.laydate-ym-show .laydate-prev-m,
12395
.laydate-ym-show .laydate-next-m {
@@ -693,9 +665,14 @@ html #layuicss-laydate {
693665
transition: all 0.3s;
694666
}
695667
}
696-
/* 静态面板 */
697-
// .layui-date-picker-static {
698-
// width: auto !important;
699-
// height: 100% !important;
700-
// border: 1px solid var(--input-border-color);
701-
// }
668+
669+
.layui-date-picker-static {
670+
&[size] {
671+
display: inline-flex;
672+
width: auto;
673+
height: auto;
674+
background-color: #fff;
675+
border: 1px solid var(--input-border-color);
676+
border-radius: var(--global-border-radius);
677+
}
678+
}

packages/component/component/datePicker/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const props = withDefaults(defineProps<DatePickerProps>(), {
3535
defaultTime: null,
3636
yearPage: 15,
3737
// yearStep: 1,
38-
// static: false,
38+
static: false,
3939
});
4040
4141
dayjs.extend(customParseFormat);

packages/component/component/datePicker/interface.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import type { DropdownTeleportProps } from "@layui/component/component/dropdown/interface";
2+
import type { CommonClass, CommonSize } from "@layui/component/types/common";
13
import type { ConfigType, Dayjs } from "dayjs";
24
import type { Component, InjectionKey, StyleValue } from "vue";
3-
import type { CommonClass, CommonSize } from "../../types/common";
45

56
export type DatePickerType =
67
| "date"
@@ -60,11 +61,12 @@ export interface DatePickerProps {
6061
* @version 2.19.0
6162
*/
6263
shortcuts?: Array<Shortcuts>;
63-
// /**
64-
// * 静态面板
65-
// * @version 2.19.0
66-
// */
67-
// static?: boolean;
64+
/**
65+
* 静态面板
66+
* @version 2.22.1
67+
*/
68+
static?: boolean;
69+
teleportProps?: DropdownTeleportProps;
6870
}
6971

7072
export interface RequiredDatePickerProps extends DatePickerProps {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy