import {designComponent, getComponentCls, PropType, useClassCache, useStyleCache} from "@peryl/react-compose"; import {StyleProps, useStyle} from "../../uses/useStyle"; import {unit} from "@peryl/utils/unit"; import './corner.scss'; import {createEnum} from "@peryl/utils/createEnum"; const eCornerType = createEnum([ 'bottom-left', 'bottom-right', 'top-left', 'top-right', 'left-top', 'left-bottom', 'right-top', 'right-bottom', ] as const); export const Corner = designComponent({ name: 'corner', props: { ...StyleProps, customSize: { type: String }, type: { type: String as PropType, required: true }, color: { type: String }, }, setup({ props }) { const { styleComputed } = useStyle(); const classes = useClassCache(() => [ getComponentCls('corner'), { [`corner-status-${props.status}`]: !!props.status, [`corner-size-${styleComputed.value.size}`]: !props.customSize, }, ]); const styles = useStyleCache((style) => { if (!!props.customSize) { style.height = unit(props.customSize); style.width = unit(props.customSize); } if (!!props.color) { style.color = props.color; } }); return () => { return ( ); }; }, }); const pathDValues = { 1: 'M 100 0 L 100 100 L 0 100 A 100 100 0 0 0 100 0 Z', 2: 'M 0 0 L 0 100 L 100 100 A 100 100 0 0 1 0 0 Z', 3: 'M 0 0 L 100 0 L 100 100 A 100 100 0 0 0 0 0', 4: 'M 100 0 L 0 0 L 0 100 A 100 100 0 0 1 100 0', }; const type2key: Record = { [eCornerType["bottom-left"]]: 1 as const, [eCornerType["right-top"]]: 1 as const, [eCornerType["bottom-right"]]: 2 as const, [eCornerType["left-top"]]: 2 as const, [eCornerType["top-left"]]: 3 as const, [eCornerType["right-bottom"]]: 3 as const, [eCornerType["top-right"]]: 4 as const, [eCornerType["left-bottom"]]: 4 as const, }; export default Corner;