From 291fd37ec3b3422695d2ac360007f5abe1960517 Mon Sep 17 00:00:00 2001
From: kanghuiyi <1193185379@qq.com>
Date: Mon, 22 Feb 2021 16:12:52 +0800
Subject: [PATCH 1/2] style: modify the display style
---
packages/varlet-cli/site/mobile/App.vue | 40 +++---
packages/varlet-cli/site/pc/App.vue | 162 +++++++++++++++---------
packages/varlet-ui/src/cell/cell.less | 1 +
3 files changed, 126 insertions(+), 77 deletions(-)
diff --git a/packages/varlet-cli/site/mobile/App.vue b/packages/varlet-cli/site/mobile/App.vue
index edf6fd6bb24..fb2be9b92f3 100644
--- a/packages/varlet-cli/site/mobile/App.vue
+++ b/packages/varlet-cli/site/mobile/App.vue
@@ -8,23 +8,31 @@
diff --git a/packages/varlet-ui/src/time-picker/__tests__/index.spec.js b/packages/varlet-ui/src/time-picker/__tests__/index.spec.js
new file mode 100644
index 00000000000..9072568f0b5
--- /dev/null
+++ b/packages/varlet-ui/src/time-picker/__tests__/index.spec.js
@@ -0,0 +1,7 @@
+const TimePicker = require('../../../cjs/time-picker').default
+const { render } = require('@testing-library/vue')
+
+test('test timePicker', async () => {
+ const wrapper = render(TimePicker)
+ console.log(wrapper)
+})
diff --git a/packages/varlet-ui/src/time-picker/clock.vue b/packages/varlet-ui/src/time-picker/clock.vue
new file mode 100644
index 00000000000..9e25c03fe0d
--- /dev/null
+++ b/packages/varlet-ui/src/time-picker/clock.vue
@@ -0,0 +1,272 @@
+
+
+
+
+
diff --git a/packages/varlet-ui/src/time-picker/docs/en_US.md b/packages/varlet-ui/src/time-picker/docs/en_US.md
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/packages/varlet-ui/src/time-picker/docs/zh_CN.md b/packages/varlet-ui/src/time-picker/docs/zh_CN.md
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/packages/varlet-ui/src/time-picker/example/index.vue b/packages/varlet-ui/src/time-picker/example/index.vue
new file mode 100644
index 00000000000..ff7a450b083
--- /dev/null
+++ b/packages/varlet-ui/src/time-picker/example/index.vue
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
diff --git a/packages/varlet-ui/src/time-picker/index.ts b/packages/varlet-ui/src/time-picker/index.ts
new file mode 100644
index 00000000000..baf6ea7292a
--- /dev/null
+++ b/packages/varlet-ui/src/time-picker/index.ts
@@ -0,0 +1,8 @@
+import { App } from 'vue'
+import TimePicker from './TimePicker.vue'
+
+TimePicker.install = function (app: App) {
+ app.component(TimePicker.name, TimePicker)
+}
+
+export default TimePicker
diff --git a/packages/varlet-ui/src/time-picker/props.ts b/packages/varlet-ui/src/time-picker/props.ts
new file mode 100644
index 00000000000..4df65d61a3f
--- /dev/null
+++ b/packages/varlet-ui/src/time-picker/props.ts
@@ -0,0 +1,53 @@
+import { PropType } from 'vue'
+
+export type Format = 'ampm' | '24hr'
+export type AmPm = 'am' | 'pm'
+export type Time = {
+ hour: string
+ minute: string
+ second?: string
+}
+
+export const hoursAmpm = ['12', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11']
+export const hours24 = ['00', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23']
+export const minSec = ['00', '05', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55']
+
+export const props = {
+ modelValue: {
+ type: String,
+ },
+ shadow: {
+ type: Boolean,
+ default: false,
+ },
+ color: {
+ type: String,
+ },
+ headerColor: {
+ type: String,
+ },
+ format: {
+ type: String as PropType,
+ default: 'ampm',
+ },
+ min: {
+ type: String,
+ },
+ max: {
+ type: String,
+ },
+ useSeconds: {
+ type: Boolean,
+ default: false,
+ },
+ readonly: {
+ type: Boolean,
+ default: false,
+ },
+ 'onUpdate:modelValue': {
+ type: Function,
+ },
+ onChange: {
+ type: Function,
+ },
+}
diff --git a/packages/varlet-ui/src/time-picker/timePicker.less b/packages/varlet-ui/src/time-picker/timePicker.less
new file mode 100644
index 00000000000..1839944c262
--- /dev/null
+++ b/packages/varlet-ui/src/time-picker/timePicker.less
@@ -0,0 +1,156 @@
+@import '../styles/elevation';
+@import '../styles/var';
+
+.var-time-picker {
+ border-radius: 4px;
+ contain: layout style;
+ display: flex;
+ flex-direction: column;
+ font-size: @font-size-md;
+ position: relative;
+ min-width: 290px;
+ height: 385px;
+ overflow: hidden;
+
+ &-title {
+ padding: 16px;
+ color: white;
+ background: @color-primary;
+ display: flex;
+ align-items: flex-end;
+ justify-content: flex-end;
+
+ &__time {
+ display: flex;
+ justify-content: flex-end;
+
+ .var-time-picker-title__btn {
+ font-size: 50px;
+ align-items: center;
+ margin: 0 5px;
+ }
+
+ span {
+ font-size: 50px;
+ }
+ }
+
+ &__btn {
+ opacity: 0.6;
+ cursor: pointer;
+ transition: 0.3s cubic-bezier(0.25, 0.8, 0.5, 1);
+ white-space: nowrap;
+
+ &--active {
+ opacity: 1;
+ }
+ }
+
+ &__ampm {
+ margin-left: 5px;
+ }
+ }
+
+ &-body {
+ flex: 1;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ }
+
+ &-clock {
+ position: absolute;
+ bottom: 27px;
+ left: 27px;
+ right: 27px;
+ top: 27px;
+
+ &__container {
+ width: 270px;
+ height: 270px;
+ background: #e0e0e0;
+ border-radius: 50%;
+ position: relative;
+ }
+
+ &__hand {
+ height: calc(50% - 4px);
+ width: 2px;
+ bottom: 50%;
+ left: calc(50% - 1px);
+ transform-origin: center bottom;
+ position: absolute;
+ will-change: transform;
+ z-index: 1;
+ background-color: @color-primary;
+ border-color: @color-primary;
+
+ &::before,
+ &::after {
+ content: '';
+ position: absolute;
+ border-radius: 100%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ }
+
+ &::before {
+ background: transparent;
+ border: 2px solid;
+ border-color: inherit;
+ width: 10px;
+ height: 10px;
+ top: -5px;
+ }
+
+ &::after {
+ height: 4px;
+ width: 4px;
+ top: 100%;
+ border-style: solid;
+ border-color: inherit;
+ background-color: inherit;
+ }
+ }
+
+ &__item {
+ align-items: center;
+ border-radius: 100%;
+ display: flex;
+ justify-content: center;
+ height: 32px;
+ position: absolute;
+ width: 32px;
+ user-select: none;
+ transform: translate(-50%, -50%);
+
+ &--active {
+ background: @color-primary;
+ z-index: 2;
+ color: #fff;
+ }
+
+ &--disable {
+ color: rgba(0, 0, 0, 0.26);
+ }
+ }
+
+ &__inner {
+ position: absolute;
+ bottom: 36px;
+ left: 36px;
+ right: 36px;
+ top: 36px;
+ }
+ }
+
+ &-panel-fade-enter-from,
+ &-panel-fade-leave-to {
+ transition: 0.3s cubic-bezier(0.25, 0.8, 0.5, 1);
+ opacity: 0;
+ }
+
+ &-panel-fade-leave-active {
+ position: absolute;
+ }
+}
diff --git a/packages/varlet-ui/src/time-picker/utils.ts b/packages/varlet-ui/src/time-picker/utils.ts
new file mode 100644
index 00000000000..4b8f21b68b3
--- /dev/null
+++ b/packages/varlet-ui/src/time-picker/utils.ts
@@ -0,0 +1,8 @@
+import { hours24, hoursAmpm, AmPm } from './props'
+
+export const notConvert = (format: string, ampm: AmPm | undefined) => format === '24hr' || ampm === 'am'
+
+export const convertHour = (format: string, ampm: AmPm | undefined, hour: string) => {
+ const index = hoursAmpm.findIndex((hourAmpm) => +hourAmpm === +hour)
+ return notConvert(format, ampm) ? hour : hours24[index]
+}