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.

width-picker.tsx 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import * as RadioGroup from '@radix-ui/react-radio-group'
  2. import { ChangeEvent } from 'react'
  3. import { Circle } from 'react-feather'
  4. import state from 'state'
  5. import styled from 'styles'
  6. function setWidth(e: ChangeEvent<HTMLInputElement>) {
  7. state.send('CHANGED_STYLE', {
  8. strokeWidth: Number(e.currentTarget.value),
  9. })
  10. }
  11. export default function WidthPicker({
  12. strokeWidth = 2,
  13. }: {
  14. strokeWidth?: number
  15. }) {
  16. return (
  17. <Group name="width" onValueChange={setWidth}>
  18. <RadioItem value="2" isActive={strokeWidth === 2}>
  19. <Circle size={6} />
  20. </RadioItem>
  21. <RadioItem value="4" isActive={strokeWidth === 4}>
  22. <Circle size={12} />
  23. </RadioItem>
  24. <RadioItem value="8" isActive={strokeWidth === 8}>
  25. <Circle size={22} />
  26. </RadioItem>
  27. </Group>
  28. )
  29. }
  30. const Group = styled(RadioGroup.Root, {
  31. display: 'flex',
  32. })
  33. const RadioItem = styled(RadioGroup.Item, {
  34. height: '32px',
  35. width: '32px',
  36. backgroundColor: '$panel',
  37. borderRadius: '4px',
  38. padding: '0',
  39. margin: '0',
  40. display: 'flex',
  41. alignItems: 'center',
  42. justifyContent: 'center',
  43. outline: 'none',
  44. border: 'none',
  45. pointerEvents: 'all',
  46. cursor: 'pointer',
  47. '&:hover:not(:disabled)': {
  48. backgroundColor: '$hover',
  49. '& svg': {
  50. fill: '$text',
  51. strokeWidth: '0',
  52. },
  53. },
  54. '&:disabled': {
  55. opacity: '0.5',
  56. },
  57. variants: {
  58. isActive: {
  59. true: {
  60. '& svg': {
  61. fill: '$text',
  62. strokeWidth: '0',
  63. },
  64. },
  65. false: {
  66. '& svg': {
  67. fill: '$inactive',
  68. strokeWidth: '0',
  69. },
  70. },
  71. },
  72. },
  73. })