More homogeneous storybook setup

This commit is contained in:
Joseph Garrone
2024-06-03 00:11:19 +02:00
parent e011fb094c
commit ba4d9675a8
34 changed files with 1235 additions and 1130 deletions

View File

@ -1,92 +1,106 @@
import React from "react";
import type { ComponentMeta } from "@storybook/react";
import type { Meta, StoryObj } from "@storybook/react";
import { createPageStory, parameters } from "../createPageStory";
const pageId = "register.ftl";
const { PageStory } = createPageStory({ pageId });
const meta: ComponentMeta<any> = {
const meta = {
title: `login/${pageId}`,
component: PageStory,
parameters
};
} satisfies Meta<typeof PageStory>;
export default meta;
export const Default = () => <PageStory />;
type Story = StoryObj<typeof meta>;
export const WithFieldError = () => (
<PageStory
kcContext={{
profile: {
attributes: [
{
name: "email",
value: "max.mustermann@gmail.com"
}
]
},
messagesPerField: {
existsError: (fieldName: string) => fieldName === "email",
exists: (fieldName: string) => fieldName === "email",
get: (fieldName: string) => (fieldName === "email" ? "I don't like your email address" : undefined),
printIfExists: <T,>(fieldName: string, x: T) => (fieldName === "email" ? x : undefined)
}
}}
/>
);
export const Default: Story = {
render: () => <PageStory />
};
export const WithEmailAsUsername = () => (
<PageStory
kcContext={{
realm: {
registrationEmailAsUsername: true
}
}}
/>
);
export const WithFieldError: Story = {
render: () => (
<PageStory
kcContext={{
profile: {
attributes: [
{
name: "email",
value: "max.mustermann@gmail.com"
}
]
},
messagesPerField: {
existsError: (fieldName: string) => fieldName === "email",
exists: (fieldName: string) => fieldName === "email",
get: (fieldName: string) => (fieldName === "email" ? "I don't like your email address" : undefined),
printIfExists: <T,>(fieldName: string, x: T) => (fieldName === "email" ? x : undefined)
}
}}
/>
)
};
export const WithoutPassword = () => (
<PageStory
kcContext={{
passwordRequired: false
}}
/>
);
export const WithEmailAsUsername: Story = {
render: () => (
<PageStory
kcContext={{
realm: {
registrationEmailAsUsername: true
}
}}
/>
)
};
export const WithRecaptcha = () => (
<PageStory
kcContext={{
recaptchaRequired: true,
recaptchaSiteKey: "foobar"
}}
/>
);
export const WithoutPassword: Story = {
render: () => (
<PageStory
kcContext={{
passwordRequired: false
}}
/>
)
};
export const WithPresets = () => (
<PageStory
kcContext={{
profile: {
attributes: [
{
name: "firstName",
value: "Max"
},
{
name: "lastName",
value: "Mustermann"
},
{
name: "email",
value: "max.mustermann@gmail.com"
},
{
name: "username",
value: "max.mustermann"
}
]
}
}}
/>
);
export const WithRecaptcha: Story = {
render: () => (
<PageStory
kcContext={{
recaptchaRequired: true,
recaptchaSiteKey: "foobar"
}}
/>
)
};
export const WithPresets: Story = {
render: () => (
<PageStory
kcContext={{
profile: {
attributes: [
{
name: "firstName",
value: "Max"
},
{
name: "lastName",
value: "Mustermann"
},
{
name: "email",
value: "max.mustermann@gmail.com"
},
{
name: "username",
value: "max.mustermann"
}
]
}
}}
/>
)
};