aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-attributes.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/hooks/use-attributes.tsx')
-rw-r--r--src/utils/hooks/use-attributes.tsx50
1 files changed, 0 insertions, 50 deletions
diff --git a/src/utils/hooks/use-attributes.tsx b/src/utils/hooks/use-attributes.tsx
deleted file mode 100644
index 20e9947..0000000
--- a/src/utils/hooks/use-attributes.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-import { useCallback, useEffect } from 'react';
-import { fromKebabCaseToCamelCase } from '../helpers';
-
-export type useAttributesProps = {
- /**
- * An HTML element.
- */
- element?: HTMLElement;
- /**
- * A node list of HTML Element.
- */
- elements?: NodeListOf<HTMLElement> | HTMLElement[];
- /**
- * The attribute name.
- */
- attribute: string;
- /**
- * The attribute value.
- */
- value: string;
-};
-
-/**
- * Set HTML attributes to the given element or to the HTML document.
- *
- * @param props - An object with element, attribute name and value.
- */
-export const useAttributes = ({
- element,
- elements,
- attribute,
- value,
-}: useAttributesProps) => {
- const setAttribute = useCallback(
- (el: HTMLElement) => {
- if (attribute.startsWith('data')) {
- el.setAttribute(attribute, value);
- } else {
- const camelCaseAttribute = fromKebabCaseToCamelCase(attribute);
- el.dataset[camelCaseAttribute] = value;
- }
- },
- [attribute, value]
- );
-
- useEffect(() => {
- if (element) setAttribute(element);
- if (elements && elements.length > 0) elements.forEach(setAttribute);
- }, [element, elements, setAttribute]);
-};