From dae6e2dbd437a6c69e65f493625ac37426c5dd09 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 30 Aug 2020 20:17:37 +0800 Subject: [PATCH] feat(ActionSheet): add description slot (#7068) --- src/action-sheet/README.md | 7 +++++++ src/action-sheet/README.zh-CN.md | 7 +++++++ src/action-sheet/index.tsx | 19 +++++++++++++------ .../test/__snapshots__/index.spec.js.snap | 6 ++++++ src/action-sheet/test/index.spec.js | 14 ++++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/action-sheet/README.md b/src/action-sheet/README.md index 819482acd..b05851344 100644 --- a/src/action-sheet/README.md +++ b/src/action-sheet/README.md @@ -189,3 +189,10 @@ export default { | opened | Triggered when opened ActionSheet | - | | closed | Triggered when closed ActionSheet | - | | click-overlay | Triggered when click overlay | - | + +### Slots + +| Name | Description | +| --------------------- | ------------------ | +| default | Custom content | +| description `v2.10.4` | Custom description | diff --git a/src/action-sheet/README.zh-CN.md b/src/action-sheet/README.zh-CN.md index afd55d34b..66123e881 100644 --- a/src/action-sheet/README.zh-CN.md +++ b/src/action-sheet/README.zh-CN.md @@ -198,6 +198,13 @@ export default { | closed | 关闭面板且动画结束后触发 | - | | click-overlay | 点击遮罩层时触发 | - | +### Slots + +| 名称 | 说明 | +| --------------------- | -------------------- | +| default | 自定义面板的展示内容 | +| description `v2.10.4` | 自定义描述文案 | + ## 常见问题 ### 引入时提示 dependencies not found? diff --git a/src/action-sheet/index.tsx b/src/action-sheet/index.tsx index 2c5adcd53..b06e657ec 100644 --- a/src/action-sheet/index.tsx +++ b/src/action-sheet/index.tsx @@ -12,7 +12,7 @@ import Loading from '../loading'; // Types import { CreateElement, RenderContext } from 'vue/types'; -import { DefaultSlots } from '../utils/types'; +import { ScopedSlot, DefaultSlots } from '../utils/types'; import { PopupMixinProps } from '../mixins/popup/type'; export type ActionSheetItem = { @@ -38,12 +38,16 @@ export type ActionSheetProps = PopupMixinProps & { safeAreaInsetBottom?: boolean; }; +export type ActionSheetSlots = DefaultSlots & { + description?: ScopedSlot; +}; + const [createComponent, bem] = createNamespace('action-sheet'); function ActionSheet( h: CreateElement, props: ActionSheetProps, - slots: DefaultSlots, + slots: ActionSheetSlots, ctx: RenderContext ) { const { title, cancelText } = props; @@ -129,9 +133,12 @@ function ActionSheet( } } - const Description = props.description && ( -
{props.description}
- ); + function Description() { + const description = slots.description?.() || props.description; + if (description) { + return
{description}
; + } + } return ( {Header()} - {Description} + {Description()} {props.actions && props.actions.map(Option)} {Content()} {CancelText()} diff --git a/src/action-sheet/test/__snapshots__/index.spec.js.snap b/src/action-sheet/test/__snapshots__/index.spec.js.snap index d1bb01fd6..e27c3187b 100644 --- a/src/action-sheet/test/__snapshots__/index.spec.js.snap +++ b/src/action-sheet/test/__snapshots__/index.spec.js.snap @@ -24,6 +24,12 @@ exports[`description prop 1`] = ` `; +exports[`description slot 1`] = ` +
+
Custom Description
+
+`; + exports[`disable lazy-render 1`] = `