postcss-focus-within 1.0.0 → 2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changes to PostCSS Focus Within
2
2
 
3
+ ### 2.0.0 (April 7, 2018)
4
+
5
+ - Changed: default functionality to preserve the original rule
6
+ - Added: `preserve` option to preserve the original rule using `:focus-within`
7
+
3
8
  ### 1.0.0 (February 17, 2018)
4
9
 
5
10
  - Initial version
package/README.md CHANGED
@@ -5,8 +5,10 @@
5
5
  [![Windows Build Status][win-img]][win-url]
6
6
  [![Gitter Chat][git-img]][git-url]
7
7
 
8
- [PostCSS Focus Within] lets you use the `:focus-within` pseudo-selector in
9
- CSS, following the [Selectors Level 4 specification].
8
+ [PostCSS Focus Within] lets you use the `:focus-within` pseudo-class in CSS,
9
+ following the [Selectors Level 4 specification].
10
+
11
+ It is the companion to the [focus-within polyfill].
10
12
 
11
13
  ```css
12
14
  .my-form-field:focus-within label {
@@ -18,12 +20,17 @@ CSS, following the [Selectors Level 4 specification].
18
20
  .my-form-field[focus-within] label {
19
21
  background-color: yellow;
20
22
  }
23
+
24
+ .my-form-field:focus-within label {
25
+ background-color: yellow;
26
+ }
21
27
  ```
22
28
 
23
- [PostCSS Focus Within] replaces the `:focus-within` pseudo-selector with a
24
- `.focus-within` class selector, the same selector used by the
25
- [focus-within polyfill]. The replacement selector can be changed using the
26
- `replaceWith` option.
29
+ [PostCSS Focus Within] duplicates rules using the `:focus-within` pseudo-class
30
+ with a `[focus-within]` attribute selector, the same selector used by the
31
+ [focus-within polyfill]. This replacement selector can be changed using the
32
+ `replaceWith` option. Also, the preservation of the original `:focus-within`
33
+ rule can be disabled using the `preserve` option.
27
34
 
28
35
  ## Usage
29
36
 
@@ -148,6 +155,27 @@ grunt.initConfig({
148
155
 
149
156
  ## Options
150
157
 
158
+ ### preserve
159
+
160
+ The `preserve` option defines whether the original selector should remain. By
161
+ default, the original selector is preserved.
162
+
163
+ ```js
164
+ focusWithin({ preserve: false });
165
+ ```
166
+
167
+ ```css
168
+ .my-form-field:focus-within label {
169
+ background-color: yellow;
170
+ }
171
+
172
+ /* becomes */
173
+
174
+ .my-form-field[focus-within] label {
175
+ background-color: yellow;
176
+ }
177
+ ```
178
+
151
179
  ### replaceWith
152
180
 
153
181
  The `replaceWith` option defines the selector to replace `:focus-within`. By
@@ -158,14 +186,18 @@ focusWithin({ replaceWith: '.focus-within' });
158
186
  ```
159
187
 
160
188
  ```css
161
- :focus:not(:focus-within) {
162
- outline: none;
189
+ .my-form-field:focus-within label {
190
+ background-color: yellow;
163
191
  }
164
192
 
165
193
  /* becomes */
166
194
 
167
- :focus:not(.focus-within]) {
168
- outline: none;
195
+ .my-form-field.focus-within label {
196
+ background-color: yellow;
197
+ }
198
+
199
+ .my-form-field:focus-within label {
200
+ background-color: yellow;
169
201
  }
170
202
  ```
171
203
 
@@ -176,7 +208,7 @@ focusWithin({ replaceWith: '.focus-within' });
176
208
  [win-url]: https://ci.appveyor.com/project/jonathantneal/postcss-focus-within
177
209
  [win-img]: https://img.shields.io/appveyor/ci/jonathantneal/postcss-focus-within.svg
178
210
  [git-url]: https://gitter.im/postcss/postcss
179
- [git-img]: https://img.shields.io/badge/chat-gitter-blue.svg
211
+ [git-img]: https://img.shields.io/badge/support-chat-blue.svg
180
212
 
181
213
  [focus-within polyfill]: https://github.com/jonathantneal/focus-within
182
214
  [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
@@ -184,3 +216,4 @@ focusWithin({ replaceWith: '.focus-within' });
184
216
  [PostCSS]: https://github.com/postcss/postcss
185
217
  [PostCSS Focus Within]: https://github.com/jonathantneal/postcss-focus-within
186
218
  [PostCSS Loader]: https://github.com/postcss/postcss-loader
219
+ [Selectors Level 4 specification]: https://www.w3.org/TR/selectors-4/#the-focus-within-pseudo
@@ -8,12 +8,21 @@ var selectorRegExp = /:focus-within([^\w-]|$)/gi;
8
8
 
9
9
  var index = postcss.plugin('postcss-focus-within', function (opts) {
10
10
  var replaceWith = String(Object(opts).replaceWith || '[focus-within]');
11
+ var preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
11
12
 
12
13
  return function (root) {
13
14
  root.walkRules(selectorRegExp, function (rule) {
14
- rule.selector = rule.selector.replace(selectorRegExp, function ($0, $1) {
15
+ var selector = rule.selector.replace(selectorRegExp, function ($0, $1) {
15
16
  return `${replaceWith}${$1}`;
16
17
  });
18
+
19
+ var clone = rule.clone({ selector });
20
+
21
+ if (preserve) {
22
+ rule.before(clone);
23
+ } else {
24
+ rule.replaceWith(clone);
25
+ }
17
26
  });
18
27
  };
19
28
  });
package/index.es.js ADDED
@@ -0,0 +1,26 @@
1
+ import postcss from 'postcss';
2
+
3
+ var selectorRegExp = /:focus-within([^\w-]|$)/gi;
4
+
5
+ var index = postcss.plugin('postcss-focus-within', function (opts) {
6
+ var replaceWith = String(Object(opts).replaceWith || '[focus-within]');
7
+ var preserve = Boolean('preserve' in Object(opts) ? opts.preserve : true);
8
+
9
+ return function (root) {
10
+ root.walkRules(selectorRegExp, function (rule) {
11
+ var selector = rule.selector.replace(selectorRegExp, function ($0, $1) {
12
+ return `${replaceWith}${$1}`;
13
+ });
14
+
15
+ var clone = rule.clone({ selector });
16
+
17
+ if (preserve) {
18
+ rule.before(clone);
19
+ } else {
20
+ rule.replaceWith(clone);
21
+ }
22
+ });
23
+ };
24
+ });
25
+
26
+ export default index;
package/package.json CHANGED
@@ -1,23 +1,22 @@
1
1
  {
2
2
  "name": "postcss-focus-within",
3
- "version": "1.0.0",
4
- "description": "",
3
+ "version": "2.0.0",
4
+ "description": "Ise the :focus-within pseudo-selector in CSS",
5
5
  "author": "Jonathan Neal <jonathantneal@hotmail.com>",
6
6
  "license": "CC0-1.0",
7
7
  "repository": "jonathantneal/postcss-focus-within",
8
8
  "homepage": "https://github.com/jonathantneal/postcss-focus-within#readme",
9
9
  "bugs": "https://github.com/jonathantneal/postcss-focus-within/issues",
10
- "main": "index.bundle.js",
11
- "module": "index.js",
10
+ "main": "index.cjs.js",
11
+ "module": "index.es.js",
12
12
  "files": [
13
- "index.js",
14
- "index.bundle.js"
13
+ "index.cjs.js",
14
+ "index.es.js"
15
15
  ],
16
16
  "scripts": {
17
17
  "prepublishOnly": "npm test",
18
18
  "pretest": "rollup -c .rollup.js --silent",
19
- "test": "echo 'Running tests...'; npm run test:ec && npm run test:js && npm run test:tape",
20
- "test:ec": "echint --ignore index.bundle.js test",
19
+ "test": "echo 'Running tests...'; npm run test:js && npm run test:tape",
21
20
  "test:js": "eslint *.js --cache --ignore-path .gitignore --quiet",
22
21
  "test:tape": "postcss-tape"
23
22
  },
@@ -25,19 +24,18 @@
25
24
  "node": ">=4.0.0"
26
25
  },
27
26
  "dependencies": {
28
- "postcss": "^6.0"
27
+ "postcss": "^6.0.21"
29
28
  },
30
29
  "devDependencies": {
31
- "babel-core": "^6.26",
32
- "babel-eslint": "^8.2",
33
- "babel-preset-env": "^1.6",
34
- "echint": "^4.0",
35
- "eslint": "^4.18",
36
- "eslint-config-dev": "2.0",
37
- "postcss-tape": "2.2",
38
- "pre-commit": "^1.2",
39
- "rollup": "^0.56",
40
- "rollup-plugin-babel": "^3.0"
30
+ "babel-core": "^6.26.0",
31
+ "babel-eslint": "^8.2.2",
32
+ "babel-preset-env": "^1.6.1",
33
+ "eslint": "^4.19.1",
34
+ "eslint-config-dev": "2.0.0",
35
+ "postcss-tape": "2.2.0",
36
+ "pre-commit": "^1.2.2",
37
+ "rollup": "^0.57.1",
38
+ "rollup-plugin-babel": "^3.0.3"
41
39
  },
42
40
  "eslintConfig": {
43
41
  "extends": "dev",
package/index.js DELETED
@@ -1,15 +0,0 @@
1
- import postcss from 'postcss';
2
-
3
- const selectorRegExp = /:focus-within([^\w-]|$)/gi;
4
-
5
- export default postcss.plugin('postcss-focus-within', opts => {
6
- const replaceWith = String(Object(opts).replaceWith || '[focus-within]');
7
-
8
- return root => {
9
- root.walkRules(selectorRegExp, rule => {
10
- rule.selector = rule.selector.replace(selectorRegExp, ($0, $1) => {
11
- return `${replaceWith}${$1}`;
12
- });
13
- });
14
- };
15
- });