Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit e75da0b

Browse files
committed
Add can-hover and no-hover variants (fix #5)
1 parent df1a213 commit e75da0b

File tree

4 files changed

+212
-96
lines changed

4 files changed

+212
-96
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.1.0] - 2020-02-13
9+
10+
### Added
11+
- Added `can-hover` and `no-hover` variants
12+
813
## [3.0.0] - 2020-02-05
914

1015
### Added
@@ -49,7 +54,8 @@ No change since 2.0.0-beta.1
4954

5055
Initial release
5156

52-
[Unreleased]: https://github.com/benface/tailwindcss-interaction-variants/compare/v3.0.0...HEAD
57+
[Unreleased]: https://github.com/benface/tailwindcss-interaction-variants/compare/v3.1.0...HEAD
58+
[3.1.0]: https://github.com/benface/tailwindcss-interaction-variants/compare/v3.0.0...v3.1.0
5359
[3.0.0]: https://github.com/benface/tailwindcss-interaction-variants/compare/v2.4.0...v3.0.0
5460
[2.4.0]: https://github.com/benface/tailwindcss-interaction-variants/compare/v2.3.0...v2.4.0
5561
[2.3.0]: https://github.com/benface/tailwindcss-interaction-variants/compare/v2.2.0...v2.3.0

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
},
2222
},
2323
variants: {
24-
backgroundColor: ['checked', 'group-focus', 'group-focus-within', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus'],
24+
backgroundColor: ['checked', 'group-focus', 'group-focus-within', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus', 'can-hover', 'no-hover'],
2525
},
2626
plugins: [
2727
require('tailwindcss-interaction-variants'),
@@ -67,4 +67,16 @@ The above configuration would generate the following CSS:
6767
.group:hover .group-hocus\:bg-black, .group:focus .group-hocus\:bg-black {
6868
background-color: black;
6969
}
70+
71+
@media (hover: hover) {
72+
.can-hover\:bg-black {
73+
background-color: black;
74+
}
75+
}
76+
77+
@media (hover: none) {
78+
.no-hover\:bg-black {
79+
background-color: black;
80+
}
81+
}
7082
```

index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const plugin = require('tailwindcss/plugin');
22
const _ = require('lodash');
33
const selectorParser = require('postcss-selector-parser');
44

5-
module.exports = plugin(function({ addVariant, config }) {
5+
module.exports = plugin(function({ addVariant, config, e, postcss }) {
66
const prefixClass = function(className) {
77
const prefix = config('prefix');
88
const getPrefix = typeof prefix === 'function' ? prefix : () => prefix;
@@ -71,4 +71,22 @@ module.exports = plugin(function({ addVariant, config }) {
7171
}).processSync(selector)
7272
});
7373
});
74+
75+
addVariant('can-hover', ({ container, separator }) => {
76+
const atRule = postcss.atRule({ name: 'media', params: '(hover: hover)' });
77+
atRule.append(container.nodes);
78+
container.append(atRule);
79+
atRule.walkRules(rule => {
80+
rule.selector = `.${e(`can-hover${separator}`)}${rule.selector.slice(1)}`;
81+
});
82+
});
83+
84+
addVariant('no-hover', ({ container, separator }) => {
85+
const atRule = postcss.atRule({ name: 'media', params: '(hover: none)' });
86+
atRule.append(container.nodes);
87+
container.append(atRule);
88+
atRule.walkRules(rule => {
89+
rule.selector = `.${e(`no-hover${separator}`)}${rule.selector.slice(1)}`;
90+
});
91+
});
7492
});

0 commit comments

Comments
 (0)