Skip to content

Commit

Permalink
Move addClass to css namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
demiazz committed May 4, 2017
1 parent 91893b8 commit 165aeba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion spec/addClass.spec.js → spec/css/add-class.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addClass } from "../src";
import { addClass } from "../../src";

describe("addClass", () => {
afterEach(clearFixtures);
Expand Down
17 changes: 17 additions & 0 deletions src/css/add-class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* @flow */

import type { CSSClass } from "../types";

import hasClass from "./has-class";

function addClass(element: Element, cssClass: CSSClass): boolean {
const result = !hasClass(element, cssClass);

if (result) {
element.classList.add(cssClass);
}

return result;
}

export default addClass;
11 changes: 1 addition & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type { CSSClass, Selector } from "./types";

import { html, body } from "./aliases";
import addClass from "./css/add-class";
import hasClass from "./css/has-class";
import query from "./queries/query";
import queryAll from "./queries/query-all";
Expand All @@ -24,16 +25,6 @@ type PredicateFn = (element: Element) => boolean;

/* Classes */

function addClass(element: Element, cssClass: CSSClass): boolean {
const result = !hasClass(element, cssClass);

if (result) {
element.classList.add(cssClass);
}

return result;
}

function removeClass(element: Element, cssClass: CSSClass): boolean {
const result = hasClass(element, cssClass);

Expand Down

0 comments on commit 165aeba

Please sign in to comment.