2
0

_button.scss 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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-button-outline-hover');
  46. border-color: theme('colors.border-button-outline-hover');
  47. color: theme('colors.text-button-outline-hover');
  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.text-error');
  69. color: theme('colors.text-error');
  70. &:hover {
  71. color: theme('colors.text-button-critical-outline-hover');
  72. border-color: theme('colors.text-button-critical-outline-hover');
  73. background-color: theme('colors.surface-button-critical-hover');
  74. }
  75. }
  76. &.bicolor {
  77. padding-inline-start: 3.5em;
  78. .icon-wrapper {
  79. background-color: theme('colors.black-20');
  80. display: flex;
  81. align-items: center;
  82. justify-content: center;
  83. position: absolute;
  84. inset-inline-start: 0;
  85. top: 0;
  86. width: 3em;
  87. height: 100%;
  88. box-sizing: content-box;
  89. text-align: center;
  90. border-start-start-radius: inherit;
  91. border-end-start-radius: inherit;
  92. }
  93. &.button--icon {
  94. .icon {
  95. @include svg-icon();
  96. }
  97. }
  98. &.button--icon-flipped {
  99. .icon {
  100. transform: scaleX(-1);
  101. }
  102. }
  103. &.button-secondary {
  104. .icon-wrapper {
  105. border-inline-end: 1px solid theme('colors.surface-button-default');
  106. background-color: transparent;
  107. }
  108. &:hover {
  109. background-color: theme('colors.text-button');
  110. }
  111. &:disabled,
  112. &[disabled],
  113. &.disabled {
  114. .icon-wrapper {
  115. border-color: theme('colors.surface-button-inactive');
  116. }
  117. }
  118. }
  119. &.button-small {
  120. padding-inline-start: 3.5em;
  121. .icon-wrapper {
  122. width: theme('spacing.8');
  123. }
  124. &.button--icon .icon {
  125. @include svg-icon(0.9rem);
  126. padding: 0.25em;
  127. }
  128. &.button-secondary {
  129. border: 0;
  130. padding-inline-start: 2.2em;
  131. .icon-wrapper {
  132. border: 1px solid theme('colors.surface-button-default');
  133. border-radius: 50%;
  134. height: fit-content;
  135. width: fit-content;
  136. }
  137. &:hover {
  138. background-color: transparent;
  139. .icon-wrapper {
  140. background-color: theme('colors.surface-button-default');
  141. color: theme('colors.text-button');
  142. }
  143. }
  144. &:disabled,
  145. &[disabled],
  146. &.disabled {
  147. .icon-wrapper {
  148. background-color: transparent;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. &.button-longrunning {
  155. em {
  156. font-style: normal;
  157. }
  158. svg.icon-spinner {
  159. @include transition(all 0.3s ease);
  160. display: none;
  161. }
  162. }
  163. &.button-longrunning-active {
  164. display: inline-flex;
  165. align-items: center;
  166. svg.icon-spinner {
  167. @include svg-icon();
  168. display: inline-block;
  169. opacity: 0.8;
  170. padding: 0;
  171. margin-inline-end: 0.5em;
  172. }
  173. .button-longrunning__icon {
  174. display: none;
  175. }
  176. }
  177. // Base hover state
  178. &:hover {
  179. background-color: theme('colors.surface-button-hover');
  180. color: theme('colors.text-button');
  181. border-color: transparent;
  182. }
  183. // Disabled state
  184. &:disabled,
  185. &[disabled],
  186. &.disabled {
  187. background-color: theme('colors.surface-button-inactive');
  188. border-color: theme('colors.surface-button-inactive');
  189. color: theme('colors.text-button');
  190. cursor: default;
  191. pointer-events: none;
  192. &:hover {
  193. background-color: theme('colors.surface-button-inactive');
  194. border-color: theme('colors.surface-button-inactive');
  195. color: theme('colors.text-button');
  196. cursor: default;
  197. }
  198. @media (forced-colors: active) {
  199. color: GrayText;
  200. border-color: GrayText;
  201. border-style: dashed;
  202. }
  203. }
  204. &.button-secondary:disabled,
  205. &.button-secondary[disabled],
  206. &.button-secondary.disabled {
  207. background-color: theme('colors.surface-page');
  208. border-color: theme('colors.surface-button-inactive');
  209. color: theme('colors.text-placeholder');
  210. }
  211. // Buttons which are only an icon
  212. &.text-replace {
  213. &.button--icon {
  214. background-color: transparent;
  215. color: theme('colors.icon-secondary');
  216. border-color: transparent;
  217. font-size: 0;
  218. text-align: center;
  219. height: inherit;
  220. width: inherit;
  221. &:hover {
  222. color: theme('colors.icon-secondary-hover');
  223. }
  224. .icon {
  225. @include svg-icon(1rem, middle);
  226. font-size: initial;
  227. padding: 0.5em;
  228. box-sizing: content-box;
  229. }
  230. &.button-small {
  231. line-height: 1.75em;
  232. .icon {
  233. padding: 0.25em;
  234. }
  235. }
  236. }
  237. @include media-breakpoint-up(sm) {
  238. &.icon {
  239. &.button-small {
  240. width: 1.75em;
  241. height: 1.75em;
  242. }
  243. }
  244. }
  245. }
  246. // Larger viewport width adjustments
  247. @include media-breakpoint-up(sm) {
  248. font-size: theme('fontSize.14');
  249. padding: 0 1.4em;
  250. height: 3em;
  251. line-height: calc(3em - 2px); // account for border
  252. &.bicolor {
  253. padding-inline-start: 3.5em;
  254. &.button-small {
  255. padding-inline-start: 3em;
  256. }
  257. }
  258. }
  259. // Ensure visual consistency between button and a elements in WHCM
  260. @media (forced-colors: active) {
  261. &:not(:disabled):not(.disabled):not([disabled]) {
  262. color: ButtonText;
  263. border-color: ButtonText;
  264. &:hover {
  265. border-color: Highlight;
  266. }
  267. }
  268. }
  269. }
  270. .w-header-button {
  271. @include more-contrast-interactive();
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. gap: theme('spacing.1');
  276. height: theme('spacing.8');
  277. min-width: theme('spacing.8');
  278. appearance: none;
  279. background-color: initial;
  280. border: 1px solid transparent;
  281. color: theme('colors.text-button-outline-default');
  282. padding: 0 theme('spacing[1.5]');
  283. font-size: theme('fontSize.14');
  284. font-weight: theme('fontWeight.medium');
  285. cursor: pointer;
  286. .icon {
  287. width: theme('spacing.4');
  288. height: theme('spacing.4');
  289. padding: theme('spacing.[0.5]');
  290. border: 1px solid currentColor;
  291. border-radius: theme('borderRadius.full');
  292. transition: transform 0.3s ease;
  293. }
  294. &:hover {
  295. border-color: theme('colors.border-button-outline-hover');
  296. background-color: theme('colors.surface-button-outline-hover');
  297. }
  298. &:hover,
  299. &:focus-visible {
  300. .icon {
  301. // This ideally should use a solid variant of the icon instead.
  302. color: theme('colors.surface-page');
  303. border-color: theme('colors.text-button-outline-hover');
  304. background-color: theme('colors.text-button-outline-hover');
  305. }
  306. color: theme('colors.text-link-hover');
  307. }
  308. }