button.scss 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. color: getCssVar('button', 'hover', 'text-color');
  42. border-color: getCssVar('button', 'hover', 'border-color');
  43. background-color: getCssVar('button', 'hover', 'bg-color');
  44. outline: none;
  45. }
  46. &:active {
  47. color: getCssVar('button', 'active', 'text-color');
  48. border-color: getCssVar('button', 'active', 'border-color');
  49. background-color: getCssVar('button', 'active', 'bg-color');
  50. outline: none;
  51. }
  52. &:focus-visible {
  53. outline: 2px solid getCssVar('button', 'outline-color');
  54. outline-offset: 1px;
  55. transition: outline-offset 0s, outline 0s;
  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. color: getCssVar('button', 'disabled', 'text-color');
  105. cursor: not-allowed;
  106. background-image: none;
  107. background-color: getCssVar('button', 'disabled', 'bg-color');
  108. border-color: getCssVar('button', 'disabled', 'border-color');
  109. }
  110. }
  111. @include when(loading) {
  112. position: relative;
  113. pointer-events: none;
  114. &:before {
  115. // mask the button
  116. z-index: 1;
  117. pointer-events: none;
  118. content: '';
  119. position: absolute;
  120. left: -1px;
  121. top: -1px;
  122. right: -1px;
  123. bottom: -1px;
  124. border-radius: inherit;
  125. background-color: getCssVar('mask-color', 'extra-light');
  126. }
  127. }
  128. @include when(round) {
  129. border-radius: getCssVar('border-radius', 'round');
  130. }
  131. @include when(circle) {
  132. width: map.get($input-height, 'default');
  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. background-color: getCssVar('fill-color', 'light');
  147. }
  148. &:focus-visible {
  149. outline: 2px solid getCssVar('button', 'outline-color');
  150. outline-offset: 1px;
  151. transition: outline-offset 0s, outline 0s;
  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. background-color: getCssVar('fill-color');
  160. }
  161. &:active {
  162. background-color: getCssVar('fill-color', 'dark');
  163. }
  164. }
  165. }
  166. }
  167. @include e(text) {
  168. @include m(expand) {
  169. letter-spacing: 0.3em;
  170. margin-right: -0.3em;
  171. }
  172. }
  173. @include when(link) {
  174. border-color: transparent;
  175. color: getCssVar('button', 'text-color');
  176. background: transparent;
  177. padding: 2px;
  178. height: auto;
  179. &:hover {
  180. color: getCssVar('button', 'hover', 'link-text-color');
  181. }
  182. @include when(disabled) {
  183. color: getCssVar('button', 'disabled', 'text-color');
  184. background-color: transparent !important;
  185. border-color: transparent !important;
  186. }
  187. &:not(.is-disabled) {
  188. &:hover {
  189. border-color: transparent;
  190. background-color: transparent;
  191. }
  192. &:active {
  193. color: getCssVar('button', 'active-color');
  194. border-color: transparent;
  195. background-color: transparent;
  196. }
  197. }
  198. }
  199. @include m(text) {
  200. border-color: transparent;
  201. background: transparent;
  202. color: getCssVar('color', 'primary');
  203. padding-left: 0;
  204. padding-right: 0;
  205. @include when(disabled) {
  206. color: getCssVar('button', 'disabled', 'text-color');
  207. background-color: transparent !important;
  208. border-color: transparent !important;
  209. }
  210. &:not(.is-disabled) {
  211. &:hover {
  212. color: getCssVar('color', 'primary', 'light-3');
  213. border-color: transparent;
  214. background-color: transparent;
  215. }
  216. &:active {
  217. color: getCssVar('color', 'primary', 'dark-2');
  218. border-color: transparent;
  219. background-color: transparent;
  220. }
  221. }
  222. }
  223. @include e(link) {
  224. @include m(expand) {
  225. letter-spacing: 0.3em;
  226. margin-right: -0.3em;
  227. }
  228. }
  229. @each $type in (primary, success, warning, danger, info) {
  230. @include m($type) {
  231. @include button-variant($type);
  232. }
  233. }
  234. @each $size in (large, small) {
  235. @include m($size) {
  236. @include set-css-var-value(
  237. ('button', 'size'),
  238. map.get($input-height, $size)
  239. );
  240. height: getCssVar('button', 'size');
  241. & [class*='#{$namespace}-icon'] {
  242. & + span {
  243. margin-left: map.get($button-icon-span-gap, $size);
  244. }
  245. }
  246. @include button-size(
  247. map.get($button-padding-vertical, $size) - $button-border-width,
  248. map.get($button-padding-horizontal, $size) - $button-border-width,
  249. map.get($button-font-size, $size),
  250. map.get($button-border-radius, $size)
  251. );
  252. @include when(circle) {
  253. width: getCssVar('button', 'size');
  254. padding: map.get($button-padding-vertical, $size) - $button-border-width;
  255. }
  256. }
  257. }
  258. }