aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorFeuerfuchs <git@feuerfuchs.dev>2020-11-01 20:55:14 +0100
committerFeuerfuchs <git@feuerfuchs.dev>2020-11-01 20:55:14 +0100
commitd07f664450ddaaebb44127a4bd057763d13d3f82 (patch)
tree234cfd673ac527869a8dda4f32afbec48c87b512 /README.md
downloadiro-sass-d07f664450ddaaebb44127a4bd057763d13d3f82.tar.gz
iro-sass-d07f664450ddaaebb44127a4bd057763d13d3f82.tar.bz2
iro-sass-d07f664450ddaaebb44127a4bd057763d13d3f82.zip
Init
Diffstat (limited to 'README.md')
-rw-r--r--README.md346
1 files changed, 346 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..62b15cc
--- /dev/null
+++ b/README.md
@@ -0,0 +1,346 @@
1# iro-sass
2
3iro-sass is a [Sass](http://sass-lang.com/) library that I developed to create websites.
4
5Its main feature is a **[BEM system](#bem-system)**, though it also includes some other useful features:
6
7- Easing background gradients
8- Context stacks: A temporary data storage
9- Property trees]: A persistent data storage
10- Responsive properties: A generalization of responsive typography
11- Modular scales
12
13All features are explained in greater detail in the [Wiki](https://git.vulpes.one/Feuerfuchs/iro-sass/wiki).
14The rest of this document is a quick overview over what iro-sass has to offer.
15
16- [iro-sass](#iro-sass)
17 - [Getting started](#getting-started)
18 - [Development](#development)
19 - [Changelog](#changelog)
20 - [Known issues](#known-issues)
21 - [Features](#features)
22 - [BEM system](#bem-system)
23 - [Easing background gradients](#easing-background-gradients)
24 - [Context stacks](#context-stacks)
25 - [Property trees](#property-trees)
26 - [Responsive properties](#responsive-properties)
27 - [Modular scales](#modular-scales)
28
29## Getting started
30
31Install the package [iro-sass](https://www.npmjs.com/package/iro-sass) from the npm repository using the package manager of your choice.
32
33- npm: `npm install iro-sass`
34- yarn: `yarn add iro-sass`
35
36Then include iro-sass in your Sass stylesheet:
37
38```scss
39@import 'iro-sass/src/main';
40// (overrides)
41// files that depend on iro-sass
42```
43
44iro-sass uses function, mixin and variable names that are prefixed with 'iro-' to avoid clashes with other libraries.
45There are, however, shorter versions of many mixins and functions available (referred to as "shortcodes").
46Just import one of these files to use a certain set of shortcodes:
47
48- `iro-sass/src/bem-shortcodes`: BEM
49- `iro-sass/src/responsive-shortcodes`: Responsive properties
50- `iro-sass/src/harmony-shortcodes`: Modular scales
51
52**Note:** If the 'node_modules' folder isn't a search path for Sass imports, you have to prefix your imports with the path to 'node_modules'.
53An import might then look like this: `@import 'node_modules/iro-sass/src/main';`
54
55## Development
56
57Clone the repository, then run `npm install` or `yarn` to install all dependencies.
58
59The following npm scripts are available:
60
61- `lint`: Lint the source code with [sass-lint](https://www.npmjs.com/package/sass-lint).
62- `livelint`: Lint automatically whenever the code changes.
63- `doc`: Generate the SassDoc documentation with [sassdoc](http://sassdoc.com/).
64- `test`: Run unit tests with [sass-true](https://www.npmjs.com/package/sass-true) and [Mocha](https://mochajs.org/).
65
66## Changelog
67
68[Changelog](https://git.vulpes.one/Feuerfuchs/iro-sass/blob/main/CHANGELOG.md)
69
70## Known issues
71
72Check out the [issue tracker](https://git.vulpes.one/Feuerfuchs/iro-sass/issues).
73
74## Features
75
76### BEM system
77
78iro-sass' main feature is its BEM system which was developed over the course of two years. Features include:
79
80- **Full [BEM](https://en.bem.info/) and [BEMIT](https://csswizardry.com/2015/08/bemit-taking-the-bem-naming-convention-a-step-further/) support:** Namespaced blocks, suffixes, states, and so on.
81- **Robustness:** Most selector-related operations use Sass' native selector functions instead of manual parsing and assembling.
82- **Quality:** All mixins generate optimal selectors with a minimal degree of specificity.
83- **Safety:** All mixins perform checks if they are used correctly.
84- **Flexibility:** Mix BEM selectors and other selectors however you like — the BEM system will adapt.
85- **Strictness:** The BEM system allows you to define rules that control how the BEM mixins may or may not be used.
86
87Below is a basic example showing how the BEM system can be used:
88
89```scss
90@include iro-bem-object('media') {
91 display: flex;
92 align-items: flex-start;
93 justify-content: flex-start;
94
95 @include iro-bem-element('image') {
96 display: block;
97 flex: 0 0 auto;
98 order: 1;
99 overflow: hidden;
100 }
101
102 @include iro-bem-element('body') {
103 order: 2;
104 }
105
106 @include iro-bem-modifier('rtl') {
107 justify-content: flex-end;
108
109 @include iro-bem-element('image') {
110 order: 2;
111 }
112
113 @include iro-bem-element('body') {
114 order: 1;
115 }
116 }
117}
118```
119
120The result is this CSS:
121
122```css
123.o-media {
124 display: flex;
125 align-items: flex-start;
126 justify-content: flex-start;
127}
128
129.o-media__image {
130 display: block;
131 flex: 0 0 auto;
132 order: 1;
133 overflow: hidden;
134}
135
136.o-media__body {
137 order: 2;
138}
139
140.o-media--rtl {
141 justify-content: flex-end;
142}
143
144.o-media--rtl .o-media__image {
145 order: 2;
146}
147
148.o-media--rtl .o-media__body {
149 order: 1;
150}
151```
152
153### Easing background gradients
154
155The background gradients generated by browsers usually have a pretty hard transition from one color to another. In some situations, this results in a clearly visible edge where the transition ends.
156
157[Andreas Larsen wrote an article on CSS-Tricks](https://css-tricks.com/easing-linear-gradients/) where this whole problem is explained in detail.
158He also developed a solution, a [PostCSS plugin](https://github.com/larsenwork/postcss-easing-gradients) which automatically converts linear gradients using an easing function into regular linear-gradients.
159
160This solution works for simple use cases, but unfortunately it wasn't suitable for me.
161First, I wanted to use easing radial-gradients as well, which aren't supported by the PostCSS plugin.
162And second, I wanted to freely position the color stops and not be locked to 0% for the start and 100% for the end.
163
164The easing gradients provided by iro-sass address the above problems.
165Moreover, they have one more major feature: You can use multiple color stops with varying easing functions.
166
167The syntax is kept as close to the [new CSSWG proposal](https://github.com/w3c/csswg-drafts/issues/1332) as possible to make the transition to the native easing gradients easier later on.
168
169Example usage:
170
171```scss
172.test {
173 background-image: iro-easing-linear-gradient(
174 to right,
175 #000 2em,
176 #f00,
177 ease-in-out-sine,
178 transparent 10em
179 );
180}
181```
182
183This will generate a linear-gradient where black normally fades into red, from 2em to 6em.
184Then, red *smoothly* fades into transparent, from 6em to 10em.
185After that, the gradient remains transparent.
186
187### Context stacks
188
189Context stacks are a temporary data storage and, as the name suggests, are used like a conventional stack data structure.
190This means: Whenever you want to store a context -- which is an identifier and any kind of data, such as a map, a list, a string, etc... -- you push it to the stack.
191From then on, this context is publicly accessible.
192In order to remove it, you pop the stack.
193
194This feature becomes extremely useful when paired with mixins and their `@content` directive: Pushing a context to the stack before `@content` and popping the stack afterwards gives it the role of a call stack.
195Thats how the BEM system, for example, attaches metadata to the selectors it generates.
196These information are used to generate optimal selectors without much parsing.
197
198Below is an example of how context stacks can be used:
199
200```scss
201$context-id: 'some-context-stack';
202
203@mixin anything($p) {
204 @include iro-context-push($context-id, 'anything', (
205 --this: 1,
206 --is: true,
207 --the: 'test',
208 --data: $p
209 ));
210
211 @content;
212
213 @include iro-context-pop($context-id);
214}
215
216// Usage:
217
218.test {
219 @include anything('hello') {
220 $context-data: nth(iro-context-get($context-id, 'anything'), 2);
221 $this: map-get($context-data, --this); // 1
222 $is: map-get($context-data, --is); // true
223 $the: map-get($context-data, --the); // 'test'
224 $data: map-get($context-data, --data); // 'hello'
225 }
226}
227```
228
229### Property trees
230
231Property trees are basically global maps that are immutable as long as you just use the intended functions.
232
233It's a very simple feature, but it makes managing large sets of structured data much easier.
234
235Example usage:
236
237```scss
238@include iro-props-save((
239 --accent: #f00,
240 --accent-text: #fff,
241
242 --background: #fff,
243 --text: #222,
244
245 --link: (
246 --idle: (
247 --text: #000,
248 --underline: #f00
249 ),
250 --hover: (
251 --text: #f00,
252 --underline: #f00
253 )
254 )
255), 'light');
256
257// Usage:
258
259p {
260 color: iro-props-get(--text, 'light'); // #222
261 background-color: iro-props-get(--background, 'light'); // #fff
262}
263
264a {
265 color: iro-props-get(--link --idle --text, 'light'); // #000
266 border-bottom: 1px solid iro-props-get(--link --idle --underline, 'light'); // #f00
267 text-decoration: none;
268
269 &:hover {
270 color: iro-props-get(--link --hover --text, 'light'); // #f00
271 border-bottom-color: iro-props-get(--link --hover --underline, 'light'); // #f00
272 }
273}
274```
275
276### Responsive properties
277
278Responsive properties allow you to assign values to properties depending on the current viewport width.
279iro-sass provides a large number of mixins for this task to cover many use cases.
280The most simple one is the following:
281
282```scss
283.title {
284 @include iro-responsive-property(padding, ( 20rem: 2.1rem, 40rem: 2.6rem, 60rem: 3.5rem ));
285}
286```
287
288The padding will be 2.1rem if the viewport is 20rem wide, 2.6rem if it's 40rem wide, and 3.5rem if it's 60rem wide.
289If the viewport is narrower than 20rem, the padding will stick with 2.1rem.
290If the viewport is wider than 60rem, the padding will stick with 3.5rem.
291
292By default, iro-sass will dynamically scale the property value between viewport widths, which is technique known from [fluid typography](https://css-tricks.com/snippets/css/fluid-typography/).
293This behavior can be switched off if it's undesired.
294
295If you use [include-media](https://include-media.com/), all responsive mixins also support named viewports.
296The example above could then be written like this:
297
298```scss
299.title {
300 @include iro-responsive-property(padding, ( phone: 2.1rem, tablet: 2.6rem, desktop: 3.5rem ));
301}
302```
303
304### Modular scales
305
306From the description of [modularscale-sass](https://github.com/modularscale/modularscale-sass):
307
308> A modular scale is a list of values that share the same relationship. These values are often used to size type and create a sense of harmony in a design. Proportions within modular scales are all around us from the spacing of the joints on our fingers to branches on trees. These natural proportions have been used since the time of the ancient Greeks in architecture and design and can be a tremendously helpful tool to leverage for web designers.
309
310iro-sass provides a mixin to create basic and multi-stranded modular scales.
311It's a lightweight alternative to modularscale-sass.
312
313Example with a multi-stranded modular scale:
314
315```scss
316$mod-scale: 1em 2em, 1.1;
317
318h1 {
319 font-size: iro-harmony-modular-scale(3, $mod-scale...); // Will be: 1.128em
320}
321h2 {
322 font-size: iro-harmony-modular-scale(2, $mod-scale...); // Will be: 1.1em
323}
324h3 {
325 font-size: iro-harmony-modular-scale(1, $mod-scale...); // Will be: 1.026em
326}
327```
328
329Combined with iro-sass' responsive properties:
330
331```scss
332$responsive-mod-scale: (
333 320px: (1rem 2rem, 1.1),
334 640px: (1rem 2rem, 1.2)
335);
336
337h1 {
338 @include iro-responsive-modular-scale(font-size, 3, $responsive-mod-scale);
339}
340h2 {
341 @include iro-responsive-modular-scale(font-size, 2, $responsive-mod-scale);
342}
343h3 {
344 @include iro-responsive-modular-scale(font-size, 1, $responsive-mod-scale);
345}
346```