From 68ecffc6e506832adeb7a5e6a4c09026770b1ca3 Mon Sep 17 00:00:00 2001
From: Quentin Ruhier <99256289+QRuhier@users.noreply.github.com>
Date: Tue, 10 Dec 2024 09:04:09 +0100
Subject: [PATCH] feat: enable to always display detail value (#1187)
---
docs/docs/hook/parameters.mdx | 4 +-
e2e/checkbox.spec.ts | 2 +-
.../CheckboxGroup/CheckboxGroup.tsx | 3 ++
.../CheckboxGroup/CustomCheckboxGroup.tsx | 17 ++----
src/components/CheckboxOne/CheckboxOne.tsx | 3 ++
src/components/Radio/Radio.tsx | 3 ++
.../shared/Checkbox/CheckboxOption.spec.tsx | 21 ++++++++
.../shared/Checkbox/CheckboxOption.tsx | 19 +++++++
src/components/shared/Radio/RadioGroup.tsx | 3 ++
.../shared/Radio/RadioOption.spec.tsx | 36 +++++++++++++
src/components/shared/Radio/RadioOption.tsx | 6 ++-
src/components/type.ts | 3 ++
.../behaviour/missing/missing.stories.jsx | 9 ++++
.../checkbox-group/checkbox-group.stories.jsx | 31 ++++++++---
.../checkbox-one/checkboxOne.stories.jsx | 26 +++++++++-
src/stories/overview/overview.stories.jsx | 9 +++-
src/stories/radio/radio.stories.jsx | 52 ++++++++++++++++---
src/stories/utils/default-arg-types.js | 12 ++++-
src/stories/utils/default-args.js | 3 ++
src/stories/utils/orchestrator.jsx | 10 +++-
src/use-lunatic/lunatic-context.tsx | 9 ++++
src/use-lunatic/props/propOptions.ts | 3 +-
src/use-lunatic/type.ts | 1 +
src/use-lunatic/use-lunatic.ts | 4 ++
24 files changed, 254 insertions(+), 35 deletions(-)
create mode 100644 src/stories/utils/default-args.js
diff --git a/docs/docs/hook/parameters.mdx b/docs/docs/hook/parameters.mdx
index 960f83154..919c4d907 100644
--- a/docs/docs/hook/parameters.mdx
+++ b/docs/docs/hook/parameters.mdx
@@ -30,7 +30,9 @@ Toutes les options sont **optionnelles**.
- **missingShortcut** raccourcis clavier déclanchant les boutons missing (défaut `{ dontKnow: '', refused: '' }`)
- **dontKnowButton** label du bouton "Ne sait pas" (défaut `{ fr: 'Ne sais pas', en: "Don't know" }`)
- **refusedButton** label du bouton "Refus" (défaut `{ fr: 'Refus', en: 'Refused' }`)
-- **trackChanges**, active le [suivi des changements](#trackChanges) (défaut `false`)
+- **trackChanges**, active le [suivi des changements](#trackChanges) (défaut `false`),
+- **componentsOptions** permet de définir des options sur le fonctionnement des composants. Toutes les options sont optionnelles (défaut objet contenant la valeur par défaut de chaque paramètre)
+ - **detailAlwaysDisplayed** permet d'afficher par défaut les modalités 'detail' associées aux modalités de réponse
### Vue d'ensemble {#vue-densemble}
diff --git a/e2e/checkbox.spec.ts b/e2e/checkbox.spec.ts
index 31e3cd053..12b1d1454 100644
--- a/e2e/checkbox.spec.ts
+++ b/e2e/checkbox.spec.ts
@@ -38,7 +38,7 @@ test.describe('Checkboxes', () => {
});
test('Can select arbitrary value', async ({ page }) => {
- await goToStory(page, 'components-checkboxgroup--arbitrary');
+ await goToStory(page, 'components-checkboxgroup--with-detail');
const selector = page.getByRole('checkbox', { name: 'Autre préciser' });
await expect(selector).toBeVisible();
await selector.click();
diff --git a/src/components/CheckboxGroup/CheckboxGroup.tsx b/src/components/CheckboxGroup/CheckboxGroup.tsx
index db276e067..52543fcda 100644
--- a/src/components/CheckboxGroup/CheckboxGroup.tsx
+++ b/src/components/CheckboxGroup/CheckboxGroup.tsx
@@ -1,6 +1,7 @@
import type { LunaticComponentProps } from '../type';
import { CustomCheckboxGroup } from './CustomCheckboxGroup';
import { getComponentErrors } from '../shared/ComponentErrors/ComponentErrors';
+import { useLunaticComponentsOptions } from '../../use-lunatic/lunatic-context';
export function CheckboxGroup({
id,
@@ -14,6 +15,7 @@ export function CheckboxGroup({
declarations,
orientation,
}: LunaticComponentProps<'CheckboxGroup'>) {
+ const { detailAlwaysDisplayed } = useLunaticComponentsOptions();
return (
);
}
diff --git a/src/components/CheckboxGroup/CustomCheckboxGroup.tsx b/src/components/CheckboxGroup/CustomCheckboxGroup.tsx
index 0b07267d0..582bed504 100644
--- a/src/components/CheckboxGroup/CustomCheckboxGroup.tsx
+++ b/src/components/CheckboxGroup/CustomCheckboxGroup.tsx
@@ -6,7 +6,6 @@ import { CheckboxOption } from '../shared/Checkbox/CheckboxOption';
import { getShortcutKey } from '../shared/Checkbox/getShortcutKey';
import type { LunaticComponentProps } from '../type';
import { Declarations } from '../shared/Declarations/Declarations';
-import { CustomInput } from '../Input/Input';
type Props = Pick<
LunaticComponentProps<'CheckboxGroup'>,
@@ -19,6 +18,7 @@ type Props = Pick<
| 'disabled'
| 'options'
| 'orientation'
+ | 'detailAlwaysDisplayed'
> & {
errors?: LunaticError[];
};
@@ -35,6 +35,7 @@ export const CustomCheckboxGroup = slottableComponent(
readOnly,
declarations,
orientation,
+ detailAlwaysDisplayed,
}: Props) => {
return (