Checkbox.styles.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { css } from '@emotion/react'
  2. import styled from '@emotion/styled'
  3. import { SvgActionCheck } from '@/assets/icons'
  4. import { cVar, sizes, square, zIndex } from '@/styles'
  5. export const Container = styled.div`
  6. position: relative;
  7. z-index: 0;
  8. width: max-content;
  9. padding: ${sizes(2)};
  10. margin: -${sizes(2)};
  11. cursor: pointer;
  12. border-radius: 100%;
  13. color: ${cVar('colorCoreNeutral300')};
  14. `
  15. export const Checkmark = styled.div<{ error: boolean }>`
  16. ${square('16px')};
  17. display: flex;
  18. align-items: center;
  19. justify-content: center;
  20. transition: all ${cVar('animationTransitionFast')};
  21. border: 1px solid ${({ error }) => cVar(error ? 'colorBorderError' : 'colorBorderAlpha')};
  22. border-radius: ${cVar('radiusSmall')};
  23. position: relative;
  24. ::before {
  25. content: '';
  26. display: block;
  27. position: absolute;
  28. top: -9px;
  29. bottom: -9px;
  30. left: -9px;
  31. right: -9px;
  32. z-index: -1;
  33. border-radius: 50%;
  34. }
  35. `
  36. type CheckboxInputProps = {
  37. error: boolean
  38. }
  39. const hoverCheckedStyles = ({ error }: CheckboxInputProps) => css`
  40. + ${Checkmark} {
  41. background-color: ${cVar(error ? 'colorBackgroundErrorStrong' : 'colorBackgroundPrimaryStrong')};
  42. ::before {
  43. background-color: ${cVar('colorBackgroundStrongAlpha')};
  44. }
  45. }
  46. `
  47. const hoverUncheckedStyles = css`
  48. + ${Checkmark} {
  49. ::before {
  50. background-color: ${cVar('colorBackgroundStrongAlpha')};
  51. }
  52. }
  53. `
  54. export const CheckboxInput = styled.input<CheckboxInputProps>`
  55. ${square('100%')};
  56. top: 0;
  57. left: 0;
  58. margin: 0;
  59. opacity: 0;
  60. position: absolute;
  61. cursor: inherit;
  62. z-index: ${zIndex.overlay};
  63. :disabled:not(:checked) {
  64. + ${Checkmark} {
  65. background-color: ${cVar('colorBackgroundAlpha')};
  66. border: 1px solid ${cVar('colorBorderMutedAlpha')};
  67. }
  68. }
  69. :disabled:checked {
  70. + ${Checkmark} {
  71. background-color: ${cVar('colorBackgroundStrongAlpha')};
  72. border: 0;
  73. path {
  74. fill: ${cVar('colorTextMuted')};
  75. }
  76. }
  77. }
  78. :checked:disabled {
  79. + ${Checkmark} {
  80. background-color: ${cVar('colorBackgroundStrongAlpha')};
  81. }
  82. }
  83. :checked:not(:disabled) {
  84. :hover {
  85. ${hoverCheckedStyles}
  86. }
  87. :active {
  88. + ${Checkmark} {
  89. background-color: ${({ error }) => cVar(error ? 'colorBackgroundErrorMuted' : 'colorBackgroundPrimaryMuted')};
  90. ::before {
  91. background-color: ${cVar('colorBackgroundAlpha')};
  92. }
  93. }
  94. }
  95. + ${Checkmark} {
  96. background-color: ${({ error }) => cVar(error ? 'colorBackgroundError' : 'colorBackgroundPrimary')};
  97. border: 0;
  98. ::before {
  99. top: -8px;
  100. bottom: -8px;
  101. left: -8px;
  102. right: -8px;
  103. }
  104. }
  105. }
  106. :active:not(:checked):not(:disabled) {
  107. + ${Checkmark} {
  108. border: 1px solid ${cVar('colorBorderStrongAlpha')};
  109. ::before {
  110. background-color: ${cVar('colorBackgroundAlpha')};
  111. }
  112. }
  113. }
  114. :hover:not(:disabled):not(:active) {
  115. ${hoverUncheckedStyles}
  116. }
  117. @supports selector(:focus-visible) {
  118. :focus-visible:not(:disabled):not(:checked) {
  119. ${hoverUncheckedStyles};
  120. }
  121. :focus-visible:checked:not(:disabled):not(:active) {
  122. ${hoverCheckedStyles};
  123. }
  124. }
  125. @supports selector(not(:focus-visible)) {
  126. :focus:not(:disabled):not(:checked) {
  127. ${hoverUncheckedStyles};
  128. }
  129. :focus:checked:not(:disabled):not(:active) {
  130. ${hoverCheckedStyles};
  131. }
  132. }
  133. `
  134. export const StyledGlyphCheck = styled(SvgActionCheck)`
  135. position: absolute;
  136. `