-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(slash): add ChildrenQuestion component
- Loading branch information
Showing
8 changed files
with
126 additions
and
0 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
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: 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: white; | ||
transform: rotate(45deg); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
slash/css/src/Form/ChildrenQuestion/ChildrenQuestion.stories.ts
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,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", | ||
}, | ||
}; |
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
23 changes: 23 additions & 0 deletions
23
slash/react/src/Form/ChildrenQuestion/ChildrenQuestion.mdx
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,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
22
slash/react/src/Form/ChildrenQuestion/ChildrenQuestion.stories.tsx
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,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
12
slash/react/src/Form/ChildrenQuestion/ChildrenQuestion.tsx
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,12 @@ | ||
import "@axa-fr/design-system-slash-css/dist/Form/ChildrenQuestion/ChildrenQuestion.scss"; | ||
|
||
export const ChildrenQuestion = ({ content }: { content: React.ReactNode }) => { | ||
const componentClassName = "af-form__children-question"; | ||
|
||
return ( | ||
<section className={componentClassName}> | ||
<span className={`${componentClassName}-arrow`} /> | ||
<section>{content}</section> | ||
</section> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
slash/react/src/Form/ChildrenQuestion/__tests__/ChildrenQuestion.spec.tsx
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,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(); | ||
}); | ||
}); |
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