From 289a7ee14f7e837647d1debbcafe5cd860837946 Mon Sep 17 00:00:00 2001 From: Jimmy Svensson Date: Wed, 4 Dec 2024 13:58:48 +0100 Subject: [PATCH] =?UTF-8?q?chore:=20more=20strict=20type=20illusterationki?= =?UTF-8?q?nd=20and=20prop=20drill=20classname=20an=E2=80=A6=20(#367)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: more strict typing for illusterationkind and prop drill classname and style --- components/empty-view/src/constants.ts | 6 ++- components/empty-view/src/styles.ts | 15 +++++- components/empty-view/src/types.ts | 41 +++++++++++---- components/empty-view/src/view.tsx | 72 +++++++++++++++++--------- 4 files changed, 98 insertions(+), 36 deletions(-) diff --git a/components/empty-view/src/constants.ts b/components/empty-view/src/constants.ts index 6e5d9ab4..cd1a09bc 100644 --- a/components/empty-view/src/constants.ts +++ b/components/empty-view/src/constants.ts @@ -14,6 +14,8 @@ import { EmptySpaceLight, FileMissingDark, FileMissingLight, + MediaDark, + MediaLight, NoAccessDark, NoAccessLight, NoConnectionDark, @@ -35,9 +37,10 @@ import { UnderConstructionDark, UnderConstructionLight, } from "@axiscommunications/fluent-illustrations"; +import { IllustrationKind } from "./types"; export const Illustration: Record< - string, + IllustrationKind, ReturnType > = { "add-user-profile": bundleIllustrationSmart( @@ -50,6 +53,7 @@ export const Illustration: Record< "empty-space": bundleIllustrationSmart(EmptySpaceDark, EmptySpaceLight), "file-missing": bundleIllustrationSmart(FileMissingDark, FileMissingLight), general: bundleIllustrationSmart(EmptyGeneralDark, EmptyGeneralLight), + media: bundleIllustrationSmart(MediaDark, MediaLight), "no-access": bundleIllustrationSmart(NoAccessDark, NoAccessLight), "no-connection": bundleIllustrationSmart(NoConnectionDark, NoConnectionLight), "no-content": bundleIllustrationSmart(NoContentDark, NoContentLight), diff --git a/components/empty-view/src/styles.ts b/components/empty-view/src/styles.ts index 2db0cbd1..a5c54459 100644 --- a/components/empty-view/src/styles.ts +++ b/components/empty-view/src/styles.ts @@ -1,4 +1,10 @@ -import { makeStyles, shorthands, tokens } from "@fluentui/react-components"; +import { + makeStyles, + mergeClasses, + shorthands, + tokens, +} from "@fluentui/react-components"; +import { HtmlDivAttributesRestProps } from "./types"; export const useStyles = makeStyles({ container: { @@ -48,3 +54,10 @@ export const useStyles = makeStyles({ verticalAlign: "middle", }, }); + +export function useContainerStyle({ className }: HtmlDivAttributesRestProps) { + const styles = useStyles(); + const containerStyle = mergeClasses(styles.container, className); + + return containerStyle; +} diff --git a/components/empty-view/src/types.ts b/components/empty-view/src/types.ts index 56ff32b1..2cd1314f 100644 --- a/components/empty-view/src/types.ts +++ b/components/empty-view/src/types.ts @@ -1,8 +1,24 @@ -import { PropsWithChildren, ReactNode } from "react"; +import { HTMLAttributes, PropsWithChildren, ReactNode } from "react"; -import { Illustration } from "./constants"; - -export type IllustrationKind = keyof typeof Illustration; +export type IllustrationKind = + | "add-user-profile" + | "data" + | "devices" + | "empty-folder" + | "empty-space" + | "file-missing" + | "general" + | "media" + | "no-access" + | "no-connection" + | "no-content" + | "no-match" + | "no-sites" + | "not-found" + | "settings" + | "success" + | "team" + | "under-construction"; export interface ContentProps { readonly body: ReactNode; @@ -10,8 +26,15 @@ export interface ContentProps { readonly title: string; } -export type EmptyViewProps = PropsWithChildren<{ - readonly after?: ReactNode; - readonly illustration: IllustrationKind; - readonly title: string; -}>; +export type EmptyViewProps = PropsWithChildren< + { + readonly after?: ReactNode; + readonly illustration: IllustrationKind; + readonly title: string; + } & HtmlDivAttributesRestProps +>; + +export type HtmlDivAttributesRestProps = Pick< + HTMLAttributes, + "className" | "style" +>; diff --git a/components/empty-view/src/view.tsx b/components/empty-view/src/view.tsx index 58d20069..91ce5ec0 100644 --- a/components/empty-view/src/view.tsx +++ b/components/empty-view/src/view.tsx @@ -11,38 +11,60 @@ import { import { useMediaQuery } from "@axiscommunications/fluent-hooks"; -import { useStyles } from "./styles"; -import { ContentProps, EmptyViewProps } from "./types"; +import { useContainerStyle, useStyles } from "./styles"; +import { + ContentProps, + EmptyViewProps, + HtmlDivAttributesRestProps, +} from "./types"; import { Illustration } from "./constants"; -function ContainerSpacious({ children }: PropsWithChildren) { - const screenStyles = useStyles(); +function ContainerSpacious( + { children, className, ...rest }: PropsWithChildren< + HtmlDivAttributesRestProps + > +) { + const styles = useStyles(); + const containerStyle = useContainerStyle({ className }); + return ( -
-
+
+
{children} -
-
+
+
); } -function ContainerCompact({ children }: PropsWithChildren) { - const screenStyles = useStyles(); +function ContainerCompact( + { children, className, ...rest }: PropsWithChildren< + HtmlDivAttributesRestProps + > +) { + const styles = useStyles(); + const containerStyle = useContainerStyle({ className }); + return ( -
-
+
+
{children} -
+
); } -function ContainerTop({ children }: PropsWithChildren) { - const screenStyles = useStyles(); +function ContainerTop( + { children, className, ...rest }: PropsWithChildren< + HtmlDivAttributesRestProps + > +) { + const styles = useStyles(); + const containerStyle = useContainerStyle({ className }); + return ( -
-
+
+
{children}
); @@ -97,12 +119,12 @@ function ContentExtraSmall( } export function MainEmptyView( - { after, illustration, title, children }: EmptyViewProps + { after, illustration, title, children, ...rest }: EmptyViewProps ) { const screenStyles = useStyles(); const media = useMediaQuery(); return ( - + {media === "small" ? ( + + { illustration, title, children, ...rest }: Omit ) { return ( - + ); @@ -163,11 +185,11 @@ export function SubmenuEmptyView( * ``` */ export function DialogEmptyView( - { after, title, children }: Omit + { after, title, children, ...rest }: Omit ) { const screenStyles = useStyles(); return ( - +
{after}