radio.scss 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. @import "./animation.scss";
  2. @import "./variables.scss";
  3. $module: #{$prefix}-radio;
  4. $inner-width: $width-icon-medium;
  5. .#{$module} {
  6. @include box-sizing;
  7. @include font-size-regular;
  8. position: relative;
  9. display: inline-flex;
  10. column-gap: $spacing-radio_addon-paddingLeft;
  11. transition: background-color $transition_duration-radio-bg $transition_function-radio-bg $transition_delay-radio-bg,
  12. border $transition_duration-radio-border $transition_function-radio-border $transition_delay-radio-border;
  13. &.#{$module}-vertical {
  14. display: block;
  15. }
  16. min-height: $height-radio_inner_min;
  17. min-width: $width-radio_inner;
  18. cursor: pointer;
  19. vertical-align: bottom;
  20. text-align: left;
  21. input[type="checkbox"],
  22. input[type="radio"] {
  23. position: absolute;
  24. left: 0;
  25. top: 0;
  26. opacity: 0;
  27. width: 100%;
  28. height: 100%;
  29. margin: 0;
  30. cursor: pointer;
  31. }
  32. &:hover {
  33. .#{$module}-inner-display {
  34. background: $color-radio_default-bg-hover;
  35. border: solid $width-radio_hover-border $color-radio_default-border-hover;
  36. }
  37. &.#{$module}-cardRadioGroup {
  38. .#{$module}-inner-display {
  39. background: $color-radio_card-bg-hover;
  40. }
  41. }
  42. .#{$module}-inner-checked {
  43. .#{$module}-inner-display {
  44. background: $color-radio_primary-bg-hover;
  45. border-color: $color-radio_checked-border-hover;
  46. }
  47. }
  48. }
  49. &:active {
  50. .#{$module}-inner-display {
  51. background: $color-radio_default-bg-active;
  52. }
  53. &.#{$module}-cardRadioGroup {
  54. .#{$module}-inner-display {
  55. background: $color-radio_card-bg-active;
  56. }
  57. }
  58. .#{$module}-inner-checked {
  59. .#{$module}-inner-display {
  60. background: $color-radio_primary-bg-active;
  61. border-color: $color-radio_checked-border-active;
  62. }
  63. }
  64. }
  65. &-buttonRadioComponent {
  66. padding: $spacing-radio_buttonRadio-padding;
  67. background: $color-radio_buttonRadio-bg-default;
  68. border-radius: $radius-radio_buttonRadio;
  69. }
  70. &-buttonRadioGroup {
  71. // Button needs to be positioned relative to parent
  72. position: relative;
  73. padding: $spacing-radio_buttonRadioGroup_middle-padding;
  74. border-radius: $radius-radio_buttonRadio;
  75. line-height: $font-radio_buttonRadioGroup_middle-lineHeight;
  76. &:not(:last-child) {
  77. padding-right: $spacing-radio_buttonRadioGroup-paddingRight;
  78. }
  79. &-small {
  80. padding: $spacing-radio_buttonRadioGroup_small-paddingX $spacing-radio_buttonRadioGroup_small-paddingY;
  81. line-height: $font-radio_buttonRadioGroup_small-lineHeight;
  82. }
  83. &-large {
  84. padding: $spacing-radio_buttonRadioGroup_large-padding;
  85. line-height: $font-radio_buttonRadioGroup_large-lineHeight;
  86. }
  87. }
  88. &-cardRadioGroup {
  89. flex-wrap: nowrap;
  90. border-radius: $radius-radio_cardRadioGroup;
  91. padding: $spacing-radio_cardRadioGroup-paddingY $spacing-radio_cardRadioGroup-paddingX;
  92. background: $color-radio_cardRadioGroup-bg-default;
  93. border: $width-radio_cardRadioGroup_checked-border solid $color-radio_cardRadioGroup_border-default;
  94. transition: background-color $transition_duration_radio-bg $transition_function-radio-bg $transition_delay-radio-bg,
  95. border $transition_duration-radio-border $transition_function-radio-border $transition_delay-radio-border;
  96. .#{$module}-inner {
  97. &-display {
  98. background: $color-radio_card-bg-default;
  99. }
  100. flex-shrink: 0;
  101. }
  102. .#{$module}-addon {
  103. font-weight: $font-radio_cardRadioGroup_addon-fontWeight;
  104. font-size: $font-radio_cardRadioGroup_addon-size;
  105. line-height: $font-radio_cardRadioGroup_addon-lineHeight;
  106. color: $color-radio_cardRadioGroup_addon-text-default;
  107. }
  108. .#{$module}-extra {
  109. font-weight: $font-radio_cardRadioGroup_extra-fontWeight;
  110. font-size: $font-radio_cardRadioGroup_extra-size;
  111. line-height: $font-radio_cardRadioGroup_extra-lineHeight;
  112. color: $color-radio_cardRadioGroup_extra-text-default;
  113. padding-left: 0;
  114. }
  115. &:active {
  116. background: $color-radio_cardRadioGroup-bg-active;
  117. }
  118. &_checked {
  119. background: $color-radio_cardRadioGroup-bg-checked;
  120. border: $width-radio_cardRadioGroup_checked-border solid $color-radio_cardRadioGroup_border-active;
  121. &:hover {
  122. border: $width-radio_cardRadioGroup_checked-border solid $color-radio_cardRadioGroup_checked_border-hover;
  123. .#{$module}-inner-checked .#{$module}-inner-display {
  124. border-color: $color-radio_cardRadioGroup_checked_border-hover;
  125. }
  126. }
  127. &:active {
  128. background: $color-radio_cardRadioGroup-bg-checked;
  129. border: $width-radio_cardRadioGroup_checked-border solid $color-radio_cardRadioGroup_checked_border-active;
  130. .#{$module}-inner-checked {
  131. .#{$module}-inner-display {
  132. border-color: $color-radio_cardRadioGroup_checked_border-active;
  133. }
  134. &:hover .#{$module}-inner-display {
  135. background: $color-radio_primary-bg-active;
  136. }
  137. }
  138. }
  139. }
  140. &_hover {
  141. background: $color-radio_cardRadioGroup-bg-hover;
  142. }
  143. &_disabled {
  144. &:active {
  145. background: $color-radio_cardRadioGroup_disabled-bg-active;
  146. }
  147. }
  148. &_checked_disabled.#{$module}-cardRadioGroup {
  149. background: $color-radio_cardRadioGroup_disabled-bg-checked;
  150. border: $width-radio_cardRadioGroup_checked_disabled-border solid $color-radio_cardRadioGroup_border_disabled-active;
  151. .#{$module}-inner-checked .#{$module}-inner-display {
  152. border-color: $color-radio_cardRadioGroup_checked_disabled-border-default;
  153. }
  154. &:hover {
  155. .#{$module}-inner-checked .#{$module}-inner-display {
  156. border-color: $color-radio_cardRadioGroup_checked_disabled-border-hover;
  157. }
  158. }
  159. }
  160. }
  161. &.#{$module}-disabled:hover,
  162. &.#{$module}-disabled:active {
  163. .#{$module}-inner-display {
  164. background: $color-radio_disabled-bg-default;
  165. border: solid $width-radio_disabled-border $color-radio_disabled-border-default;
  166. }
  167. .#{$module}-inner-checked {
  168. .#{$module}-inner-display {
  169. background: $color-radio_checked-bg-disabled;
  170. border-color: $color-radio_checked-border-disabled;
  171. }
  172. }
  173. }
  174. &-inner {
  175. display: inline-flex;
  176. margin-top: 2px;
  177. // WARN: The absolute positioning used by the input does not occupy space, and relative cannot be removed here.
  178. position: relative;
  179. width: $width-radio_inner;
  180. height: $width-radio_inner;
  181. vertical-align: sub;
  182. user-select: none; // prevent text under it will be selected when double click
  183. &-display {
  184. display: inline-flex;
  185. align-items: center;
  186. justify-content: center;
  187. @include box-sizing;
  188. width: $width-radio_inner;
  189. height: $width-radio_inner;
  190. border: solid $width-radio_innder-border $color-radio_default-border-default;
  191. border-radius: $width-radio_inner;
  192. background: $color-radio_default-bg-default;
  193. transition: background-color $transition_duration-radio-bg $transition_function-radio-bg $transition_delay-radio-bg,
  194. border $transition_duration-radio-border $transition_function-radio-border $transition_delay-radio-border;
  195. .#{$prefix}-icon {
  196. width: 100%;
  197. height: 100%;
  198. font-size: 14px;
  199. }
  200. }
  201. }
  202. &-content {
  203. display: flex;
  204. flex-direction: column;
  205. row-gap: $spacing-radio_content-rowGap;
  206. }
  207. &:hover {
  208. .#{$module}-inner-display {
  209. background: $color-radio_default-bg-hover;
  210. }
  211. }
  212. &:active {
  213. .#{$module}-inner-display {
  214. background: $color-radio_default-bg-active;
  215. }
  216. }
  217. &-addon {
  218. user-select: none;
  219. color: $color-radio_default-text-default;
  220. display: inline-flex;
  221. align-items: center;
  222. &-buttonRadio {
  223. text-align: center;
  224. border-radius: $radius-radio_addon_buttonRadio;
  225. font-weight: $font-radio_buttonRadio-default-fontWeight;
  226. color: $color-radio_buttonRadio-text-default;
  227. font-size: $font-radio_buttonRadio_middle-default-size;
  228. padding: $spacing-radio_addon_buttonRadio_middle-paddingY $spacing-radio_addon_buttonRadio_middle-paddingX;
  229. transition: background-color $transition_duration-radio-bg $transition_function-radio-bg $transition_delay-radio-bg,
  230. border $transition_duration-radio-border $transition_function-radio-border $transition_delay-radio-border;
  231. &-hover {
  232. font-weight: $font-radio_buttonRadio-hover-fontWeight;
  233. background: $color-radio_addon_buttonRadio-bg-hover;
  234. }
  235. &-checked {
  236. font-weight: $font-radio_buttonRadio-checked-fontWeight;
  237. background: $color-radio_addon_buttonRadio-bg-checked;
  238. color: $color-radio_addon_buttonRadio-text-checked;
  239. }
  240. &-disabled {
  241. cursor: not-allowed;
  242. color: $color-radio_buttonRadio-text-disabled;
  243. }
  244. &-small {
  245. font-size: $font-radio_buttonRadio_small-default-size;
  246. padding: $spacing-radio_addon_buttonRadio_small-paddingY $spacing-radio_addon_buttonRadio_small-paddingX;
  247. }
  248. &-large {
  249. font-size: $font-radio_buttonRadio_large-default-size;
  250. padding: $spacing-radio_addon_buttonRadio_large-paddingY $spacing-radio_addon_buttonRadio_large-paddingX;
  251. }
  252. }
  253. }
  254. .#{$module}-inner-checked {
  255. &:hover {
  256. .#{$module}-inner-display {
  257. background: $color-radio_primary-bg-hover;
  258. }
  259. }
  260. &:active {
  261. .#{$module}-inner-display {
  262. background: $color-radio_primary-bg-active;
  263. }
  264. }
  265. .#{$module}-inner-display {
  266. border: solid $width-radio_innder-border $color-radio_primary-border-default;
  267. background: $color-radio_primary-bg-default;
  268. color: $color-radio_primary-text-default;
  269. border-radius: $width-radio_inner;
  270. }
  271. >.#{$module}-addon {
  272. color: $color-radio_default-text-default;
  273. }
  274. }
  275. // A11y: arrow keyboard control
  276. .#{$module}-inner-buttonRadio,
  277. .#{$module}-inner-pureCardRadio {
  278. position: absolute;
  279. top: 0;
  280. left: 0;
  281. width: 100%;
  282. height: 100%;
  283. margin-top: 0; // when type= button/card/pureCard, reset margin
  284. z-index: -1;
  285. opacity: 0;
  286. }
  287. &-disabled {
  288. &,
  289. &:hover {
  290. cursor: not-allowed;
  291. }
  292. .#{$module}-inner {
  293. cursor: not-allowed;
  294. &-display {
  295. opacity: 0.75;
  296. background: $color-radio_disabled-bg-default;
  297. border-color: $color-radio_default-border-disabled;
  298. &:hover {
  299. background: $color-radio_disabled-bg-hover;
  300. }
  301. }
  302. }
  303. .#{$module}-inner-checked {
  304. .#{$module}-inner-display {
  305. background: $color-radio_checked-bg-disabled;
  306. border-color: $color-radio_checked-border-disabled;
  307. &:hover {
  308. background: $color-radio_checked-bg-disabled;
  309. border-color: $color-radio_checked-border-disabled;
  310. }
  311. }
  312. }
  313. .#{$module}-addon {
  314. color: $color-radio_disabled-text-default;
  315. }
  316. .#{$module}-extra {
  317. color: $color-radio_disabled-text-default;
  318. }
  319. }
  320. &-extra {
  321. color: $color-radio_extra-text-default;
  322. box-sizing: border-box;
  323. }
  324. &-focus {
  325. outline: $width-radio-outline solid $color-radio_primary-outline-focus;
  326. &-border {
  327. border: solid $width-radio_hover-border $color-radio_default-border-hover;
  328. }
  329. }
  330. }
  331. .#{$module}Group {
  332. @include font-size-regular;
  333. &-vertical {
  334. display: flex;
  335. flex-direction: column;
  336. row-gap: $spacing-radio_group_vertical-marginBottom;
  337. &-default {
  338. .#{$module} {
  339. display: flex;
  340. }
  341. }
  342. &-card {
  343. .#{$module} {
  344. display: flex;
  345. }
  346. }
  347. }
  348. &-horizontal {
  349. display: inline-flex;
  350. flex-wrap: wrap;
  351. vertical-align: bottom; // Fix 1573
  352. gap: $spacing-radio_group_horizontal-marginRight;
  353. }
  354. &-buttonRadio {
  355. display: inline-block;
  356. background: $color-radio_buttonRadio-bg-default;
  357. border-radius: $radius-radio_buttonRadio;
  358. vertical-align: middle;
  359. }
  360. }
  361. @import "./rtl.scss";