From b21410440a09359c2dcadabfbd85d2baf4b0cbf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?0o=E5=BC=A0=E4=B8=8D=E6=AD=AAo0?= Date: Tue, 19 Jul 2022 10:25:46 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(component):=20switch=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=96=B0=E5=A2=9E=20=E5=B0=BA=E5=AF=B8=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/src/component/switch/index.less | 64 ++++++++++++++++--- .../component/src/component/switch/index.vue | 4 +- .../src/document/zh-CN/components/switch.md | 32 ++++++++++ 3 files changed, 90 insertions(+), 10 deletions(-) diff --git a/package/component/src/component/switch/index.less b/package/component/src/component/switch/index.less index 8cbc7caa..71d700af 100644 --- a/package/component/src/component/switch/index.less +++ b/package/component/src/component/switch/index.less @@ -1,3 +1,54 @@ +@lg: 28px; +@md: 22px; +@sm: 16px; +@xs: 13px; + +@lg-min-width: 55px; +@md-min-width: 35px; +@sm-min-width: 26px; +@xs-min-width: 20px; + +.set-size(@size, @min-width) { + & { + .layui-form-switch { + height: @size; + min-width: @min-width; + span{ + width: calc(@size - 4px); + height: calc(@size - 4px); + transition:all 0.1s linear; + } + em{ + margin-left: calc(@size - 3px); + } + } + .layui-form-onswitch{ + span{ + left: calc(100% - calc(@size - 1px)); + } + em{ + margin-right: calc(@size - 3px); + margin-left: 0px; + } + } + } +} + +.layui-switch-container{ + &[size="lg"] { + .set-size(@lg,@lg-min-width); + } + &[size="md"] { + .set-size(@md,@md-min-width); + } + &[size="sm"] { + .set-size(@sm,@sm-min-width); + } + &[size="xs"] { + .set-size(@xs,@xs-min-width); + } +} + .layui-form-switch { position: relative; height: 22px; @@ -7,8 +58,8 @@ border-radius: 20px; cursor: pointer; background-color: var(--global-neutral-color-6); - -webkit-transition: 0.1s linear; - transition: 0.1s linear; + -webkit-transition:all 0.1s linear; + transition:all 0.1s linear; } .layui-form-switch span { @@ -24,15 +75,14 @@ border-radius: 20px; background-color: #fff; box-shadow: 0 2px 4px #00230b33; - -webkit-transition: 0.1s linear; - transition: 0.1s linear; + -webkit-transition:all 0.1s linear; + transition:all 0.1s linear; } .layui-form-switch em { position: relative; top: 0; width: 25px; - margin-left: 21px; padding: 0 !important; text-align: center !important; color: #999 !important; @@ -46,14 +96,10 @@ } .layui-form-onswitch span { - left: 100%; - margin-left: -21px; background-color: #fff; } .layui-form-onswitch em { - margin-left: 5px; - margin-right: 21px; color: #fff !important; } diff --git a/package/component/src/component/switch/index.vue b/package/component/src/component/switch/index.vue index c2777202..474a45da 100644 --- a/package/component/src/component/switch/index.vue +++ b/package/component/src/component/switch/index.vue @@ -17,12 +17,14 @@ export interface LaySwitchProps { unswitchColor?: string; onswitchValue?: string | number | boolean; unswitchValue?: string | number | boolean; + size?: "lg" | "md" | "sm" | "xs"; } const props = withDefaults(defineProps(), { disabled: false, onswitchValue: true, unswitchValue: false, + size:'md' }); const emit = defineEmits(["update:modelValue", "change"]); @@ -58,7 +60,7 @@ const styles = computed(() => { + + + +::: + ::: title Switch 属性 ::: @@ -186,6 +217,7 @@ export default { | unswitch-text | 禁用描述 | `禁用` | | onswitch-value | 启用值 | `true` | | unswitch-value | 禁用值 | `false` | +| size | 尺寸 | `lg` `md` `sm` `xs` | :::