aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-add-classname.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-10-28 17:12:58 +0200
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:15:27 +0100
commit60c49f18389ff625177a57277ef8f292a31097bf (patch)
tree76b0f1f1792b57659e54d282f93df70088446e3c /src/utils/hooks/use-add-classname.tsx
parent05f1dfc6896d3affa7c494a1b955f230d836a4b7 (diff)
refactor(providers,hooks): rewrite PrismThemeProvider & usePrismTheme
* reuse Theme provider logic * move DOM mutation from provider to hook * add a script to init theme before page load
Diffstat (limited to 'src/utils/hooks/use-add-classname.tsx')
-rw-r--r--src/utils/hooks/use-add-classname.tsx32
1 files changed, 0 insertions, 32 deletions
diff --git a/src/utils/hooks/use-add-classname.tsx b/src/utils/hooks/use-add-classname.tsx
deleted file mode 100644
index 8b0f6d6..0000000
--- a/src/utils/hooks/use-add-classname.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-import { useCallback, useEffect } from 'react';
-
-export type UseAddClassNameProps = {
- className: string;
- element?: HTMLElement;
- elements?: NodeListOf<HTMLElement> | HTMLElement[];
-};
-
-/**
- * Add className to the given element(s).
- *
- * @param {UseAddClassNameProps} props - An object with classnames and one or more elements.
- */
-export const useAddClassName = ({
- className,
- element,
- elements,
-}: UseAddClassNameProps) => {
- const classNames = className.split(' ').filter((string) => string !== '');
-
- const setClassName = useCallback(
- (el: HTMLElement) => {
- el.classList.add(...classNames);
- },
- [classNames]
- );
-
- useEffect(() => {
- if (element) setClassName(element);
- if (elements && elements.length > 0) elements.forEach(setClassName);
- }, [element, elements, setClassName]);
-};