_button.scss 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. // stylelint-disable max-nesting-depth
  2. // Core button styles
  3. @use 'sass:color';
  4. .button {
  5. border-radius: theme('borderRadius.sm');
  6. width: auto;
  7. height: 2.25em;
  8. padding: 0 1em;
  9. font-size: theme('fontSize.14');
  10. font-weight: theme('fontWeight.normal');
  11. line-height: calc(2.25em - 2px); // account for border
  12. vertical-align: middle;
  13. display: inline-block;
  14. background-color: theme('colors.surface-button-default');
  15. border: 1px solid theme('colors.surface-button-default');
  16. outline-offset: $focus-outline-width;
  17. color: theme('colors.text-button');
  18. text-decoration: none;
  19. white-space: nowrap;
  20. position: relative;
  21. overflow: hidden;
  22. transition: background-color 0.1s ease;
  23. // stylelint-disable-next-line property-no-vendor-prefix
  24. -moz-appearance: none;
  25. -webkit-font-smoothing: auto;
  26. + .button {
  27. // ensure buttons can sit next to each other with a nice margin
  28. margin-inline-start: theme('spacing.4');
  29. }
  30. &.button-small {
  31. padding: 0 theme('spacing.3');
  32. height: 2em;
  33. font-size: calc(theme('fontSize.14') * 0.87);
  34. line-height: calc(2em - 2px); // account for border
  35. }
  36. &.button--icon {
  37. .icon {
  38. @include svg-icon();
  39. }
  40. }
  41. &.button-secondary {
  42. color: theme('colors.text-button-outline-default');
  43. background-color: transparent;
  44. &:hover {
  45. background-color: theme('colors.surface-page');
  46. border-color: currentColor;
  47. color: theme('colors.surface-button-default');
  48. }
  49. }
  50. &.warning {
  51. background-color: theme('colors.warning.100');
  52. border-color: theme('colors.warning.100');
  53. &.button-secondary {
  54. border-color: theme('colors.warning.100');
  55. color: theme('colors.warning.100');
  56. background-color: transparent;
  57. }
  58. &:hover {
  59. color: theme('colors.text-button');
  60. border-color: transparent;
  61. background-color: theme('colors.warning.100');
  62. }
  63. }
  64. // no/serious is not compatible with the button-secondary class
  65. &.no,
  66. &.serious {
  67. background-color: theme('colors.surface-page');
  68. border: 1px solid theme('colors.critical.200');
  69. color: theme('colors.critical.200');
  70. &:hover {
  71. color: theme('colors.critical.200');
  72. border-color: theme('colors.critical.200');
  73. background-color: theme('colors.critical.50');
  74. }
  75. }
  76. &.bicolor {
  77. padding-inline-start: 3.5em;
  78. &:before {
  79. // iconfont
  80. font-size: theme('fontSize.15');
  81. position: absolute;
  82. inset-inline-start: 0;
  83. top: 0;
  84. width: 2em;
  85. line-height: inherit;
  86. height: 100%;
  87. text-align: center;
  88. background-color: theme('colors.black-20');
  89. display: block;
  90. // Remove once we drop support for Safari 14.
  91. // stylelint-disable-next-line property-disallowed-list
  92. border-top-left-radius: inherit;
  93. border-start-start-radius: inherit;
  94. // Remove once we drop support for Safari 14.
  95. // stylelint-disable-next-line property-disallowed-list
  96. border-bottom-left-radius: inherit;
  97. border-end-start-radius: inherit;
  98. }
  99. .icon-wrapper {
  100. background-color: theme('colors.black-20');
  101. display: flex;
  102. align-items: center;
  103. justify-content: center;
  104. position: absolute;
  105. inset-inline-start: 0;
  106. top: 0;
  107. width: 3em;
  108. height: 100%;
  109. box-sizing: content-box;
  110. text-align: center;
  111. // Remove once we drop support for Safari 14.
  112. // stylelint-disable-next-line property-disallowed-list
  113. border-top-left-radius: inherit;
  114. border-start-start-radius: inherit;
  115. // Remove once we drop support for Safari 14.
  116. // stylelint-disable-next-line property-disallowed-list
  117. border-bottom-left-radius: inherit;
  118. border-end-start-radius: inherit;
  119. }
  120. &.button--icon {
  121. &:before {
  122. display: none; // TODO: remove once the icon font styles are gone
  123. }
  124. .icon {
  125. @include svg-icon();
  126. }
  127. }
  128. &.button--icon-flipped {
  129. .icon {
  130. transform: scaleX(-1);
  131. }
  132. }
  133. &.button-secondary {
  134. .icon-wrapper {
  135. border-inline-end: 1px solid theme('colors.surface-button-default');
  136. background-color: transparent;
  137. }
  138. &:hover {
  139. background-color: theme('colors.text-button');
  140. }
  141. &:disabled,
  142. &[disabled],
  143. &.disabled {
  144. .icon-wrapper {
  145. border-color: theme('colors.surface-button-inactive');
  146. }
  147. }
  148. }
  149. &.button-small {
  150. padding-inline-start: 3.5em;
  151. .icon-wrapper {
  152. width: theme('spacing.8');
  153. }
  154. &.button--icon .icon {
  155. @include svg-icon(0.9rem);
  156. padding: 0.25em;
  157. }
  158. &.button-secondary {
  159. border: 0;
  160. padding-inline-start: 2.2em;
  161. .icon-wrapper {
  162. border: 1px solid theme('colors.surface-button-default');
  163. border-radius: 50%;
  164. height: fit-content;
  165. width: fit-content;
  166. }
  167. &:hover {
  168. background-color: transparent;
  169. .icon-wrapper {
  170. background-color: theme('colors.surface-button-default');
  171. color: theme('colors.text-button');
  172. }
  173. }
  174. &:disabled,
  175. &[disabled],
  176. &.disabled {
  177. .icon-wrapper {
  178. background-color: transparent;
  179. }
  180. }
  181. }
  182. }
  183. }
  184. &.button-longrunning {
  185. span {
  186. // iconfont
  187. @include transition(all 0.3s ease);
  188. transform: scale(0.9);
  189. display: inline-block;
  190. height: 1em;
  191. position: relative;
  192. opacity: 0;
  193. width: 0;
  194. visibility: hidden;
  195. text-align: center;
  196. padding-inline-end: 0;
  197. }
  198. em {
  199. font-style: normal;
  200. }
  201. span.icon-spinner:after {
  202. // iconfont
  203. text-align: center;
  204. position: absolute;
  205. inset-inline-start: 0;
  206. margin: 0;
  207. line-height: 1em;
  208. display: inline-block;
  209. font-size: 1em;
  210. }
  211. svg.icon-spinner {
  212. @include transition(all 0.3s ease);
  213. display: none;
  214. }
  215. }
  216. &.button-longrunning-active {
  217. display: inline-flex;
  218. align-items: center;
  219. span {
  220. // iconfont
  221. transform: scale(1);
  222. visibility: visible;
  223. width: 1em;
  224. height: 1em;
  225. opacity: 0.8;
  226. padding-inline-end: 0.5em;
  227. }
  228. svg.icon-spinner {
  229. @include svg-icon();
  230. display: inline-block;
  231. opacity: 0.8;
  232. padding: 0;
  233. margin-inline-end: 0.5em;
  234. }
  235. .button-longrunning__icon {
  236. display: none;
  237. }
  238. }
  239. // Base hover state
  240. &:hover {
  241. background-color: theme('colors.surface-button-hover');
  242. color: theme('colors.text-button');
  243. border-color: transparent;
  244. }
  245. // Disabled state
  246. &:disabled,
  247. &[disabled],
  248. &.disabled {
  249. background-color: theme('colors.surface-button-inactive');
  250. border-color: theme('colors.surface-button-inactive');
  251. color: theme('colors.text-button');
  252. cursor: default;
  253. pointer-events: none;
  254. &:hover {
  255. background-color: theme('colors.surface-button-inactive');
  256. border-color: theme('colors.surface-button-inactive');
  257. color: theme('colors.text-button');
  258. cursor: default;
  259. }
  260. @media (forced-colors: active) {
  261. color: GrayText;
  262. border-color: GrayText;
  263. border-style: dashed;
  264. }
  265. }
  266. &.button-secondary:disabled,
  267. &.button-secondary[disabled],
  268. &.button-secondary.disabled {
  269. background-color: theme('colors.surface-page');
  270. border-color: theme('colors.surface-button-inactive');
  271. color: theme('colors.text-placeholder');
  272. }
  273. // Buttons which are only an icon
  274. &.text-replace {
  275. &.icon {
  276. // iconfont
  277. font-size: 0; // unavoidable duplication of setting in icons.scss
  278. height: inherit;
  279. width: inherit;
  280. box-sizing: content-box;
  281. &:before {
  282. line-height: 1.7em;
  283. }
  284. }
  285. &.button--icon {
  286. background-color: transparent;
  287. color: theme('colors.icon-secondary');
  288. border-color: transparent;
  289. font-size: 0;
  290. text-align: center;
  291. height: inherit;
  292. width: inherit;
  293. &:hover {
  294. color: theme('colors.icon-secondary-hover');
  295. }
  296. .icon {
  297. @include svg-icon(1rem, middle);
  298. font-size: initial;
  299. padding: 0.5em;
  300. box-sizing: content-box;
  301. }
  302. &.button-small {
  303. line-height: 1.75em;
  304. .icon {
  305. padding: 0.25em;
  306. }
  307. }
  308. }
  309. @include media-breakpoint-up(sm) {
  310. &.icon {
  311. &:before {
  312. line-height: 2.1em;
  313. }
  314. &.button-small {
  315. width: 1.75em;
  316. height: 1.75em;
  317. &:before {
  318. line-height: 1.7em;
  319. }
  320. }
  321. }
  322. }
  323. }
  324. // Larger viewport width adjustments
  325. @include media-breakpoint-up(sm) {
  326. font-size: theme('fontSize.14');
  327. padding: 0 1.4em;
  328. height: 3em;
  329. line-height: calc(3em - 2px); // account for border
  330. &.bicolor {
  331. padding-inline-start: 3.5em;
  332. &:before {
  333. width: 2em;
  334. font-size: theme('fontSize.16');
  335. }
  336. &.button-small {
  337. padding-inline-start: 3em;
  338. &:before {
  339. width: 1.75em;
  340. }
  341. }
  342. }
  343. }
  344. // Ensure visual consistency between button and a elements in WHCM
  345. @media (forced-colors: active) {
  346. &:not(:disabled):not(.disabled):not([disabled]) {
  347. color: ButtonText;
  348. border-color: ButtonText;
  349. &:hover {
  350. border-color: Highlight;
  351. }
  352. }
  353. }
  354. }