button.scss 7.2 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. 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. & {
  65. @include button-size(
  66. map.get($button-padding-vertical, 'default') - $button-border-width,
  67. map.get($button-padding-horizontal, 'default') - $button-border-width,
  68. map.get($button-font-size, 'default'),
  69. map.get($button-border-radius, 'default')
  70. );
  71. }
  72. &::-moz-focus-inner {
  73. border: 0;
  74. }
  75. & [class*='#{$namespace}-icon'] {
  76. & + span {
  77. margin-left: map.get($button-icon-span-gap, 'default');
  78. }
  79. svg {
  80. vertical-align: bottom;
  81. }
  82. }
  83. @include when(plain) {
  84. @include css-var-from-global(
  85. ('button', 'hover', 'text-color'),
  86. ('color', 'primary')
  87. );
  88. @include css-var-from-global(
  89. ('button', 'hover', 'bg-color'),
  90. ('fill-color', 'blank')
  91. );
  92. @include css-var-from-global(
  93. ('button', 'hover', 'border-color'),
  94. ('color', 'primary')
  95. );
  96. }
  97. @include when(active) {
  98. color: getCssVar('button', 'active', 'text-color');
  99. border-color: getCssVar('button', 'active', 'border-color');
  100. background-color: getCssVar('button', 'active', 'bg-color');
  101. outline: none;
  102. }
  103. @include when(disabled) {
  104. &,
  105. &:hover {
  106. color: getCssVar('button', 'disabled', 'text-color');
  107. cursor: not-allowed;
  108. background-image: none;
  109. background-color: getCssVar('button', 'disabled', 'bg-color');
  110. border-color: getCssVar('button', 'disabled', 'border-color');
  111. }
  112. }
  113. @include when(loading) {
  114. position: relative;
  115. pointer-events: none;
  116. &:before {
  117. // mask the button
  118. z-index: 1;
  119. pointer-events: none;
  120. content: '';
  121. position: absolute;
  122. left: -1px;
  123. top: -1px;
  124. right: -1px;
  125. bottom: -1px;
  126. border-radius: inherit;
  127. background-color: getCssVar('mask-color', 'extra-light');
  128. }
  129. }
  130. @include when(round) {
  131. border-radius: getCssVar('border-radius', 'round');
  132. }
  133. @include when(circle) {
  134. width: map.get($input-height, 'default');
  135. border-radius: 50%;
  136. padding: map.get($button-padding-vertical, 'default') - $button-border-width;
  137. }
  138. @include when(text) {
  139. color: getCssVar('button', 'text-color');
  140. border: 0 solid transparent;
  141. background-color: transparent;
  142. @include when(disabled) {
  143. color: getCssVar('button', 'disabled', 'text-color');
  144. background-color: transparent !important;
  145. }
  146. &:not(.is-disabled) {
  147. &:hover {
  148. background-color: getCssVar('fill-color', 'light');
  149. }
  150. &:focus-visible {
  151. outline: 2px solid getCssVar('button', 'outline-color');
  152. outline-offset: 1px;
  153. transition: outline-offset 0s, outline 0s;
  154. }
  155. &:active {
  156. background-color: getCssVar('fill-color');
  157. }
  158. @include when(has-bg) {
  159. background-color: getCssVar('fill-color', 'light');
  160. &:hover {
  161. background-color: getCssVar('fill-color');
  162. }
  163. &:active {
  164. background-color: getCssVar('fill-color', 'dark');
  165. }
  166. }
  167. }
  168. }
  169. @include e(text) {
  170. @include m(expand) {
  171. letter-spacing: 0.3em;
  172. margin-right: -0.3em;
  173. }
  174. }
  175. @include when(link) {
  176. border-color: transparent;
  177. color: getCssVar('button', 'text-color');
  178. background: transparent;
  179. padding: 2px;
  180. height: auto;
  181. &:hover {
  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. border-color: transparent;
  192. background-color: transparent;
  193. }
  194. &:active {
  195. color: getCssVar('button', 'active-color');
  196. border-color: transparent;
  197. background-color: transparent;
  198. }
  199. }
  200. }
  201. @include m(text) {
  202. border-color: transparent;
  203. background: transparent;
  204. color: getCssVar('color', 'primary');
  205. padding-left: 0;
  206. padding-right: 0;
  207. @include when(disabled) {
  208. color: getCssVar('button', 'disabled', 'text-color');
  209. background-color: transparent !important;
  210. border-color: transparent !important;
  211. }
  212. &:not(.is-disabled) {
  213. &:hover {
  214. color: getCssVar('color', 'primary', 'light-3');
  215. border-color: transparent;
  216. background-color: transparent;
  217. }
  218. &:active {
  219. color: getCssVar('color', 'primary', 'dark-2');
  220. border-color: transparent;
  221. background-color: transparent;
  222. }
  223. }
  224. }
  225. @include e(link) {
  226. @include m(expand) {
  227. letter-spacing: 0.3em;
  228. margin-right: -0.3em;
  229. }
  230. }
  231. @each $type in (primary, success, warning, danger, info) {
  232. @include m($type) {
  233. @include button-variant($type);
  234. }
  235. }
  236. @each $size in (large, small) {
  237. @include m($size) {
  238. @include set-css-var-value(
  239. ('button', 'size'),
  240. map.get($input-height, $size)
  241. );
  242. height: getCssVar('button', 'size');
  243. & [class*='#{$namespace}-icon'] {
  244. & + span {
  245. margin-left: map.get($button-icon-span-gap, $size);
  246. }
  247. }
  248. & {
  249. @include button-size(
  250. map.get($button-padding-vertical, $size) - $button-border-width,
  251. map.get($button-padding-horizontal, $size) - $button-border-width,
  252. map.get($button-font-size, $size),
  253. map.get($button-border-radius, $size)
  254. );
  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. }