_tools.mq.scss 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. @charset "UTF-8"; // Fixes an issue where Ruby locale is not set properly
  2. // See https://github.com/sass-mq/sass-mq/pull/10
  3. /// Base font size on the `<body>` element
  4. /// @type Number (unit)
  5. $mq-base-font-size: 16px !default;
  6. /// Responsive mode
  7. ///
  8. /// Set to `false` to enable support for browsers that do not support @media queries,
  9. /// (IE <= 8, Firefox <= 3, Opera <= 9)
  10. ///
  11. /// You could create a stylesheet served exclusively to older browsers,
  12. /// where @media queries are rasterized
  13. ///
  14. /// @example scss
  15. /// // old-ie.scss
  16. /// $mq-responsive: false;
  17. /// @import 'main'; // @media queries in this file will be rasterized up to $mq-static-breakpoint
  18. /// // larger breakpoints will be ignored
  19. ///
  20. /// @type Boolean
  21. /// @link https://github.com/sass-mq/sass-mq#responsive-mode-off Disabled responsive mode documentation
  22. $mq-responsive: true !default;
  23. /// Breakpoint list
  24. ///
  25. /// Name your breakpoints in a way that creates a ubiquitous language
  26. /// across team members. It will improve communication between
  27. /// stakeholders, designers, developers, and testers.
  28. ///
  29. /// @type Map
  30. /// @link https://github.com/sass-mq/sass-mq#seeing-the-currently-active-breakpoint Full documentation and examples
  31. $mq-breakpoints: (
  32. mobile: 375px,
  33. tablet: 768px,
  34. laptop: 1024px,
  35. laptop_mid: 1200px,
  36. desktop: 1440px,
  37. desktop_wide: 1650px,
  38. wide: 2560px
  39. ) !default;
  40. /// Static breakpoint (for fixed-width layouts)
  41. ///
  42. /// Define the breakpoint from $mq-breakpoints that should
  43. /// be used as the target width for the fixed-width layout
  44. /// (i.e. when $mq-responsive is set to 'false') in a old-ie.scss
  45. ///
  46. /// @example scss
  47. /// // tablet-only.scss
  48. /// //
  49. /// // Ignore all styles above tablet breakpoint,
  50. /// // and fix the styles (e.g. layout) at tablet width
  51. /// $mq-responsive: false;
  52. /// $mq-static-breakpoint: tablet;
  53. /// @import 'main'; // @media queries in this file will be rasterized up to tablet
  54. /// // larger breakpoints will be ignored
  55. ///
  56. /// @type String
  57. /// @link https://github.com/sass-mq/sass-mq#adding-custom-breakpoints Full documentation and examples
  58. $mq-static-breakpoint: desktop !default;
  59. /// Show breakpoints in the top right corner
  60. ///
  61. /// If you want to display the currently active breakpoint in the top
  62. /// right corner of your site during development, add the breakpoints
  63. /// to this list, ordered by width, e.g. (mobile, tablet, desktop).
  64. ///
  65. /// @example scss
  66. /// $mq-show-breakpoints: (mobile, tablet, desktop);
  67. /// @import 'path/to/mq';
  68. ///
  69. /// @type map
  70. $mq-show-breakpoints: () !default;
  71. /// Customize the media type (e.g. `@media screen` or `@media print`)
  72. /// By default sass-mq uses an "all" media type (`@media all and …`)
  73. ///
  74. /// @type String
  75. /// @link https://github.com/sass-mq/sass-mq#changing-media-type Full documentation and examples
  76. $mq-media-type: all !default;
  77. /// Convert pixels to ems
  78. ///
  79. /// @param {Number} $px - value to convert
  80. /// @param {Number} $base-font-size ($mq-base-font-size) - `<body>` font size
  81. ///
  82. /// @example scss
  83. /// $font-size-in-ems: mq-px2em(16px);
  84. /// p { font-size: mq-px2em(16px); }
  85. ///
  86. /// @requires $mq-base-font-size
  87. /// @returns {Number}
  88. @function mq-px2em($px, $base-font-size: $mq-base-font-size) {
  89. @if unitless($px) {
  90. @warn "Assuming #{$px} to be in pixels, attempting to convert it into pixels.";
  91. @return mq-px2em($px * 1px, $base-font-size);
  92. } @else if unit($px) == em {
  93. @return $px;
  94. }
  95. @return ($px / $base-font-size) * 1em;
  96. }
  97. /// Get a breakpoint's width
  98. ///
  99. /// @param {String} $name - Name of the breakpoint. One of $mq-breakpoints
  100. ///
  101. /// @example scss
  102. /// $tablet-width: mq-get-breakpoint-width(tablet);
  103. /// @media (min-width: mq-get-breakpoint-width(desktop)) {}
  104. ///
  105. /// @requires {Variable} $mq-breakpoints
  106. ///
  107. /// @returns {Number} Value in pixels
  108. @function mq-get-breakpoint-width($name, $breakpoints: $mq-breakpoints) {
  109. @if map-has-key($breakpoints, $name) {
  110. @return map-get($breakpoints, $name);
  111. } @else {
  112. @warn "Breakpoint #{$name} wasn't found in $breakpoints.";
  113. }
  114. }
  115. /// Media Query mixin
  116. ///
  117. /// @param {String | Boolean} $from (false) - One of $mq-breakpoints
  118. /// @param {String | Boolean} $until (false) - One of $mq-breakpoints
  119. /// @param {String | Boolean} $and (false) - Additional media query parameters
  120. /// @param {String} $media-type ($mq-media-type) - Media type: screen, print…
  121. ///
  122. /// @ignore Undocumented API, for advanced use only:
  123. /// @ignore @param {Map} $breakpoints ($mq-breakpoints)
  124. /// @ignore @param {String} $static-breakpoint ($mq-static-breakpoint)
  125. ///
  126. /// @content styling rules, wrapped into a @media query when $responsive is true
  127. ///
  128. /// @requires {Variable} $mq-media-type
  129. /// @requires {Variable} $mq-breakpoints
  130. /// @requires {Variable} $mq-static-breakpoint
  131. /// @requires {function} mq-px2em
  132. /// @requires {function} mq-get-breakpoint-width
  133. ///
  134. /// @link https://github.com/sass-mq/sass-mq#responsive-mode-on-default Full documentation and examples
  135. ///
  136. /// @example scss
  137. /// .element {
  138. /// @include mq($from: mobile) {
  139. /// color: red;
  140. /// }
  141. /// @include mq($until: tablet) {
  142. /// color: blue;
  143. /// }
  144. /// @include mq(mobile, tablet) {
  145. /// color: green;
  146. /// }
  147. /// @include mq($from: tablet, $and: '(orientation: landscape)') {
  148. /// color: teal;
  149. /// }
  150. /// @include mq(950px) {
  151. /// color: hotpink;
  152. /// }
  153. /// @include mq(tablet, $media-type: screen) {
  154. /// color: hotpink;
  155. /// }
  156. /// // Advanced use:
  157. /// $my-breakpoints: (L: 900px, XL: 1200px);
  158. /// @include mq(L, $breakpoints: $my-breakpoints, $static-breakpoint: L) {
  159. /// color: hotpink;
  160. /// }
  161. /// }
  162. @mixin mq(
  163. $from: false,
  164. $until: false,
  165. $and: false,
  166. $media-type: $mq-media-type,
  167. $breakpoints: $mq-breakpoints,
  168. $responsive: $mq-responsive,
  169. $static-breakpoint: $mq-static-breakpoint
  170. ) {
  171. $min-width: 0;
  172. $max-width: 0;
  173. $media-query: '';
  174. // From: this breakpoint (inclusive)
  175. @if $from {
  176. @if type-of($from) == number {
  177. $min-width: mq-px2em($from);
  178. } @else {
  179. $min-width: mq-px2em(mq-get-breakpoint-width($from, $breakpoints));
  180. }
  181. }
  182. // Until: that breakpoint (exclusive)
  183. @if $until {
  184. @if type-of($until) == number {
  185. $max-width: mq-px2em($until);
  186. } @else {
  187. $max-width: mq-px2em(mq-get-breakpoint-width($until, $breakpoints)) - .01em;
  188. }
  189. }
  190. // Responsive support is disabled, rasterize the output outside @media blocks
  191. // The browser will rely on the cascade itself.
  192. @if $responsive == false {
  193. $static-breakpoint-width: mq-get-breakpoint-width($static-breakpoint, $breakpoints);
  194. $target-width: mq-px2em($static-breakpoint-width);
  195. // Output only rules that start at or span our target width
  196. @if (
  197. $and == false
  198. and $min-width <= $target-width
  199. and (
  200. $until == false or $max-width >= $target-width
  201. )
  202. and $media-type != 'print'
  203. ) {
  204. @content;
  205. }
  206. }
  207. // Responsive support is enabled, output rules inside @media queries
  208. @else {
  209. @if $min-width != 0 { $media-query: '#{$media-query} and (min-width: #{$min-width})'; }
  210. @if $max-width != 0 { $media-query: '#{$media-query} and (max-width: #{$max-width})'; }
  211. @if $and { $media-query: '#{$media-query} and #{$and}'; }
  212. // Remove unnecessary media query prefix 'all and '
  213. @if ($media-type == 'all' and $media-query != '') {
  214. $media-type: '';
  215. $media-query: str-slice(unquote($media-query), 6);
  216. }
  217. @media #{$media-type + $media-query} {
  218. @content;
  219. }
  220. }
  221. }
  222. /// Quick sort
  223. ///
  224. /// @author Sam Richards
  225. /// @access private
  226. /// @param {List} $list - List to sort
  227. /// @returns {List} Sorted List
  228. @function _mq-quick-sort($list) {
  229. $less: ();
  230. $equal: ();
  231. $large: ();
  232. @if length($list) > 1 {
  233. $seed: nth($list, ceil(length($list) / 2));
  234. @each $item in $list {
  235. @if ($item == $seed) {
  236. $equal: append($equal, $item);
  237. } @else if ($item < $seed) {
  238. $less: append($less, $item);
  239. } @else if ($item > $seed) {
  240. $large: append($large, $item);
  241. }
  242. }
  243. @return join(join(_mq-quick-sort($less), $equal), _mq-quick-sort($large));
  244. }
  245. @return $list;
  246. }
  247. /// Sort a map by values (works with numbers only)
  248. ///
  249. /// @access private
  250. /// @param {Map} $map - Map to sort
  251. /// @returns {Map} Map sorted by value
  252. @function _mq-map-sort-by-value($map) {
  253. $map-sorted: ();
  254. $map-keys: map-keys($map);
  255. $map-values: map-values($map);
  256. $map-values-sorted: _mq-quick-sort($map-values);
  257. // Reorder key/value pairs based on key values
  258. @each $value in $map-values-sorted {
  259. $index: index($map-values, $value);
  260. $key: nth($map-keys, $index);
  261. $map-sorted: map-merge($map-sorted, ($key: $value));
  262. // Unset the value in $map-values to prevent the loop
  263. // from finding the same index twice
  264. $map-values: set-nth($map-values, $index, 0);
  265. }
  266. @return $map-sorted;
  267. }
  268. /// Add a breakpoint
  269. ///
  270. /// @param {String} $name - Name of the breakpoint
  271. /// @param {Number} $width - Width of the breakpoint
  272. ///
  273. /// @requires {Variable} $mq-breakpoints
  274. ///
  275. /// @example scss
  276. /// @include mq-add-breakpoint(tvscreen, 1920px);
  277. /// @include mq(tvscreen) {}
  278. @mixin mq-add-breakpoint($name, $width) {
  279. $new-breakpoint: ($name: $width);
  280. $mq-breakpoints: map-merge($mq-breakpoints, $new-breakpoint) !global;
  281. $mq-breakpoints: _mq-map-sort-by-value($mq-breakpoints) !global;
  282. }
  283. /// Show the active breakpoint in the top right corner of the viewport
  284. /// @link https://github.com/sass-mq/sass-mq#seeing-the-currently-active-breakpoint
  285. ///
  286. /// @param {List} $show-breakpoints ($mq-show-breakpoints) - List of breakpoints to show in the top right corner
  287. /// @param {Map} $breakpoints ($mq-breakpoints) - Breakpoint names and sizes
  288. ///
  289. /// @requires {Variable} $mq-breakpoints
  290. /// @requires {Variable} $mq-show-breakpoints
  291. ///
  292. /// @example scss
  293. /// // Show breakpoints using global settings
  294. /// @include mq-show-breakpoints;
  295. ///
  296. /// // Show breakpoints using custom settings
  297. /// @include mq-show-breakpoints((L, XL), (S: 300px, L: 800px, XL: 1200px));
  298. @mixin mq-show-breakpoints($show-breakpoints: $mq-show-breakpoints, $breakpoints: $mq-breakpoints) {
  299. body:before {
  300. background-color: #FCF8E3;
  301. border-bottom: 1px solid #FBEED5;
  302. border-left: 1px solid #FBEED5;
  303. color: #C09853;
  304. font: small-caption;
  305. padding: 3px 6px;
  306. pointer-events: none;
  307. position: fixed;
  308. right: 0;
  309. top: 0;
  310. z-index: 100;
  311. // Loop through the breakpoints that should be shown
  312. @each $show-breakpoint in $show-breakpoints {
  313. $width: mq-get-breakpoint-width($show-breakpoint, $breakpoints);
  314. @include mq($show-breakpoint, $breakpoints: $breakpoints) {
  315. content: "#{$show-breakpoint} ≥ #{$width} (#{mq-px2em($width)})";
  316. }
  317. }
  318. }
  319. }
  320. @if length($mq-show-breakpoints) > 0 {
  321. @include mq-show-breakpoints;
  322. }