Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(slash): add ChildrenQuestion component #881

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions slash/css/src/Form/ChildrenQuestion/ChildrenQuestion.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@use "../../common/common" as common;

.af-form__children-question {
position: relative;
margin-bottom: 2rem;
padding: 1.5rem 1.25rem;
border: 1px solid common.$color-gray-1;
border-radius: 4px;
background-color: common.$white;

&-arrow {
position: absolute;
top: -0.75rem;
left: 4.5rem;
width: 1.3256rem;
height: 1.3256rem;
border-top: 1px solid common.$color-gray-1;
border-left: 1px solid common.$color-gray-1;
background-color: common.$white;
transform: rotate(45deg);
}
}
20 changes: 20 additions & 0 deletions slash/css/src/Form/ChildrenQuestion/ChildrenQuestion.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Meta, StoryObj } from "@storybook/html";
import "./ChildrenQuestion.scss";

const meta: Meta = {
title: "Components/Form/ChildrenQuestion",
};

export default meta;

export const Primary: StoryObj = {
render: (args) => {
const container = document.createElement("div");
container.innerHTML = `<section class="af-form__children-question"><span class="af-form__children-question-arrow"></span><section>${args.content}</section></section>`;

return container;
},
args: {
content: "ChildrenQuestion",
},
};
1 change: 1 addition & 0 deletions slash/css/src/slash.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@use "./Form/MultiSelect/MultiSelect";
@use "./Form/Text/Text";
@use "./Form/Textarea/Textarea";
@use "./Form/ChildrenQuestion/ChildrenQuestion";
@use "./Modal/Modal";
@use "./Title/Title";
@use "./Layout/Footer/Footer";
Expand Down
23 changes: 23 additions & 0 deletions slash/react/src/Form/ChildrenQuestion/ChildrenQuestion.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Canvas, Controls, Meta } from "@storybook/addon-docs";
import * as ChildrenQuestionStories from "./ChildrenQuestion.stories";

<Meta of={ChildrenQuestionStories} name="ChildrenQuestion" />

# ChildrenQuestion

The `ChildrenQuestion` component is a form component that allows the user to add some children input bloc under an input.

To use the ChildrenQuestion import it like that:

```tsx
import { ChildrenQuestion } from "@axa-fr/design-system-slash-react";

const MyComponent = () => (
<ChildrenQuestion content={<p>Whatever you want here</p>} />
);
```

## Playground

<Canvas of={ChildrenQuestionStories.Playground} />
<Controls of={ChildrenQuestionStories.Playground} />
22 changes: 22 additions & 0 deletions slash/react/src/Form/ChildrenQuestion/ChildrenQuestion.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Meta, StoryObj } from "@storybook/react";
import { ChildrenQuestion } from "./ChildrenQuestion";
import { TextInput } from "../Text";

const meta: Meta<typeof ChildrenQuestion> = {
component: ChildrenQuestion,
title: "Components/Form/ChildrenQuestion",
args: { content: <TextInput label="Champ texte" /> },
};

export default meta;

type StoryProps = React.ComponentProps<typeof ChildrenQuestion>;
type Story = StoryObj<StoryProps>;

export const Playground: Story = {
name: "ChildrenQuestion",
render: ({ content }) => <ChildrenQuestion content={content} />,
args: {
content: <TextInput label="Champ texte" />,
},
};
12 changes: 12 additions & 0 deletions slash/react/src/Form/ChildrenQuestion/ChildrenQuestion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "@axa-fr/design-system-slash-css/dist/Form/ChildrenQuestion/ChildrenQuestion.scss";

export const ChildrenQuestion = ({ content }: { content: React.ReactNode }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: rajouter un className optionnel pour pouvoir surcharger

const componentClassName = "af-form__children-question";

return (
<section className={componentClassName}>
<div className={`${componentClassName}-arrow`} />
<section>{content}</section>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi ne pas utiliser le children au lieu de créer une props content ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je ne suis pas certain que 2 section imbriqué comme cela ca valide d'un point de vue a11y.

</section>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { render, screen } from "@testing-library/react";
import { axe } from "jest-axe";
import { ChildrenQuestion } from "../ChildrenQuestion";

describe("ChildrenQuestion", () => {
it("should render ChildrenQuestion", () => {
// Act
render(<ChildrenQuestion content="Content of the children question" />);

// Assert
expect(
screen.getByText("Content of the children question"),
).toBeInTheDocument();
});

it("shouldn't have an accessibility violation <ChildrenQuestion/>", async () => {
// Act
const { container } = render(
<ChildrenQuestion content="Content of the children question" />,
);

// Assert
expect(await axe(container)).toHaveNoViolations();
});
});
1 change: 1 addition & 0 deletions slash/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export { Select, SelectBase, SelectInput } from "./Form/Select";
export { Slider, SliderInput } from "./Form/Slider";
export { Text, TextInput } from "./Form/Text";
export { Textarea, TextareaInput } from "./Form/Textarea";
export { ChildrenQuestion } from "./Form/ChildrenQuestion/ChildrenQuestion";
export { Footer } from "./Layout/Footer";
export {
Header,
Expand Down
Loading