-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbf0e66
commit 7ea15b6
Showing
4 changed files
with
108 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 11 additions & 10 deletions
21
packages/embla-carousel-class-names/src/components/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
export function removeClass(node: HTMLElement, className: string): void { | ||
if (!node || !className) return | ||
const { classList } = node | ||
if (classList.contains(className)) classList.remove(className) | ||
import { ClassNameOptionType } from './Options' | ||
|
||
export function normalizeClassNames(classNames: ClassNameOptionType): string[] { | ||
const normalized = Array.isArray(classNames) ? classNames : [classNames] | ||
return normalized.filter(Boolean) | ||
} | ||
|
||
export function addClass(node: HTMLElement, className: string): void { | ||
if (!node || !className) return | ||
const { classList } = node | ||
if (!classList.contains(className)) classList.add(className) | ||
export function removeClass(node: HTMLElement, classNames: string[]): void { | ||
if (!node || !classNames.length) return | ||
node.classList.remove(...classNames) | ||
} | ||
|
||
export function nodeListToArray(nodeList: NodeListOf<Element>): HTMLElement[] { | ||
return <HTMLElement[]>Array.from(nodeList) | ||
export function addClass(node: HTMLElement, classNames: string[]): void { | ||
if (!node || !classNames.length) return | ||
node.classList.add(...classNames) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters