Skip to content

Commit

Permalink
Merge pull request #57 from InseeFr/develop
Browse files Browse the repository at this point in the history
Implement QuestionContext and QuestionInformation
  • Loading branch information
isMattCoding authored May 26, 2023
2 parents 2b9af3c + ca12eea commit 1084861
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 153 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@inseefr/lunatic-dsfr",
"version": "0.0.12",
"version": "0.0.13",
"description": "Couche graphique pour Lunatic reposant sur le Système de Design de l'État (DSFR)",
"repository": {
"type": "git",
Expand Down Expand Up @@ -78,8 +78,8 @@
"typescript": "^4.3.5"
},
"dependencies": {
"@inseefr/lunatic": "2.4.4-FeatAltDeclarations",
"classnames": "^2.3.2",
"@inseefr/lunatic": "2.4.2",
"react-number-format": "^5.1.4",
"sass-loader": "^13.2.0",
"tss-react": "^4.8.3"
Expand Down
2 changes: 2 additions & 0 deletions src/Questions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as QuestionContext } from "./question-context";
export { default as QuestionInformation } from "./question-information";
9 changes: 9 additions & 0 deletions src/Questions/question-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { LunaticComponentProps } from "../type";
import { CallOut } from "@codegouvfr/react-dsfr/CallOut";

function QuestionContext(props: LunaticComponentProps<"Question">) {
const { label, description } = props;
return <CallOut title={label && label}>{description && description}</CallOut>;
}

export default QuestionContext;
20 changes: 20 additions & 0 deletions src/Questions/question-information.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { LunaticComponentProps } from "../type";
import { Alert } from "@codegouvfr/react-dsfr/Alert";

function QuestionInformation(props: LunaticComponentProps<"Question">) {
const { label, description } = props;
if (!label && !description) {
return null;
}
return (
<Alert
description={description ? description : ""}
severity="info"
small={false}
closable={false}
title={label ? label : ""}
/>
);
}

export default QuestionInformation;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export * from "./Radio";
export * from "./Datepicker";
export * from "./Roundabout";
export * from "./ComponentSet";
export * from "./Questions";
export * from "./Sequence";
export * from "./Subsequence";
11 changes: 11 additions & 0 deletions src/stories/component-set/source.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"maxPage": "5",
"components": [
{
"componentType": "QuestionContext",
"label": { "value": "\"Question Context\"", "type": "VTL|MD" },
"description": { "value": "\"Question Context description\"", "type": "VTL|MD" },
"page": "1"
},
{
"id": "component-set",
"componentType": "ComponentSet",
Expand All @@ -17,6 +23,11 @@
"type": "VTL"
},
"components": [
{
"componentType": "QuestionInformation",
"label": { "value": "\"Question Information\"", "type": "VTL|MD" },
"description": { "value": "\"Question Information description\"", "type": "VTL|MD" }
},
{
"id": "prenom",
"componentType": "Input",
Expand Down
20 changes: 18 additions & 2 deletions src/stories/input/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"criticality": "ERROR",
"typeOfControl": "FORMAT",
"control": {
"value": "false",
"value": "NAME = \"BLABLA\"",
"type": "VTL"
},
"errorMessage": {
Expand All @@ -27,6 +27,14 @@
"id": "name",
"response": {
"name": "NAME"
},
"questionInformation": {
"value": "\"Question Information\"",
"type": "VTL"
},
"questionContext": {
"value": "\"Question Context\"",
"type": "VTL"
}
},
{
Expand All @@ -37,7 +45,15 @@
"type": "VTL|MD"
},
"conditionFilter": { "value": "true", "type": "VTL" },
"page": "2"
"page": "2",
"questionInformation": {
"value": "\"Question Information\"",
"type": "VTL|MD"
},
"questionContext": {
"value": "\"Question Context\"",
"type": "VTL|MD"
}
}
],
"variables": [
Expand Down
194 changes: 194 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import {
LunaticComponentDefinition,
LunaticError,
LunaticExpression,
LunaticState,
} from "./utils/type/type";
import { CSSProperties, FunctionComponent, ReactNode } from "react";

export type LunaticBaseProps<ValueType = unknown> = {
id: string;
handleChange: (response: { name: string }, value: ValueType, args?: Record<string, unknown>) => void;
errors?: { [id: string]: LunaticError[] };
preferences?: LunaticState["preferences"];
declarations?: {
id: string;
declarationType: string;
position: string;
label: ReactNode;
}[];
label?: ReactNode;
disabled?: boolean;
missing?: unknown;
missingResponse?: { name: string; value?: unknown };
management?: LunaticState["management"];
description?: ReactNode;
shortcut?: boolean;
required?: boolean;
value: null | ValueType;
readOnly?: boolean;
className?: string;
style?: CSSProperties;
iteration?: number;
executeExpression: LunaticState["executeExpression"];
features?: string[];
componentType?: string;
};

export type SuggesterOption = {
children?: string[];
id?: string;
description?: ReactNode;
label?: ReactNode;
value: string;
niveau?: string;
parent?: string;
tokensMap?: Record<string, { count: number; fields: string[] }>;
};

type ComponentPropsByType = {
InputNumber: LunaticBaseProps<number | null> & {
min: number;
max: number;
decimals: number;
unit?: string;
response: { name: string };
};
Input: LunaticBaseProps<string> & {
maxLength?: number;
value: null | string;
response: { name: string };
};
Sequence: Pick<LunaticBaseProps<string>, "id" | "declarations" | "label" | "style">;
Subsequence: Pick<LunaticBaseProps<string>, "id" | "declarations" | "label">;
Question: Pick<LunaticBaseProps<unknown>, "label" | "description">;
ComponentSet: LunaticBaseProps<unknown> & {
components: LunaticComponentDefinition[];
value: Record<string, unknown>;
};
RosterForLoop: LunaticBaseProps<unknown> & {
lines: { min: number; max: number };
iterations?: number;
components: LunaticComponentDefinition[];
executeExpression: LunaticState["executeExpression"];
value: Record<string, unknown[]>;
headers?: Array<{ label: ReactNode }>;
paginatedLoop?: boolean;
};
Loop: LunaticBaseProps<unknown> & {
lines: { min: number; max: number };
iterations?: number;
components: LunaticComponentDefinition[];
executeExpression: LunaticState["executeExpression"];
value: Record<string, unknown[]>;
headers?: Array<{ label: ReactNode }>;
paginatedLoop?: boolean;
};
Table: LunaticBaseProps<unknown> & {
value: Record<string, unknown>;
header: Array<{
label: ReactNode;
rowspan?: number;
colspan?: number;
}>;
body: Array<Array<{ label: LunaticExpression }>>;
executeExpression: LunaticState["executeExpression"];
iteration: LunaticState["pager"]["iteration"];
};
Datepicker: LunaticBaseProps<string | null> & {
min?: string;
max?: string;
response: { name: string };
};
CheckboxGroup: LunaticBaseProps<Record<string, boolean | null>> & {
responses: Array<{
id: string;
label: ReactNode;
description?: ReactNode;
response: { name: string };
}>;
handleChange: (
response: { name: string },
value: boolean,
args?: Record<string, unknown>,
) => void;
};
CheckboxOne: LunaticBaseProps<string | null> & {
options: Array<{
description: ReactNode;
label: ReactNode;
value: string;
}>;
response: { name: string };
};
Switch: LunaticBaseProps<boolean> & {
response: { name: string };
statusLabel?: { true: string; false: string };
};
CheckboxBoolean: LunaticBaseProps<boolean> & {
options: Array<{ description: ReactNode; label: ReactNode; value: string }>;
response: { name: string };
};
Radio: LunaticBaseProps<string | null> & {
options: Array<{ description: ReactNode; label: ReactNode; value: string }>;
checkboxStyle?: boolean;
response: { name: string };
};
Roundabout: LunaticBaseProps<string> & {
iterations: number;
page: string;
locked?: boolean;
expressions: {
unnecessary?: Array<boolean>;
complete?: Array<boolean>;
partial?: Array<boolean>;
label?: Array<string>;
};
};
Dropdown: LunaticBaseProps<string | null> & {
options: Array<{ description: ReactNode; label: ReactNode; value: string }>;
response: { name: string };
writable?: boolean;
};
Textarea: LunaticBaseProps<string> & {
cols?: number;
placeHolder?: string;
maxLength?: number;
rows?: number;
response: { name: string };
};
FilterDescription: Pick<LunaticBaseProps<string>, "id" | "label">;
PairwiseLinks: Omit<LunaticBaseProps, "value"> & {
components: LunaticComponentDefinition[];
features?: LunaticState["features"];
executeExpression: LunaticState["executeExpression"];
xAxisIterations: number;
yAxisIterations: number;
symLinks: Record<string, Record<string, string>>;
value: Record<string, unknown[]>;
};
Suggester: LunaticBaseProps<string | null> & {
storeName: string;
getSuggesterStatus: (name: string) => {
timestamp: number;
};
optionRenderer: FunctionComponent<{
option: SuggesterOption;
placeholder?: string;
search?: string;
}>;
labelRenderer: FunctionComponent<{
option?: SuggesterOption;
selected?: boolean;
search?: string;
}>;
idbVersion?: string;
focused: boolean;
response: { name: string };
};
};

export type LunaticComponentType = keyof ComponentPropsByType;

export type LunaticComponentProps<T extends LunaticComponentType = LunaticComponentType> =
ComponentPropsByType[T];
Loading

0 comments on commit 1084861

Please sign in to comment.