import './card.scss'; import {designComponent, getComponentCls, useClasses, useRefs, useStyles} from "@peryl/react-compose"; import {unit} from "@peryl/utils/unit"; import {useStyle} from "../../uses/useStyle"; export const Card = designComponent({ name: '-card', props: { width: { type: [String, Number], default: '300' }, // 卡片宽度 noPadding: { type: Boolean }, // 去掉标题以及内容的内边距 mini: { type: Boolean }, // 小型卡片 shadow: { type: String, default: 'normal' }, // 阴影, normal,hover title: { type: String }, // 卡片标题 }, slots: [ 'head', 'desc', 'default', 'operator', 'poster', 'foot', ], inheritPropsType: HTMLDivElement, setup({ props, slots }) { const { refs, onRef } = useRefs({ el: HTMLDivElement }); useStyle({ adjust: data => {if (props.mini) {data.size = 'mini';}} }); const classes = useClasses(() => [ getComponentCls('card'), { 'card-mini': props.mini, 'card-no-padding': props.noPadding, [`card-shadow-${props.shadow}`]: !!props.shadow, } ]); const styles = useStyles(style => { !!props.width && (style.width = unit(props.width)); }); return { refer: { refs, }, render: () => (
{slots.poster.isExist() &&
{slots.poster()}
} {(props.title || slots.head.isExist() || slots.desc.isExist() || slots.operator.isExist()) && (
{(props.title || slots.head.isExist()) &&
{slots.head(props.title)}
} {slots.operator.isExist() &&
{slots.operator()}
}
)} {(slots.desc.isExist()) &&
{slots.desc()}
} {slots.default.isExist() &&
{slots.default()}
} {slots.foot.isExist() &&
{slots.foot()}
}
) }; }, }); export default Card;