You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shape-styles.ts 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { SVGProps } from 'react'
  2. import { ColorStyle, DashStyle, Shape, ShapeStyles, SizeStyle } from 'types'
  3. export const strokes: Record<ColorStyle, string> = {
  4. [ColorStyle.White]: 'rgba(248, 249, 250, 1.000)',
  5. [ColorStyle.LightGray]: 'rgba(224, 226, 230, 1.000)',
  6. [ColorStyle.Gray]: 'rgba(172, 181, 189, 1.000)',
  7. [ColorStyle.Black]: 'rgba(0,0,0, 1.000)',
  8. [ColorStyle.Lime]: 'rgba(115, 184, 23, 1.000)',
  9. [ColorStyle.Green]: 'rgba(54, 178, 77, 1.000)',
  10. [ColorStyle.Teal]: 'rgba(9, 167, 120, 1.000)',
  11. [ColorStyle.Cyan]: 'rgba(14, 152, 173, 1.000)',
  12. [ColorStyle.Blue]: 'rgba(28, 126, 214, 1.000)',
  13. [ColorStyle.Indigo]: 'rgba(66, 99, 235, 1.000)',
  14. [ColorStyle.Violet]: 'rgba(112, 72, 232, 1.000)',
  15. [ColorStyle.Grape]: 'rgba(174, 62, 200, 1.000)',
  16. [ColorStyle.Pink]: 'rgba(214, 51, 108, 1.000)',
  17. [ColorStyle.Red]: 'rgba(240, 63, 63, 1.000)',
  18. [ColorStyle.Orange]: 'rgba(247, 103, 6, 1.000)',
  19. [ColorStyle.Yellow]: 'rgba(245, 159, 0, 1.000)',
  20. }
  21. export const fills = {
  22. [ColorStyle.White]: 'rgba(224, 226, 230, 1.000)',
  23. [ColorStyle.LightGray]: 'rgba(255, 255, 255, 1.000)',
  24. [ColorStyle.Gray]: 'rgba(224, 226, 230, 1.000)',
  25. [ColorStyle.Black]: 'rgba(224, 226, 230, 1.000)',
  26. [ColorStyle.Lime]: 'rgba(243, 252, 227, 1.000)',
  27. [ColorStyle.Green]: 'rgba(235, 251, 238, 1.000)',
  28. [ColorStyle.Teal]: 'rgba(230, 252, 245, 1.000)',
  29. [ColorStyle.Cyan]: 'rgba(227, 250, 251, 1.000)',
  30. [ColorStyle.Blue]: 'rgba(231, 245, 255, 1.000)',
  31. [ColorStyle.Indigo]: 'rgba(237, 242, 255, 1.000)',
  32. [ColorStyle.Violet]: 'rgba(242, 240, 255, 1.000)',
  33. [ColorStyle.Grape]: 'rgba(249, 240, 252, 1.000)',
  34. [ColorStyle.Pink]: 'rgba(254, 241, 246, 1.000)',
  35. [ColorStyle.Red]: 'rgba(255, 245, 245, 1.000)',
  36. [ColorStyle.Orange]: 'rgba(255, 244, 229, 1.000)',
  37. [ColorStyle.Yellow]: 'rgba(255, 249, 219, 1.000)',
  38. }
  39. const strokeWidths = {
  40. [SizeStyle.Small]: 2,
  41. [SizeStyle.Medium]: 4,
  42. [SizeStyle.Large]: 8,
  43. }
  44. const dashArrays = {
  45. [DashStyle.Solid]: () => 'none',
  46. [DashStyle.Dashed]: (sw: number) => `${sw} ${sw * 2}`,
  47. [DashStyle.Dotted]: (sw: number) => `0 ${sw * 1.5}`,
  48. }
  49. function getStrokeWidth(size: SizeStyle) {
  50. return strokeWidths[size]
  51. }
  52. function getStrokeDashArray(dash: DashStyle, strokeWidth: number) {
  53. return dashArrays[dash](strokeWidth)
  54. }
  55. export function getShapeStyle(
  56. style: ShapeStyles
  57. ): Partial<SVGProps<SVGUseElement>> {
  58. const { color, size, dash, isFilled } = style
  59. const strokeWidth = getStrokeWidth(size)
  60. const strokeDasharray = getStrokeDashArray(dash, strokeWidth)
  61. return {
  62. stroke: strokes[color],
  63. fill: isFilled ? fills[color] : 'none',
  64. strokeWidth,
  65. strokeDasharray,
  66. }
  67. }
  68. export const defaultStyle = {
  69. color: ColorStyle.Black,
  70. size: SizeStyle.Medium,
  71. isFilled: false,
  72. dash: DashStyle.Solid,
  73. }