Skip to content

Commit

Permalink
Merge pull request #6 from allaboutapps/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
gottfired authored Aug 13, 2024
2 parents b1cf276 + a9f8020 commit b25fe75
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 243 deletions.
3 changes: 3 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const preview: Preview = {
date: /Date$/i,
},
},
nextjs: {
appDirectory: true,
},
},
decorators: [
(Story) => (
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ For headless CraftCMS projects there is a separate branch. Use `npm_config_yes=t
- Sample Login-Page in the frontend code.
- Docker setup

## Storybook
For developing, previewing and testing UI components we **highly recommend** using [storybook](https://storybook.js.org/). Support
for storybook is built in. For examples how to write simple stories see `*.stories.tsx` files (e.g. `src/components/ui/Buttons.stories.tsx`).

To start the storybook use `yarn storybook`.

## Builds
- Builds are configured as `standalone` in next.config.mjs. SPA style builds (aka `output: "export"`) are not practical,
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.
Expand Down Expand Up @@ -116,8 +122,3 @@ For social media link images you can use this: https://nextjs.org/docs/app/api-r
E.g. robots.txt, sitemap, manifest:
See https://nextjs.org/docs/app/api-reference/file-conventions/metadata

## Storybook
For developing and testing UI components we recommend using [storybook](https://storybook.js.org/). Support
for storybook is built in. For examples how to write simple stories see `*.stories.tsx` files (e.g. `src/components/Buttons.stories.tsx`).

To start the storybook use `yarn storybook`.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ts": "tsc --noEmit --incremental --preserveWatchOutput --pretty",
"ts:watch": "npm run ts -- --watch --project tsconfig.watch.json",
"prepare": "husky install",
"storybook": "storybook dev -p 6006",
"storybook": "storybook dev -p 6006 --ci",
"build-storybook": "storybook build"
},
"dependencies": {
Expand Down Expand Up @@ -52,13 +52,13 @@
},
"devDependencies": {
"@chromatic-com/storybook": "^1.6.1",
"@storybook/addon-essentials": "^8.2.8",
"@storybook/addon-interactions": "^8.2.8",
"@storybook/addon-links": "^8.2.8",
"@storybook/blocks": "^8.2.8",
"@storybook/nextjs": "^8.2.8",
"@storybook/react": "^8.2.8",
"@storybook/test": "^8.2.8",
"@storybook/addon-essentials": "^8.2.9",
"@storybook/addon-interactions": "^8.2.9",
"@storybook/addon-links": "^8.2.9",
"@storybook/blocks": "^8.2.9",
"@storybook/nextjs": "^8.2.9",
"@storybook/react": "^8.2.9",
"@storybook/test": "^8.2.9",
"@testing-library/react": "^16.0.0",
"@types/negotiator": "^0.6.3",
"@types/node": "^20",
Expand All @@ -76,7 +76,7 @@
"husky": "^8.0.3",
"license-checker": "^25.0.1",
"postcss": "^8",
"storybook": "^8.2.8",
"storybook": "^8.2.9",
"tailwindcss": "^3.4.1",
"typescript": "^5",
"vitest": "^2.0.5"
Expand Down
43 changes: 3 additions & 40 deletions src/app/[lang]/(pages)/dashboard/ClientComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,20 @@
"use client";

import NextLink from "next/link";
import { useLocale } from "@/hooks/useLocale";
import { t, tHtml } from "@/i18n/clientUtil";
import { Button, Link } from "@mui/material";
import { sleep } from "@/util/helpers";
import { useGeneralStore } from "@/stores/generalStore";
import { IntlLink } from "@/routing/IntlLink";
import { useLocale } from "@/hooks/useLocale";
import { Routes } from "@/routing/Routes";
import { useIntlRouter } from "@/routing/useIntlRouter";
import { useDebugStore } from "@/stores/debugStore";
import { Button, Link } from "@mui/material";
import NextLink from "next/link";

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

const loading = (
<>
<Button
variant="outlined"
onClick={async () => {
setIsLoading(true);
await sleep(100);
setIsLoading(false);
}}
>
{t("button.loadingShort")}
</Button>
<Button
variant="outlined"
onClick={async () => {
setIsLoading(true);
await sleep(1000);
setIsLoading(false);
}}
>
{t("button.loadingLong")}
</Button>
</>
);

return (
<>
<IntlLink href={Routes.ROOT}>
Expand All @@ -61,15 +33,6 @@ export const ClientComponent = () => {
{t(locale === "de" ? "language.english" : "language.german")}
</Button>
<div>Debug: {debugEnabled ? "enabled" : "disabled"}</div>
{loading}
<Button
variant="outlined"
onClick={async () => {
setError(t("error.general"));
}}
>
{t("button.showError")}
</Button>
<Link href="/assets/third-party-licenses.txt" component={NextLink}>
{t("common.licenses")}
</Link>
Expand Down
14 changes: 1 addition & 13 deletions src/app/[lang]/(pages)/dashboard/ServerComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Icon } from "@/components/Icon";
import { tServer } from "@/i18n/util";
import { PageProps } from "@/types/PageProps";
import { debug } from "@/util/debug";
Expand All @@ -16,16 +15,5 @@ export const ServerComponent = async ({ pageProps }: { pageProps: PageProps }) =
await sleep(100);
debug.log("loading ServerComponent done");

return (
<>
{tServer(pageProps.params.lang, "serverComponent.text")}
<h1 className="text-primary">H1 headline</h1>
<h2>H2 headline</h2>
<h3>H3 headline</h3>
<h4>H4 headline</h4>
<p>Paragraph body1</p>
<p className="body2">Paragraph body2</p>
<Icon name="close" />
</>
);
return <>{tServer(pageProps.params.lang, "serverComponent.text")}</>;
};
29 changes: 21 additions & 8 deletions src/components/ui/Buttons.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Icon } from "@/components/Icon";
import { SiteContainer } from "@/components/ui/SiteContainer";
import { Button, IconButton } from "@mui/material";
import { Meta, StoryObj } from "@storybook/react";
import { SiteContainer } from "./SiteContainer";
import { Icon } from "../Icon";

export default {
title: "Buttons",
} satisfies Meta;

export const Buttons: StoryObj = {
export const Contained: StoryObj = {
render: () => {
return (
<SiteContainer>
Expand All @@ -17,12 +17,30 @@ export const Buttons: StoryObj = {
<Button variant="contained" color="secondary">
Secondary
</Button>
</SiteContainer>
);
},
};

export const Outlined: StoryObj = {
render: () => {
return (
<SiteContainer>
<Button variant="outlined" color="primary">
Outlined Primary
</Button>
<Button variant="outlined" color="primary">
Outlined Secondary
</Button>
</SiteContainer>
);
},
};

export const Icons: StoryObj = {
render: () => {
return (
<SiteContainer>
<div className="flex gap-2 items-center">
Icon button:
<IconButton>
Expand All @@ -32,9 +50,4 @@ export const Buttons: StoryObj = {
</SiteContainer>
);
},
parameters: {
nextjs: {
appDirectory: true,
},
},
};
11 changes: 3 additions & 8 deletions src/components/ui/ErrorToast.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ErrorToast } from "@/components/ui/ErrorToast";
import { SiteContainer } from "@/components/ui/SiteContainer";
import { useGeneralStore } from "@/stores/generalStore";
import { Button } from "@mui/material";
import { Meta, StoryObj } from "@storybook/react";
import { ErrorToast } from "./ErrorToast";
import { SiteContainer } from "./SiteContainer";

export default {
title: "Error Toast",
} satisfies Meta;

export const TriggerError: StoryObj = {
export const TriggerSingleError: StoryObj = {
render: () => {
const [setError] = useGeneralStore((state) => [state.setError]);

Expand All @@ -21,9 +21,4 @@ export const TriggerError: StoryObj = {
</SiteContainer>
);
},
parameters: {
nextjs: {
appDirectory: true,
},
},
};
12 changes: 4 additions & 8 deletions src/components/ui/Inputs.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { CustomInputField } from "@/components/ui/CustomInputField";
import { SiteContainer } from "@/components/ui/SiteContainer";
import { tServer } from "@/i18n/util";
import { yupResolver } from "@hookform/resolvers/yup";
import { Meta, StoryObj } from "@storybook/react";
import { useForm } from "react-hook-form";
import * as Yup from "yup";
import { CustomInputField } from "./CustomInputField";
import { SiteContainer } from "./SiteContainer";

export default {
title: "Inputs",
} satisfies Meta;

export const Inputs: StoryObj = {
export const EmailInput: StoryObj = {
render: () => {
const { control } = useForm<{ email: string }>({
defaultValues: {
Expand All @@ -36,13 +36,9 @@ export const Inputs: StoryObj = {
type="email"
autoComplete="username"
required
style={{ width: 300 }}
/>
</SiteContainer>
);
},
parameters: {
nextjs: {
appDirectory: true,
},
},
};
43 changes: 43 additions & 0 deletions src/components/ui/LoadingOverlay.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { SiteContainer } from "@/components/ui/SiteContainer";
import { tServer } from "@/i18n/util";
import { useGeneralStore } from "@/stores/generalStore";
import { sleep } from "@/util/helpers";
import { Button } from "@mui/material";
import { Meta, StoryObj } from "@storybook/react";
import { LoadingOverlay } from "./LoadingOverlay";

export default {
title: "Loading Overlay",
} satisfies Meta;

export const TriggerOverlay: StoryObj = {
render: () => {
const [setIsLoading] = useGeneralStore((state) => [state.setIsLoading]);

return (
<SiteContainer>
<Button
variant="outlined"
onClick={async () => {
setIsLoading(true);
await sleep(100);
setIsLoading(false);
}}
>
{tServer("de", "button.loadingShort")}
</Button>
<Button
variant="outlined"
onClick={async () => {
setIsLoading(true);
await sleep(2000);
setIsLoading(false);
}}
>
{tServer("de", "button.loadingLong")}
</Button>
<LoadingOverlay />
</SiteContainer>
);
},
};
30 changes: 30 additions & 0 deletions src/styles/TextStyles.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { SiteContainer } from "@/components/ui/SiteContainer";
import { Meta, StoryObj } from "@storybook/react";

export default {
title: "Text Styles",
} satisfies Meta;

export const Headlines: StoryObj = {
render: () => {
return (
<SiteContainer>
<h1 className="text-primary">H1 headline</h1>
<h2>H2 headline</h2>
<h3>H3 headline</h3>
<h4>H4 headline</h4>
</SiteContainer>
);
},
};

export const Paragraphs: StoryObj = {
render: () => {
return (
<SiteContainer>
<p>Paragraph body1</p>
<p className="body2">Paragraph body2</p>
</SiteContainer>
);
},
};
24 changes: 24 additions & 0 deletions src/styles/colors.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { SiteContainer } from "@/components/ui/SiteContainer";
import { Meta, StoryObj } from "@storybook/react";
import { Colors as C } from "./colors";

export default {
title: "Colors",
} satisfies Meta;

export const ColorPalette: StoryObj = {
render: () => {
return (
<SiteContainer>
<div className="flex flex-col gap-4">
{Object.entries(C).map((entry) => (
<div key={entry[0]} className="flex justify-between">
{`${entry[0]}: `}
<div style={{ marginLeft: 16, width: 100, height: 32, backgroundColor: entry[1] }} />
</div>
))}
</div>
</SiteContainer>
);
},
};
6 changes: 1 addition & 5 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import type { Config } from "tailwindcss";
import plugin from "tailwindcss/plugin";

const config: Config = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
content: ["./src/**/*.{js,ts,jsx,tsx,mdx}"],
theme: {
extend: {
colors: {
Expand Down
Loading

0 comments on commit b25fe75

Please sign in to comment.