Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // @flow
- import { parseColor } from './utils'
- type Props = {
- fill: string,
- fillOpacity: number,
- strokeAlign: 'center' | 'inside' | 'outside',
- strokeOpacity: number,
- strokeWeight: number,
- stroke: string,
- visible: boolean,
- }
- function shape({
- fill,
- fillOpacity,
- strokeAlign = 'outside',
- strokeOpacity,
- strokeWeight = 1,
- stroke,
- visible,
- ...styles
- }: Props) {
- if (fill) {
- styles.backgroundColor = parseColor({ base: fill, alpha: fillOpacity })
- }
- if (stroke && strokeWeight) {
- const color = parseColor({ base: stroke, alpha: strokeOpacity })
- const shadow = styles.boxShadow ? styles.boxShadow.split(', ') : []
- if (strokeAlign === 'inside') {
- shadow.push(`inset 0px 0px 0px ${strokeWeight}px ${color}`)
- } else if (strokeAlign === 'outside') {
- shadow.push(`0px 0px 0px ${strokeWeight}px ${color}`)
- } else if (strokeAlign === 'center') {
- shadow.push(`inset 0px 0px 0px ${strokeWeight / 2}px ${color}`)
- shadow.push(`0px 0px 0px ${strokeWeight / 2}px ${color}`)
- }
- styles.boxShadow = shadow.join(', ')
- }
- if (visible === false) {
- styles.visibility = 'hidden'
- }
- return styles
- }
- export default shape
Add Comment
Please, Sign In to add comment