_buttons.scss 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. // Foundation by ZURB
  2. // foundation.zurb.com
  3. // Licensed under MIT Open Source
  4. @import 'global';
  5. //
  6. // @variables
  7. //
  8. $include-html-button-classes: $include-html-classes !default;
  9. // We use these to build padding for buttons.
  10. $button-tny: rem-calc(10) !default;
  11. $button-sml: rem-calc(14) !default;
  12. $button-med: rem-calc(16) !default;
  13. $button-lrg: rem-calc(18) !default;
  14. // We use this to control the display property.
  15. $button-display: inline-block !default;
  16. $button-margin-bottom: rem-calc(20) !default;
  17. // We use these to control button text styles.
  18. $button-font-family: $body-font-family !default;
  19. $button-font-color: $white !default;
  20. $button-font-color-alt: $oil !default;
  21. $button-font-tny: rem-calc(11) !default;
  22. $button-font-sml: rem-calc(13) !default;
  23. $button-font-med: rem-calc(16) !default;
  24. $button-font-lrg: rem-calc(20) !default;
  25. $button-font-weight: $font-weight-normal !default;
  26. $button-font-align: center !default;
  27. // We use these to control various hover effects.
  28. $button-function-factor: -20% !default;
  29. // We use these to control button border styles.
  30. $button-border-width: 0 !default;
  31. $button-border-style: solid !default;
  32. $button-bg-color: $primary-color !default;
  33. $button-bg-hover: scale-color($button-bg-color, $lightness: $button-function-factor) !default;
  34. $button-border-color: $button-bg-hover !default;
  35. $secondary-button-bg-color: $secondary-color !default;
  36. $secondary-button-bg-hover: scale-color($secondary-color, $lightness: $button-function-factor) !default;
  37. $secondary-button-border-color: $secondary-button-bg-hover !default;
  38. $success-button-bg-color: $success-color !default;
  39. $success-button-bg-hover: scale-color($success-color, $lightness: $button-function-factor) !default;
  40. $success-button-border-color: $success-button-bg-hover !default;
  41. $alert-button-bg-color: $alert-color !default;
  42. $alert-button-bg-hover: scale-color($alert-color, $lightness: $button-function-factor) !default;
  43. $alert-button-border-color: $alert-button-bg-hover !default;
  44. $warning-button-bg-color: $warning-color !default;
  45. $warning-button-bg-hover: scale-color($warning-color, $lightness: $button-function-factor) !default;
  46. $warning-button-border-color: $warning-button-bg-hover !default;
  47. $info-button-bg-color: $info-color !default;
  48. $info-button-bg-hover: scale-color($info-color, $lightness: $button-function-factor) !default;
  49. $info-button-border-color: $info-button-bg-hover !default;
  50. // We use this to set the default radius used throughout the core.
  51. $button-radius: $global-radius !default;
  52. $button-round: $global-rounded !default;
  53. // We use this to set default opacity and cursor for disabled buttons.
  54. $button-disabled-opacity: .7 !default;
  55. $button-disabled-cursor: $cursor-default-value !default;
  56. //
  57. // @MIXIN
  58. //
  59. // We use this mixin to create a default button base.
  60. //
  61. // $style - Sets base styles. Can be set to false. Default: true.
  62. // $display - Used to control display property. Default: $button-display || inline-block
  63. @mixin button-base($style:true, $display:$button-display) {
  64. @if $style {
  65. -webkit-appearance: none;
  66. -moz-appearance: none;
  67. border-radius:0;
  68. border-style: $button-border-style;
  69. border-width: $button-border-width;
  70. cursor: $cursor-pointer-value;
  71. font-family: $button-font-family;
  72. font-weight: $button-font-weight;
  73. line-height: normal;
  74. margin: 0 0 $button-margin-bottom;
  75. position: relative;
  76. text-align: $button-font-align;
  77. text-decoration: none;
  78. }
  79. @if $display { display: $display; }
  80. }
  81. // @MIXIN
  82. //
  83. // We use this mixin to add button size styles
  84. //
  85. // $padding - Used to build padding for buttons Default: $button-med ||= rem-calc(12)
  86. // $full-width - We can set $full-width:true to remove side padding extend width - Default: false
  87. @mixin button-size($padding:$button-med, $full-width:false) {
  88. // We control which padding styles come through,
  89. // these can be turned off by setting $padding:false
  90. @if $padding {
  91. padding: $padding ($padding * 2) ($padding + rem-calc(1)) ($padding * 2);
  92. // We control the font-size based on mixin input.
  93. @if $padding == $button-med { font-size: $button-font-med; }
  94. @else if $padding == $button-tny { font-size: $button-font-tny; }
  95. @else if $padding == $button-sml { font-size: $button-font-sml; }
  96. @else if $padding == $button-lrg { font-size: $button-font-lrg; }
  97. }
  98. // We can set $full-width:true to remove side padding extend width.
  99. @if $full-width {
  100. // We still need to check if $padding is set.
  101. @if $padding {
  102. padding-bottom: $padding + rem-calc(1);
  103. padding-top: $padding;
  104. } @else if $padding == false {
  105. padding-bottom:0;
  106. padding-top:0;
  107. }
  108. padding-left: $button-med;
  109. padding-right: $button-med;
  110. width: 100%;
  111. }
  112. }
  113. // @MIXIN
  114. //
  115. // we use this mixin to create the button hover and border colors
  116. // @MIXIN
  117. //
  118. // We use this mixin to add button color styles
  119. //
  120. // $bg - Background color. We can set $bg:false for a transparent background. Default: $primary-color.
  121. // $radius - If true, set to button radius which is $button-radius || explicitly set radius amount in px (ex. $radius:10px). Default: false
  122. // $disabled - We can set $disabled:true to create a disabled transparent button. Default: false
  123. // $bg-hover - Button Hover Background Color. Default: $button-bg-hover
  124. // $border-color - Button Border Color. Default: $button-border-color
  125. @mixin button-style($bg:$button-bg-color, $radius:false, $disabled:false, $bg-hover:null, $border-color:null) {
  126. // We control which background styles are used,
  127. // these can be removed by setting $bg:false
  128. @if $bg {
  129. @if $bg-hover == null {
  130. $bg-hover: if($bg == $button-bg-color, $button-bg-hover, scale-color($bg, $lightness: $button-function-factor));
  131. }
  132. @if $border-color == null {
  133. $border-color: if($bg == $button-bg-color, $button-border-color, scale-color($bg, $lightness: $button-function-factor));
  134. }
  135. // This find the lightness percentage of the background color.
  136. $bg-lightness: lightness($bg);
  137. $bg-hover-lightness: lightness($bg-hover);
  138. background-color: $bg;
  139. border-color: $border-color;
  140. &:hover,
  141. &:focus { background-color: $bg-hover; }
  142. // We control the text color for you based on the background color.
  143. color: if($bg-lightness > 70%, $button-font-color-alt, $button-font-color);
  144. &:hover,
  145. &:focus {
  146. color: if($bg-hover-lightness > 70%, $button-font-color-alt, $button-font-color);
  147. }
  148. }
  149. // We can set $disabled:true to create a disabled transparent button.
  150. @if $disabled {
  151. box-shadow: none;
  152. cursor: $button-disabled-cursor;
  153. opacity: $button-disabled-opacity;
  154. &:hover,
  155. &:focus { background-color: $bg; }
  156. }
  157. // We can control how much button radius is used.
  158. @if $radius == true { @include radius($button-radius); }
  159. @else if $radius { @include radius($radius); }
  160. }
  161. // @MIXIN
  162. //
  163. // We use this to quickly create buttons with a single mixin. As @jaredhardy puts it, "the kitchen sink mixin"
  164. //
  165. // $padding - Used to build padding for buttons Default: $button-med ||= rem-calc(12)
  166. // $bg - Primary color set in settings file. Default: $button-bg.
  167. // $radius - If true, set to button radius which is $global-radius || explicitly set radius amount in px (ex. $radius:10px). Default:false.
  168. // $full-width - We can set $full-width:true to remove side padding extend width. Default:false.
  169. // $disabled - We can set $disabled:true to create a disabled transparent button. Default:false.
  170. // $is-prefix - Not used? Default:false.
  171. // $bg-hover - Button Hover Color - Default null - see button-style mixin
  172. // $border-color - Button Border Color - Default null - see button-style mixin
  173. // $transition - We can control whether or not to include the background-color transition property - Default:true.
  174. @mixin button($padding:$button-med, $bg:$button-bg-color, $radius:false, $full-width:false, $disabled:false, $is-prefix:false, $bg-hover:null, $border-color:null, $transition: true) {
  175. @include button-base;
  176. @include button-size($padding, $full-width);
  177. @include button-style($bg, $radius, $disabled, $bg-hover, $border-color);
  178. @if $transition {
  179. @include single-transition(background-color);
  180. }
  181. }
  182. @include exports("button") {
  183. @if $include-html-button-classes {
  184. // Default styles applied outside of media query
  185. button, .button {
  186. @include button-base;
  187. @include button-size;
  188. @include button-style;
  189. @include single-transition(background-color);
  190. &.secondary { @include button-style($bg:$secondary-button-bg-color, $bg-hover:$secondary-button-bg-hover, $border-color:$secondary-button-border-color); }
  191. &.success { @include button-style($bg:$success-button-bg-color, $bg-hover:$success-button-bg-hover, $border-color:$success-button-border-color); }
  192. &.alert { @include button-style($bg:$alert-button-bg-color, $bg-hover:$alert-button-bg-hover, $border-color:$alert-button-border-color); }
  193. &.warning { @include button-style($bg:$warning-button-bg-color, $bg-hover:$warning-button-bg-hover, $border-color:$warning-button-border-color); }
  194. &.info { @include button-style($bg:$info-button-bg-color, $bg-hover:$info-button-bg-hover, $border-color:$info-button-border-color); }
  195. &.large { @include button-size($padding:$button-lrg); }
  196. &.small { @include button-size($padding:$button-sml); }
  197. &.tiny { @include button-size($padding:$button-tny); }
  198. &.expand { @include button-size($full-width:true); }
  199. &.left-align { text-align: left; text-indent: rem-calc(12); }
  200. &.right-align { text-align: right; padding-right: rem-calc(12); }
  201. &.radius { @include button-style($bg:false, $radius:true); }
  202. &.round { @include button-style($bg:false, $radius:$button-round); }
  203. &.disabled, &[disabled] { @include button-style($bg:$button-bg-color, $disabled:true, $bg-hover:$button-bg-hover, $border-color:$button-border-color);
  204. &.secondary { @include button-style($bg:$secondary-button-bg-color, $disabled:true, $bg-hover:$secondary-button-bg-hover, $border-color:$secondary-button-border-color); }
  205. &.success { @include button-style($bg:$success-button-bg-color, $disabled:true, $bg-hover:$success-button-bg-hover, $border-color:$success-button-border-color); }
  206. &.alert { @include button-style($bg:$alert-button-bg-color, $disabled:true, $bg-hover:$alert-button-bg-hover, $border-color:$alert-button-border-color); }
  207. &.warning { @include button-style($bg:$warning-button-bg-color, $disabled:true, $bg-hover:$warning-button-bg-hover, $border-color:$warning-button-border-color); }
  208. &.info { @include button-style($bg:$info-button-bg-color, $disabled:true, $bg-hover:$info-button-bg-hover, $border-color:$info-button-border-color); }
  209. }
  210. }
  211. //firefox 2px fix
  212. button::-moz-focus-inner {border:0; padding:0;}
  213. @media #{$medium-up} {
  214. button, .button {
  215. @include button-base($style:false, $display:inline-block);
  216. @include button-size($padding:false, $full-width:false);
  217. }
  218. }
  219. }
  220. }