_button.scss 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. @use 'sass:color';
  2. // Core button style
  3. // Note that these styles include methods to render buttons the same x-browser, described here:
  4. // http: //cbjdigital.com/blog/2010/08/bulletproof_css_input_button_heights
  5. // input[type=submit],
  6. // input[type=reset],
  7. // input[type=button],
  8. .button {
  9. border-radius: 3px;
  10. font-family: $font-sans;
  11. width: auto;
  12. height: 2.4em;
  13. padding: 0 1em;
  14. font-size: 0.9em;
  15. font-weight: normal;
  16. vertical-align: middle;
  17. display: inline-block;
  18. background-color: $color-button;
  19. border: 1px solid $color-button;
  20. color: $color-white;
  21. text-decoration: none;
  22. white-space: nowrap;
  23. position: relative;
  24. overflow: hidden;
  25. box-sizing: border-box;
  26. -webkit-font-smoothing: auto;
  27. // stylelint-disable-next-line property-no-vendor-prefix
  28. -moz-appearance: none;
  29. transition: background-color 0.1s ease;
  30. &:hover {
  31. color: $color-teal;
  32. }
  33. &.yes {
  34. background-color: $color-button-yes;
  35. border: 1px solid $color-button-yes;
  36. &.button-secondary {
  37. border: 1px solid $color-button-yes;
  38. color: $color-button-yes;
  39. background-color: transparent;
  40. }
  41. &:hover {
  42. color: $color-white;
  43. border-color: transparent;
  44. background-color: $color-button-yes;
  45. }
  46. }
  47. &.warning {
  48. background-color: $color-button-warning;
  49. border: 1px solid $color-button-warning;
  50. &.button-secondary {
  51. border: 1px solid $color-button-warning;
  52. color: $color-button-warning;
  53. background-color: transparent;
  54. }
  55. &:hover {
  56. color: $color-white;
  57. border-color: transparent;
  58. background-color: $color-button-warning;
  59. }
  60. }
  61. &.no,
  62. &.serious {
  63. background-color: $color-button-no;
  64. border: 1px solid $color-button-no;
  65. &.button-secondary {
  66. border: 1px solid $color-button-no;
  67. color: $color-button-no;
  68. background-color: transparent;
  69. }
  70. &:hover {
  71. color: $color-white;
  72. border-color: transparent;
  73. background-color: $color-button-no;
  74. }
  75. }
  76. &.bicolor {
  77. border: 1px solid transparent;
  78. padding-inline-start: 3.5em;
  79. &:before {
  80. // iconfont
  81. font-size: 1rem;
  82. position: absolute;
  83. inset-inline-start: 0;
  84. top: 0;
  85. width: 2em;
  86. line-height: 1.85em;
  87. height: 100%;
  88. text-align: center;
  89. background-color: theme('colors.black-20');
  90. display: block;
  91. // Remove once we drop support for Safari 14.
  92. // stylelint-disable-next-line property-disallowed-list
  93. border-top-left-radius: inherit;
  94. border-start-start-radius: inherit;
  95. // Remove once we drop support for Safari 14.
  96. // stylelint-disable-next-line property-disallowed-list
  97. border-bottom-left-radius: inherit;
  98. border-end-start-radius: inherit;
  99. }
  100. .icon-wrapper {
  101. background-color: theme('colors.black-20');
  102. display: flex;
  103. align-items: center;
  104. justify-content: center;
  105. position: absolute;
  106. inset-inline-start: 0;
  107. top: 0;
  108. width: 3em;
  109. height: 100%;
  110. box-sizing: content-box;
  111. text-align: center;
  112. // Remove once we drop support for Safari 14.
  113. // stylelint-disable-next-line property-disallowed-list
  114. border-top-left-radius: inherit;
  115. border-start-start-radius: inherit;
  116. // Remove once we drop support for Safari 14.
  117. // stylelint-disable-next-line property-disallowed-list
  118. border-bottom-left-radius: inherit;
  119. border-end-start-radius: inherit;
  120. }
  121. &.button--icon {
  122. &:before {
  123. display: none; // TODO: remove once the icon font styles are gone
  124. }
  125. }
  126. &.button--icon-flipped {
  127. .icon {
  128. transform: scaleX(-1);
  129. }
  130. }
  131. &.button-secondary {
  132. border: 1px solid theme('colors.black-20');
  133. }
  134. }
  135. &.button-small.bicolor {
  136. padding-inline-start: 3.5em;
  137. .icon-wrapper {
  138. width: 2em;
  139. }
  140. &.button--icon .icon {
  141. @include svg-icon(0.9rem);
  142. padding: 0.25em;
  143. }
  144. }
  145. // + input[type=submit],
  146. // + input[type=reset],
  147. // + input[type=button],
  148. + .button {
  149. // + button {
  150. margin-inline-start: 1em;
  151. }
  152. // A completely unstyled button
  153. &.unbutton {
  154. border-radius: 0;
  155. width: auto;
  156. height: auto;
  157. padding: 0;
  158. font-size: inherit;
  159. font-weight: normal;
  160. vertical-align: middle;
  161. display: inline;
  162. background-color: transparent;
  163. border: 0;
  164. color: inherit;
  165. text-decoration: none;
  166. white-space: nowrap;
  167. position: relative;
  168. overflow: hidden;
  169. box-sizing: border-box;
  170. -webkit-font-smoothing: auto;
  171. // stylelint-disable-next-line property-no-vendor-prefix
  172. -moz-appearance: none;
  173. &:hover,
  174. &:focus,
  175. &:active {
  176. background-color: transparent;
  177. }
  178. }
  179. // stylelint-disable-next-line no-duplicate-selectors
  180. &:hover {
  181. background-color: $color-button-hover;
  182. color: $color-white;
  183. border-color: transparent;
  184. &.hover-no {
  185. background-color: $color-button-no;
  186. }
  187. }
  188. &.button-longrunning {
  189. span {
  190. // iconfont
  191. @include transition(all 0.3s ease);
  192. transform: scale(0.9);
  193. display: inline-block;
  194. height: 0.9em;
  195. position: relative;
  196. opacity: 0;
  197. width: 0;
  198. visibility: hidden;
  199. text-align: center;
  200. padding-inline-end: 0;
  201. }
  202. em {
  203. font-style: normal;
  204. }
  205. &-active {
  206. display: inline-flex;
  207. align-items: center;
  208. }
  209. &-active span {
  210. // iconfont
  211. transform: scale(1);
  212. visibility: visible;
  213. width: 1em;
  214. height: 1em;
  215. opacity: 0.8;
  216. padding-inline-end: 0.5em;
  217. }
  218. span.icon-spinner:after {
  219. // iconfont
  220. text-align: center;
  221. position: absolute;
  222. inset-inline-start: 0;
  223. margin: 0;
  224. line-height: 1em;
  225. display: inline-block;
  226. font-size: 1em;
  227. }
  228. svg.icon-spinner {
  229. @include transition(all 0.3s ease);
  230. display: none;
  231. }
  232. &-active svg.icon-spinner {
  233. @include svg-icon();
  234. display: inline-block;
  235. opacity: 0.8;
  236. padding: 0;
  237. }
  238. &-active .button-longrunning__icon {
  239. display: none;
  240. }
  241. }
  242. &:disabled,
  243. &[disabled],
  244. &.disabled {
  245. background-color: $color-grey-3;
  246. border-color: $color-grey-3;
  247. color: $color-grey-2;
  248. cursor: default;
  249. @media (forced-colors: active) {
  250. color: GrayText;
  251. border-color: GrayText;
  252. border-style: dashed;
  253. }
  254. }
  255. &.button-secondary:disabled,
  256. &.button-secondary[disabled],
  257. &.button-secondary.disabled {
  258. background-color: $color-white;
  259. border-color: $color-grey-3;
  260. color: $color-grey-3;
  261. }
  262. &.button-strokeonhover {
  263. border: 1px solid transparent;
  264. &:hover {
  265. border-color: $color-grey-2;
  266. }
  267. }
  268. &.button--icon {
  269. .icon {
  270. @include svg-icon(1.5em);
  271. }
  272. }
  273. @include media-breakpoint-up(sm) {
  274. font-size: 0.95em;
  275. padding: 0 1.4em;
  276. height: 3em;
  277. &.bicolor {
  278. padding-inline-start: 3.7em;
  279. &:before {
  280. width: 2em;
  281. line-height: 2.2em;
  282. font-size: 1.1rem;
  283. }
  284. }
  285. &.button-small.bicolor {
  286. // line-height: 2.2em;
  287. padding-inline-start: 3em;
  288. &:before {
  289. width: 1.8em;
  290. line-height: 1.65em;
  291. }
  292. }
  293. }
  294. }
  295. .button-small {
  296. padding: 0 0.8em;
  297. height: 2em;
  298. font-size: 0.95em;
  299. }
  300. .button-secondary {
  301. color: $color-button;
  302. background-color: transparent;
  303. }
  304. // Buttons which are only an icon
  305. .button.icon.text-replace {
  306. // iconfont
  307. font-size: 0; // unavoidable duplication of setting in icons.scss
  308. width: 1.8rem;
  309. height: 1.8rem;
  310. box-sizing: content-box;
  311. &:before {
  312. line-height: 1.7em;
  313. }
  314. @include media-breakpoint-up(sm) {
  315. width: 2.2rem;
  316. height: 2.2rem;
  317. &:before {
  318. line-height: 2.1em;
  319. }
  320. &.button-small {
  321. height: 1.8rem;
  322. width: 1.8rem;
  323. &:before {
  324. line-height: 1.7em;
  325. }
  326. }
  327. }
  328. }
  329. .button--icon.text-replace {
  330. background-color: transparent;
  331. color: $color-grey-2;
  332. border-color: transparent;
  333. font-size: 0;
  334. text-align: center;
  335. &:hover {
  336. color: $color-grey-1;
  337. }
  338. .icon {
  339. font-size: initial;
  340. @include svg-icon(1rem, middle);
  341. padding: 0.5em;
  342. box-sizing: content-box;
  343. }
  344. &.button-small {
  345. line-height: 1.7rem;
  346. height: 1.8rem;
  347. width: 1.8rem;
  348. .icon {
  349. padding: 0.25em;
  350. }
  351. }
  352. @include media-breakpoint-up(sm) {
  353. width: 2.2rem;
  354. height: 2.2rem;
  355. }
  356. }
  357. button.button.bicolor .icon-wrapper {
  358. line-height: 1.65em; // work around differences in a and button elements
  359. }
  360. .button-neutral {
  361. color: $color-grey-2;
  362. &:hover {
  363. color: $color-teal;
  364. }
  365. }
  366. .yes {
  367. background-color: $color-button-yes;
  368. border: 1px solid $color-button-yes;
  369. &.button-secondary {
  370. border: 1px solid $color-button-yes;
  371. color: $color-button-yes;
  372. background-color: transparent;
  373. }
  374. &:hover {
  375. color: $color-white;
  376. border-color: transparent;
  377. background-color: $color-button-yes;
  378. }
  379. }
  380. .no,
  381. .serious {
  382. background-color: $color-button-no;
  383. border: 1px solid $color-button-no;
  384. &.button-secondary {
  385. border: 1px solid $color-button-no;
  386. color: $color-button-no;
  387. background-color: transparent;
  388. }
  389. &:hover {
  390. color: $color-white;
  391. border-color: transparent;
  392. background-color: $color-button-no;
  393. }
  394. }
  395. .bicolor {
  396. border: 0;
  397. padding-inline-start: 3.5em;
  398. &:before {
  399. font-size: 1rem;
  400. position: absolute;
  401. inset-inline-start: 0;
  402. top: 0;
  403. width: 2em;
  404. line-height: 1.85em;
  405. height: 100%;
  406. text-align: center;
  407. background-color: theme('colors.black-20');
  408. display: block;
  409. }
  410. }
  411. .button-small.bicolor {
  412. padding-inline-start: 3.5em;
  413. &:before {
  414. width: 2em;
  415. font-size: 0.8rem;
  416. line-height: 1.65em;
  417. }
  418. }
  419. a.button {
  420. line-height: 2.4em;
  421. height: auto;
  422. &.button-small {
  423. line-height: 1.85em;
  424. }
  425. @include media-breakpoint-up(sm) {
  426. line-height: 2.9em;
  427. }
  428. }
  429. // Special styles to counteract Firefox's completely unwarranted assumptions about button styles
  430. input[type='submit'],
  431. input[type='reset'],
  432. input[type='button'],
  433. button {
  434. padding: 0 1em;
  435. @include media-breakpoint-up(sm) {
  436. &.button-small {
  437. height: 2em;
  438. }
  439. }
  440. }