Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

shape-styles.ts 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.Green]: 'rgba(54, 178, 77, 1.000)',
  9. [ColorStyle.Cyan]: 'rgba(14, 152, 173, 1.000)',
  10. [ColorStyle.Blue]: 'rgba(28, 126, 214, 1.000)',
  11. [ColorStyle.Indigo]: 'rgba(66, 99, 235, 1.000)',
  12. [ColorStyle.Violet]: 'rgba(112, 72, 232, 1.000)',
  13. [ColorStyle.Red]: 'rgba(240, 63, 63, 1.000)',
  14. [ColorStyle.Orange]: 'rgba(247, 103, 6, 1.000)',
  15. [ColorStyle.Yellow]: 'rgba(245, 159, 0, 1.000)',
  16. }
  17. export const fills = {
  18. [ColorStyle.White]: 'rgba(224, 226, 230, 1.000)',
  19. [ColorStyle.LightGray]: 'rgba(255, 255, 255, 1.000)',
  20. [ColorStyle.Gray]: 'rgba(224, 226, 230, 1.000)',
  21. [ColorStyle.Black]: 'rgba(255, 255, 255, 1.000)',
  22. [ColorStyle.Green]: 'rgba(235, 251, 238, 1.000)',
  23. [ColorStyle.Cyan]: 'rgba(227, 250, 251, 1.000)',
  24. [ColorStyle.Blue]: 'rgba(231, 245, 255, 1.000)',
  25. [ColorStyle.Indigo]: 'rgba(237, 242, 255, 1.000)',
  26. [ColorStyle.Violet]: 'rgba(242, 240, 255, 1.000)',
  27. [ColorStyle.Red]: 'rgba(255, 245, 245, 1.000)',
  28. [ColorStyle.Orange]: 'rgba(255, 244, 229, 1.000)',
  29. [ColorStyle.Yellow]: 'rgba(255, 249, 219, 1.000)',
  30. }
  31. const strokeWidths = {
  32. [SizeStyle.Small]: 2,
  33. [SizeStyle.Medium]: 4,
  34. [SizeStyle.Large]: 8,
  35. }
  36. const dashArrays = {
  37. [DashStyle.Solid]: () => 'none',
  38. [DashStyle.Dashed]: (sw: number) => `${sw} ${sw * 2}`,
  39. [DashStyle.Dotted]: (sw: number) => `0 ${sw * 1.5}`,
  40. }
  41. function getStrokeWidth(size: SizeStyle) {
  42. return strokeWidths[size]
  43. }
  44. function getStrokeDashArray(dash: DashStyle, strokeWidth: number) {
  45. return dashArrays[dash](strokeWidth)
  46. }
  47. export function getShapeStyle(
  48. style: ShapeStyles
  49. ): Partial<SVGProps<SVGUseElement>> {
  50. const { color, size, dash, isFilled } = style
  51. const strokeWidth = getStrokeWidth(size)
  52. const strokeDasharray = getStrokeDashArray(dash, strokeWidth)
  53. return {
  54. stroke: strokes[color],
  55. fill: isFilled ? fills[color] : 'none',
  56. strokeWidth,
  57. strokeDasharray,
  58. }
  59. }
  60. export const defaultStyle = {
  61. color: ColorStyle.Black,
  62. size: SizeStyle.Medium,
  63. isFilled: false,
  64. dash: DashStyle.Solid,
  65. }