2022-03-26 22:52:54 +08:00
|
|
|
import type { ExtractPropTypes, FunctionalComponent, PropType } from 'vue';
|
2021-09-25 16:51:32 +08:00
|
|
|
import omit from '../_util/omit';
|
2021-03-16 12:54:22 +08:00
|
|
|
import warning from '../_util/warning';
|
2022-03-26 22:52:54 +08:00
|
|
|
import type { EllipsisConfig } from './Base';
|
2021-06-26 09:35:40 +08:00
|
|
|
import Base, { baseProps } from './Base';
|
2021-03-16 12:54:22 +08:00
|
|
|
|
2022-03-26 22:52:54 +08:00
|
|
|
export const textProps = () => ({
|
|
|
|
...omit(baseProps(), ['component']),
|
|
|
|
ellipsis: {
|
|
|
|
type: [Boolean, Object] as PropType<
|
|
|
|
boolean | Omit<EllipsisConfig, 'expandable' | 'rows' | 'onExpand'>
|
|
|
|
>,
|
|
|
|
default: undefined as boolean | Omit<EllipsisConfig, 'expandable' | 'rows' | 'onExpand'>,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export type TextProps = Partial<ExtractPropTypes<ReturnType<typeof textProps>>>;
|
2021-03-16 12:54:22 +08:00
|
|
|
|
|
|
|
const Text: FunctionalComponent<TextProps> = (props, { slots, attrs }) => {
|
|
|
|
const { ellipsis } = props;
|
|
|
|
warning(
|
|
|
|
typeof ellipsis !== 'object' ||
|
|
|
|
!ellipsis ||
|
|
|
|
(!('expandable' in ellipsis) && !('rows' in ellipsis)),
|
|
|
|
'Typography.Text',
|
|
|
|
'`ellipsis` do not support `expandable` or `rows` props.',
|
|
|
|
);
|
|
|
|
const textProps = {
|
|
|
|
...props,
|
|
|
|
ellipsis:
|
|
|
|
ellipsis && typeof ellipsis === 'object'
|
2021-09-25 16:51:32 +08:00
|
|
|
? omit(ellipsis as any, ['expandable', 'rows'])
|
2021-03-16 12:54:22 +08:00
|
|
|
: ellipsis,
|
|
|
|
component: 'span',
|
|
|
|
...attrs,
|
|
|
|
};
|
|
|
|
return <Base {...textProps} v-slots={slots}></Base>;
|
|
|
|
};
|
|
|
|
|
|
|
|
Text.displayName = 'ATypographyText';
|
|
|
|
Text.inheritAttrs = false;
|
2022-03-26 22:52:54 +08:00
|
|
|
Text.props = textProps();
|
2021-03-16 12:54:22 +08:00
|
|
|
|
|
|
|
export default Text;
|