diff --git a/apps/demo/src/App.tsx b/apps/demo/src/App.tsx index cd4e39f..b5b122c 100644 --- a/apps/demo/src/App.tsx +++ b/apps/demo/src/App.tsx @@ -1,4 +1,9 @@ -import { Button, CunninghamProvider, Select } from "@openfun/cunningham-react"; +import { + Button, + CunninghamProvider, + Select, + useModal, +} from "@openfun/cunningham-react"; import React, { useEffect, useMemo, useState } from "react"; import { Create } from "./Create"; import { Home } from "./Home"; @@ -29,14 +34,7 @@ const THEMES: Record> = { }, }; -export enum Page { - HOME, - CREATE, -} - -export interface PageProps { - changePage: (page: Page) => void; -} +export type PageProps = ReturnType; const preferredScheme = window.matchMedia("(prefers-color-scheme: dark)") .matches @@ -54,7 +52,7 @@ export const App = () => { preferredScheme.variant, ); const activeTheme = useMemo(() => THEMES[theme][variant], [theme, variant]); - const [page, setPage] = useState(Page.HOME); + const modal = useModal(); const handleThemeChange = (event: MediaQueryListEvent) => { const nextVariant = event.matches ? Variant.DARK : Variant.LIGHT; if (THEMES[theme][nextVariant] !== undefined) { @@ -92,8 +90,8 @@ export const App = () => { alt="Background pattern" /> )} - {page === Page.HOME && setPage(p)} />} - {page === Page.CREATE && setPage(p)} />} + +
diff --git a/apps/demo/src/Create.tsx b/apps/demo/src/Create.tsx index 9e632bf..cfa2eac 100644 --- a/apps/demo/src/Create.tsx +++ b/apps/demo/src/Create.tsx @@ -7,6 +7,8 @@ import { DateRangePicker, FileUploader, Input, + Modal, + ModalSize, Radio, RadioGroup, Select, @@ -16,10 +18,10 @@ import { VariantType, } from "@openfun/cunningham-react"; import { faker } from "@faker-js/faker"; +import { PageProps } from "./App"; import { Character, database, randomDates } from "./Character"; -import { Page, PageProps } from "./App"; -export const Create = ({ changePage }: PageProps) => { +export const Create = (props: PageProps) => { const { toast } = useToastProvider(); const submit: React.FormEventHandler = (e) => { @@ -40,102 +42,104 @@ export const Create = ({ changePage }: PageProps) => { }; database.unshift(character); - changePage(Page.HOME); + props.close(); toast("Character created successfully", VariantType.SUCCESS); }; return ( -
-

Add a character

-
-

General Information

- - You are about to add a new character to the collection - - -