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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { SVGProps } from 'react'
  2. import { ColorStyle, DashStyle, FontSize, 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. const fontSizes = {
  42. [FontSize.Small]: 16,
  43. [FontSize.Medium]: 28,
  44. [FontSize.Large]: 32,
  45. [FontSize.ExtraLarge]: 72,
  46. auto: 'auto',
  47. }
  48. function getStrokeWidth(size: SizeStyle) {
  49. return strokeWidths[size]
  50. }
  51. function getStrokeDashArray(dash: DashStyle, strokeWidth: number) {
  52. return dashArrays[dash](strokeWidth)
  53. }
  54. export function getFontSize(size: FontSize) {
  55. return fontSizes[size]
  56. }
  57. export function getFontStyle(
  58. size: FontSize,
  59. scale: number,
  60. style: ShapeStyles
  61. ) {
  62. const fontSize = getFontSize(size)
  63. return `${fontSize * scale}px/1.4 Verveine Regular`
  64. }
  65. export function getShapeStyle(
  66. style: ShapeStyles
  67. ): Partial<SVGProps<SVGUseElement>> {
  68. const { color, size, dash, isFilled } = style
  69. const strokeWidth = getStrokeWidth(size)
  70. const strokeDasharray = getStrokeDashArray(dash, strokeWidth)
  71. return {
  72. stroke: strokes[color],
  73. fill: isFilled ? fills[color] : 'none',
  74. strokeWidth,
  75. strokeDasharray,
  76. }
  77. }
  78. export const defaultStyle = {
  79. color: ColorStyle.Black,
  80. size: SizeStyle.Medium,
  81. isFilled: false,
  82. dash: DashStyle.Solid,
  83. }