From 294d712718f9e6e40f33cc3baebbfa6be7e739b9 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Thu, 14 Nov 2024 13:47:55 +0100 Subject: [PATCH] Fix warning in storybook --- src/stories/getStory.tsx | 50 ++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/src/stories/getStory.tsx b/src/stories/getStory.tsx index d8586b9e..b99b2059 100644 --- a/src/stories/getStory.tsx +++ b/src/stories/getStory.tsx @@ -11,6 +11,8 @@ import type { ReactComponent } from "../tools/ReactComponent"; import { OnyxiaUi } from "./theme"; import { Text } from "../Text"; import { getIsDarkModeEnabledOsDefault } from "../tools/getIsDarkModeEnabledOsDefault"; +import { assert, type Equals } from "tsafe/assert"; +import { is } from "tsafe/is"; export function getStoryFactory>(params: { sectionName: string; @@ -60,18 +62,42 @@ export function getStoryFactory>(params: { ); } - const Template: Story< - Props & { - darkMode: boolean; - width: number; - } - > = props => ( - - - - ); + type ReservedProps = { + darkMode: boolean; + width: number; + }; + + const reservedPropsName = ["darkMode", "width"] as const; + + assert>(); + + const Template: Story = props => { + const { darkMode, width, ...componentProps } = props; + + assert( + Object.keys(componentProps).every( + key => !id(reservedPropsName).includes(key), + ), + ); + assert(is(componentProps)); + + return ( + + + + ); + }; - const ContextualizedTemplate: typeof Template = ({ width, ...props }) => { + const ContextualizedTemplate = ({ + width, + componentProps, + }: { + componentProps: Props; + width: number; + }) => { const theme = useTheme(); return ( @@ -95,7 +121,7 @@ export function getStoryFactory>(params: { display: "inline-block", }} > - + );