From d75b9a1e150ab211c1052fb49bede9bd16320aca Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Sat, 7 Oct 2023 18:44:14 +0200
Subject: feat(components): add a generic Flip component

The flipping animation is used at several places so it makes sense to
use a single component to handle the animation. It will avoid styles
duplication.
---
 src/components/atoms/flip/flip-side.tsx | 35 +++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 src/components/atoms/flip/flip-side.tsx

(limited to 'src/components/atoms/flip/flip-side.tsx')

diff --git a/src/components/atoms/flip/flip-side.tsx b/src/components/atoms/flip/flip-side.tsx
new file mode 100644
index 0000000..31c23f5
--- /dev/null
+++ b/src/components/atoms/flip/flip-side.tsx
@@ -0,0 +1,35 @@
+import {
+  type ForwardRefRenderFunction,
+  type HTMLAttributes,
+  forwardRef,
+  type ReactNode,
+} from 'react';
+import styles from './flip.module.scss';
+
+export type FlipSideProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
+  /**
+   * The side contents.
+   */
+  children: ReactNode;
+  /**
+   * Is it the back side of the flip component?
+   *
+   * @default false
+   */
+  isBack?: boolean;
+};
+
+const FlipSideWithRef: ForwardRefRenderFunction<
+  HTMLDivElement,
+  FlipSideProps
+> = ({ children, className = '', isBack = false, ...props }, ref) => {
+  const sideClass = [isBack ? styles.back : styles.front, className].join(' ');
+
+  return (
+    <div {...props} className={sideClass} ref={ref}>
+      {children}
+    </div>
+  );
+};
+
+export const FlipSide = forwardRef(FlipSideWithRef);
-- 
cgit v1.2.3

