diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-07 18:44:14 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:14:41 +0100 |
| commit | d75b9a1e150ab211c1052fb49bede9bd16320aca (patch) | |
| tree | e5bb221d2b8dc83151697fe646e9194f921b5807 /src/components/atoms/flip/flip-side.tsx | |
| parent | 12a03a9a72f7895d571dbaeeb245d92aa277a610 (diff) | |
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.
Diffstat (limited to 'src/components/atoms/flip/flip-side.tsx')
| -rw-r--r-- | src/components/atoms/flip/flip-side.tsx | 35 |
1 files changed, 35 insertions, 0 deletions
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); |
