radio.scss 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. @use 'sass:map';
  2. @use 'mixins/mixins' as *;
  3. @use 'mixins/var' as *;
  4. @use 'mixins/button' as *;
  5. @use 'common/var' as *;
  6. $radio-font-size: () !default;
  7. $radio-font-size: map.merge(
  8. (
  9. 'large': 14px,
  10. 'small': 12px,
  11. ),
  12. $radio-font-size
  13. );
  14. @include b(radio) {
  15. @include set-component-css-var('radio', $radio);
  16. }
  17. @include b(radio) {
  18. color: getCssVar('radio-text-color');
  19. font-weight: getCssVar('radio-font-weight');
  20. position: relative;
  21. cursor: pointer;
  22. display: inline-flex;
  23. align-items: center;
  24. white-space: nowrap;
  25. outline: none;
  26. font-size: getCssVar('font-size', 'base');
  27. user-select: none;
  28. margin-right: 30px;
  29. height: map.get($radio-height, 'default');
  30. @each $size in (large, small) {
  31. &.#{$namespace}-radio--#{$size} {
  32. height: map.get($radio-height, $size);
  33. }
  34. }
  35. @include when(bordered) {
  36. padding: 0
  37. map.get($checkbox-bordered-padding-right, 'default')-$border-width 0
  38. map.get($checkbox-bordered-padding-left, 'default')-$border-width;
  39. border-radius: getCssVar('border-radius-base');
  40. border: getCssVar('border');
  41. box-sizing: border-box;
  42. &.is-checked {
  43. border-color: getCssVar('color-primary');
  44. }
  45. &.is-disabled {
  46. cursor: not-allowed;
  47. border-color: getCssVar('border-color-lighter');
  48. }
  49. @each $size in (large, small) {
  50. &.#{$namespace}-radio--#{$size} {
  51. padding: 0
  52. map.get($checkbox-bordered-padding-right, $size)-$border-width
  53. 0
  54. map.get($checkbox-bordered-padding-left, $size)-$border-width;
  55. border-radius: getCssVar('border-radius-base');
  56. .#{$namespace}-radio__label {
  57. font-size: map.get($button-font-size, $size);
  58. }
  59. .#{$namespace}-radio__inner {
  60. height: map.get($radio-bordered-input-height, $size);
  61. width: map.get($radio-bordered-input-width, $size);
  62. }
  63. }
  64. }
  65. }
  66. &:last-child {
  67. margin-right: 0;
  68. }
  69. @include e(input) {
  70. white-space: nowrap;
  71. cursor: pointer;
  72. outline: none;
  73. display: inline-flex;
  74. position: relative;
  75. vertical-align: middle;
  76. @include when(disabled) {
  77. .#{$namespace}-radio__inner {
  78. background-color: map.get($radio-disabled, 'input-fill');
  79. border-color: map.get($radio-disabled, 'input-border-color');
  80. cursor: not-allowed;
  81. &::after {
  82. cursor: not-allowed;
  83. background-color: map.get($radio-disabled, 'icon-color');
  84. }
  85. & + .#{$namespace}-radio__label {
  86. cursor: not-allowed;
  87. }
  88. }
  89. &.is-checked {
  90. .#{$namespace}-radio__inner {
  91. background-color: map.get($radio-disabled, 'checked-input-fill');
  92. border-color: map.get($radio-disabled, 'checked-input-border-color');
  93. &::after {
  94. background-color: map.get($radio-disabled, 'checked-icon-color');
  95. }
  96. }
  97. }
  98. & + span.#{$namespace}-radio__label {
  99. color: getCssVar('text-color', 'placeholder');
  100. cursor: not-allowed;
  101. }
  102. }
  103. @include when(checked) {
  104. .#{$namespace}-radio__inner {
  105. border-color: map.get($radio-checked, 'input-border-color');
  106. background: map.get($radio-checked, 'icon-color');
  107. &::after {
  108. background-color: getCssVar('color-white');
  109. transform: translate(-50%, -50%) scale(1);
  110. }
  111. }
  112. & + .#{$namespace}-radio__label {
  113. color: map.get($radio-checked, 'text-color');
  114. }
  115. }
  116. @include when(focus) {
  117. .#{$namespace}-radio__inner {
  118. border-color: getCssVar('radio-input-border-color-hover');
  119. }
  120. }
  121. }
  122. @include e(inner) {
  123. border: getCssVar('radio-input-border');
  124. border-radius: getCssVar('radio-input-border-radius');
  125. width: getCssVar('radio-input-width');
  126. height: getCssVar('radio-input-height');
  127. background-color: getCssVar('radio-input-bg-color');
  128. position: relative;
  129. cursor: pointer;
  130. display: inline-block;
  131. box-sizing: border-box;
  132. transition: all 0.3s;
  133. &:hover {
  134. border-color: getCssVar('radio-input-border-color-hover');
  135. }
  136. &::after {
  137. width: 4px;
  138. height: 4px;
  139. border-radius: getCssVar('radio-input-border-radius');
  140. content: '';
  141. position: absolute;
  142. left: 50%;
  143. top: 50%;
  144. transform: translate(-50%, -50%) scale(0);
  145. transition: transform 0.15s ease-in;
  146. }
  147. }
  148. @include e(original) {
  149. opacity: 0;
  150. outline: none;
  151. position: absolute;
  152. z-index: -1;
  153. top: 0;
  154. left: 0;
  155. right: 0;
  156. bottom: 0;
  157. margin: 0;
  158. &:focus-visible {
  159. & + .#{$namespace}-radio__inner {
  160. outline: 2px solid getCssVar('radio-input-border-color-hover');
  161. outline-offset: 1px;
  162. border-radius: getCssVar('radio-input-border-radius');
  163. }
  164. }
  165. }
  166. &:focus:not(:focus-visible):not(.is-focus):not(:active):not(.is-disabled) {
  167. /*获得焦点时 样式提醒*/
  168. .#{$namespace}-radio__inner {
  169. box-shadow: 0 0 2px 2px getCssVar('radio-input-border-color-hover');
  170. }
  171. }
  172. @include e(label) {
  173. font-size: getCssVar('radio-font-size');
  174. padding-left: 8px;
  175. }
  176. @each $size in (large, small) {
  177. &.#{$namespace}-radio--#{$size} {
  178. @include e(label) {
  179. font-size: map.get($radio-font-size, $size);
  180. }
  181. @include e(inner) {
  182. width: map.get($radio-font-size, $size);
  183. height: map.get($radio-font-size, $size);
  184. }
  185. }
  186. }
  187. }