1 | # SCSS Mixins
|
2 | Collection of useful style mixins.
|
3 |
|
4 | **Why?** — Some pieces of SCSS code are often reused in different
|
5 | stylesheets of different apps, thus it is useful to have them all in one place,
|
6 | and implmented in a standard way.
|
7 |
|
8 | To use, import the main mixins file into your SCSS, e.g.:
|
9 | ```scss
|
10 | @import "topcoder-react-utils/src/styles/mixins";
|
11 | ```
|
12 |
|
13 | ### Font Mixins
|
14 | - **`@mixin font-family($name, $weight, $style, $url, $file);`**
|
15 | The `font-family` mixins generates a `@font-face` declaration for
|
16 | inclusion of the specified font into the app. The font is assumed
|
17 | to be provided in the following formats: EOT, WOFF, TTF, SVG.
|
18 | - **`$name`** Font name (to reference the loaded font from SCSS in
|
19 | the SCSS stylesheets);
|
20 | - **`$weight`** Font weight;
|
21 | - **`$style`** Font style, *normal* or *italic*;
|
22 | - **`$url`** Path to the font files (without the filename);
|
23 | - **`$file`** Name of the font files (without extension). It is
|
24 | supposed that all files related to the font have the same name,
|
25 | and differs only be their extensions.
|
26 |
|
27 | - **`font-family-ttf($name, $weight, $style, $url);`**
|
28 | Similar to the `font-family` mixins, but loads only fonts in TTF
|
29 | format.
|
30 | - **`$name`** Font name (to reference the loaded font from SCSS in
|
31 | the SCSS stylesheets);
|
32 | - **`$weight`** Font weight;
|
33 | - **`$style`** Font style, *normal* or *italic*;
|
34 | - **`$url`** Path to the font file, including the filename (without
|
35 | file extension).
|
36 |
|
37 | ### Media Mixins
|
38 | These mixins help to create conditional SCSS, responsive to the viewport size.
|
39 |
|
40 | We consider five viewport sizes: extra-small (XS), small (SM), medium (MD),
|
41 | large (LG), and extra-large (XL). It is assumed that mobile devices have SM
|
42 | screen size; tablets have MD screens, and desktops have LG or XL screen size.
|
43 | The actual break-points between these sizes are defined by four variables with
|
44 | the following default values:
|
45 | - **`$screen-xs`** — 320px;
|
46 | - **`$screen-sm`** — 768px;
|
47 | - **`$screen-md`** — 1024px;
|
48 | - **`$screen-lg`** — 1280px.
|
49 |
|
50 | Each of these variables set the maximal pixel size of the corresponding
|
51 | viewport; i.e. XS viewport may have any width under `$screen-xs` (inclusive);
|
52 | MD viewport may have a width from `$screen-sm` (exclusive) up to `$screen-md`
|
53 | (inclusive); XL viewport may have any width above `$screen-lg` (exclusive).
|
54 |
|
55 | Based on these variables, we provide two sets of media mixins:
|
56 | - **`@mixin xs`**, **`@mixin sm`**, **`@mixin md`**, **`@mixin lg`**,
|
57 | **`@mixin xl`** — allow to apply styling to a single specified
|
58 | size of the viewport;
|
59 | - **`@mixin xs-to-sm`**, **`@mixin xs-to-md`**, **`@mixin xs-to-lg`**,
|
60 | **`@mixin sm-to-md`**, **`@mixin sm-to-lg`**, **`@mixin sm-to-xl`**,
|
61 | **`@mixin md-to-lg`**, **`@mixin md-to-xl`**, **`@mixin lg-to-xl`** —
|
62 | allow to apply styling for a range of viewport sizes, from the first mentioned
|
63 | in the mixin name to the last one, both inclusive.
|
64 |
|
65 | The both kinds of these mixins you can use the same way:
|
66 | ```scss
|
67 | // style.scss
|
68 |
|
69 | .someClass {
|
70 | // General style
|
71 | background: green;
|
72 |
|
73 | // The element will become red on the smallest screens (XS to SM), which means
|
74 | // any screen smaller than MD.
|
75 | @include xs-to-sm {
|
76 | background: red;
|
77 | }
|
78 | }
|
79 | ```
|