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

Commit

Permalink
Add checked variant (fix #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
benface committed Feb 5, 2020
1 parent ee2a38a commit 6606903
Show file tree
Hide file tree
Showing 7 changed files with 1,994 additions and 1,930 deletions.
3 changes: 2 additions & 1 deletion .release-it.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"git": {
"tagName": "v%s"
"tagName": "v%s",
"requireCleanWorkingDir": false
}
}
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.0] - XXXX-XX-XX
## [3.0.0] - 2020-02-05

### Added
- Added a `checked` variant

### Changed
- Changed to use Tailwind 1.2’s new plugin definition syntax
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
},
},
variants: {
backgroundColor: ['group-focus', 'group-focus-within', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus'],
backgroundColor: ['checked', 'group-focus', 'group-focus-within', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus'],
},
plugins: [
require('tailwindcss-interaction-variants'),
Expand All @@ -32,6 +32,10 @@ The above configuration would generate the following CSS:
background-color: black;
}

.checked\:bg-black:checked {
background-color: black;
}

.group:focus .group-focus\:bg-black {
background-color: black;
}
Expand Down
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ module.exports = plugin(function({ addVariant, config }) {
return `${getPrefix(`.${className}`)}${className}`;
};

const pseudoClassVariant = function(pseudoClass) {
return ({ modifySelectors, separator }) => {
return modifySelectors(({ selector }) => {
return selectorParser(selectors => {
selectors.walkClasses(classNode => {
classNode.value = `${pseudoClass}${separator}${classNode.value}`;
classNode.parent.insertAfter(classNode, selectorParser.pseudo({ value: `:${pseudoClass}` }));
});
}).processSync(selector);
});
};
};

const groupPseudoClassVariant = function(pseudoClass) {
return ({ modifySelectors, separator }) => {
return modifySelectors(({ selector }) => {
Expand All @@ -22,6 +35,7 @@ module.exports = plugin(function({ addVariant, config }) {
};
};

addVariant('checked', pseudoClassVariant('checked'));
addVariant('group-focus', groupPseudoClassVariant('focus'));
addVariant('group-focus-within', groupPseudoClassVariant('focus-within'));
addVariant('group-active', groupPseudoClassVariant('active'));
Expand Down
Loading

0 comments on commit 6606903

Please sign in to comment.