|
| 1 | +import Notice from '../vc-notification/Notice'; |
| 2 | +import type { NoticeProps } from '../vc-notification/Notice'; |
| 3 | +import useStyle from './style'; |
| 4 | +import type { NoticeType } from './interface'; |
| 5 | +import { |
| 6 | + CheckCircleFilled, |
| 7 | + CloseCircleFilled, |
| 8 | + ExclamationCircleFilled, |
| 9 | + InfoCircleFilled, |
| 10 | + LoadingOutlined, |
| 11 | +} from '@ant-design/icons-vue'; |
| 12 | +import type { VueNode } from '../_util/type'; |
| 13 | +import classNames from '../_util/classNames'; |
| 14 | +import { useConfigContextInject } from '../config-provider/context'; |
| 15 | +import { computed, defineComponent } from 'vue'; |
| 16 | + |
| 17 | +export const TypeIcon = { |
| 18 | + info: <InfoCircleFilled />, |
| 19 | + success: <CheckCircleFilled />, |
| 20 | + error: <CloseCircleFilled />, |
| 21 | + warning: <ExclamationCircleFilled />, |
| 22 | + loading: <LoadingOutlined />, |
| 23 | +}; |
| 24 | + |
| 25 | +export interface PureContentProps { |
| 26 | + prefixCls: string; |
| 27 | + type?: NoticeType; |
| 28 | + icon?: VueNode; |
| 29 | + children: VueNode; |
| 30 | +} |
| 31 | + |
| 32 | +export const PureContent = defineComponent({ |
| 33 | + name: 'PureContent', |
| 34 | + inheritAttrs: false, |
| 35 | + props: ['prefixCls', 'type', 'icon'] as any, |
| 36 | + |
| 37 | + setup(props, { slots }) { |
| 38 | + return () => ( |
| 39 | + <div |
| 40 | + class={classNames(`${props.prefixCls}-custom-content`, `${props.prefixCls}-${props.type}`)} |
| 41 | + > |
| 42 | + {props.icon || TypeIcon[props.type!]} |
| 43 | + <span>{slots.default?.()}</span> |
| 44 | + </div> |
| 45 | + ); |
| 46 | + }, |
| 47 | +}); |
| 48 | + |
| 49 | +export interface PurePanelProps |
| 50 | + extends Omit<NoticeProps, 'prefixCls' | 'eventKey'>, |
| 51 | + Omit<PureContentProps, 'prefixCls' | 'children'> { |
| 52 | + prefixCls?: string; |
| 53 | +} |
| 54 | + |
| 55 | +/** @private Internal Component. Do not use in your production. */ |
| 56 | + |
| 57 | +export default defineComponent({ |
| 58 | + name: 'PurePanel', |
| 59 | + inheritAttrs: false, |
| 60 | + props: ['prefixCls', 'class', 'type', 'icon', 'content'] as any, |
| 61 | + setup(props, { slots, attrs }) { |
| 62 | + const { getPrefixCls } = useConfigContextInject(); |
| 63 | + const prefixCls = computed(() => props.staticPrefixCls || getPrefixCls('message')); |
| 64 | + const [, hashId] = useStyle(prefixCls); |
| 65 | + return ( |
| 66 | + <Notice |
| 67 | + {...attrs} |
| 68 | + prefixCls={prefixCls.value} |
| 69 | + class={classNames(hashId, `${prefixCls.value}-notice-pure-panel`)} |
| 70 | + noticeKey="pure" |
| 71 | + duration={null} |
| 72 | + > |
| 73 | + <PureContent prefixCls={props.prefixCls} type={props.type} icon={props.icon}> |
| 74 | + {slots.default?.()} |
| 75 | + </PureContent> |
| 76 | + </Notice> |
| 77 | + ); |
| 78 | + }, |
| 79 | +}); |
0 commit comments