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.

shared.tsx 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. import { FloatingContainer } from 'components/shared'
  2. import Tooltip from 'components/tooltip'
  3. import styled from 'styles'
  4. export const ToolButton = styled('button', {
  5. position: 'relative',
  6. height: '32px',
  7. width: '32px',
  8. color: '$text',
  9. backgroundColor: '$panel',
  10. borderRadius: '4px',
  11. padding: '0',
  12. margin: '0',
  13. display: 'grid',
  14. alignItems: 'center',
  15. justifyContent: 'center',
  16. outline: 'none',
  17. border: 'none',
  18. pointerEvents: 'all',
  19. fontSize: '$0',
  20. cursor: 'pointer',
  21. '& > *': {
  22. gridRow: 1,
  23. gridColumn: 1,
  24. },
  25. '&:disabled': {
  26. opacity: '0.5',
  27. },
  28. '& > span': {
  29. width: '100%',
  30. height: '100%',
  31. display: 'flex',
  32. alignItems: 'center',
  33. },
  34. })
  35. export const PrimaryToolButton = styled(ToolButton, {
  36. variants: {
  37. bp: {
  38. mobile: {
  39. height: 44,
  40. width: 44,
  41. '& svg:nth-of-type(1)': {
  42. height: '20px',
  43. width: '20px',
  44. },
  45. },
  46. small: {
  47. '&:hover:not(:disabled)': {
  48. backgroundColor: '$hover',
  49. },
  50. },
  51. medium: {},
  52. large: {},
  53. },
  54. isActive: {
  55. true: {
  56. color: '$selected',
  57. },
  58. },
  59. },
  60. })
  61. export const SecondaryToolButton = styled(ToolButton, {
  62. variants: {
  63. bp: {
  64. mobile: {
  65. height: 44,
  66. width: 44,
  67. '& svg:nth-of-type(1)': {
  68. height: '18px',
  69. width: '18px',
  70. },
  71. },
  72. small: {
  73. '&:hover:not(:disabled)': {
  74. backgroundColor: '$hover',
  75. },
  76. },
  77. medium: {},
  78. large: {},
  79. },
  80. isActive: {
  81. true: {
  82. color: '$selected',
  83. },
  84. },
  85. },
  86. })
  87. export const TertiaryToolButton = styled(ToolButton, {
  88. variants: {
  89. bp: {
  90. mobile: {
  91. height: 32,
  92. width: 44,
  93. '& svg:nth-of-type(1)': {
  94. height: '16px',
  95. width: '16px',
  96. },
  97. },
  98. small: {
  99. height: 40,
  100. width: 40,
  101. '& svg:nth-of-type(1)': {
  102. height: '18px',
  103. width: '18px',
  104. },
  105. '&:hover:not(:disabled)': {
  106. backgroundColor: '$hover',
  107. },
  108. },
  109. medium: {},
  110. large: {},
  111. },
  112. },
  113. })
  114. interface PrimaryToolButtonProps {
  115. label: string
  116. kbd: string
  117. onClick: () => void
  118. onDoubleClick?: () => void
  119. isActive: boolean
  120. children: React.ReactNode
  121. }
  122. export function PrimaryButton({
  123. label,
  124. kbd,
  125. onClick,
  126. onDoubleClick,
  127. isActive,
  128. children,
  129. }: PrimaryToolButtonProps): JSX.Element {
  130. return (
  131. <Tooltip label={label[0].toUpperCase() + label.slice(1)} kbd={kbd}>
  132. <PrimaryToolButton
  133. name={label}
  134. bp={{
  135. '@initial': 'mobile',
  136. '@sm': 'small',
  137. '@md': 'medium',
  138. '@lg': 'large',
  139. }}
  140. onClick={onClick}
  141. onDoubleClick={onDoubleClick}
  142. isActive={isActive}
  143. >
  144. {children}
  145. </PrimaryToolButton>
  146. </Tooltip>
  147. )
  148. }
  149. interface SecondaryToolButtonProps {
  150. label: string
  151. kbd: string
  152. onClick: () => void
  153. onDoubleClick?: () => void
  154. isActive: boolean
  155. children: React.ReactNode
  156. }
  157. export function SecondaryButton({
  158. label,
  159. kbd,
  160. onClick,
  161. onDoubleClick,
  162. isActive,
  163. children,
  164. }: SecondaryToolButtonProps): JSX.Element {
  165. return (
  166. <Tooltip label={label[0].toUpperCase() + label.slice(1)} kbd={kbd}>
  167. <SecondaryToolButton
  168. name={label}
  169. bp={{
  170. '@initial': 'mobile',
  171. '@sm': 'small',
  172. '@md': 'medium',
  173. '@lg': 'large',
  174. }}
  175. onClick={onClick}
  176. onDoubleClick={onDoubleClick}
  177. isActive={isActive}
  178. >
  179. {children}
  180. </SecondaryToolButton>
  181. </Tooltip>
  182. )
  183. }
  184. interface TertiaryToolProps {
  185. label: string
  186. kbd: string
  187. onClick: () => void
  188. onDoubleClick?: () => void
  189. children: React.ReactNode
  190. }
  191. export function TertiaryButton({
  192. label,
  193. kbd,
  194. onClick,
  195. onDoubleClick,
  196. children,
  197. }: TertiaryToolProps): JSX.Element {
  198. return (
  199. <Tooltip label={label[0].toUpperCase() + label.slice(1)} kbd={kbd}>
  200. <TertiaryToolButton
  201. name={label}
  202. bp={{
  203. '@initial': 'mobile',
  204. '@sm': 'small',
  205. '@md': 'medium',
  206. '@lg': 'large',
  207. }}
  208. onClick={onClick}
  209. onDoubleClick={onDoubleClick}
  210. >
  211. {children}
  212. </TertiaryToolButton>
  213. </Tooltip>
  214. )
  215. }
  216. export const TertiaryButtonsContainer = styled(FloatingContainer, {
  217. boxShadow: '$3',
  218. variants: {
  219. bp: {
  220. mobile: {
  221. alignItems: 'center',
  222. flexDirection: 'column',
  223. },
  224. small: {
  225. alignItems: 'center',
  226. flexDirection: 'row',
  227. },
  228. },
  229. },
  230. })