-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from InseeFr/develop
bump version 0.0.27, modal component
- Loading branch information
Showing
7 changed files
with
240 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { useCallback, useEffect, useRef, KeyboardEvent } from "react"; | ||
import { createPortal } from "react-dom"; | ||
import { Button } from "./Button"; | ||
import { LunaticComponentProps } from "./type"; | ||
import classnames from "classnames"; | ||
|
||
export function Modal( | ||
props: Pick< | ||
LunaticComponentProps<"Modal">, | ||
"id" | "label" | "description" | "goToPage" | "page" | "goNextPage" | "goPreviousPage" | ||
>, | ||
) { | ||
const { id, label, description, goNextPage, goPreviousPage } = props; | ||
const first = useRef<HTMLDivElement>(null); | ||
const last = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
const focusOnInit = first?.current?.lastElementChild as HTMLButtonElement; | ||
focusOnInit.focus(); | ||
}, [first]); | ||
|
||
const onKeyDown = useCallback( | ||
(e: KeyboardEvent<HTMLElement>) => { | ||
const firstButtonToFocus = first?.current?.lastElementChild as HTMLButtonElement; | ||
const lastButtonToFocus = last?.current?.lastElementChild as HTMLButtonElement; | ||
if (e.key === "Tab") { | ||
if (e.shiftKey) { | ||
if (document.activeElement === firstButtonToFocus) { | ||
lastButtonToFocus.focus(); | ||
e.nativeEvent.preventDefault(); | ||
} | ||
} else if (document.activeElement === lastButtonToFocus) { | ||
firstButtonToFocus.focus(); | ||
e.nativeEvent.preventDefault(); | ||
} | ||
} | ||
}, | ||
[first, last], | ||
); | ||
|
||
const handleNextClick = useCallback( | ||
function () { | ||
goNextPage(); | ||
}, | ||
[goNextPage], | ||
); | ||
const handlePreviousClick = useCallback( | ||
function () { | ||
goPreviousPage(); | ||
}, | ||
[goPreviousPage], | ||
); | ||
|
||
return createPortal( | ||
<dialog | ||
aria-labelledby={`${id}-title`} | ||
id={id} | ||
className={classnames("lunatic-modal", "fr-modal", "fr-modal--opened")} | ||
open={true} | ||
> | ||
<div className="fr-container fr-container--fluid fr-container-md" onKeyDown={onKeyDown}> | ||
<div className="fr-grid-row fr-grid-row--center"> | ||
<div className="fr-col-12 fr-col-md-8 fr-col-lg-6"> | ||
<div className="fr-modal__body"> | ||
<div className="fr-modal__header" ref={first}> | ||
<Button | ||
className={"fr-btn--close"} | ||
onClick={handlePreviousClick} | ||
disabled={false} | ||
priority={"tertiary no outline"} | ||
> | ||
Fermer | ||
</Button> | ||
</div> | ||
<div className="fr-modal__content"> | ||
<span id={`${id}-title`} className="fr-modal__title"> | ||
{/* Label is defined in the source.json, and we can accept VTL|MD or VTL */} | ||
{label} | ||
</span> | ||
{/* Label is defined in the source.json, and we can accept VTL|MD or VTL */} | ||
<span>{description}</span> | ||
</div> | ||
<div className="fr-modal__footer"> | ||
<ul className="fr-btns-group fr-btns-group--right fr-btns-group--inline-reverse fr-btns-group--inline-lg fr-btns-group--icon-left"> | ||
<li> | ||
<Button | ||
onClick={handlePreviousClick} | ||
disabled={false} | ||
priority={"secondary"} | ||
> | ||
Annuler | ||
</Button> | ||
</li> | ||
<li> | ||
<Button | ||
onClick={handleNextClick} | ||
disabled={false} | ||
priority={"primary"} | ||
> | ||
Je confirme | ||
</Button> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</dialog>, | ||
document.body, | ||
); | ||
} | ||
|
||
export default Modal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
import defaultArgTypes from "../utils/default-arg-types"; | ||
import Orchestrator from "../utils/Orchestrator"; | ||
import source from "./source.json"; | ||
import * as custom from "../.."; | ||
|
||
// eslint-disable-next-line no-undef | ||
console.log(custom); | ||
|
||
const stories = { | ||
title: "Components/Modal", | ||
component: Orchestrator, | ||
argTypes: defaultArgTypes, | ||
}; | ||
|
||
export default stories; | ||
|
||
const Template = args => <Orchestrator {...args} custom={custom} />; | ||
export const Default = Template.bind({}); | ||
|
||
Default.args = { id: "modal", source }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"maxPage": "4", | ||
"components": [ | ||
{ | ||
"id": "kze792d8", | ||
"componentType": "InputNumber", | ||
"mandatory": false, | ||
"page": "1", | ||
"min": 0, | ||
"max": 10, | ||
"decimals": 0, | ||
"label": { | ||
"value": "\"➡ 1. \" || \"In put for Number \"", | ||
"type": "VTL|MD" | ||
}, | ||
"description": { "value": "\"Description\"", "type": "VTL|MD" }, | ||
"conditionFilter": { "value": "true", "type": "VTL" }, | ||
"response": { "name": "COUNT_PERSONS" } | ||
}, | ||
{ | ||
"id": "modaltoto", | ||
"componentType": "ConfirmationModal", | ||
"conditionFilter": { "value": "true", "type": "VTL" }, | ||
"page": "2", | ||
"label": { | ||
"value": "\"Vous avez indiqué \" || (if COUNT_PERSONS = 0 then \"que personne vivait\" else if COUNT_PERSONS = 1 then \"qu'une personne vivait\" else \"que \" || cast(COUNT_PERSONS, string) || \" personnes vivait\") || \" dans ce logement. Êtes-vous sur de n’avoir oublié personne, y compris: \"", | ||
"type": "VTL" | ||
}, | ||
"description": { | ||
"value": "\"* vous-même \n * les nourrissons encore à la maternité \n * les personnes temporairement absentes (vacances, voyage d'affaires, hospitalisation de moins d'un mois, etc.) \n * les personnes qui vivent également une partie du temps ailleurs (enfants ou étudiants scolarisés ailleurs, conjoints éloignés pour raisons professionnelles, enfants en résidence alternée, personnes âgées en institution, etc.) \n * les colocataires et les sous-locataires \n\"", | ||
"type": "VTL|MD" | ||
}, | ||
"declarations": [ | ||
{ | ||
"id": "kb9hi4j0-krnoclfe", | ||
"declarationType": "INSTRUCTION", | ||
"position": "BEFORE_QUESTION_TEXT", | ||
"label": { | ||
"value": "\"Déclaration Before\"", | ||
"type": "VTL|MD" | ||
} | ||
}, | ||
{ | ||
"id": "kb9hi4j0-krnoclfe", | ||
"declarationType": "INSTRUCTION", | ||
"position": "AFTER_QUESTION_TEXT", | ||
"label": { | ||
"value": "\"Déclaration AFTER\"", | ||
"type": "VTL|MD" | ||
} | ||
}, | ||
{ | ||
"id": "kb9hi4j0-krnoclfe", | ||
"declarationType": "HELP", | ||
"position": "DETACHABLE", | ||
"label": { | ||
"value": "\"Declaration Detachable\"", | ||
"type": "VTL|MD" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "modaltoto", | ||
"componentType": "Sequence", | ||
"conditionFilter": { "value": "false", "type": "VTL" }, | ||
"page": "3", | ||
"label": { | ||
"value": "toto to skip", | ||
"type": "VTL" | ||
} | ||
}, | ||
{ | ||
"id": "modaltoto", | ||
"componentType": "Sequence", | ||
"conditionFilter": { "value": "true", "type": "VTL" }, | ||
"page": "4", | ||
"label": { | ||
"value": "toto to not skip", | ||
"type": "VTL" | ||
} | ||
} | ||
], | ||
"variables": [ | ||
{ | ||
"variableType": "COLLECTED", | ||
"name": "COUNT_PERSONS", | ||
"values": { | ||
"PREVIOUS": null, | ||
"COLLECTED": null, | ||
"FORCED": null, | ||
"EDITED": null, | ||
"INPUTED": null | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters