Skip to content

Commit b25fe75

Browse files
authored
Merge pull request #6 from allaboutapps/dev
Dev
2 parents b1cf276 + a9f8020 commit b25fe75

File tree

13 files changed

+295
-243
lines changed

13 files changed

+295
-243
lines changed

.storybook/preview.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const preview: Preview = {
1414
date: /Date$/i,
1515
},
1616
},
17+
nextjs: {
18+
appDirectory: true,
19+
},
1720
},
1821
decorators: [
1922
(Story) => (

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ For headless CraftCMS projects there is a separate branch. Use `npm_config_yes=t
2222
- Sample Login-Page in the frontend code.
2323
- Docker setup
2424

25+
## Storybook
26+
For developing, previewing and testing UI components we **highly recommend** using [storybook](https://storybook.js.org/). Support
27+
for storybook is built in. For examples how to write simple stories see `*.stories.tsx` files (e.g. `src/components/ui/Buttons.stories.tsx`).
28+
29+
To start the storybook use `yarn storybook`.
30+
2531
## Builds
2632
- Builds are configured as `standalone` in next.config.mjs. SPA style builds (aka `output: "export"`) are not practical,
2733
since dynamic routes without `generateStaticParams()` are not supported (see https://nextjs.org/docs/app/building-your-application/deploying/static-exports#unsupported-features). This limitation would not allow any detail sites like `product/[productId]` because those cannot be generated statically.
@@ -116,8 +122,3 @@ For social media link images you can use this: https://nextjs.org/docs/app/api-r
116122
E.g. robots.txt, sitemap, manifest:
117123
See https://nextjs.org/docs/app/api-reference/file-conventions/metadata
118124

119-
## Storybook
120-
For developing and testing UI components we recommend using [storybook](https://storybook.js.org/). Support
121-
for storybook is built in. For examples how to write simple stories see `*.stories.tsx` files (e.g. `src/components/Buttons.stories.tsx`).
122-
123-
To start the storybook use `yarn storybook`.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"ts": "tsc --noEmit --incremental --preserveWatchOutput --pretty",
2525
"ts:watch": "npm run ts -- --watch --project tsconfig.watch.json",
2626
"prepare": "husky install",
27-
"storybook": "storybook dev -p 6006",
27+
"storybook": "storybook dev -p 6006 --ci",
2828
"build-storybook": "storybook build"
2929
},
3030
"dependencies": {
@@ -52,13 +52,13 @@
5252
},
5353
"devDependencies": {
5454
"@chromatic-com/storybook": "^1.6.1",
55-
"@storybook/addon-essentials": "^8.2.8",
56-
"@storybook/addon-interactions": "^8.2.8",
57-
"@storybook/addon-links": "^8.2.8",
58-
"@storybook/blocks": "^8.2.8",
59-
"@storybook/nextjs": "^8.2.8",
60-
"@storybook/react": "^8.2.8",
61-
"@storybook/test": "^8.2.8",
55+
"@storybook/addon-essentials": "^8.2.9",
56+
"@storybook/addon-interactions": "^8.2.9",
57+
"@storybook/addon-links": "^8.2.9",
58+
"@storybook/blocks": "^8.2.9",
59+
"@storybook/nextjs": "^8.2.9",
60+
"@storybook/react": "^8.2.9",
61+
"@storybook/test": "^8.2.9",
6262
"@testing-library/react": "^16.0.0",
6363
"@types/negotiator": "^0.6.3",
6464
"@types/node": "^20",
@@ -76,7 +76,7 @@
7676
"husky": "^8.0.3",
7777
"license-checker": "^25.0.1",
7878
"postcss": "^8",
79-
"storybook": "^8.2.8",
79+
"storybook": "^8.2.9",
8080
"tailwindcss": "^3.4.1",
8181
"typescript": "^5",
8282
"vitest": "^2.0.5"

src/app/[lang]/(pages)/dashboard/ClientComponent.tsx

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,20 @@
11
"use client";
22

3-
import NextLink from "next/link";
3+
import { useLocale } from "@/hooks/useLocale";
44
import { t, tHtml } from "@/i18n/clientUtil";
5-
import { Button, Link } from "@mui/material";
6-
import { sleep } from "@/util/helpers";
7-
import { useGeneralStore } from "@/stores/generalStore";
85
import { IntlLink } from "@/routing/IntlLink";
9-
import { useLocale } from "@/hooks/useLocale";
106
import { Routes } from "@/routing/Routes";
117
import { useIntlRouter } from "@/routing/useIntlRouter";
128
import { useDebugStore } from "@/stores/debugStore";
9+
import { Button, Link } from "@mui/material";
10+
import NextLink from "next/link";
1311

1412
// Stuff that has to be in a client component (uses t, tHtml)
1513
export const ClientComponent = () => {
16-
const [setIsLoading, setError] = useGeneralStore((state) => [state.setIsLoading, state.setError]);
1714
const locale = useLocale();
1815
const router = useIntlRouter();
1916
const debugEnabled = useDebugStore((state) => state.enabled);
2017

21-
const loading = (
22-
<>
23-
<Button
24-
variant="outlined"
25-
onClick={async () => {
26-
setIsLoading(true);
27-
await sleep(100);
28-
setIsLoading(false);
29-
}}
30-
>
31-
{t("button.loadingShort")}
32-
</Button>
33-
<Button
34-
variant="outlined"
35-
onClick={async () => {
36-
setIsLoading(true);
37-
await sleep(1000);
38-
setIsLoading(false);
39-
}}
40-
>
41-
{t("button.loadingLong")}
42-
</Button>
43-
</>
44-
);
45-
4618
return (
4719
<>
4820
<IntlLink href={Routes.ROOT}>
@@ -61,15 +33,6 @@ export const ClientComponent = () => {
6133
{t(locale === "de" ? "language.english" : "language.german")}
6234
</Button>
6335
<div>Debug: {debugEnabled ? "enabled" : "disabled"}</div>
64-
{loading}
65-
<Button
66-
variant="outlined"
67-
onClick={async () => {
68-
setError(t("error.general"));
69-
}}
70-
>
71-
{t("button.showError")}
72-
</Button>
7336
<Link href="/assets/third-party-licenses.txt" component={NextLink}>
7437
{t("common.licenses")}
7538
</Link>
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Icon } from "@/components/Icon";
21
import { tServer } from "@/i18n/util";
32
import { PageProps } from "@/types/PageProps";
43
import { debug } from "@/util/debug";
@@ -16,16 +15,5 @@ export const ServerComponent = async ({ pageProps }: { pageProps: PageProps }) =
1615
await sleep(100);
1716
debug.log("loading ServerComponent done");
1817

19-
return (
20-
<>
21-
{tServer(pageProps.params.lang, "serverComponent.text")}
22-
<h1 className="text-primary">H1 headline</h1>
23-
<h2>H2 headline</h2>
24-
<h3>H3 headline</h3>
25-
<h4>H4 headline</h4>
26-
<p>Paragraph body1</p>
27-
<p className="body2">Paragraph body2</p>
28-
<Icon name="close" />
29-
</>
30-
);
18+
return <>{tServer(pageProps.params.lang, "serverComponent.text")}</>;
3119
};
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import { Icon } from "@/components/Icon";
2+
import { SiteContainer } from "@/components/ui/SiteContainer";
13
import { Button, IconButton } from "@mui/material";
24
import { Meta, StoryObj } from "@storybook/react";
3-
import { SiteContainer } from "./SiteContainer";
4-
import { Icon } from "../Icon";
55

66
export default {
77
title: "Buttons",
88
} satisfies Meta;
99

10-
export const Buttons: StoryObj = {
10+
export const Contained: StoryObj = {
1111
render: () => {
1212
return (
1313
<SiteContainer>
@@ -17,12 +17,30 @@ export const Buttons: StoryObj = {
1717
<Button variant="contained" color="secondary">
1818
Secondary
1919
</Button>
20+
</SiteContainer>
21+
);
22+
},
23+
};
24+
25+
export const Outlined: StoryObj = {
26+
render: () => {
27+
return (
28+
<SiteContainer>
2029
<Button variant="outlined" color="primary">
2130
Outlined Primary
2231
</Button>
2332
<Button variant="outlined" color="primary">
2433
Outlined Secondary
2534
</Button>
35+
</SiteContainer>
36+
);
37+
},
38+
};
39+
40+
export const Icons: StoryObj = {
41+
render: () => {
42+
return (
43+
<SiteContainer>
2644
<div className="flex gap-2 items-center">
2745
Icon button:
2846
<IconButton>
@@ -32,9 +50,4 @@ export const Buttons: StoryObj = {
3250
</SiteContainer>
3351
);
3452
},
35-
parameters: {
36-
nextjs: {
37-
appDirectory: true,
38-
},
39-
},
4053
};
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { ErrorToast } from "@/components/ui/ErrorToast";
2+
import { SiteContainer } from "@/components/ui/SiteContainer";
13
import { useGeneralStore } from "@/stores/generalStore";
24
import { Button } from "@mui/material";
35
import { Meta, StoryObj } from "@storybook/react";
4-
import { ErrorToast } from "./ErrorToast";
5-
import { SiteContainer } from "./SiteContainer";
66

77
export default {
88
title: "Error Toast",
99
} satisfies Meta;
1010

11-
export const TriggerError: StoryObj = {
11+
export const TriggerSingleError: StoryObj = {
1212
render: () => {
1313
const [setError] = useGeneralStore((state) => [state.setError]);
1414

@@ -21,9 +21,4 @@ export const TriggerError: StoryObj = {
2121
</SiteContainer>
2222
);
2323
},
24-
parameters: {
25-
nextjs: {
26-
appDirectory: true,
27-
},
28-
},
2924
};

src/components/ui/Inputs.stories.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import { CustomInputField } from "@/components/ui/CustomInputField";
2+
import { SiteContainer } from "@/components/ui/SiteContainer";
13
import { tServer } from "@/i18n/util";
24
import { yupResolver } from "@hookform/resolvers/yup";
35
import { Meta, StoryObj } from "@storybook/react";
46
import { useForm } from "react-hook-form";
57
import * as Yup from "yup";
6-
import { CustomInputField } from "./CustomInputField";
7-
import { SiteContainer } from "./SiteContainer";
88

99
export default {
1010
title: "Inputs",
1111
} satisfies Meta;
1212

13-
export const Inputs: StoryObj = {
13+
export const EmailInput: StoryObj = {
1414
render: () => {
1515
const { control } = useForm<{ email: string }>({
1616
defaultValues: {
@@ -36,13 +36,9 @@ export const Inputs: StoryObj = {
3636
type="email"
3737
autoComplete="username"
3838
required
39+
style={{ width: 300 }}
3940
/>
4041
</SiteContainer>
4142
);
4243
},
43-
parameters: {
44-
nextjs: {
45-
appDirectory: true,
46-
},
47-
},
4844
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { SiteContainer } from "@/components/ui/SiteContainer";
2+
import { tServer } from "@/i18n/util";
3+
import { useGeneralStore } from "@/stores/generalStore";
4+
import { sleep } from "@/util/helpers";
5+
import { Button } from "@mui/material";
6+
import { Meta, StoryObj } from "@storybook/react";
7+
import { LoadingOverlay } from "./LoadingOverlay";
8+
9+
export default {
10+
title: "Loading Overlay",
11+
} satisfies Meta;
12+
13+
export const TriggerOverlay: StoryObj = {
14+
render: () => {
15+
const [setIsLoading] = useGeneralStore((state) => [state.setIsLoading]);
16+
17+
return (
18+
<SiteContainer>
19+
<Button
20+
variant="outlined"
21+
onClick={async () => {
22+
setIsLoading(true);
23+
await sleep(100);
24+
setIsLoading(false);
25+
}}
26+
>
27+
{tServer("de", "button.loadingShort")}
28+
</Button>
29+
<Button
30+
variant="outlined"
31+
onClick={async () => {
32+
setIsLoading(true);
33+
await sleep(2000);
34+
setIsLoading(false);
35+
}}
36+
>
37+
{tServer("de", "button.loadingLong")}
38+
</Button>
39+
<LoadingOverlay />
40+
</SiteContainer>
41+
);
42+
},
43+
};

src/styles/TextStyles.stories.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { SiteContainer } from "@/components/ui/SiteContainer";
2+
import { Meta, StoryObj } from "@storybook/react";
3+
4+
export default {
5+
title: "Text Styles",
6+
} satisfies Meta;
7+
8+
export const Headlines: StoryObj = {
9+
render: () => {
10+
return (
11+
<SiteContainer>
12+
<h1 className="text-primary">H1 headline</h1>
13+
<h2>H2 headline</h2>
14+
<h3>H3 headline</h3>
15+
<h4>H4 headline</h4>
16+
</SiteContainer>
17+
);
18+
},
19+
};
20+
21+
export const Paragraphs: StoryObj = {
22+
render: () => {
23+
return (
24+
<SiteContainer>
25+
<p>Paragraph body1</p>
26+
<p className="body2">Paragraph body2</p>
27+
</SiteContainer>
28+
);
29+
},
30+
};

0 commit comments

Comments
 (0)