From a4a36aba99c1d367f6c688ec36a89ff91ba33b84 Mon Sep 17 00:00:00 2001 From: You-Hw-Y <1664677472@qq.com> Date: Thu, 12 Sep 2024 05:54:12 -0700 Subject: [PATCH 1/3] feat(switch): [switch] Adapting to the SMB theme --- .../demos/pc/app/switch/basic-usage.spec.ts | 8 ++--- .../pc/app/switch/dynamic-disable.spec.ts | 6 ++-- .../pc/app/switch/loading-composition-api.vue | 24 +++++++++++++ .../sites/demos/pc/app/switch/loading.spec.ts | 13 +++++++ .../sites/demos/pc/app/switch/loading.vue | 34 +++++++++++++++++++ .../demos/pc/app/switch/mini-mode.spec.ts | 2 +- .../demos/pc/app/switch/webdoc/switch.js | 12 +++++++ packages/theme/src/switch/index.less | 12 +++++++ packages/theme/src/switch/vars.less | 6 ++++ packages/vue/src/switch/src/pc.vue | 18 +++++++--- 10 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 examples/sites/demos/pc/app/switch/loading-composition-api.vue create mode 100644 examples/sites/demos/pc/app/switch/loading.spec.ts create mode 100644 examples/sites/demos/pc/app/switch/loading.vue diff --git a/examples/sites/demos/pc/app/switch/basic-usage.spec.ts b/examples/sites/demos/pc/app/switch/basic-usage.spec.ts index 84351ea35d..f8372d6630 100644 --- a/examples/sites/demos/pc/app/switch/basic-usage.spec.ts +++ b/examples/sites/demos/pc/app/switch/basic-usage.spec.ts @@ -7,9 +7,9 @@ test('基本用法', async ({ page }) => { const demo = page.locator('#basic-usage') const switchBtn = demo.locator('.tiny-switch') - await expect(switchBtn).toHaveCSS('background-color', 'rgb(94, 124, 224)') - await expect(switchBtn).toHaveCSS('border-top-color', 'rgb(94, 124, 224)') + await expect(switchBtn).toHaveCSS('background-color', 'rgb(20, 118, 255)') + await expect(switchBtn).toHaveCSS('border-top-color', 'rgb(20, 118, 255)') await switchBtn.click() - await expect(switchBtn).toHaveCSS('background-color', 'rgb(173, 176, 184)') - await expect(switchBtn).toHaveCSS('border-top-color', 'rgb(173, 176, 184)') + await expect(switchBtn).toHaveCSS('background-color', 'rgb(194, 194, 194)') + await expect(switchBtn).toHaveCSS('border-top-color', 'rgb(194, 194, 194)') }) diff --git a/examples/sites/demos/pc/app/switch/dynamic-disable.spec.ts b/examples/sites/demos/pc/app/switch/dynamic-disable.spec.ts index f9e86d4c32..fdefcc84d9 100644 --- a/examples/sites/demos/pc/app/switch/dynamic-disable.spec.ts +++ b/examples/sites/demos/pc/app/switch/dynamic-disable.spec.ts @@ -7,8 +7,6 @@ test('禁用状态', async ({ page }) => { const demo = page.locator('#dynamic-disable') const switchBtn = demo.locator('.tiny-switch') - await expect(switchBtn.first()).toHaveCSS('background-color', 'rgb(190, 204, 250)') - await expect(switchBtn.first()).toHaveCSS('background-color', 'rgb(190, 204, 250)') - await expect(switchBtn.nth(1)).toHaveCSS('background-color', 'rgb(223, 225, 230)') - await expect(switchBtn.nth(1)).toHaveCSS('background-color', 'rgb(223, 225, 230)') + await expect(switchBtn.first()).toHaveCSS('background-color', 'rgb(179, 214, 255)') + await expect(switchBtn.nth(1)).toHaveCSS('background-color', 'rgb(219, 219, 219)') }) diff --git a/examples/sites/demos/pc/app/switch/loading-composition-api.vue b/examples/sites/demos/pc/app/switch/loading-composition-api.vue new file mode 100644 index 0000000000..3560df5ca1 --- /dev/null +++ b/examples/sites/demos/pc/app/switch/loading-composition-api.vue @@ -0,0 +1,24 @@ + + + + + diff --git a/examples/sites/demos/pc/app/switch/loading.spec.ts b/examples/sites/demos/pc/app/switch/loading.spec.ts new file mode 100644 index 0000000000..a5b6529f29 --- /dev/null +++ b/examples/sites/demos/pc/app/switch/loading.spec.ts @@ -0,0 +1,13 @@ +import { test, expect } from '@playwright/test' + +test('加载状态', async ({ page }) => { + page.on('pageerror', (exception) => expect(exception).toBeNull()) + await page.goto('switch#loading') + + const demo = page.locator('#loading') + const switchBtn = demo.locator('.tiny-switch__button').first().locator('svg') + const switchBtn2 = demo.locator('span:nth-child(2) > .tiny-switch__button').locator('svg') + + await expect(switchBtn).toHaveClass(/tiny-switch__on-loading/) + await expect(switchBtn2).toHaveClass(/tiny-switch__off-loading/) +}) diff --git a/examples/sites/demos/pc/app/switch/loading.vue b/examples/sites/demos/pc/app/switch/loading.vue new file mode 100644 index 0000000000..0a5db14fbf --- /dev/null +++ b/examples/sites/demos/pc/app/switch/loading.vue @@ -0,0 +1,34 @@ + + + + + diff --git a/examples/sites/demos/pc/app/switch/mini-mode.spec.ts b/examples/sites/demos/pc/app/switch/mini-mode.spec.ts index e7ca11a2b4..a102b7cfe9 100644 --- a/examples/sites/demos/pc/app/switch/mini-mode.spec.ts +++ b/examples/sites/demos/pc/app/switch/mini-mode.spec.ts @@ -7,5 +7,5 @@ test('迷你尺寸', async ({ page }) => { const demo = page.locator('#mini-mode') const switchBtn = demo.locator('.tiny-switch') - await expect(switchBtn).toHaveCSS('width', '34px') + await expect(switchBtn).toHaveCSS('width', '32px') }) diff --git a/examples/sites/demos/pc/app/switch/webdoc/switch.js b/examples/sites/demos/pc/app/switch/webdoc/switch.js index 337c579b00..4eb3349a3f 100644 --- a/examples/sites/demos/pc/app/switch/webdoc/switch.js +++ b/examples/sites/demos/pc/app/switch/webdoc/switch.js @@ -26,6 +26,18 @@ export default { }, codeFiles: ['mini-mode.vue'] }, + { + demoId: 'loading', + name: { + 'zh-CN': '加载中状态', + 'en-US': 'Loading status' + }, + desc: { + 'zh-CN': '

通过 loading 设置开关显示加载状态。

', + 'en-US': '

Set the switch to display the loading status throughloading.' + }, + codeFiles: ['loading.vue'] + }, { demoId: 'custom-open-close', name: { diff --git a/packages/theme/src/switch/index.less b/packages/theme/src/switch/index.less index b7a7301058..c92fb6b84a 100644 --- a/packages/theme/src/switch/index.less +++ b/packages/theme/src/switch/index.less @@ -54,6 +54,18 @@ } } + &__on-loading { + font-size: var(--ti-switch-on-loading-font-size); + fill: var(--ti-switch-on-loading-fill); + } + &__off-loading { + font-size: var(--ti-switch-off-loading-font-size); + fill: var(--ti-switch-off-loading-fill); + } + &__loading-mini { + font-size: var(--ti-switch-loading-mini-font-size); + } + &.mini { width: var(--ti-switch-mini-width); height: var(--ti-switch-mini-height); diff --git a/packages/theme/src/switch/vars.less b/packages/theme/src/switch/vars.less index a7a866ab3a..5111215a31 100644 --- a/packages/theme/src/switch/vars.less +++ b/packages/theme/src/switch/vars.less @@ -58,4 +58,10 @@ --ti-switch-mini-button-height: calc(var(--ti-common-size-height-small)/2); --ti-switch-mini-button-width: calc(var(--ti-common-size-width-mini)/2); --ti-switch-mini-button-left: calc(var(--ti-common-space-4x) + 2px); + // 加载ICON样式 + --ti-switch-on-loading-font-size: var(--ti-common-font-size-0); + --ti-switch-on-loading-fill: var(--ti-common-color-bg-light-emphasize); + --ti-switch-off-loading-font-size: var(--ti-common-font-size-0); + --ti-switch-off-loading-fill: #DBDBDB; + --ti-switch-loading-mini-font-size: 8px; } diff --git a/packages/vue/src/switch/src/pc.vue b/packages/vue/src/switch/src/pc.vue index f368df9201..ba20f2be95 100644 --- a/packages/vue/src/switch/src/pc.vue +++ b/packages/vue/src/switch/src/pc.vue @@ -19,14 +19,21 @@ @keydown.enter="toggle" > -

+
ON OFF
- - + + + @@ -40,6 +47,7 @@ import { renderless, api } from '@opentiny/vue-renderless/switch/vue' import { props, setup, defineComponent } from '@opentiny/vue-common' import '@opentiny/vue-theme/switch/index.less' import type { ISwitchApi } from '@opentiny/vue-renderless/types/switch.type' +import { IconLoadingShadow } from '@opentiny/vue-icon' export default defineComponent({ emits: ['change', 'update:modelValue'], @@ -53,8 +61,10 @@ export default defineComponent({ 'tabindex', 'showText', 'beforeChange', - 'displayOnly' + 'displayOnly', + 'loading' ], + components: { IconLoading: IconLoadingShadow() }, setup(props, context) { return setup({ props, context, renderless, api }) as unknown as ISwitchApi } From ffdf3e274fb81896e9a889a6680a309136f9dda6 Mon Sep 17 00:00:00 2001 From: You-Hw-Y <1664677472@qq.com> Date: Thu, 12 Sep 2024 18:31:16 -0700 Subject: [PATCH 2/3] feat(switch): [switch] Adapting to the SMB theme --- examples/sites/demos/pc/app/switch/loading-composition-api.vue | 2 +- examples/sites/demos/pc/app/switch/loading.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/sites/demos/pc/app/switch/loading-composition-api.vue b/examples/sites/demos/pc/app/switch/loading-composition-api.vue index 3560df5ca1..31d68b7cab 100644 --- a/examples/sites/demos/pc/app/switch/loading-composition-api.vue +++ b/examples/sites/demos/pc/app/switch/loading-composition-api.vue @@ -19,6 +19,6 @@ function change() { diff --git a/examples/sites/demos/pc/app/switch/loading.vue b/examples/sites/demos/pc/app/switch/loading.vue index 0a5db14fbf..203d6e874f 100644 --- a/examples/sites/demos/pc/app/switch/loading.vue +++ b/examples/sites/demos/pc/app/switch/loading.vue @@ -29,6 +29,6 @@ export default { From 5a3bac330d2272b5fc81e0c0cc62ddc43fc788c1 Mon Sep 17 00:00:00 2001 From: You-Hw-Y <1664677472@qq.com> Date: Fri, 13 Sep 2024 01:36:21 -0700 Subject: [PATCH 3/3] feat(switch): [switch] Adapting to the SMB theme --- examples/sites/demos/apis/switch.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/sites/demos/apis/switch.js b/examples/sites/demos/apis/switch.js index 1626bbdc2e..e7b5f638aa 100644 --- a/examples/sites/demos/apis/switch.js +++ b/examples/sites/demos/apis/switch.js @@ -29,6 +29,20 @@ export default { mobileDemo: 'disabled', mfDemo: '' }, + { + name: 'loading', + type: 'boolean', + defaultValue: 'false', + desc: { + 'zh-CN': '是否加载中状态', + 'en-US': 'Loading status' + }, + meta: { + stable: '3.19.0' + }, + mode: ['pc'], + pcDemo: 'loading' + }, { name: 'false-value', type: 'boolean | string | number',