mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Toast): add wordBreak prop (#11147)
This commit is contained in:
parent
2729ebff85
commit
c98f3e19c9
@ -199,6 +199,7 @@ Vant exports following Toast utility functions:
|
|||||||
| type | Can be set to `loading` `success` `fail` `html` | _ToastType_ | `text` |
|
| type | Can be set to `loading` `success` `fail` `html` | _ToastType_ | `text` |
|
||||||
| position | Can be set to `top` `middle` `bottom` | _ToastPosition_ | `middle` |
|
| position | Can be set to `top` `middle` `bottom` | _ToastPosition_ | `middle` |
|
||||||
| message | Message | _string_ | `''` |
|
| message | Message | _string_ | `''` |
|
||||||
|
| wordBreak | Can be set to `break-normal` `break-all` `break-word` | _ToastWordBreak_ | `''` |
|
||||||
| icon | Custom icon | _string_ | - |
|
| icon | Custom icon | _string_ | - |
|
||||||
| iconSize | Custom icon size | _number \| string_ | `36px` |
|
| iconSize | Custom icon size | _number \| string_ | `36px` |
|
||||||
| iconPrefix | Icon className prefix | _string_ | `van-icon` |
|
| iconPrefix | Icon className prefix | _string_ | `van-icon` |
|
||||||
@ -229,7 +230,13 @@ You can use following slots when using `Toast` component:
|
|||||||
The component exports the following type definitions:
|
The component exports the following type definitions:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import type { ToastType, ToastProps, ToastOptions, ToastPosition } from 'vant';
|
import type {
|
||||||
|
ToastType,
|
||||||
|
ToastProps,
|
||||||
|
ToastOptions,
|
||||||
|
ToastPosition,
|
||||||
|
ToastWordBreak,
|
||||||
|
} from 'vant';
|
||||||
```
|
```
|
||||||
|
|
||||||
## Theming
|
## Theming
|
||||||
|
@ -216,6 +216,7 @@ Vant 中导出了以下 Toast 相关的辅助函数:
|
|||||||
| type | 提示类型,可选值为 `loading` `success`<br>`fail` `html` | _ToastType_ | `text` |
|
| type | 提示类型,可选值为 `loading` `success`<br>`fail` `html` | _ToastType_ | `text` |
|
||||||
| position | 位置,可选值为 `top` `bottom` | _ToastPosition_ | `middle` |
|
| position | 位置,可选值为 `top` `bottom` | _ToastPosition_ | `middle` |
|
||||||
| message | 文本内容,支持通过`\n`换行 | _string_ | `''` |
|
| message | 文本内容,支持通过`\n`换行 | _string_ | `''` |
|
||||||
|
| wordBreak | 文本内容的换行方式,可选值为 `break-normal` `break-all` `break-word` | _ToastWordBreak_ | `''` |
|
||||||
| icon | 自定义图标,支持传入图标名称或图片链接,等同于 Icon 组件的 [name 属性](#/zh-CN/icon#props) | _string_ | - |
|
| icon | 自定义图标,支持传入图标名称或图片链接,等同于 Icon 组件的 [name 属性](#/zh-CN/icon#props) | _string_ | - |
|
||||||
| iconSize | 图标大小,如 `20px` `2em`,默认单位为 `px` | _number \| string_ | `36px` |
|
| iconSize | 图标大小,如 `20px` `2em`,默认单位为 `px` | _number \| string_ | `36px` |
|
||||||
| iconPrefix | 图标类名前缀,等同于 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
| iconPrefix | 图标类名前缀,等同于 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
||||||
@ -246,7 +247,13 @@ Vant 中导出了以下 Toast 相关的辅助函数:
|
|||||||
组件导出以下类型定义:
|
组件导出以下类型定义:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import type { ToastType, ToastProps, ToastOptions, ToastPosition } from 'vant';
|
import type {
|
||||||
|
ToastType,
|
||||||
|
ToastProps,
|
||||||
|
ToastOptions,
|
||||||
|
ToastPosition,
|
||||||
|
ToastWordBreak,
|
||||||
|
} from 'vant';
|
||||||
```
|
```
|
||||||
|
|
||||||
## 主题定制
|
## 主题定制
|
||||||
|
@ -27,7 +27,7 @@ import { Popup } from '../popup';
|
|||||||
import { Loading, LoadingType } from '../loading';
|
import { Loading, LoadingType } from '../loading';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import type { ToastType, ToastPosition } from './types';
|
import type { ToastType, ToastPosition, ToastWordBreak } from './types';
|
||||||
|
|
||||||
const [name, bem] = createNamespace('toast');
|
const [name, bem] = createNamespace('toast');
|
||||||
|
|
||||||
@ -51,6 +51,7 @@ export const toastProps = {
|
|||||||
duration: makeNumberProp(2000),
|
duration: makeNumberProp(2000),
|
||||||
position: makeStringProp<ToastPosition>('middle'),
|
position: makeStringProp<ToastPosition>('middle'),
|
||||||
teleport: [String, Object] as PropType<TeleportProps['to']>,
|
teleport: [String, Object] as PropType<TeleportProps['to']>,
|
||||||
|
wordBreak: String as PropType<ToastWordBreak>,
|
||||||
className: unknownProp,
|
className: unknownProp,
|
||||||
iconPrefix: String,
|
iconPrefix: String,
|
||||||
transition: makeStringProp('van-fade'),
|
transition: makeStringProp('van-fade'),
|
||||||
@ -151,7 +152,7 @@ export default defineComponent({
|
|||||||
return () => (
|
return () => (
|
||||||
<Popup
|
<Popup
|
||||||
class={[
|
class={[
|
||||||
bem([props.position, { [props.type]: !props.icon }]),
|
bem([props.position, props.wordBreak, { [props.type]: !props.icon }]),
|
||||||
props.className,
|
props.className,
|
||||||
]}
|
]}
|
||||||
lockScroll={false}
|
lockScroll={false}
|
||||||
|
@ -35,12 +35,28 @@
|
|||||||
|
|
||||||
// allow newline character
|
// allow newline character
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
text-align: center;
|
|
||||||
// https://github.com/vant-ui/vant/issues/8959
|
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
|
text-align: center;
|
||||||
background: var(--van-toast-background);
|
background: var(--van-toast-background);
|
||||||
border-radius: var(--van-toast-radius);
|
border-radius: var(--van-toast-radius);
|
||||||
|
|
||||||
|
&--break {
|
||||||
|
&-normal {
|
||||||
|
word-break: normal;
|
||||||
|
word-wrap: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-all {
|
||||||
|
word-wrap: normal;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-word {
|
||||||
|
word-break: normal;
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&--unclickable {
|
&--unclickable {
|
||||||
// lock scroll
|
// lock scroll
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -4,6 +4,7 @@ import type { Numeric } from '../utils';
|
|||||||
|
|
||||||
export type ToastType = 'text' | 'loading' | 'success' | 'fail' | 'html';
|
export type ToastType = 'text' | 'loading' | 'success' | 'fail' | 'html';
|
||||||
export type ToastPosition = 'top' | 'middle' | 'bottom';
|
export type ToastPosition = 'top' | 'middle' | 'bottom';
|
||||||
|
export type ToastWordBreak = 'break-all' | 'break-word' | 'break-normal';
|
||||||
|
|
||||||
export type ToastOptions = {
|
export type ToastOptions = {
|
||||||
icon?: string;
|
icon?: string;
|
||||||
@ -20,6 +21,7 @@ export type ToastOptions = {
|
|||||||
className?: unknown;
|
className?: unknown;
|
||||||
transition?: string;
|
transition?: string;
|
||||||
iconPrefix?: string;
|
iconPrefix?: string;
|
||||||
|
wordBreak?: ToastWordBreak;
|
||||||
loadingType?: LoadingType;
|
loadingType?: LoadingType;
|
||||||
forbidClick?: boolean;
|
forbidClick?: boolean;
|
||||||
closeOnClick?: boolean;
|
closeOnClick?: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user