radio.scss 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. @use 'sass:map';
  2. @use 'mixins/mixins' as *;
  3. @use 'mixins/utils' as *;
  4. @use 'mixins/var' as *;
  5. @use 'mixins/button' as *;
  6. @use 'common/var' as *;
  7. $radio-font-size: () !default;
  8. $radio-font-size: map.merge(
  9. (
  10. 'large': 14px,
  11. 'small': 12px,
  12. ),
  13. $radio-font-size
  14. );
  15. @include b(radio) {
  16. @include set-component-css-var('radio', $radio);
  17. }
  18. @include b(radio) {
  19. color: getCssVar('radio-text-color');
  20. font-weight: getCssVar('radio-font-weight');
  21. position: relative;
  22. cursor: pointer;
  23. display: inline-flex;
  24. align-items: center;
  25. white-space: nowrap;
  26. outline: none;
  27. font-size: getCssVar('font-size', 'base');
  28. user-select: none;
  29. margin-right: 30px;
  30. height: map.get($radio-height, 'default');
  31. @each $size in (large, small) {
  32. &.#{$namespace}-radio--#{$size} {
  33. height: map.get($radio-height, $size);
  34. }
  35. }
  36. @include when(bordered) {
  37. padding: 0 map.get($checkbox-bordered-padding-right, 'default')-$border-width
  38. 0 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. transform: translate(-50%, -50%) scale(1);
  109. }
  110. }
  111. & + .#{$namespace}-radio__label {
  112. color: map.get($radio-checked, 'text-color');
  113. }
  114. }
  115. @include when(focus) {
  116. .#{$namespace}-radio__inner {
  117. border-color: getCssVar('radio-input-border-color-hover');
  118. }
  119. }
  120. }
  121. @include e(inner) {
  122. border: getCssVar('radio-input-border');
  123. border-radius: getCssVar('radio-input-border-radius');
  124. width: getCssVar('radio-input-width');
  125. height: getCssVar('radio-input-height');
  126. background-color: getCssVar('radio-input-bg-color');
  127. position: relative;
  128. cursor: pointer;
  129. display: inline-block;
  130. box-sizing: border-box;
  131. &:hover {
  132. border-color: getCssVar('radio-input-border-color-hover');
  133. }
  134. &::after {
  135. width: 4px;
  136. height: 4px;
  137. border-radius: getCssVar('radio-input-border-radius');
  138. background-color: getCssVar('color-white');
  139. content: '';
  140. position: absolute;
  141. left: 50%;
  142. top: 50%;
  143. transform: translate(-50%, -50%) scale(0);
  144. transition: transform 0.15s ease-in;
  145. }
  146. }
  147. @include e(original) {
  148. opacity: 0;
  149. outline: none;
  150. position: absolute;
  151. z-index: -1;
  152. top: 0;
  153. left: 0;
  154. right: 0;
  155. bottom: 0;
  156. margin: 0;
  157. &:focus-visible {
  158. & + .#{$namespace}-radio__inner {
  159. outline: 2px solid getCssVar('radio-input-border-color-hover');
  160. outline-offset: 1px;
  161. border-radius: getCssVar('radio-input-border-radius');
  162. }
  163. }
  164. }
  165. &:focus:not(:focus-visible):not(.is-focus):not(:active):not(.is-disabled) {
  166. /*获得焦点时 样式提醒*/
  167. .#{$namespace}-radio__inner {
  168. box-shadow: 0 0 2px 2px getCssVar('radio-input-border-color-hover');
  169. }
  170. }
  171. @include e(label) {
  172. font-size: getCssVar('radio-font-size');
  173. padding-left: 8px;
  174. }
  175. @each $size in (large, small) {
  176. &.#{$namespace}-radio--#{$size} {
  177. @include e(label) {
  178. font-size: map.get($radio-font-size, $size);
  179. }
  180. @include e(inner) {
  181. width: map.get($radio-font-size, $size);
  182. height: map.get($radio-font-size, $size);
  183. }
  184. }
  185. }
  186. }