2
0

_button.scss 8.3 KB

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