aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/atoms/layout/section/section.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-09-27 15:40:16 +0200
committerArmand Philippot <git@armandphilippot.com>2023-10-24 12:25:00 +0200
commitba793e043e4d8515b1a9ea490ee2c5f92b1fd6c2 (patch)
treef7240a681fb3ee8c886a0c9ec3944082ba2d89bd /src/components/atoms/layout/section/section.tsx
parent388e687857345c85ee550cd5da472675e05a6ff5 (diff)
refactor(components): rewrite Section component
* Make it compliant with ESlint rules * Remove mandatory heading, it now depends on the consumer * Change defaults for hasBorder and variant
Diffstat (limited to 'src/components/atoms/layout/section/section.tsx')
-rw-r--r--src/components/atoms/layout/section/section.tsx50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/components/atoms/layout/section/section.tsx b/src/components/atoms/layout/section/section.tsx
new file mode 100644
index 0000000..63c658a
--- /dev/null
+++ b/src/components/atoms/layout/section/section.tsx
@@ -0,0 +1,50 @@
+import {
+ forwardRef,
+ type ForwardRefRenderFunction,
+ type HTMLAttributes,
+ type ReactNode,
+} from 'react';
+import styles from './section.module.scss';
+
+export type SectionVariant = 'dark' | 'light';
+
+export type SectionProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
+ /**
+ * The section content.
+ */
+ children: ReactNode | ReactNode[];
+ /**
+ * Add a border at the bottom of the section.
+ *
+ * @default false
+ */
+ hasBorder?: boolean;
+ /**
+ * The section variant.
+ *
+ * @default 'light'
+ */
+ variant?: SectionVariant;
+};
+
+const SectionWithRef: ForwardRefRenderFunction<HTMLElement, SectionProps> = (
+ { children, className = '', hasBorder = false, variant = 'light', ...props },
+ ref
+) => {
+ const borderClass = hasBorder ? styles[`wrapper--borders`] : '';
+ const variantClass = styles[`wrapper--${variant}`];
+ const sectionClass = `${styles.wrapper} ${borderClass} ${variantClass} ${className}`;
+
+ return (
+ <section {...props} className={sectionClass} ref={ref}>
+ {children}
+ </section>
+ );
+};
+
+/**
+ * Section component
+ *
+ * Render a section element with a heading and a body.
+ */
+export const Section = forwardRef(SectionWithRef);