Created
November 22, 2017 07:52
-
-
Save souporserious/cc3fbe5e016b7fb2bc97f1bf557c74eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment