button.sass 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. @import "../utilities/controls"
  2. @import "../utilities/mixins"
  3. $button-color: $text-strong !default
  4. $button-background-color: $scheme-main !default
  5. $button-family: false !default
  6. $button-border-color: $border !default
  7. $button-border-width: $control-border-width !default
  8. $button-padding-vertical: calc(0.5em - #{$button-border-width}) !default
  9. $button-padding-horizontal: 1em !default
  10. $button-hover-color: $link-hover !default
  11. $button-hover-border-color: $link-hover-border !default
  12. $button-focus-color: $link-focus !default
  13. $button-focus-border-color: $link-focus-border !default
  14. $button-focus-box-shadow-size: 0 0 0 0.125em !default
  15. $button-focus-box-shadow-color: bulmaRgba($link, 0.25) !default
  16. $button-active-color: $link-active !default
  17. $button-active-border-color: $link-active-border !default
  18. $button-text-color: $text !default
  19. $button-text-decoration: underline !default
  20. $button-text-hover-background-color: $background !default
  21. $button-text-hover-color: $text-strong !default
  22. $button-ghost-background: none !default
  23. $button-ghost-border-color: transparent !default
  24. $button-ghost-color: $link !default
  25. $button-ghost-decoration: none !default
  26. $button-ghost-hover-color: $link !default
  27. $button-ghost-hover-decoration: underline !default
  28. $button-disabled-background-color: $scheme-main !default
  29. $button-disabled-border-color: $border !default
  30. $button-disabled-shadow: none !default
  31. $button-disabled-opacity: 0.5 !default
  32. $button-static-color: $text-light !default
  33. $button-static-background-color: $scheme-main-ter !default
  34. $button-static-border-color: $border !default
  35. $button-colors: $colors !default
  36. // The button sizes use mixins so they can be used at different breakpoints
  37. =button-small
  38. &:not(.is-rounded)
  39. border-radius: $radius-small
  40. font-size: $size-small
  41. =button-normal
  42. font-size: $size-normal
  43. =button-medium
  44. font-size: $size-medium
  45. =button-large
  46. font-size: $size-large
  47. .button
  48. @extend %control
  49. @extend %unselectable
  50. background-color: $button-background-color
  51. border-color: $button-border-color
  52. border-width: $button-border-width
  53. color: $button-color
  54. cursor: pointer
  55. @if $button-family
  56. font-family: $button-family
  57. justify-content: center
  58. padding-bottom: $button-padding-vertical
  59. padding-left: $button-padding-horizontal
  60. padding-right: $button-padding-horizontal
  61. padding-top: $button-padding-vertical
  62. text-align: center
  63. white-space: nowrap
  64. strong
  65. color: inherit
  66. .icon
  67. &,
  68. &.is-small,
  69. &.is-medium,
  70. &.is-large
  71. height: 1.5em
  72. width: 1.5em
  73. &:first-child:not(:last-child)
  74. +ltr-property("margin", calc(#{-1 / 2 * $button-padding-horizontal} - #{$button-border-width}), false)
  75. +ltr-property("margin", $button-padding-horizontal / 4)
  76. &:last-child:not(:first-child)
  77. +ltr-property("margin", $button-padding-horizontal / 4, false)
  78. +ltr-property("margin", calc(#{-1 / 2 * $button-padding-horizontal} - #{$button-border-width}))
  79. &:first-child:last-child
  80. margin-left: calc(#{-1 / 2 * $button-padding-horizontal} - #{$button-border-width})
  81. margin-right: calc(#{-1 / 2 * $button-padding-horizontal} - #{$button-border-width})
  82. // States
  83. &:hover,
  84. &.is-hovered
  85. border-color: $button-hover-border-color
  86. color: $button-hover-color
  87. &:focus,
  88. &.is-focused
  89. border-color: $button-focus-border-color
  90. color: $button-focus-color
  91. &:not(:active)
  92. box-shadow: $button-focus-box-shadow-size $button-focus-box-shadow-color
  93. &:active,
  94. &.is-active
  95. border-color: $button-active-border-color
  96. color: $button-active-color
  97. // Colors
  98. &.is-text
  99. background-color: transparent
  100. border-color: transparent
  101. color: $button-text-color
  102. text-decoration: $button-text-decoration
  103. &:hover,
  104. &.is-hovered,
  105. &:focus,
  106. &.is-focused
  107. background-color: $button-text-hover-background-color
  108. color: $button-text-hover-color
  109. &:active,
  110. &.is-active
  111. background-color: bulmaDarken($button-text-hover-background-color, 5%)
  112. color: $button-text-hover-color
  113. &[disabled],
  114. fieldset[disabled] &
  115. background-color: transparent
  116. border-color: transparent
  117. box-shadow: none
  118. &.is-ghost
  119. background: $button-ghost-background
  120. border-color: $button-ghost-border-color
  121. color: $button-ghost-color
  122. text-decoration: $button-ghost-decoration
  123. &:hover,
  124. &.is-hovered
  125. color: $button-ghost-hover-color
  126. text-decoration: $button-ghost-hover-decoration
  127. @each $name, $pair in $button-colors
  128. $color: nth($pair, 1)
  129. $color-invert: nth($pair, 2)
  130. &.is-#{$name}
  131. background-color: $color
  132. border-color: transparent
  133. color: $color-invert
  134. &:hover,
  135. &.is-hovered
  136. background-color: bulmaDarken($color, 2.5%)
  137. border-color: transparent
  138. color: $color-invert
  139. &:focus,
  140. &.is-focused
  141. border-color: transparent
  142. color: $color-invert
  143. &:not(:active)
  144. box-shadow: $button-focus-box-shadow-size bulmaRgba($color, 0.25)
  145. &:active,
  146. &.is-active
  147. background-color: bulmaDarken($color, 5%)
  148. border-color: transparent
  149. color: $color-invert
  150. &[disabled],
  151. fieldset[disabled] &
  152. background-color: $color
  153. border-color: transparent
  154. box-shadow: none
  155. &.is-inverted
  156. background-color: $color-invert
  157. color: $color
  158. &:hover,
  159. &.is-hovered
  160. background-color: bulmaDarken($color-invert, 5%)
  161. &[disabled],
  162. fieldset[disabled] &
  163. background-color: $color-invert
  164. border-color: transparent
  165. box-shadow: none
  166. color: $color
  167. &.is-loading
  168. &::after
  169. border-color: transparent transparent $color-invert $color-invert !important
  170. &.is-outlined
  171. background-color: transparent
  172. border-color: $color
  173. color: $color
  174. &:hover,
  175. &.is-hovered,
  176. &:focus,
  177. &.is-focused
  178. background-color: $color
  179. border-color: $color
  180. color: $color-invert
  181. &.is-loading
  182. &::after
  183. border-color: transparent transparent $color $color !important
  184. &:hover,
  185. &.is-hovered,
  186. &:focus,
  187. &.is-focused
  188. &::after
  189. border-color: transparent transparent $color-invert $color-invert !important
  190. &[disabled],
  191. fieldset[disabled] &
  192. background-color: transparent
  193. border-color: $color
  194. box-shadow: none
  195. color: $color
  196. &.is-inverted.is-outlined
  197. background-color: transparent
  198. border-color: $color-invert
  199. color: $color-invert
  200. &:hover,
  201. &.is-hovered,
  202. &:focus,
  203. &.is-focused
  204. background-color: $color-invert
  205. color: $color
  206. &.is-loading
  207. &:hover,
  208. &.is-hovered,
  209. &:focus,
  210. &.is-focused
  211. &::after
  212. border-color: transparent transparent $color $color !important
  213. &[disabled],
  214. fieldset[disabled] &
  215. background-color: transparent
  216. border-color: $color-invert
  217. box-shadow: none
  218. color: $color-invert
  219. // If light and dark colors are provided
  220. @if length($pair) >= 4
  221. $color-light: nth($pair, 3)
  222. $color-dark: nth($pair, 4)
  223. &.is-light
  224. background-color: $color-light
  225. color: $color-dark
  226. &:hover,
  227. &.is-hovered
  228. background-color: bulmaDarken($color-light, 2.5%)
  229. border-color: transparent
  230. color: $color-dark
  231. &:active,
  232. &.is-active
  233. background-color: bulmaDarken($color-light, 5%)
  234. border-color: transparent
  235. color: $color-dark
  236. // Sizes
  237. &.is-small
  238. +button-small
  239. &.is-normal
  240. +button-normal
  241. &.is-medium
  242. +button-medium
  243. &.is-large
  244. +button-large
  245. // Modifiers
  246. &[disabled],
  247. fieldset[disabled] &
  248. background-color: $button-disabled-background-color
  249. border-color: $button-disabled-border-color
  250. box-shadow: $button-disabled-shadow
  251. opacity: $button-disabled-opacity
  252. &.is-fullwidth
  253. display: flex
  254. width: 100%
  255. &.is-loading
  256. color: transparent !important
  257. pointer-events: none
  258. &::after
  259. @extend %loader
  260. +center(1em)
  261. position: absolute !important
  262. &.is-static
  263. background-color: $button-static-background-color
  264. border-color: $button-static-border-color
  265. color: $button-static-color
  266. box-shadow: none
  267. pointer-events: none
  268. &.is-rounded
  269. border-radius: $radius-rounded
  270. padding-left: calc(#{$button-padding-horizontal} + 0.25em)
  271. padding-right: calc(#{$button-padding-horizontal} + 0.25em)
  272. .buttons
  273. align-items: center
  274. display: flex
  275. flex-wrap: wrap
  276. justify-content: flex-start
  277. .button
  278. margin-bottom: 0.5rem
  279. &:not(:last-child):not(.is-fullwidth)
  280. +ltr-property("margin", 0.5rem)
  281. &:last-child
  282. margin-bottom: -0.5rem
  283. &:not(:last-child)
  284. margin-bottom: 1rem
  285. // Sizes
  286. &.are-small
  287. .button:not(.is-normal):not(.is-medium):not(.is-large)
  288. +button-small
  289. &.are-medium
  290. .button:not(.is-small):not(.is-normal):not(.is-large)
  291. +button-medium
  292. &.are-large
  293. .button:not(.is-small):not(.is-normal):not(.is-medium)
  294. +button-large
  295. &.has-addons
  296. .button
  297. &:not(:first-child)
  298. border-bottom-left-radius: 0
  299. border-top-left-radius: 0
  300. &:not(:last-child)
  301. border-bottom-right-radius: 0
  302. border-top-right-radius: 0
  303. +ltr-property("margin", -1px)
  304. &:last-child
  305. +ltr-property("margin", 0)
  306. &:hover,
  307. &.is-hovered
  308. z-index: 2
  309. &:focus,
  310. &.is-focused,
  311. &:active,
  312. &.is-active,
  313. &.is-selected
  314. z-index: 3
  315. &:hover
  316. z-index: 4
  317. &.is-expanded
  318. flex-grow: 1
  319. flex-shrink: 1
  320. &.is-centered
  321. justify-content: center
  322. &:not(.has-addons)
  323. .button:not(.is-fullwidth)
  324. margin-left: 0.25rem
  325. margin-right: 0.25rem
  326. &.is-right
  327. justify-content: flex-end
  328. &:not(.has-addons)
  329. .button:not(.is-fullwidth)
  330. margin-left: 0.25rem
  331. margin-right: 0.25rem