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

feature/summary-component #210

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
30 changes: 30 additions & 0 deletions packages/react/src/Summary/Summary.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Controls, Canvas, Meta } from "@storybook/blocks";
import * as SummaryStories from "./Summary.stories.tsx";

<Meta of={SummaryStories} />

## Summary

### Import

```tsx title="test.js"
import { Summary } from "@axa-fr/design-system-react/agent";
```

### Use

```tsx title="test.js"
export const SummaryForm = () => (
<Summary
messages={[
<span>Field Author is required</span>,
"Field PlaceName is required",
]}
/>
);
```

### Playground

<Canvas of={SummaryStories.Template} />
<Controls of={SummaryStories.Template} />
27 changes: 27 additions & 0 deletions packages/react/src/Summary/Summary.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Meta, StoryObj } from "@storybook/react";
import { Summary } from "./Summary";

export default {
title: "Agent/Components/Summary",
component: Summary,
argTypes: {
classModifier: {
options: ["success", "info", "danger", "error"],
control: { type: "select" },
},
},
} as Meta;

const messages = [<>Field Author is required</>, "Field PlaceName is required"];

type SummaryProps = React.ComponentProps<typeof Summary>;
type Story = StoryObj<SummaryProps>;

export const Template: Story = {
name: "Summary",
render: (args) => <Summary {...args} />,
args: {
messages,
isVisible: true,
},
};
43 changes: 43 additions & 0 deletions packages/react/src/Summary/Summary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ComponentPropsWithoutRef, ReactNode } from "react";
import { Alert } from "../agent";

type SummaryProps = Omit<ComponentPropsWithoutRef<typeof Alert>, "title"> & {
title?: string;
messages?: ReactNode[];
isVisible?: boolean;
};

export const Summary = ({
messages = [],
isVisible = true,
title = "Invalid form",
...args
}: SummaryProps) => {
if (!messages || !isVisible) {
return null;
}

const messagesNotBlank = messages.filter((message) => Boolean(message));
if (!messagesNotBlank.length) {
return null;
}

return (
<Alert
iconClassName="glyphicon glyphicon-warning-sign"
title={title}
classModifier="error"
{...args}
>
<ul className="af-summary__message-list">
{messages.map((message) => {
return (
<li className="af-summary__message-item" key={`message_${message}`}>
{message}
</li>
);
})}
Comment on lines +33 to +39
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{messages.map((message) => {
return (
<li className="af-summary__message-item" key={`message_${message}`}>
{message}
</li>
);
})}
{messages.map((message) => (
<li className="af-summary__message-item" key={`message_${message}`}>
{message}
</li>
))}

</ul>
</Alert>
);
};
1 change: 1 addition & 0 deletions packages/react/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export {
CheckboxModes,
} from "./Form/Checkbox/Agent";
export { Choice, ChoiceInput } from "./Form/Choice";
export { Summary } from "./Summary/Summary";
Copy link
Contributor

Choose a reason for hiding this comment

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

il faudrait peut-être créer un ./Summary/index.ts afin d'importer en faisant "./Summary" (comme pour les autres composants).

export {
Field,
FieldError,
Expand Down