Skip to content

Commit 9f55a9b

Browse files
authored
Update README.md
1 parent bf8db58 commit 9f55a9b

File tree

1 file changed

+265
-11
lines changed

1 file changed

+265
-11
lines changed

README.md

Lines changed: 265 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,277 @@
44

55
SCSS helpers for every day usage
66

7-
This is a WIP repository. For details about the current helpers, please see below.
7+
This is a WIP repository. For details about the current helpers and tools, please see below.
8+
9+
## Download
10+
11+
You can [download](https://github.com/scriptex/scss-helpers/archive/master.zip) this repository directly or install it via `npm` or `yarn`:
12+
13+
```sh
14+
# later we will have a real name for the package (let's hope so)
15+
16+
npm i https://github.com/scriptex/scss-helpers
17+
18+
# or
19+
20+
yarn add https://github.com/scriptex/scss-helpers
21+
```
22+
23+
## Usage
24+
25+
If installed via `npm` or `yarn`, just `@import` the main file:
26+
27+
```scss
28+
@import 'scss-helpers';
29+
/* or if that does not work */
30+
@import 'scss-helpers/index.scss';
31+
```
32+
33+
If manually downloaded, then copy the `scss-helpers` folder in your application folder and manually import the `index.scss` file or the file that you wish to use.
34+
35+
More details about each file can be found below.
836

937
## Helpers
1038

11-
1. [Rainbow](https://codepen.io/scriptex/pen/pQPKXJ): Multiple color stops gradient without fade and blur between color stops
12-
2. [Triangle](https://codepen.io/scriptex/pen/xQgZBg): Triange with rounded corners and optionally gradient background
13-
3. [Unbreak](https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/): Prevent long urls from breaking out of container
14-
4. SVG Loader - A mixin which accepts an SVG string and some options (`background-repeat`, `background-position`, `background-size`) and creates an SVG background image
39+
### Rainbow
40+
41+
This is a mixin for multiple color stops gradient without blurs and fading between stops.
42+
You can see a demo [here](https://codepen.io/scriptex/pen/pQPKXJ).
43+
44+
To import only this mixin, use
45+
46+
```scss
47+
@import 'scss-helpers/helpers/rainbow';
48+
```
49+
50+
Then use the mixin:
51+
52+
```scss
53+
/*
54+
* @param $colors - SCSS Map of colors
55+
* @param $stops - SCSS Map of color stops
56+
* @param $direction - One of 'horizontal' or 'vertical'
57+
*/
58+
@include rainbow($colors, $stops, $direction);
59+
```
60+
61+
---
62+
63+
### Triangle
64+
65+
This is a mixin for triangle shape with rounded corners (or without, it's up to you).
66+
The triangle can also have a gradient background.
67+
You can see a demo [here](https://codepen.io/scriptex/pen/xQgZBg).
68+
69+
To import only this mixin, use
70+
71+
```scss
72+
@import 'scss-helpers/helpers/triangle';
73+
```
74+
75+
Then use the mixin:
76+
77+
```scss
78+
/*
79+
* @param: $size - width/height of the triangle. Default: 2rem
80+
* @param: $background - any valid CSS background declaration. Default: red
81+
* @param: $radius - true or false (if false, no radius). Default: true
82+
*/
83+
@include rainbow($size, $background, $radius);
84+
```
85+
86+
---
87+
88+
### Unbreak
89+
90+
This is a mixin which, when included, prevents long text strings from breaking out of their container (and introducing horizontal scrollbars).
91+
For more info, please refer to [this CSS Tricks post](https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/).
92+
93+
To import only this mixin, use
94+
95+
```scss
96+
@import 'scss-helpers/helpers/unbreak';
97+
```
98+
99+
Then use the mixin:
100+
101+
```scss
102+
/*
103+
* @param: $hyphens - one of 'none', 'manual' or 'auto'. Default: auto
104+
*/
105+
@include unbreak($size, $background, $radius);
106+
```
107+
108+
---
109+
110+
### SVG Loader
111+
112+
This is an animated SVG loader with predefined SVG image embeded into the stylesheet.
113+
114+
To import only this mixin, use
115+
116+
```scss
117+
@import 'scss-helpers/helpers/loader';
118+
```
119+
120+
Then use the mixin:
121+
122+
```scss
123+
/*
124+
* @param: $loader - SVG image code. Defaults to [this](https://github.com/scriptex/scss-helpers/blob/master/helpers/_loader.scss#L3)
125+
* @param: $repeat - background-repeat property. Default: no-repeat
126+
* @param: $position - background-position property. Default: 50% 50%
127+
* @param: $size - background-size property. Default: 2rem 2rem
128+
*/
129+
@include loader($loader, $repeat, $position, $size);
130+
```
15131

16132
## Tools
17133

18-
1. Media query for hover.
19-
2. Function for easy usage of CSS custom properties
20-
3. Function for replacing string
21-
4. Function for converting a SVG code to CSS friendly string
22-
5. SVG background
23-
6. SVG multiple background images
134+
---
135+
136+
### Hover media query
137+
138+
This is a(n experimental) media query for detecting devices which support hover.
139+
Since IE does not support this, the hover will work in any version of IE (above 9 of course) which makes the hover media just noise.
140+
141+
To import only this file, use
142+
143+
```scss
144+
@import 'scss-helpers/tools/hover';
145+
```
146+
147+
Then use the media query:
148+
149+
```scss
150+
@include hover {
151+
/* your hover state goes here */
152+
}
153+
```
154+
155+
---
156+
157+
### String replace function
158+
159+
A handy function which replaces all occurences of a string in another string.
160+
161+
To import only this file, use
162+
163+
```scss
164+
@import 'scss-helpers/tools/string-replace';
165+
```
166+
167+
Then use the function:
168+
169+
```scss
170+
$string: 'something meaningful';
171+
$search: 'meaningful';
172+
$replace: 'awesome';
173+
174+
$result: str-replace($string, $search, $replace: '');
175+
176+
/*
177+
* $result should equal to 'something awesome'
178+
*/
179+
```
180+
181+
---
182+
183+
### Mixin for SVG background
184+
185+
This is similar to the `loader` mixin but accepts a valid SVG code as first argument
186+
187+
To import only this mixin, use
188+
189+
```scss
190+
@import 'scss-helpers/tools/svg-background';
191+
```
192+
193+
Then use the mixin:
194+
195+
```scss
196+
/*
197+
* @param: $svg - SVG image code
198+
* @param: $repeat - background-repeat property. Default: no-repeat
199+
* @param: $position - background-position property. Default: 0 0
200+
* @param: $size - background-size property. Default: 100% 100%
201+
*/
202+
@include background-svg($svg, $repeat, $position, $size);
203+
```
204+
205+
---
206+
207+
### Mixin for multiple SVG background image
208+
209+
This mixins accepts a list of SVG image codes and returns a `background-image` containing all of the SVGs
210+
211+
To import only this mixin, use
212+
213+
```scss
214+
@import 'scss-helpers/tools/svg-background-multiple';
215+
```
216+
217+
Then use the mixin:
218+
219+
```scss
220+
/*
221+
* Each parameter is a valid SVG code string
222+
*/
223+
@include multi-background-svg($svg1, $svg2, $svg3, $svg4);
224+
```
225+
226+
---
227+
228+
### Function for converting SVG code to CSS friendly encoded string
229+
230+
This function accepts a valid SVG code as string and returns base64 encoded string.
231+
232+
To import only this function, use
233+
234+
```scss
235+
@import 'scss-helpers/tools/svg-url';
236+
```
237+
238+
Then use the function:
239+
240+
```scss
241+
$svg-image: '<svg xmlns="http://www.w3.org/2000/svg">MORE SVG CODE HERE</svg>';
242+
$svg-string: svg-url($svg-image);
243+
```
244+
245+
---
246+
247+
### Function for easy usage of CSS custom properties
248+
249+
Let's say that you have several CSS custom properties defined:
250+
251+
```css
252+
:root {
253+
--main-color: #bada55;
254+
--font-size-base: 1.25rem;
255+
}
256+
```
257+
258+
And you use these custom properties everywhere.
259+
Instead of doing this:
260+
261+
```css
262+
body {
263+
font-size: var(--font-size-base);
264+
color: var(--main-color);
265+
}
266+
```
267+
268+
you can do this:
269+
270+
```scss
271+
@import 'scss-helpers/tools/v';
272+
273+
body {
274+
font-size: v(font-size-base);
275+
color: v(main-color);
276+
}
277+
```
24278

25279
## LICENSE
26280

0 commit comments

Comments
 (0)