Guest User

Untitled

a guest
Nov 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // @flow
  2. import { parseColor } from './utils'
  3.  
  4. type Props = {
  5. fill: string,
  6. fillOpacity: number,
  7. strokeAlign: 'center' | 'inside' | 'outside',
  8. strokeOpacity: number,
  9. strokeWeight: number,
  10. stroke: string,
  11. visible: boolean,
  12. }
  13.  
  14. function shape({
  15. fill,
  16. fillOpacity,
  17. strokeAlign = 'outside',
  18. strokeOpacity,
  19. strokeWeight = 1,
  20. stroke,
  21. visible,
  22. ...styles
  23. }: Props) {
  24. if (fill) {
  25. styles.backgroundColor = parseColor({ base: fill, alpha: fillOpacity })
  26. }
  27.  
  28. if (stroke && strokeWeight) {
  29. const color = parseColor({ base: stroke, alpha: strokeOpacity })
  30. const shadow = styles.boxShadow ? styles.boxShadow.split(', ') : []
  31. if (strokeAlign === 'inside') {
  32. shadow.push(`inset 0px 0px 0px ${strokeWeight}px ${color}`)
  33. } else if (strokeAlign === 'outside') {
  34. shadow.push(`0px 0px 0px ${strokeWeight}px ${color}`)
  35. } else if (strokeAlign === 'center') {
  36. shadow.push(`inset 0px 0px 0px ${strokeWeight / 2}px ${color}`)
  37. shadow.push(`0px 0px 0px ${strokeWeight / 2}px ${color}`)
  38. }
  39. styles.boxShadow = shadow.join(', ')
  40. }
  41.  
  42. if (visible === false) {
  43. styles.visibility = 'hidden'
  44. }
  45.  
  46. return styles
  47. }
  48.  
  49. export default shape
Add Comment
Please, Sign In to add comment