_buttons.scss 11 KB

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