@unsass/breakpoint 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+ indent_style = space
8
+ indent_size = 4
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
13
+
14
+ [*.yml]
15
+ indent_size = 2
package/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ * text=auto
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "npm"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ assignees:
8
+ - "borisdamevin"
9
+ reviewers:
10
+ - "borisdamevin"
@@ -0,0 +1,50 @@
1
+ name: Node.js CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, develop ]
6
+ pull_request:
7
+ branches: [ main, develop ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ node-version: [ 14.x, 16.x ]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+
20
+ - name: Use Node.js ${{ matrix.node-version }}
21
+ uses: actions/setup-node@v2
22
+ with:
23
+ node-version: ${{ matrix.node-version }}
24
+ cache: 'npm'
25
+
26
+ - name: Install Dependencies
27
+ run: npm ci --ignore-scripts
28
+
29
+ - name: Test
30
+ run: npm run test
31
+
32
+ publish:
33
+ runs-on: ubuntu-latest
34
+ needs: test
35
+ if: ${{ github.ref == 'refs/heads/main' }}
36
+
37
+ steps:
38
+ - uses: actions/checkout@v2
39
+ - uses: actions/setup-node@v2
40
+ with:
41
+ node-version: ${{ matrix.node-version }}
42
+
43
+ - name: Install Dependencies
44
+ run: npm ci --ignore-scripts
45
+
46
+ - name: Release
47
+ run: npm run release
48
+ env:
49
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
50
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx --no-install commitlint --edit
@@ -0,0 +1,76 @@
1
+ {
2
+ "branches": [
3
+ "main",
4
+ {
5
+ "name": "beta",
6
+ "prerelease": true
7
+ },
8
+ {
9
+ "name": "alpha",
10
+ "prerelease": true
11
+ }
12
+ ],
13
+ "plugins": [
14
+ "@semantic-release/commit-analyzer",
15
+ [
16
+ "@semantic-release/changelog",
17
+ {
18
+ "changelogTitle": "# Changelog\n\nAll notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines."
19
+ }
20
+ ],
21
+ "@semantic-release/npm",
22
+ [
23
+ "@semantic-release/release-notes-generator",
24
+ {
25
+ "preset": "conventionalcommits",
26
+ "presetConfig": {
27
+ "types": [
28
+ {
29
+ "type": "feat",
30
+ "section": "Features"
31
+ },
32
+ {
33
+ "type": "fix",
34
+ "section": "Bug Fixes"
35
+ },
36
+ {
37
+ "type": "chore",
38
+ "hidden": true
39
+ },
40
+ {
41
+ "type": "build",
42
+ "section": "Build System"
43
+ },
44
+ {
45
+ "type": "docs",
46
+ "hidden": true
47
+ },
48
+ {
49
+ "type": "style",
50
+ "hidden": true
51
+ },
52
+ {
53
+ "type": "refactor",
54
+ "section": "Code Refactoring"
55
+ },
56
+ {
57
+ "type": "perf",
58
+ "hidden": true
59
+ },
60
+ {
61
+ "type": "test",
62
+ "hidden": true
63
+ }
64
+ ]
65
+ }
66
+ }
67
+ ],
68
+ [
69
+ "@semantic-release/git",
70
+ {
71
+ "message": "chore(release): publish version ${nextRelease.version}"
72
+ }
73
+ ],
74
+ "@semantic-release/github"
75
+ ]
76
+ }
@@ -0,0 +1,5 @@
1
+ ## Files
2
+ *.spec.scss
3
+
4
+ ## Folders
5
+ /tests
package/.stylelintrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": [
3
+ "stylelint-config-unsass"
4
+ ],
5
+ "rules": {
6
+ "function-no-unknown": null
7
+ }
8
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
+
5
+ ## 1.0.0 (2022-02-28)
6
+
7
+
8
+ ### Features
9
+
10
+ * **config:** add mixin ([7816aeb](https://github.com/unsass/breakpoint/commit/7816aeb4f4dc16c10eec64f192ca4875aa0a3bd6))
11
+ * **up, down, only, between:** add main mixins ([e005c32](https://github.com/unsass/breakpoint/commit/e005c32a300ecf8185335dc03d199bd4265a5b50))
12
+
13
+
14
+ ### Code Refactoring
15
+
16
+ * clean variables ([d2b6579](https://github.com/unsass/breakpoint/commit/d2b6579d8c7482dceded8230cbc6d64f44dd2d41))
17
+ * **config:** rename `$from-scratch` to `$reset` ([ff8628e](https://github.com/unsass/breakpoint/commit/ff8628ef5169f9a87cd73db199e919b7b81d3efc))
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 unsass
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # Breakpoint
2
+
3
+ [![Version](https://flat.badgen.net/npm/v/@unsass/breakpoint)](https://www.npmjs.com/package/@unsass/breakpoint)
4
+ [![Downloads](https://flat.badgen.net/npm/dt/@unsass/breakpoint)](https://www.npmjs.com/package/@unsass/breakpoint)
5
+ [![License](https://flat.badgen.net/github/license/@unsass/breakpoint)](https://flat.badgen.net/github/license/@unsass/breakpoint)
6
+
7
+ ## Introduction
8
+
9
+ Easily manage your CSS breakpoint rules.
10
+
11
+ ## Installing
12
+
13
+ ```shell
14
+ npm install @unsass/breakpoint
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```scss
20
+ @use "@unsass/breakpoint";
21
+
22
+ .foo {
23
+ @include breakpoint.up(lg) {
24
+ // ...
25
+ }
26
+ }
27
+ ```
28
+
29
+ ### Configuration
30
+
31
+ ```scss
32
+ @use "@unsass/breakpoint" with (
33
+ $screens: (
34
+ "lg": 1024px
35
+ )
36
+ );
37
+ ```
38
+
39
+ ### Options
40
+
41
+ | Variable | Default | Description |
42
+ |------------|-----------------------|---------------------------------------------------------------------------------------------------|
43
+ | `$screens` | See `Tokens` section. | Sets a list of breakpoint tokens. |
44
+ | `$reset` | `false` | Erase the default `$screens` config for helping you on a fresh start with your own custom tokens. |
45
+
46
+ ### Tokens
47
+
48
+ | Key | Value |
49
+ |-------|----------|
50
+ | `xs` | `360px` |
51
+ | `sm` | `480px` |
52
+ | `md` | `768px` |
53
+ | `lg` | `960px` |
54
+ | `xl` | `1200px` |
55
+ | `2xl` | `1400px` |
56
+
57
+ You can also define new size:
58
+
59
+ ```scss
60
+ @use "@unsass/breakpoint" with (
61
+ $screens: (
62
+ "3xl": 1920px
63
+ )
64
+ );
65
+ ```
66
+
67
+ The new token named `3xl` will be added to the default tokens list.
68
+
69
+ ### Top-level config override
70
+
71
+ If variables are already configured on top-level using `@use ... with`, by another dependency for example, you can't use
72
+ this solution anymore, because the module can only be setup once, this is a Sass restriction with **Module System**, but
73
+ another solution exist for override the main configuration, with a mixin!
74
+
75
+ See [official documentation](https://sass-lang.com/documentation/at-rules/use#with-mixins) about override configuration
76
+ with mixins.
77
+
78
+ | Mixin | Description |
79
+ |----------------------------|:-----------------------------------------|
80
+ | `config($screens, $reset)` | Override top-level `with` configuration. |
81
+
82
+ #### Declare config with `breakpoint.config()`
83
+
84
+ ```scss
85
+ // Extend the default list...
86
+ @include breakpoint.config((
87
+ "3xl": 1980px
88
+ ));
89
+
90
+ // ... or reset for fresh start...
91
+ @include breakpoint.config((
92
+ "tablet": 768px,
93
+ "desktop": 960px
94
+ ), true);
95
+ ```
96
+
97
+ ## API
98
+
99
+ ### Sass mixins
100
+
101
+ | Mixin | Description |
102
+ |-----------------------|--------------------------------------------------------------------------------------------------------------------------------|
103
+ | `up($token)` | Sets media rule for minimum with only. |
104
+ | `down($token)` | Sets media rule for maximum with only. |
105
+ | `only($token)` | Sets media rule for between minimum and maximum widths, but the maximum will be automatically set with next value of `$token`. |
106
+ | `between($min, $max)` | Sets media rule for between minimum and maximum widths. |
107
+
108
+ #### Up rule with `breakpoint.up()`
109
+
110
+ The following Sass...
111
+
112
+ ```scss
113
+ @use "@unsass/breakpoint";
114
+
115
+ .foo {
116
+ @include breakpoint.up(lg) {
117
+ color: darkcyan;
118
+ }
119
+ }
120
+ ```
121
+
122
+ ...will produce the following CSS...
123
+
124
+ ```css
125
+ @media (min-width: 960px) {
126
+ .foo {
127
+ color: darkcyan;
128
+ }
129
+ }
130
+ ```
131
+
132
+ #### Down rule with `breakpoint.down()`
133
+
134
+ The following Sass...
135
+
136
+ ```scss
137
+ @use "@unsass/breakpoint";
138
+
139
+ .foo {
140
+ @include breakpoint.down(lg) {
141
+ color: darkcyan;
142
+ }
143
+ }
144
+ ```
145
+
146
+ ...will produce the following CSS...
147
+
148
+ ```css
149
+ @media (max-width: 959px) {
150
+ .foo {
151
+ color: darkcyan;
152
+ }
153
+ }
154
+ ```
155
+
156
+ #### Only rule with `breakpoint.only()`
157
+
158
+ The following Sass...
159
+
160
+ ```scss
161
+ @use "@unsass/breakpoint";
162
+
163
+ .foo {
164
+ @include breakpoint.only(lg) {
165
+ color: darkcyan;
166
+ }
167
+ }
168
+ ```
169
+
170
+ ...will produce the following CSS...
171
+
172
+ ```css
173
+ @media (min-width: 960px) and (max-width: 1199px) {
174
+ .foo {
175
+ color: darkcyan;
176
+ }
177
+ }
178
+ ```
179
+
180
+ #### Between rule with `breakpoint.between()`
181
+
182
+ The following Sass...
183
+
184
+ ```scss
185
+ @use "@unsass/breakpoint";
186
+
187
+ .foo {
188
+ @include breakpoint.between(md, xl) {
189
+ color: darkcyan;
190
+ }
191
+ }
192
+ ```
193
+
194
+ ...will produce the following CSS...
195
+
196
+ ```css
197
+ @media (min-width: 768px) and (max-width: 1199px) {
198
+ .foo {
199
+ color: darkcyan;
200
+ }
201
+ }
202
+ ```
203
+
204
+ ### Sass functions
205
+
206
+ | Function | Description |
207
+ |---------------------|---------------------------------------------|
208
+ | `get-value($token)` | Get value from the configured tokens list. |
209
+
210
+ #### Get token value with `breakpoint.get-value()`
211
+
212
+ The following Sass...
213
+
214
+ ```scss
215
+ @use "@unsass/breakpoint";
216
+
217
+ .foo {
218
+ width: breakpoint.get-value(lg);
219
+ }
220
+ ```
221
+
222
+ ...will produce the following CSS...
223
+
224
+ ```css
225
+ .foo {
226
+ width: 960px;
227
+ }
228
+ ```
@@ -0,0 +1,43 @@
1
+ // ============================================================================================= //
2
+ // FUNCTIONS //
3
+ // ============================================================================================= //
4
+
5
+ @use "sass:list";
6
+ @use "sass:map";
7
+ @use "@sass-collective/strip-unit";
8
+ @use "./variables";
9
+
10
+ ///
11
+ /// Get value.
12
+ ///
13
+ @function get-value($token) {
14
+ @return map.get(variables.$extend, $token);
15
+ }
16
+
17
+ ///
18
+ /// Get next.
19
+ ///
20
+ @function get-next($value) {
21
+ $keys: map.keys(variables.$extend);
22
+ $n: list.index($keys, $value);
23
+
24
+ @return if($n < length($keys), list.nth($keys, $n + 1), null);
25
+ }
26
+
27
+ ///
28
+ /// Set min.
29
+ ///
30
+ @function set-min($token) {
31
+ $min: get-value($token);
32
+
33
+ @return if($min != 0, $min, null);
34
+ }
35
+
36
+ ///
37
+ /// Set max.
38
+ ///
39
+ @function set-max($token) {
40
+ $max: get-value($token);
41
+
42
+ @return if($max and $max > 0, $max - 1, null);
43
+ }
package/_mixins.scss ADDED
@@ -0,0 +1,168 @@
1
+ // ============================================================================================= //
2
+ // MIXINS //
3
+ // ============================================================================================= //
4
+
5
+ @use "sass:map";
6
+ @use "sass:string";
7
+ @use "./functions";
8
+ @use "./variables";
9
+
10
+ ///
11
+ /// @example - scss
12
+ /// .foo {
13
+ /// @include up(lg) {
14
+ /// color: darkcyan;
15
+ /// }
16
+ /// }
17
+ ///
18
+ /// @example - css
19
+ /// @media (min-width: 960px) {
20
+ /// .foo {
21
+ /// color: darkcyan;
22
+ /// }
23
+ /// }
24
+ ///
25
+ /// @see {function} functions.set-min
26
+ ///
27
+ @mixin up($token) {
28
+ @if $token and not map.has-key(variables.$extend, $token) {
29
+ @error "Invalid token, `#{$token}` doesn't exist. Choose one of #{map.keys(variables.$extend)}.";
30
+ }
31
+
32
+ $min: functions.set-min($token);
33
+
34
+ @if $min {
35
+ @media (min-width: $min) {
36
+ @content;
37
+ }
38
+ } @else {
39
+ @content;
40
+ }
41
+ }
42
+
43
+ ///
44
+ /// @example - scss
45
+ /// .foo {
46
+ /// @include down(lg) {
47
+ /// color: darkcyan;
48
+ /// }
49
+ /// }
50
+ ///
51
+ /// @example - css
52
+ /// @media (max-width: 959px) {
53
+ /// .foo {
54
+ /// color: darkcyan;
55
+ /// }
56
+ /// }
57
+ ///
58
+ /// @see {function} functions.set-max
59
+ ///
60
+ @mixin down($token) {
61
+ @if $token and not map.has-key(variables.$extend, $token) {
62
+ @error "Invalid token, `#{$token}` doesn't exist. Choose one of #{map.keys(variables.$extend)}.";
63
+ }
64
+
65
+ $max: functions.set-max($token);
66
+
67
+ @if $max {
68
+ @media (max-width: $max) {
69
+ @content;
70
+ }
71
+ } @else {
72
+ @content;
73
+ }
74
+ }
75
+
76
+ ///
77
+ /// @example - scss
78
+ /// .foo {
79
+ /// @include only(lg) {
80
+ /// color: darkcyan;
81
+ /// }
82
+ /// }
83
+ ///
84
+ /// @example - css
85
+ /// @media (min-width: 960px) and (max-width: 1199px) {
86
+ /// .foo {
87
+ /// color: darkcyan;
88
+ /// }
89
+ /// }
90
+ ///
91
+ /// @see {function} functions.set-min
92
+ /// @see {function} functions.set-max
93
+ /// @see {function} functions.get-next
94
+ ///
95
+ @mixin only($token) {
96
+ @if $token and not map.has-key(variables.$extend, $token) {
97
+ @error "Invalid token, `#{$token}` doesn't exist. Choose one of #{map.keys(variables.$extend)}.";
98
+ }
99
+
100
+ $min: functions.set-min($token);
101
+ $next: functions.get-next($token);
102
+ $max: functions.set-max($next);
103
+
104
+ @if $min != null and $max != null {
105
+ @media (min-width: $min) and (max-width: $max) {
106
+ @content;
107
+ }
108
+ } @else if $max == null {
109
+ @include up($token) {
110
+ @content;
111
+ }
112
+ }
113
+ }
114
+
115
+ ///
116
+ /// @example - scss
117
+ /// .foo {
118
+ /// @include between(md, xl) {
119
+ /// color: darkcyan;
120
+ /// }
121
+ /// }
122
+ ///
123
+ /// @example - css
124
+ /// @media (min-width: 768px) and (max-width: 1199px) {
125
+ /// .foo {
126
+ /// color: darkcyan;
127
+ /// }
128
+ /// }
129
+ ///
130
+ /// @see {function} functions.set-min
131
+ /// @see {function} functions.set-max
132
+ ///
133
+ @mixin between($min, $max) {
134
+ @if $min and not map.has-key(variables.$extend, $min) {
135
+ @error "Invalid token, `#{$min}` doesn't exist. Choose one of #{map.keys(variables.$extend)}.";
136
+ } @else if $max and not map.has-key(variables.$extend, $max) {
137
+ @error "Invalid token, `#{$max}` doesn't exist. Choose one of #{map.keys(variables.$extend)}.";
138
+ }
139
+
140
+ $min: functions.set-min($min);
141
+ $max: functions.set-max($max);
142
+
143
+ @if $min != null and $max != null {
144
+ @media (min-width: $min) and (max-width: $max) {
145
+ @content;
146
+ }
147
+ }
148
+ }
149
+
150
+ ///
151
+ /// @example - scss
152
+ /// @include config((
153
+ /// "3xl": 1980px
154
+ /// ));
155
+ ///
156
+ /// @example - scss
157
+ /// @include config((
158
+ /// "tablet": 768px,
159
+ // "desktop": 960px
160
+ /// ), true);
161
+ ///
162
+ @mixin config($screens: (), $reset: false) {
163
+ @if $screens and not $reset {
164
+ variables.$extend: map.merge(variables.$extend, $screens);
165
+ } @else {
166
+ variables.$extend: $screens;
167
+ }
168
+ }
@@ -0,0 +1,24 @@
1
+ // ============================================================================================= //
2
+ // VARIABLES //
3
+ // ============================================================================================= //
4
+
5
+ @use "sass:map";
6
+
7
+ $_defaults: (
8
+ "xs": 320px,
9
+ "sm": 480px,
10
+ "md": 768px,
11
+ "lg": 960px,
12
+ "xl": 1200px,
13
+ "2xl": 1400px
14
+ );
15
+
16
+ $extend: ();
17
+ $screens: () !default;
18
+ $reset: false !default;
19
+
20
+ @if $reset {
21
+ $extend: $screens;
22
+ } @else {
23
+ $extend: map.merge($_defaults, $screens);
24
+ }
@@ -0,0 +1,9 @@
1
+ // ============================================================================================= //
2
+ // COMMITLINT //
3
+ // ============================================================================================= //
4
+
5
+ module.exports = {
6
+ extends: [
7
+ '@commitlint/config-conventional'
8
+ ]
9
+ };
package/index.scss ADDED
@@ -0,0 +1,7 @@
1
+ // ============================================================================================= //
2
+ // INDEX //
3
+ // ============================================================================================= //
4
+
5
+ @forward "./variables";
6
+ @forward "./mixins";
7
+ @forward "./functions" hide get-next, set-min, set-max;
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@unsass/breakpoint",
3
+ "version": "1.0.0",
4
+ "description": "Easily manage your CSS breakpoint rules.",
5
+ "scripts": {
6
+ "lint:css": "stylelint --fix \"**/*.scss\"",
7
+ "lint": "npm-run-all --parallel lint:*",
8
+ "test": "jest",
9
+ "prepare": "husky install",
10
+ "release": "semantic-release --branches main"
11
+ },
12
+ "engines": {
13
+ "node": ">=14.0.0",
14
+ "npm": ">=8.0.0"
15
+ },
16
+ "devDependencies": {
17
+ "@commitlint/cli": "^16.2.1",
18
+ "@commitlint/config-conventional": "^16.2.1",
19
+ "@semantic-release/changelog": "^6.0.1",
20
+ "@semantic-release/git": "^10.0.1",
21
+ "@types/node": "^17.0.21",
22
+ "glob": "^7.2.0",
23
+ "husky": "^7.0.4",
24
+ "jest": "^27.5.1",
25
+ "npm-run-all": "^4.1.5",
26
+ "sass-true": "^6.1.0-beta.1",
27
+ "semantic-release": "^19.0.2",
28
+ "stylelint": "^14.5.3",
29
+ "stylelint-config-unsass": "^1.0.0"
30
+ },
31
+ "dependencies": {
32
+ "@sass-collective/strip-unit": "^3.1.2",
33
+ "sass": "^1.49.9"
34
+ },
35
+ "keywords": [
36
+ "breakpoint",
37
+ "unsass",
38
+ "sass",
39
+ "css"
40
+ ],
41
+ "license": "MIT",
42
+ "homepage": "https://github.com/unsass/breakpoint#readme",
43
+ "bugs": {
44
+ "url": "https://github.com/unsass/breakpoint/issues"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/unsass/breakpoint.git"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }
@@ -0,0 +1,24 @@
1
+ // ============================================================================================= //
2
+ // TEST //
3
+ // ============================================================================================= //
4
+
5
+ @use "true" as *;
6
+ @use "../index" as breakpoint;
7
+
8
+ @include describe("breakpoint.get-value()") {
9
+ @include it("Should return value from token.") {
10
+ @include assert {
11
+ @include output(false) {
12
+ .foo {
13
+ width: breakpoint.get-value(lg);
14
+ }
15
+ }
16
+
17
+ @include expect(false) {
18
+ .foo {
19
+ width: 960px;
20
+ }
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,144 @@
1
+ // ============================================================================================= //
2
+ // TEST //
3
+ // ============================================================================================= //
4
+
5
+ @use "true" as *;
6
+ @use "../index" as breakpoint;
7
+
8
+ @include describe("breakpoint.up()") {
9
+ @include it("Should return breakpoint 'up' rules.") {
10
+ @include assert {
11
+ @include output(false) {
12
+ .foo {
13
+ @include breakpoint.up(lg) {
14
+ color: darkcyan;
15
+ }
16
+ }
17
+ }
18
+
19
+ @include expect(false) {
20
+ @media (min-width: 960px) {
21
+ .foo {
22
+ color: darkcyan;
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+
30
+ @include describe("breakpoint.down()") {
31
+ @include it("Should return breakpoint 'down' rules.") {
32
+ @include assert {
33
+ @include output(false) {
34
+ .foo {
35
+ @include breakpoint.down(lg) {
36
+ color: darkcyan;
37
+ }
38
+ }
39
+ }
40
+
41
+ @include expect(false) {
42
+ @media (max-width: 959px) {
43
+ .foo {
44
+ color: darkcyan;
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+
52
+ @include describe("breakpoint.only()") {
53
+ @include it("Should return breakpoint 'only' rules.") {
54
+ @include assert {
55
+ @include output(false) {
56
+ .foo {
57
+ @include breakpoint.only(lg) {
58
+ color: darkcyan;
59
+ }
60
+ }
61
+ }
62
+
63
+ @include expect(false) {
64
+ @media (min-width: 960px) and (max-width: 1199px) {
65
+ .foo {
66
+ color: darkcyan;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ @include describe("breakpoint.between()") {
75
+ @include it("Should return breakpoint 'between' rules.") {
76
+ @include assert {
77
+ @include output(false) {
78
+ .foo {
79
+ @include breakpoint.between(md, xl) {
80
+ color: darkcyan;
81
+ }
82
+ }
83
+ }
84
+
85
+ @include expect(false) {
86
+ @media (min-width: 768px) and (max-width: 1199px) {
87
+ .foo {
88
+ color: darkcyan;
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ @include describe("breakpoint.config()") {
97
+ @include it("Should return breakpoint 'config' rules.") {
98
+ @include assert {
99
+ @include output(false) {
100
+ @include breakpoint.config((
101
+ "3xl": 1980px
102
+ ));
103
+
104
+ .foo {
105
+ @include breakpoint.up("3xl") {
106
+ color: darkcyan;
107
+ }
108
+ }
109
+ }
110
+
111
+ @include expect(false) {
112
+ @media (min-width: 1980px) {
113
+ .foo {
114
+ color: darkcyan;
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ @include it("Should return breakpoint 'config' rules with '$reset' option.") {
122
+ @include assert {
123
+ @include output(false) {
124
+ @include breakpoint.config((
125
+ "tablet": 768px
126
+ ), true);
127
+
128
+ .foo {
129
+ @include breakpoint.up("tablet") {
130
+ color: darkcyan;
131
+ }
132
+ }
133
+ }
134
+
135
+ @include expect(false) {
136
+ @media (min-width: 768px) {
137
+ .foo {
138
+ color: darkcyan;
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
@@ -0,0 +1,44 @@
1
+ // ============================================================================================= //
2
+ // TESTS //
3
+ // ============================================================================================= //
4
+
5
+ const path = require('path');
6
+ const sassTrue = require('sass-true');
7
+ const glob = require('glob');
8
+
9
+ /**
10
+ *
11
+ * @param url
12
+ * @param prev
13
+ * @param done
14
+ * @returns {{file: string}}
15
+ */
16
+ function importer(url, prev, done) {
17
+ if (url[0] === '~') {
18
+ url = path.resolve('node_modules', url.substr(1));
19
+ }
20
+
21
+ return {
22
+ file: url
23
+ };
24
+ }
25
+
26
+ describe('Sass', () => {
27
+ // Find all the Sass files that end in `*.spec.scss` in any directory of this project.
28
+ // I use path.resolve because True requires absolute paths to compile test files.
29
+ const sassTestFiles = glob.sync(path.resolve(process.cwd(), '**/*.spec.scss'));
30
+
31
+ // Run True on every file found with to describe and its methods provided
32
+ sassTestFiles.forEach((file) =>
33
+ sassTrue.runSass({
34
+ importer,
35
+ file,
36
+ includePaths: [
37
+ './node_modules'
38
+ ]
39
+ }, {
40
+ describe,
41
+ it
42
+ })
43
+ );
44
+ });