Skip to content

Commit 289a7ee

Browse files
authored
chore: more strict type illusterationkind and prop drill classname an… (#367)
* chore: more strict typing for illusterationkind and prop drill classname and style
1 parent 317d05a commit 289a7ee

File tree

4 files changed

+98
-36
lines changed

4 files changed

+98
-36
lines changed

components/empty-view/src/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
EmptySpaceLight,
1515
FileMissingDark,
1616
FileMissingLight,
17+
MediaDark,
18+
MediaLight,
1719
NoAccessDark,
1820
NoAccessLight,
1921
NoConnectionDark,
@@ -35,9 +37,10 @@ import {
3537
UnderConstructionDark,
3638
UnderConstructionLight,
3739
} from "@axiscommunications/fluent-illustrations";
40+
import { IllustrationKind } from "./types";
3841

3942
export const Illustration: Record<
40-
string,
43+
IllustrationKind,
4144
ReturnType<typeof bundleIllustrationSmart>
4245
> = {
4346
"add-user-profile": bundleIllustrationSmart(
@@ -50,6 +53,7 @@ export const Illustration: Record<
5053
"empty-space": bundleIllustrationSmart(EmptySpaceDark, EmptySpaceLight),
5154
"file-missing": bundleIllustrationSmart(FileMissingDark, FileMissingLight),
5255
general: bundleIllustrationSmart(EmptyGeneralDark, EmptyGeneralLight),
56+
media: bundleIllustrationSmart(MediaDark, MediaLight),
5357
"no-access": bundleIllustrationSmart(NoAccessDark, NoAccessLight),
5458
"no-connection": bundleIllustrationSmart(NoConnectionDark, NoConnectionLight),
5559
"no-content": bundleIllustrationSmart(NoContentDark, NoContentLight),

components/empty-view/src/styles.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { makeStyles, shorthands, tokens } from "@fluentui/react-components";
1+
import {
2+
makeStyles,
3+
mergeClasses,
4+
shorthands,
5+
tokens,
6+
} from "@fluentui/react-components";
7+
import { HtmlDivAttributesRestProps } from "./types";
28

39
export const useStyles = makeStyles({
410
container: {
@@ -48,3 +54,10 @@ export const useStyles = makeStyles({
4854
verticalAlign: "middle",
4955
},
5056
});
57+
58+
export function useContainerStyle({ className }: HtmlDivAttributesRestProps) {
59+
const styles = useStyles();
60+
const containerStyle = mergeClasses(styles.container, className);
61+
62+
return containerStyle;
63+
}

components/empty-view/src/types.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1-
import { PropsWithChildren, ReactNode } from "react";
1+
import { HTMLAttributes, PropsWithChildren, ReactNode } from "react";
22

3-
import { Illustration } from "./constants";
4-
5-
export type IllustrationKind = keyof typeof Illustration;
3+
export type IllustrationKind =
4+
| "add-user-profile"
5+
| "data"
6+
| "devices"
7+
| "empty-folder"
8+
| "empty-space"
9+
| "file-missing"
10+
| "general"
11+
| "media"
12+
| "no-access"
13+
| "no-connection"
14+
| "no-content"
15+
| "no-match"
16+
| "no-sites"
17+
| "not-found"
18+
| "settings"
19+
| "success"
20+
| "team"
21+
| "under-construction";
622

723
export interface ContentProps {
824
readonly body: ReactNode;
925
readonly illustration: IllustrationKind;
1026
readonly title: string;
1127
}
1228

13-
export type EmptyViewProps = PropsWithChildren<{
14-
readonly after?: ReactNode;
15-
readonly illustration: IllustrationKind;
16-
readonly title: string;
17-
}>;
29+
export type EmptyViewProps = PropsWithChildren<
30+
{
31+
readonly after?: ReactNode;
32+
readonly illustration: IllustrationKind;
33+
readonly title: string;
34+
} & HtmlDivAttributesRestProps
35+
>;
36+
37+
export type HtmlDivAttributesRestProps = Pick<
38+
HTMLAttributes<HTMLDivElement>,
39+
"className" | "style"
40+
>;

components/empty-view/src/view.tsx

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,60 @@ import {
1111

1212
import { useMediaQuery } from "@axiscommunications/fluent-hooks";
1313

14-
import { useStyles } from "./styles";
15-
import { ContentProps, EmptyViewProps } from "./types";
14+
import { useContainerStyle, useStyles } from "./styles";
15+
import {
16+
ContentProps,
17+
EmptyViewProps,
18+
HtmlDivAttributesRestProps,
19+
} from "./types";
1620
import { Illustration } from "./constants";
1721

18-
function ContainerSpacious({ children }: PropsWithChildren) {
19-
const screenStyles = useStyles();
22+
function ContainerSpacious(
23+
{ children, className, ...rest }: PropsWithChildren<
24+
HtmlDivAttributesRestProps
25+
>
26+
) {
27+
const styles = useStyles();
28+
const containerStyle = useContainerStyle({ className });
29+
2030
return (
21-
<div className={screenStyles.container}>
22-
<div className={screenStyles.spacer} />
31+
<div className={containerStyle} {...rest}>
32+
<div className={styles.spacer} />
2333
{children}
24-
<div className={screenStyles.spacer} />
25-
<div className={screenStyles.spacer} />
34+
<div className={styles.spacer} />
35+
<div className={styles.spacer} />
2636
</div>
2737
);
2838
}
2939

30-
function ContainerCompact({ children }: PropsWithChildren) {
31-
const screenStyles = useStyles();
40+
function ContainerCompact(
41+
{ children, className, ...rest }: PropsWithChildren<
42+
HtmlDivAttributesRestProps
43+
>
44+
) {
45+
const styles = useStyles();
46+
const containerStyle = useContainerStyle({ className });
47+
3248
return (
33-
<div className={screenStyles.container}>
34-
<div className={screenStyles.spacer} />
49+
<div className={containerStyle} {...rest}>
50+
<div className={styles.spacer} />
3551
{children}
36-
<div className={screenStyles.spacer} />
52+
<div className={styles.spacer} />
3753
</div>
3854
);
3955
}
4056

41-
function ContainerTop({ children }: PropsWithChildren) {
42-
const screenStyles = useStyles();
57+
function ContainerTop(
58+
{ children, className, ...rest }: PropsWithChildren<
59+
HtmlDivAttributesRestProps
60+
>
61+
) {
62+
const styles = useStyles();
63+
const containerStyle = useContainerStyle({ className });
64+
4365
return (
44-
<div className={screenStyles.container}>
45-
<div className={screenStyles.fixedSpacer} />
66+
<div className={containerStyle} {...rest}>
67+
<div className={styles.fixedSpacer} />
4668
{children}
4769
</div>
4870
);
@@ -97,12 +119,12 @@ function ContentExtraSmall(
97119
}
98120

99121
export function MainEmptyView(
100-
{ after, illustration, title, children }: EmptyViewProps
122+
{ after, illustration, title, children, ...rest }: EmptyViewProps
101123
) {
102124
const screenStyles = useStyles();
103125
const media = useMediaQuery();
104126
return (
105-
<ContainerSpacious>
127+
<ContainerSpacious {...rest}>
106128
{media === "small"
107129
? (
108130
<ContentMedium
@@ -124,11 +146,11 @@ export function MainEmptyView(
124146
}
125147

126148
export function PanelEmptyView(
127-
{ after, illustration, title, children }: EmptyViewProps
149+
{ after, illustration, title, children, ...rest }: EmptyViewProps
128150
) {
129151
const screenStyles = useStyles();
130152
return (
131-
<ContainerTop>
153+
<ContainerTop {...rest}>
132154
<ContentMedium
133155
illustration={illustration}
134156
title={title}
@@ -140,10 +162,10 @@ export function PanelEmptyView(
140162
}
141163

142164
export function SubmenuEmptyView(
143-
{ illustration, title, children }: Omit<EmptyViewProps, "after">
165+
{ illustration, title, children, ...rest }: Omit<EmptyViewProps, "after">
144166
) {
145167
return (
146-
<ContainerTop>
168+
<ContainerTop {...rest}>
147169
<ContentSmall illustration={illustration} title={title} body={children} />
148170
</ContainerTop>
149171
);
@@ -163,11 +185,11 @@ export function SubmenuEmptyView(
163185
* ```
164186
*/
165187
export function DialogEmptyView(
166-
{ after, title, children }: Omit<EmptyViewProps, "illustration">
188+
{ after, title, children, ...rest }: Omit<EmptyViewProps, "illustration">
167189
) {
168190
const screenStyles = useStyles();
169191
return (
170-
<ContainerCompact>
192+
<ContainerCompact {...rest}>
171193
<ContentExtraSmall title={title} body={children} />
172194
<div className={screenStyles.after}>{after}</div>
173195
</ContainerCompact>

0 commit comments

Comments
 (0)