Skip to content

Commit

Permalink
Merge pull request #351 from codegouvfr/feat/input-with-action
Browse files Browse the repository at this point in the history
feat(input): add action and enable wrap class access
  • Loading branch information
garronej authored Jan 1, 2025
2 parents 9ab632d + 0bfbd3b commit 0293305
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codegouvfr/react-dsfr",
"version": "1.16.4",
"version": "1.16.5-rc.0",
"description": "French State Design System React integration library",
"repository": {
"type": "git",
Expand Down
25 changes: 17 additions & 8 deletions src/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ export namespace InputProps {
disabled?: boolean;
iconId?: FrIconClassName | RiIconClassName;
classes?: Partial<
Record<"root" | "label" | "description" | "nativeInputOrTextArea" | "message", string>
Record<
"root" | "label" | "description" | "nativeInputOrTextArea" | "message" | "wrap",
string
>
>;
style?: CSSProperties;
/** Default: "default" */
state?: "success" | "error" | "info" | "default";
/** The message won't be displayed if state is "default" */
stateRelatedMessage?: ReactNode;
addon?: ReactNode;
action?: ReactNode;
};

export type RegularInput = Common & {
Expand Down Expand Up @@ -84,6 +88,7 @@ export const Input = memo(
nativeTextAreaProps,
nativeInputProps,
addon,
action,
...rest
} = props;

Expand Down Expand Up @@ -154,7 +159,6 @@ export const Input = memo(
case "default":
return undefined;
}
assert<Equals<typeof state, never>>();
})()
),
classes.nativeInputOrTextArea
Expand All @@ -168,16 +172,22 @@ export const Input = memo(

const hasIcon = iconId !== undefined;
const hasAddon = addon !== undefined;
return hasIcon || hasAddon ? (
const hasAction = action !== undefined;
return hasIcon || hasAddon || hasAction ? (
<div
className={fr.cx(
"fr-input-wrap",
hasIcon && iconId,
hasAddon && "fr-input-wrap--addon"
className={cx(
fr.cx(
"fr-input-wrap",
hasIcon && iconId,
hasAddon && "fr-input-wrap--addon",
hasAction && "fr-input-wrap--action"
),
classes.wrap
)}
>
{nativeInputOrTextArea}
{hasAddon && addon}
{hasAction && action}
</div>
) : (
nativeInputOrTextArea
Expand All @@ -198,7 +208,6 @@ export const Input = memo(
case "info":
return "fr-info-text";
}
assert<Equals<typeof state, never>>();
})()
),
classes.message
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/PasswordInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { useAnalyticsId } from "../tools/useAnalyticsId";

export type PasswordInputProps = Omit<
InputProps.Common,
"state" | "stateRelatedMessage" | "iconId" | "classes" | "addon"
"state" | "stateRelatedMessage" | "iconId" | "classes" | "addon" | "action"
> & {
classes?: Partial<Record<"root" | "input" | "label" | "checkbox", string>>;
/** Default "Your password must contain:", if empty string the hint wont be displayed */
Expand Down
5 changes: 5 additions & 0 deletions stories/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,8 @@ export const WithButtonAddon = getStory({
"label": "Label champs de saisie",
"addon": <Button>Valider</Button>
});

export const WithButtonAction = getStory({
"label": "Label champs de saisie",
"addon": <Button title="Supprimer le champ" iconId="fr-icon-delete-line" priority="secondary" />
});

0 comments on commit 0293305

Please sign in to comment.