button.scss 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. @use 'sass:map';
  2. @use 'common/var' as *;
  3. @use 'mixins/button' as *;
  4. @use 'mixins/mixins' as *;
  5. @use 'mixins/var' as *;
  6. $button-icon-span-gap: () !default;
  7. $button-icon-span-gap: map.merge(
  8. (
  9. 'large': 8px,
  10. 'default': 6px,
  11. 'small': 4px,
  12. ),
  13. $button-icon-span-gap
  14. );
  15. @include b(button) {
  16. @include set-component-css-var('button', $button);
  17. }
  18. @include b(button) {
  19. display: inline-flex;
  20. justify-content: center;
  21. align-items: center;
  22. line-height: 1;
  23. // min-height will expand when in flex
  24. height: map.get($input-height, 'default');
  25. white-space: nowrap;
  26. cursor: pointer;
  27. color: getCssVar('button', 'text-color');
  28. text-align: center;
  29. box-sizing: border-box;
  30. outline: none;
  31. transition: 0.1s;
  32. font-weight: getCssVar('button', 'font-weight');
  33. user-select: none;
  34. vertical-align: middle;
  35. -webkit-appearance: none;
  36. background-color: getCssVar('button', 'bg-color');
  37. border: getCssVar('border');
  38. border-color: getCssVar('button', 'border-color');
  39. &:hover {
  40. color: getCssVar('button', 'hover', 'text-color');
  41. border-color: getCssVar('button', 'hover', 'border-color');
  42. background-color: getCssVar('button', 'hover', 'bg-color');
  43. outline: none;
  44. }
  45. &:active {
  46. color: getCssVar('button', 'active', 'text-color');
  47. border-color: getCssVar('button', 'active', 'border-color');
  48. background-color: getCssVar('button', 'active', 'bg-color');
  49. outline: none;
  50. }
  51. &:focus-visible {
  52. outline: 2px solid getCssVar('button', 'outline-color');
  53. outline-offset: 1px;
  54. transition:
  55. outline-offset 0s,
  56. outline 0s;
  57. }
  58. > span {
  59. display: inline-flex;
  60. align-items: center;
  61. }
  62. & + & {
  63. margin-left: 12px;
  64. }
  65. & {
  66. @include button-size(
  67. map.get($button-padding-vertical, 'default') - $button-border-width,
  68. map.get($button-padding-horizontal, 'default') - $button-border-width,
  69. map.get($button-font-size, 'default'),
  70. map.get($button-border-radius, 'default')
  71. );
  72. }
  73. &::-moz-focus-inner {
  74. border: 0;
  75. }
  76. & [class*='#{$namespace}-icon'] {
  77. & + span {
  78. margin-left: map.get($button-icon-span-gap, 'default');
  79. }
  80. svg {
  81. vertical-align: bottom;
  82. }
  83. }
  84. @include when(plain) {
  85. @include css-var-from-global(
  86. ('button', 'hover', 'text-color'),
  87. ('color', 'primary')
  88. );
  89. @include css-var-from-global(
  90. ('button', 'hover', 'bg-color'),
  91. ('fill-color', 'blank')
  92. );
  93. @include css-var-from-global(
  94. ('button', 'hover', 'border-color'),
  95. ('color', 'primary')
  96. );
  97. }
  98. @include when(active) {
  99. color: getCssVar('button', 'active', 'text-color');
  100. border-color: getCssVar('button', 'active', 'border-color');
  101. background-color: getCssVar('button', 'active', 'bg-color');
  102. outline: none;
  103. }
  104. @include when(disabled) {
  105. &,
  106. &:hover {
  107. color: getCssVar('button', 'disabled', 'text-color');
  108. cursor: not-allowed;
  109. background-image: none;
  110. background-color: getCssVar('button', 'disabled', 'bg-color');
  111. border-color: getCssVar('button', 'disabled', 'border-color');
  112. }
  113. }
  114. @include when(loading) {
  115. position: relative;
  116. pointer-events: none;
  117. &:before {
  118. // mask the button
  119. z-index: 1;
  120. pointer-events: none;
  121. content: '';
  122. position: absolute;
  123. left: -1px;
  124. top: -1px;
  125. right: -1px;
  126. bottom: -1px;
  127. border-radius: inherit;
  128. background-color: getCssVar('mask-color', 'extra-light');
  129. }
  130. }
  131. @include when(round) {
  132. border-radius: getCssVar('border-radius', 'round');
  133. }
  134. @include when(dashed) {
  135. border-style: dashed;
  136. @include css-var-from-global(
  137. ('button', 'hover', 'text-color'),
  138. ('color', 'primary')
  139. );
  140. @include css-var-from-global(
  141. ('button', 'hover', 'bg-color'),
  142. ('fill-color', 'blank')
  143. );
  144. @include css-var-from-global(
  145. ('button', 'hover', 'border-color'),
  146. ('color', 'primary')
  147. );
  148. }
  149. @include when(circle) {
  150. width: map.get($input-height, 'default');
  151. border-radius: 50%;
  152. padding: map.get($button-padding-vertical, 'default') - $button-border-width;
  153. }
  154. @include when(text) {
  155. color: getCssVar('button', 'text-color');
  156. border: 0 solid transparent;
  157. background-color: transparent;
  158. @include when(disabled) {
  159. color: getCssVar('button', 'disabled', 'text-color');
  160. background-color: transparent !important;
  161. }
  162. &:not(.is-disabled) {
  163. &:hover {
  164. background-color: getCssVar('fill-color', 'light');
  165. }
  166. &:focus-visible {
  167. outline: 2px solid getCssVar('button', 'outline-color');
  168. outline-offset: 1px;
  169. transition:
  170. outline-offset 0s,
  171. outline 0s;
  172. }
  173. &:active {
  174. background-color: getCssVar('fill-color');
  175. }
  176. @include when(has-bg) {
  177. background-color: getCssVar('fill-color', 'light');
  178. &:hover {
  179. background-color: getCssVar('fill-color');
  180. }
  181. &:active {
  182. background-color: getCssVar('fill-color', 'dark');
  183. }
  184. }
  185. }
  186. }
  187. @include e(text) {
  188. @include m(expand) {
  189. letter-spacing: 0.3em;
  190. margin-right: -0.3em;
  191. }
  192. }
  193. @include when(link) {
  194. border-color: transparent;
  195. color: getCssVar('button', 'text-color');
  196. background: transparent;
  197. padding: 2px;
  198. height: auto;
  199. &:hover {
  200. color: getCssVar('button', 'hover', 'link-text-color');
  201. }
  202. @include when(disabled) {
  203. color: getCssVar('button', 'disabled', 'text-color');
  204. background-color: transparent !important;
  205. border-color: transparent !important;
  206. }
  207. &:not(.is-disabled) {
  208. &:hover {
  209. border-color: transparent;
  210. background-color: transparent;
  211. }
  212. &:active {
  213. color: getCssVar('button', 'active-color');
  214. border-color: transparent;
  215. background-color: transparent;
  216. }
  217. }
  218. }
  219. @include m(text) {
  220. border-color: transparent;
  221. background: transparent;
  222. color: getCssVar('color', 'primary');
  223. padding-left: 0;
  224. padding-right: 0;
  225. @include when(disabled) {
  226. color: getCssVar('button', 'disabled', 'text-color');
  227. background-color: transparent !important;
  228. border-color: transparent !important;
  229. }
  230. &:not(.is-disabled) {
  231. &:hover {
  232. color: getCssVar('color', 'primary', 'light-3');
  233. border-color: transparent;
  234. background-color: transparent;
  235. }
  236. &:active {
  237. color: getCssVar('color', 'primary', 'dark-2');
  238. border-color: transparent;
  239. background-color: transparent;
  240. }
  241. }
  242. }
  243. @include e(link) {
  244. @include m(expand) {
  245. letter-spacing: 0.3em;
  246. margin-right: -0.3em;
  247. }
  248. }
  249. @each $type in (primary, success, warning, danger, info) {
  250. @include m($type) {
  251. @include button-variant($type);
  252. }
  253. }
  254. @each $size in (large, small) {
  255. @include m($size) {
  256. @include set-css-var-value(
  257. ('button', 'size'),
  258. map.get($input-height, $size)
  259. );
  260. height: getCssVar('button', 'size');
  261. & [class*='#{$namespace}-icon'] {
  262. & + span {
  263. margin-left: map.get($button-icon-span-gap, $size);
  264. }
  265. }
  266. & {
  267. @include button-size(
  268. map.get($button-padding-vertical, $size) - $button-border-width,
  269. map.get($button-padding-horizontal, $size) - $button-border-width,
  270. map.get($button-font-size, $size),
  271. map.get($button-border-radius, $size)
  272. );
  273. }
  274. @include when(circle) {
  275. width: getCssVar('button', 'size');
  276. padding: map.get($button-padding-vertical, $size) - $button-border-width;
  277. }
  278. }
  279. }
  280. }