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(input): add action and enable wrap class access #351

Merged
merged 3 commits into from
Jan 1, 2025
Merged
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
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" />
});
Loading