keycloakify-custom/src/account/KcPageStory.tsx

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-06-05 23:44:57 +00:00
import type { DeepPartial } from "keycloakify/tools/DeepPartial";
2024-06-06 03:26:06 +00:00
import type { KcContext } from "./KcContext";
2024-06-06 04:40:12 +00:00
import { createGetKcContextMock } from "keycloakify/account/KcContext";
2024-06-09 13:00:18 +00:00
import type { KcContextExtension, KcContextExtensionPerPage } from "./KcContext";
2024-06-09 10:32:25 +00:00
import KcPage from "./KcPage";
2024-06-09 08:24:14 +00:00
import { themeNames, kcEnvDefaults } from "../kc.gen";
2024-06-05 23:44:57 +00:00
2024-06-09 08:24:14 +00:00
const kcContextExtension: KcContextExtension = {
themeName: themeNames[0],
properties: {
...kcEnvDefaults
}
};
const kcContextExtensionPerPage: KcContextExtensionPerPage = {};
2024-06-05 23:44:57 +00:00
export const { getKcContextMock } = createGetKcContextMock({
2024-06-09 08:24:14 +00:00
kcContextExtension,
kcContextExtensionPerPage,
2024-06-05 23:44:57 +00:00
overrides: {},
overridesPerPage: {}
});
2024-06-09 10:32:25 +00:00
export function createKcPageStory<PageId extends KcContext["pageId"]>(params: {
2024-06-06 03:26:06 +00:00
pageId: PageId;
}) {
2024-06-05 23:44:57 +00:00
const { pageId } = params;
2024-06-09 10:32:25 +00:00
function KcPageStory(props: {
2024-06-06 03:26:06 +00:00
kcContext?: DeepPartial<Extract<KcContext, { pageId: PageId }>>;
}) {
2024-06-05 23:44:57 +00:00
const { kcContext: overrides } = props;
const kcContextMock = getKcContextMock({
pageId,
overrides
});
2024-06-09 10:32:25 +00:00
return <KcPage kcContext={kcContextMock} />;
2024-06-05 23:44:57 +00:00
}
2024-06-09 10:32:25 +00:00
return { KcPageStory };
2024-06-05 23:44:57 +00:00
}