aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/atoms/modal/modal.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-09-22 19:34:01 +0200
committerArmand Philippot <git@armandphilippot.com>2023-10-24 12:23:48 +0200
commita6ff5eee45215effb3344cb5d631a27a7c0369aa (patch)
tree5051747acf72318b4fc5c18d603e3757fbefdfdb /src/components/atoms/modal/modal.tsx
parent651ea4fc992e77d2f36b3c68f8e7a70644246067 (diff)
refactor(components): rewrite form components
Diffstat (limited to 'src/components/atoms/modal/modal.tsx')
-rw-r--r--src/components/atoms/modal/modal.tsx49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/components/atoms/modal/modal.tsx b/src/components/atoms/modal/modal.tsx
new file mode 100644
index 0000000..78b4f6e
--- /dev/null
+++ b/src/components/atoms/modal/modal.tsx
@@ -0,0 +1,49 @@
+import {
+ ForwardRefRenderFunction,
+ HTMLAttributes,
+ ReactElement,
+ ReactNode,
+ forwardRef,
+} from 'react';
+import { HeadingProps } from '../headings';
+import styles from './modal.module.scss';
+
+export type ModalProps = HTMLAttributes<HTMLDivElement> & {
+ /**
+ * The modal body.
+ */
+ children: ReactNode;
+ /**
+ * The modal title.
+ */
+ heading?: ReactElement<HeadingProps>;
+ /**
+ * The modal kind.
+ *
+ * @default 'primary'
+ */
+ kind?: 'primary' | 'secondary';
+};
+
+const ModalWithRef: ForwardRefRenderFunction<HTMLDivElement, ModalProps> = (
+ { children, className = '', heading, kind = 'primary', ...props },
+ ref
+) => {
+ const headingModifier = heading ? 'modal--has-title' : '';
+ const kindModifier = `modal--${kind}`;
+ const modalClass = `${styles.modal} ${styles[headingModifier]} ${styles[kindModifier]} ${className}`;
+
+ return (
+ <div {...props} className={modalClass} ref={ref}>
+ {heading ? <div className={styles.title}>{heading}</div> : null}
+ {children}
+ </div>
+ );
+};
+
+/**
+ * Modal component
+ *
+ * Render a modal component.
+ */
+export const Modal = forwardRef(ModalWithRef);