aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/card/card-provider.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-10-17 19:46:08 +0200
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:14:41 +0100
commitc153f93dc8691a71dc76aad3dd618298da9d238a (patch)
tree9c116c1472bab5585f98bceee19cfeca5041360d /src/components/molecules/card/card-provider.tsx
parent006b15b467a5cd835a6eab1b49023100bdc8f2e6 (diff)
refactor(components): rewrite Card component
* make the component more generic * merge `<Summary />` and `<Comment />` styles into card component to avoid repeating the same structure * remove most of the props to use composition However the CSS is a bit complex because of the two variants... Also, the component should be refactored when the CSS pseudo-class `:has` has enough support: the provider and the `cover` and `meta` props should be removed.
Diffstat (limited to 'src/components/molecules/card/card-provider.tsx')
-rw-r--r--src/components/molecules/card/card-provider.tsx43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/components/molecules/card/card-provider.tsx b/src/components/molecules/card/card-provider.tsx
new file mode 100644
index 0000000..5bcdb49
--- /dev/null
+++ b/src/components/molecules/card/card-provider.tsx
@@ -0,0 +1,43 @@
+import {
+ createContext,
+ type FC,
+ type ReactElement,
+ type ReactNode,
+ useContext,
+} from 'react';
+
+export type CardCoverProviderProps = {
+ children: ReactNode;
+ cover?: ReactElement;
+};
+
+export const CardCoverContext = createContext<ReactElement | null>(null);
+
+export const useCardCover = () => useContext(CardCoverContext);
+
+export const CardCoverProvider: FC<CardCoverProviderProps> = ({
+ children,
+ cover,
+}) => (
+ <CardCoverContext.Provider value={cover ?? null}>
+ {children}
+ </CardCoverContext.Provider>
+);
+
+export type CardFooterMetaProviderProps = {
+ children: ReactNode;
+ meta?: ReactElement;
+};
+
+export const CardFooterMetaContext = createContext<ReactElement | null>(null);
+
+export const useCardFooterMeta = () => useContext(CardFooterMetaContext);
+
+export const CardFooterMetaProvider: FC<CardFooterMetaProviderProps> = ({
+ children,
+ meta,
+}) => (
+ <CardFooterMetaContext.Provider value={meta ?? null}>
+ {children}
+ </CardFooterMetaContext.Provider>
+);