@@ -19,37 +19,42 @@ An controlled variant is coming soon.
1919
2020## The 'createModal' function
2121
22- The \`createModal(options )\` function take an \`options \` object as parameter.
22+ The \`createModal(params )\` function take an \`params \` object as parameter.
2323
2424**Options Params keys:**
2525- \`name\` (*STRING - Required*): Prefix of the \`Modal\` component name and \`ModalButtonProps\` object name.
26- - \`isOpenedByDefault\` (*BOOLEAN - Required*): Set the opening state of the Modal after it mount.
26+ - \`isOpenedByDefault\` (*boolean - Required*): Set the opening state of the Modal after it mount.
2727
2828**Return:**
29- An object with two keys. The name of these keys are computed from the value
29+ An object with four keys. The name of these keys are computed from the value
3030of \`name\` key of the \`options\` param object :
3131- \`\${PascalCasePrefix}Modal\`: The Modal component
32- - \`\${camelCasePrefix}ModalButtonProps\`: The props object for \`Button\` DSFR component
32+ - \`open\${camelCasePrefix}Modal\`: Programmatically open the modal
33+ - \`close\${camelCasePrefix}Modal\`: Programmatically close the modal
34+ - \`\${camelCasePrefix}ModalNativeButtonProps\`: The props object for <button /> component (For Next AppDir, if you want to be RSC ready)
3335
3436**Eg.:**
3537\`\`\`tsx
3638import { createModal } from "@codegouvfr/react-dsfr/Modal";
3739import { Button } from "@codegouvfr/react-dsfr/Button";
3840
39- const { FooModal, fooModalButtonProps, openFooModal, closeFooModal } = createModal({
41+ const { FooModal, fooModalButtonProps, openFooModal, closeFooModal, fooModalNativeButtonProps } = createModal({
4042 name: "foo", // The name of Modal component and modalButtonProps is compute from this string
4143 isOpenedByDefault: false
4244});
4345
44-
45- const node = (
46- <>
47- {/* ... */}
48- <FooModal title="foo modal title"/>
49- <Button {...fooModalButtonProps}>Open foo modal</Button>
50- <Button onClick={openFooModal}>Open foo modal</Button>
51- <Button onClick={closeFooModal}>Close foo modal</Button>
52- </>
46+ function Home(){
47+ return (
48+ <>
49+ {/* ... */}
50+ <FooModal title="foo modal title">
51+ <h1>Foo modal content</h1>
52+ </FooModal>
53+ <Button nativeButtonProps={fooModalNativeButtonProp}>Open foo modal</Button> {/* Use this if you are in a Server component (Next AppDir) and you don't want to add "use client"; just because of the the Modal */}
54+ <Button onClick={openFooModal}>Open foo modal</Button> {/* ...otherwise this works just as well and is more versatile */}
55+ <Button onClick={closeFooModal}>Close foo modal</Button>
56+ </>
57+ );
5358);
5459
5560\`\`\`
@@ -110,15 +115,15 @@ const node = (
110115
111116export default meta ;
112117
113- const { SimpleModal, simpleModalButtonProps } = createModal ( {
118+ const { SimpleModal, simpleModalNativeButtonProps } = createModal ( {
114119 "name" : "simple" ,
115120 "isOpenedByDefault" : false
116121} ) ;
117122
118123function Template ( args : ModalProps ) {
119124 return (
120125 < >
121- < Button { ... simpleModalButtonProps } > Open modal</ Button >
126+ < Button nativeButtonProps = { simpleModalNativeButtonProps } > Open modal</ Button >
122127 < SimpleModal { ...args } />
123128 </ >
124129 ) ;
0 commit comments