radio.scss 13 KB

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