Skip to content

Commit ed60852

Browse files
authored
feat: ✨ Toast 支持设置布局方向
Closes: #780
1 parent dd1a005 commit ed60852

7 files changed

Lines changed: 55 additions & 5 deletions

File tree

docs/component/toast.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ toast.show({
6666
})
6767
```
6868

69+
## 排版方向
70+
71+
`direction` 可设置排版方向,默认为横向排版。
72+
73+
```typescript
74+
// 纵向排版
75+
toast.success({
76+
msg: '纵向排版',
77+
direction: 'vertical'
78+
})
79+
```
80+
6981
## 关闭提示
7082

7183
```typescript
@@ -107,6 +119,7 @@ toast.close()
107119
| ------------ | --------------------------------------------------------------------------- | ---------- | ------------------------- | ---------------------- | -------- |
108120
| msg | 消息内容 | string | - | - | - |
109121
| duration | 持续时间,单位 ms,为 0 时表示不自动关闭 | number | - | 2000 | - |
122+
| direction | 排版方向 | string | vertical / horizontal | horizontal | $LOWEST_VERSION$ |
110123
| iconName | 图标类型 | string | success / error / warning | - | - |
111124
| iconSize | 左侧图标尺寸 | string | - | - | - |
112125
| iconClass | 图标类目,自定义图标,可以使用 Icon 章节的那些图标类名,iconName 优先级更高 | string | - | - | - |

src/pages/toast/Index.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<wd-button @click="showLoadingToast">Loading加载</wd-button>
2424
<wd-button @click="showLoadingToast2">ring类型loading</wd-button>
2525
</demo-block>
26+
<demo-block title="排版方向">
27+
<wd-button @click="showHorizonToast">横向排版</wd-button>
28+
<wd-button @click="showVerticalToast">纵向排版</wd-button>
29+
</demo-block>
2630
</page-wraper>
2731
</view>
2832
</template>
@@ -99,6 +103,17 @@ function showCustomIconToast() {
99103
msg: '使用自定义图标'
100104
})
101105
}
106+
107+
function showHorizonToast() {
108+
toast.success('横向排版')
109+
}
110+
111+
function showVerticalToast() {
112+
toast.success({
113+
msg: '纵向排版',
114+
direction: 'vertical'
115+
})
116+
}
102117
</script>
103118
<style lang="scss" scoped>
104119
:deep(button) {

src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ $-toast-fs: var(--wot-toast-fs, $-fs-content) !default; // 字号
647647
$-toast-with-icon-min-width: var(--wot-toast-with-icon-min-width, 150px) !default; // 有图标的情况下最小宽度
648648
$-toast-icon-size: var(--wot-toast-icon-size, 32px) !default; // 图标大小
649649
$-toast-icon-margin-right: var(--wot-toast-icon-margin-right, 12px) !default; // 图标右边距
650+
$-toast-icon-margin-bottom: var(--wot-toast-icon-margin-bottom, 12px) !default; // 图标下边距
650651
$-toast-loading-padding: var(--wot-toast-loading-padding, 10px) !default; // loading 下的padding
651652
$-toast-box-shadow: var(--wot-toast-box-shadow, 0px 6px 16px 0px rgba(0, 0, 0, 0.08)) !default; // 外部阴影
652653

src/uni_modules/wot-design-uni/components/wd-toast/index.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
box-sizing: border-box;
1414
box-shadow: $-toast-box-shadow;
1515

16+
@include when(vertical) {
17+
flex-direction: column;
18+
}
1619
@include e(msg) {
1720
font-size: $-toast-fs;
1821
line-height: 20px;
@@ -23,6 +26,11 @@
2326
display: inline-block;
2427
margin-right: $-toast-icon-margin-right;
2528
font-size: $-toast-icon-size;
29+
30+
@include when(vertical) {
31+
margin-right: 0;
32+
margin-bottom: $-toast-icon-margin-bottom;
33+
}
2634
}
2735
@include e(iconWrap){
2836
font-size: 0;

src/uni_modules/wot-design-uni/components/wd-toast/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function useToast(selector: string = ''): Toast {
6666
const info = createMethod({ iconName: 'info' })
6767

6868
const close = () => {
69-
toastOption.value = { show: false }
69+
toastOption.value.show = false
7070
}
7171
return {
7272
show,

src/uni_modules/wot-design-uni/components/wd-toast/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type ToastLoadingType = LoadingType // 提示信息加载状态类型
2020
export type ToastOptions = {
2121
msg?: string
2222
duration?: number
23+
direction?: 'vertical' | 'horizontal'
2324
iconName?: ToastIconType
2425
iconSize?: number
2526
loadingType?: ToastLoadingType

src/uni_modules/wot-design-uni/components/wd-toast/wd-toast.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,28 @@
33
<wd-transition name="fade" :show="show" :custom-style="transitionStyle" @after-enter="handleAfterEnter" @after-leave="handleAfterLeave">
44
<view :class="rootClass">
55
<!--iconName优先级更高-->
6-
<wd-loading v-if="iconName === 'loading'" :type="loadingType" :color="loadingColor" :size="loadingSize" custom-class="wd-toast__icon" />
6+
<wd-loading
7+
v-if="iconName === 'loading'"
8+
:type="loadingType"
9+
:color="loadingColor"
10+
:size="loadingSize"
11+
:custom-class="`wd-toast__icon ${toastOption.direction === 'vertical' ? 'is-vertical' : ''}`"
12+
/>
713
<view
8-
class="wd-toast__iconWrap wd-toast__icon"
14+
:class="`wd-toast__iconWrap wd-toast__icon ${toastOption.direction === 'vertical' ? 'is-vertical' : ''}`"
915
v-else-if="iconName === 'success' || iconName === 'warning' || iconName === 'info' || iconName === 'error'"
1016
>
1117
<view class="wd-toast__iconBox">
1218
<view class="wd-toast__iconSvg" :style="svgStyle"></view>
1319
</view>
1420
</view>
15-
<wd-icon v-else-if="iconClass" custom-class="wd-toast__icon" :size="iconSize" :class-prefix="classPrefix" :name="iconClass"></wd-icon>
21+
<wd-icon
22+
v-else-if="iconClass"
23+
:custom-class="`wd-toast__icon ${toastOption.direction === 'vertical' ? 'is-vertical' : ''}`"
24+
:size="iconSize"
25+
:class-prefix="classPrefix"
26+
:name="iconClass"
27+
></wd-icon>
1628
<!--文本-->
1729
<view v-if="msg" class="wd-toast__msg">{{ msg }}</view>
1830
</view>
@@ -107,7 +119,7 @@ const transitionStyle = computed(() => {
107119
const rootClass = computed(() => {
108120
return `wd-toast ${props.customClass} wd-toast--${position.value} ${
109121
(iconName.value !== 'loading' || msg.value) && (iconName.value || iconClass.value) ? 'wd-toast--with-icon' : ''
110-
} ${iconName.value === 'loading' && !msg.value ? 'wd-toast--loading' : ''}`
122+
} ${iconName.value === 'loading' && !msg.value ? 'wd-toast--loading' : ''} ${toastOption.value.direction === 'vertical' ? 'is-vertical' : ''}`
111123
})
112124
113125
const svgStyle = computed(() => {

0 commit comments

Comments
 (0)