/** * border 规则 */ import { UNIT_STR, DIRECTION_MAP, NONNEGATIVE_NUMBER_REGEX_STR } from '../constant'; const getCss = (direction: any, num: any, unit: any) => { return DIRECTION_MAP .get(direction) .reduce((t: any, c: any) => { if (c) { return [...t, `border-${c}-width: ${num}${unit}`, `border-${c}-style: solid`, `border-${c}-color: rgba(0,0,0,1)`]; } else { return [...t, `border-width: ${num}${unit}`, `border-style: solid`, `border-color: rgba(0,0,0,1)`]; } }, []) } export default { regExp: new RegExp(`^(border|border-width|border-w)-((?[trblxy])-)?(?${NONNEGATIVE_NUMBER_REGEX_STR})(?${UNIT_STR})?$`), render({ grops }) { const { direction, num, unit } = grops; return { name: direction ? `border-${direction}` : 'border', num, css: getCss(direction, num, unit) } }, }