_radio-checkbox.scss 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. @use 'sass:math';
  2. @use '../../settings' as *;
  3. @use './input-base' as *;
  4. // 24px input widget size.
  5. $size: 1.5rem;
  6. $marker-size: 1rem;
  7. $px: 0.0625rem;
  8. $marker-offset: math.div($size - $marker-size, 2) - $px;
  9. $radio-checkbox-label-gap: theme('spacing.[2.5]');
  10. // Both input types are very similar in appearance and layout.
  11. @mixin radio-checkbox-base() {
  12. display: inline-block;
  13. position: relative;
  14. height: $size;
  15. width: $size;
  16. cursor: pointer;
  17. margin-inline-end: $radio-checkbox-label-gap;
  18. // Prevent the checkbox or radio button from shrinking when the label is long.
  19. flex-shrink: 0;
  20. @include input-base();
  21. &::before {
  22. content: '';
  23. position: absolute;
  24. top: $marker-offset;
  25. inset-inline-start: $marker-offset;
  26. width: $marker-size;
  27. height: $marker-size;
  28. }
  29. &:checked::before {
  30. background: theme('colors.border-button-outline-default');
  31. @media (forced-colors: active) {
  32. background: Highlight;
  33. }
  34. }
  35. }
  36. input[type='radio'] {
  37. @include radio-checkbox-base();
  38. // stylelint-disable-next-line no-duplicate-selectors, scss/selector-no-redundant-nesting-selector
  39. & {
  40. border-radius: theme('borderRadius.full');
  41. }
  42. &:checked::before {
  43. mask-image: url('#{$images-root}icons/radio-full.svg');
  44. }
  45. }
  46. input[type='checkbox'] {
  47. @include radio-checkbox-base();
  48. // stylelint-disable-next-line no-duplicate-selectors, scss/selector-no-redundant-nesting-selector
  49. & {
  50. border-radius: theme('borderRadius.sm');
  51. // Legacy alignment for checkboxes, particularly within listings.
  52. vertical-align: bottom;
  53. }
  54. &:checked::before {
  55. mask-image: url('#{$images-root}icons/check.svg');
  56. }
  57. }