Skip to content

Commit

Permalink
add support for self referencing pseudo element
Browse files Browse the repository at this point in the history
  • Loading branch information
azukaar committed Oct 19, 2018
1 parent aa966b6 commit a1c796c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-css",
"version": "0.12.1",
"version": "0.13.0",
"description": "Proper, framework agnostic Style in JS library, without any of the fuss of CSS",
"main": "dist/index.js",
"files": [
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ const jsonToCss = function (_css, className, refresh = () => {}) {
const eventKey = caseConvert(key.replace(/^on[A-Z]/, match => match.substr(-1).toLowerCase()));

master += jsonToCss(_css[key], className + ':' + eventKey);
} else if (key.match(/^:/)) {
master += jsonToCss(_css[key], className + key);
} else if (typeof _css[key] !== null && typeof _css[key] === 'object' && !Array.isArray(_css[key]) && key.match(/^>/)) {
master += jsonToCss(_css[key], className + ' ' + key.substr(2));
} else if (typeof _css[key] !== null && typeof _css[key] === 'object' && !Array.isArray(_css[key])) {
Expand Down Expand Up @@ -421,6 +423,10 @@ function createTargetStyle() {
}
}

const is = {};

pseudoFunctionsList.forEach((name) => is[name] = (arg) => `:${caseConvert(name)}(${arg})`.replace('(:', '('));

export {
CSS,
calc,
Expand All @@ -432,6 +438,7 @@ export {
setDocumentElement,
color,
units,
is,
constants,
DynamicCSS
};
15 changes: 14 additions & 1 deletion tests/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as CONSTANTS from '../src/config';
CONSTANTS.GC_COLLECT_TIME = 1000;

import {CSS, calc, classes, resetCSS, Keyframes, MediaQuery, DynamicCSS} from '../src/index';
import {CSS, calc, classes, resetCSS, Keyframes, MediaQuery, DynamicCSS, is} from '../src/index';
import color from '../src/color';
import {borderStyle, transform} from '../src/constants';
import units from '../src/units';
Expand Down Expand Up @@ -242,6 +242,19 @@ describe('', () => {
expect(getSheet().cssRules[2].style.color).toBe('blue');
expect(getSheet().cssRules[2].selectorText).toBe('.class0:hover:focus .class1');
});

it('use self referencing pseudo-elements function', () => {
CSS({
color: 'red',
[is.not(is.nthChild(1))]: {
color: 'blue'
}
});

expect(is.not(is.nthChild(1))).toBe(':not(nth-child(1))');
expect(getSheet().cssRules[0].style.color).toBe('red');
expect(getSheet().cssRules[1].selectorText).toBe('.class0:not(nth-child(1))');
});
});

describe('Keyframes Creation', () => {
Expand Down

0 comments on commit a1c796c

Please sign in to comment.