quantity-queries 0.3 → 0.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +30 -15
- data/lib/quantity-queries.rb +2 -2
- data/stylesheets/_quantity-queries.scss +43 -7
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0560b5c09bd33a74008faa3e727e10f8675f18bd
|
4
|
+
data.tar.gz: 16fbfb76b7cefd8635062884a9fc742b9c3c2368
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b358e16029c320a4f0f40dc0df22bd8b2884536b4fb938731fc468615e04b977dd7baf36d66dd5c4b4779da04845458089af2945b3098f8a91642361bf160f2
|
7
|
+
data.tar.gz: 4f6f5f7e13fe362efa764d099a0a770e9e3fdd98bf0ab19d0e46122ffc64116040768c5896d7b78deb4c34581073c038313a94654559014d4e94c95a6a90c030
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Quantity Queries mixins
|
2
2
|
|
3
|
-
Simple quantity queries mixins for Sass. Use quantity as a condition. Learn more about quantity queries in this [A List Apart article](http://alistapart.com/article/quantity-queries-for-css).
|
3
|
+
Simple quantity queries mixins for Sass. Use quantity as a condition to style your items. Learn more about quantity queries in this [A List Apart article](http://alistapart.com/article/quantity-queries-for-css). See the mixins in action in this [CodePen Demo](http://codepen.io/danielguillan/pen/GgBOxm)
|
4
|
+
|
5
|
+
[](https://travis-ci.org/danielguillan/quantity-queries)
|
4
6
|
|
5
7
|
## Install
|
6
8
|
|
@@ -27,25 +29,32 @@ Import it into your main stylesheet:
|
|
27
29
|
|
28
30
|
@import 'quantity-queries';
|
29
31
|
|
30
|
-
### at-least
|
32
|
+
### at-least()
|
31
33
|
|
32
|
-
Target the items inside elements that contain
|
34
|
+
Target the items inside elements that contain `$count` items or more:
|
33
35
|
|
34
36
|
@include at-least($count) { ... }
|
35
37
|
|
36
38
|
|
37
|
-
### at-most
|
39
|
+
### at-most()
|
40
|
+
|
41
|
+
Target the items inside elements that contain `$count` items or less:
|
42
|
+
|
43
|
+
@include at-most($count) { ... }
|
44
|
+
|
45
|
+
|
46
|
+
### between()
|
38
47
|
|
39
|
-
Target the items inside elements that contain
|
48
|
+
Target the items inside elements that contain a range between `$first` and `$last` items:
|
40
49
|
|
41
|
-
@include
|
50
|
+
@include between($first, $last) { ... }
|
42
51
|
|
43
52
|
|
44
|
-
###
|
53
|
+
### exactly()
|
45
54
|
|
46
|
-
Target the items inside elements that contain
|
55
|
+
Target the items inside elements that contain exactly `$count` items:
|
47
56
|
|
48
|
-
@include
|
57
|
+
@include exactly($count) { ... }
|
49
58
|
|
50
59
|
### Example
|
51
60
|
|
@@ -68,22 +77,28 @@ ul > li {
|
|
68
77
|
@include between(5, 8) {
|
69
78
|
background-color: green;
|
70
79
|
}
|
80
|
+
|
81
|
+
// Add a shadow to `li` items when there are exactly 8 items
|
82
|
+
@include exactly(8) {
|
83
|
+
box-shadow: 0 1px 3px #000;
|
84
|
+
}
|
71
85
|
}
|
72
86
|
```
|
73
87
|
|
74
88
|
### Custom selector
|
75
89
|
|
76
|
-
The quantity query mixins assume you want to use the current simple selector for
|
77
|
-
all your items by default. `li` in the previous example. If you need a diffrent
|
78
|
-
selector or want it to be selector agnostic (a.k.a. the universal selector: `*`)
|
79
|
-
you just need to pass it in the mixin:
|
90
|
+
The quantity query mixins assume you want to use the current last simple selector for all the items by default (`li` in the above example). If you need a different selector or want the quantity query to be selector agnostic pass the desired selector to the mixin.
|
80
91
|
|
81
92
|
```scss
|
82
93
|
|
83
94
|
nav div {
|
84
|
-
@include at-
|
95
|
+
@include at-least(4, '*') { ... }; // selector agnostic (universal selector)
|
85
96
|
@include between(4, 8, 'span') { ... }; // use span instead of div
|
86
97
|
}
|
87
98
|
```
|
88
99
|
|
89
|
-
|
100
|
+
## Demo on [CodePen](http://codepen.io/danielguillan/pen/GgBOxm)
|
101
|
+
|
102
|
+
## [LESS version](https://github.com/adjohnson916/quantity-queries.less)
|
103
|
+
(by [@adjohnson916](https://github.com/adjohnson916))
|
104
|
+
|
data/lib/quantity-queries.rb
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
// 3. At least
|
8
8
|
// 4. At most
|
9
9
|
// 5. Between
|
10
|
+
// 6. Exactly
|
10
11
|
|
11
12
|
|
12
13
|
// -----------------------------------------------------------------------------
|
@@ -76,7 +77,7 @@
|
|
76
77
|
$selector-append: ':nth-last-child(n+#{$count})';
|
77
78
|
|
78
79
|
@if type-of($count) != 'number' or not unitless($count) or $count < 1 {
|
79
|
-
@error '`#{$count}` is not a valid number for `at-
|
80
|
+
@error '`#{$count}` is not a valid number for `at-least`';
|
80
81
|
}
|
81
82
|
|
82
83
|
@if $selector != null and (type-of($selector) != 'string' or length($selector) > 1) {
|
@@ -118,10 +119,10 @@
|
|
118
119
|
@error '`#{$selector}` is not a valid selector for `at-most`';
|
119
120
|
}
|
120
121
|
|
121
|
-
$at-
|
122
|
+
$at-most-selector: _build-quantity-selector($selector-append, $selector);
|
122
123
|
|
123
124
|
|
124
|
-
@at-root #{$at-
|
125
|
+
@at-root #{$at-most-selector} {
|
125
126
|
@content;
|
126
127
|
}
|
127
128
|
}
|
@@ -148,11 +149,11 @@
|
|
148
149
|
$selector-append: ':nth-last-child(n+#{$first}):nth-last-child(-n+#{$last}):first-child';
|
149
150
|
|
150
151
|
@if type-of($first) != 'number' or not unitless($first) or $first < 1 {
|
151
|
-
@error '`#{$first}` is not a valid number for `
|
152
|
+
@error '`#{$first}` is not a valid number for `between`';
|
152
153
|
}
|
153
154
|
|
154
155
|
@if type-of($last) != 'number' or not unitless($last) or $last < 1 {
|
155
|
-
@error '`#{$last}` is not a valid number for `
|
156
|
+
@error '`#{$last}` is not a valid number for `between`';
|
156
157
|
}
|
157
158
|
|
158
159
|
@if $first > $last {
|
@@ -163,10 +164,45 @@
|
|
163
164
|
@error '`#{$selector}` is not a valid selector for `between`';
|
164
165
|
}
|
165
166
|
|
166
|
-
$
|
167
|
+
$between-selector: _build-quantity-selector($selector-append, $selector);
|
167
168
|
|
168
169
|
|
169
|
-
@at-root #{$
|
170
|
+
@at-root #{$between-selector} {
|
171
|
+
@content;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
// -----------------------------------------------------------------------------
|
177
|
+
// 6. Exactly
|
178
|
+
// -----------------------------------------------------------------------------
|
179
|
+
|
180
|
+
/// Query when total items is exactly N items
|
181
|
+
/// @param {number} $count - Quantity to match (equal)
|
182
|
+
/// @example scss - Make the items color red when there are exactly 4 items
|
183
|
+
/// ul li {
|
184
|
+
/// @include exactly(4) { color: red; }
|
185
|
+
/// }
|
186
|
+
/// @example scss - Make the items color blue when there are exactly 6 items and use '*' (element agnostic) as the item selector
|
187
|
+
/// ul li {
|
188
|
+
/// @include exactly(6, '*') { color: blue; }
|
189
|
+
/// }
|
190
|
+
|
191
|
+
@mixin exactly($count, $selector: null) {
|
192
|
+
$selector-append: ':nth-last-child(#{$count}):first-child';
|
193
|
+
|
194
|
+
@if type-of($count) != 'number' or not unitless($count) or $count < 1 {
|
195
|
+
@error '`#{$count}` is not a valid number for `exactly`';
|
196
|
+
}
|
197
|
+
|
198
|
+
@if $selector != null and (type-of($selector) != 'string' or length($selector) > 1) {
|
199
|
+
@error '`#{$selector}` is not a valid selector for `exactly`';
|
200
|
+
}
|
201
|
+
|
202
|
+
$exactly-selector: _build-quantity-selector($selector-append, $selector);
|
203
|
+
|
204
|
+
|
205
|
+
@at-root #{$exactly-selector} {
|
170
206
|
@content;
|
171
207
|
}
|
172
208
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quantity-queries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Guillan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.0
|
40
|
+
version: '1.0'
|
41
41
|
description: Simple item quantity queries mixins for Sass
|
42
42
|
email:
|
43
43
|
- daniel.guillan@gmail.com
|