|
| 1 | +import { Badge } from "../dist/Badge"; |
| 2 | +import type { BadgeProps } from "../dist/Badge"; |
| 3 | +import { sectionName } from "./sectionName"; |
| 4 | +import { getStoryFactory } from "./getStory"; |
| 5 | +import { assert } from "tsafe/assert"; |
| 6 | +import type { Equals } from "tsafe"; |
| 7 | + |
| 8 | +const { meta, getStory } = getStoryFactory<BadgeProps>({ |
| 9 | + sectionName, |
| 10 | + wrappedComponent: { Badge }, |
| 11 | + description: ` |
| 12 | +- [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/badge) |
| 13 | +- [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/Badge.tsx)`, |
| 14 | + argTypes: { |
| 15 | + severity: { |
| 16 | + options: (() => { |
| 17 | + const severities = ["success", "warning", "info", "error", "new"] as const; |
| 18 | + |
| 19 | + assert<Equals<BadgeProps.Severity, BadgeProps.Severity>>(); |
| 20 | + |
| 21 | + return [null, ...severities]; |
| 22 | + })(), |
| 23 | + control: { type: "select", labels: { null: "no severity" } } |
| 24 | + }, |
| 25 | + noIcon: { |
| 26 | + type: { name: "boolean" }, |
| 27 | + description: "Remove badge icon when true" |
| 28 | + }, |
| 29 | + isSmall: { |
| 30 | + type: { name: "boolean" }, |
| 31 | + description: "Set small badge size (`sm`) when true" |
| 32 | + }, |
| 33 | + label: { |
| 34 | + type: { name: "string", required: true }, |
| 35 | + description: "Label to display on tne badge" |
| 36 | + } |
| 37 | + }, |
| 38 | + disabledProps: ["lang"] |
| 39 | +}); |
| 40 | + |
| 41 | +export default meta; |
| 42 | + |
| 43 | +export const Default = getStory({ |
| 44 | + severity: "success", |
| 45 | + label: "Label badge" |
| 46 | +}); |
| 47 | + |
| 48 | +export const BadgeWithoutSeverity = getStory( |
| 49 | + { |
| 50 | + label: "Label" |
| 51 | + }, |
| 52 | + { |
| 53 | + description: "Medium info `Badge` with icon" |
| 54 | + } |
| 55 | +); |
| 56 | + |
| 57 | +export const InfoBadge = getStory( |
| 58 | + { |
| 59 | + severity: "info", |
| 60 | + label: "Label info" |
| 61 | + }, |
| 62 | + { |
| 63 | + description: "Medium info `Badge` with icon" |
| 64 | + } |
| 65 | +); |
| 66 | + |
| 67 | +export const WarningBadge = getStory( |
| 68 | + { |
| 69 | + severity: "warning", |
| 70 | + noIcon: false, |
| 71 | + label: 'Label "warning"' |
| 72 | + }, |
| 73 | + { |
| 74 | + description: "Medium warning `Badge` with icon" |
| 75 | + } |
| 76 | +); |
| 77 | + |
| 78 | +export const SuccessBadge = getStory( |
| 79 | + { |
| 80 | + severity: "success", |
| 81 | + noIcon: true, |
| 82 | + label: "Label success" |
| 83 | + }, |
| 84 | + { |
| 85 | + description: "Medium success `Badge` without icon" |
| 86 | + } |
| 87 | +); |
| 88 | + |
| 89 | +export const ErrorBadge = getStory( |
| 90 | + { |
| 91 | + severity: "error", |
| 92 | + noIcon: true, |
| 93 | + label: "Label error" |
| 94 | + }, |
| 95 | + { |
| 96 | + description: "Medium error `Badge` without icon" |
| 97 | + } |
| 98 | +); |
| 99 | + |
| 100 | +export const NewBadge = getStory( |
| 101 | + { |
| 102 | + severity: "new", |
| 103 | + isSmall: true, |
| 104 | + label: "Label new" |
| 105 | + }, |
| 106 | + { |
| 107 | + description: "Small new `Badge` with icon" |
| 108 | + } |
| 109 | +); |
0 commit comments