From b9f679da2828df167567888667fd3d9d3e999f70 Mon Sep 17 00:00:00 2001 From: Onion-L Date: Wed, 13 Nov 2024 17:27:25 +0800 Subject: [PATCH 1/3] feat: add closeOnClickMask behavior to close drawer --- .../__snapshots__/drawer.spec.ts.snap | 2 +- components/Drawer/src/index.svelte | 11 ++++++++- components/Drawer/src/types.d.ts | 1 + .../__test__/__snapshots__/image.spec.ts.snap | 2 +- .../__snapshots__/image-view.spec.ts.snap | 24 +++++++++---------- .../__test__/__snapshots__/mask.spec.ts.snap | 6 ++--- components/Mask/src/index.svelte | 4 ++++ .../__test__/__snapshots__/modal.spec.ts.snap | 10 ++++---- .../__test__/__snapshots__/spin.spec.ts.snap | 11 +++++---- 9 files changed, 43 insertions(+), 28 deletions(-) diff --git a/components/Drawer/__test__/__snapshots__/drawer.spec.ts.snap b/components/Drawer/__test__/__snapshots__/drawer.spec.ts.snap index e54169d98..3bb2896f1 100644 --- a/components/Drawer/__test__/__snapshots__/drawer.spec.ts.snap +++ b/components/Drawer/__test__/__snapshots__/drawer.spec.ts.snap @@ -1,3 +1,3 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`Test: KDrawer > slot: content 1`] = `"

A person's loneliness, never had the lonely mood is wrapped by this dark night.

"`; +exports[`Test: KDrawer > slot: content 1`] = `""`; diff --git a/components/Drawer/src/index.svelte b/components/Drawer/src/index.svelte index cfa5334b1..6ef705fc6 100644 --- a/components/Drawer/src/index.svelte +++ b/components/Drawer/src/index.svelte @@ -12,6 +12,7 @@ export let cls: KDrawerProps['cls'] = undefined; export let attrs: KDrawerProps['attrs'] = {}; export let header: KDrawerProps['header'] = true; + export let closeOnClickMask: KDrawerProps['closeOnClickMask'] = true; $: cnames = clsx(cls); $: maskCls = clsx('k-drawer--base k-drawer--base__dark', isRight ? 'right-0' : 'left-0', cnames); @@ -23,14 +24,22 @@ dispatch('close'); }; + const onClickMask = () => { + if (closeOnClickMask) toggleClose(); + }; + $: isRight = placement === 'right'; - + +