button.scss 7.1 KB

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