Skip to content

Commit 0293305

Browse files
authored
Merge pull request #351 from codegouvfr/feat/input-with-action
feat(input): add action and enable wrap class access
2 parents 9ab632d + 0bfbd3b commit 0293305

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codegouvfr/react-dsfr",
3-
"version": "1.16.4",
3+
"version": "1.16.5-rc.0",
44
"description": "French State Design System React integration library",
55
"repository": {
66
"type": "git",

src/Input.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ export namespace InputProps {
2828
disabled?: boolean;
2929
iconId?: FrIconClassName | RiIconClassName;
3030
classes?: Partial<
31-
Record<"root" | "label" | "description" | "nativeInputOrTextArea" | "message", string>
31+
Record<
32+
"root" | "label" | "description" | "nativeInputOrTextArea" | "message" | "wrap",
33+
string
34+
>
3235
>;
3336
style?: CSSProperties;
3437
/** Default: "default" */
3538
state?: "success" | "error" | "info" | "default";
3639
/** The message won't be displayed if state is "default" */
3740
stateRelatedMessage?: ReactNode;
3841
addon?: ReactNode;
42+
action?: ReactNode;
3943
};
4044

4145
export type RegularInput = Common & {
@@ -84,6 +88,7 @@ export const Input = memo(
8488
nativeTextAreaProps,
8589
nativeInputProps,
8690
addon,
91+
action,
8792
...rest
8893
} = props;
8994

@@ -154,7 +159,6 @@ export const Input = memo(
154159
case "default":
155160
return undefined;
156161
}
157-
assert<Equals<typeof state, never>>();
158162
})()
159163
),
160164
classes.nativeInputOrTextArea
@@ -168,16 +172,22 @@ export const Input = memo(
168172

169173
const hasIcon = iconId !== undefined;
170174
const hasAddon = addon !== undefined;
171-
return hasIcon || hasAddon ? (
175+
const hasAction = action !== undefined;
176+
return hasIcon || hasAddon || hasAction ? (
172177
<div
173-
className={fr.cx(
174-
"fr-input-wrap",
175-
hasIcon && iconId,
176-
hasAddon && "fr-input-wrap--addon"
178+
className={cx(
179+
fr.cx(
180+
"fr-input-wrap",
181+
hasIcon && iconId,
182+
hasAddon && "fr-input-wrap--addon",
183+
hasAction && "fr-input-wrap--action"
184+
),
185+
classes.wrap
177186
)}
178187
>
179188
{nativeInputOrTextArea}
180189
{hasAddon && addon}
190+
{hasAction && action}
181191
</div>
182192
) : (
183193
nativeInputOrTextArea
@@ -198,7 +208,6 @@ export const Input = memo(
198208
case "info":
199209
return "fr-info-text";
200210
}
201-
assert<Equals<typeof state, never>>();
202211
})()
203212
),
204213
classes.message

src/blocks/PasswordInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { useAnalyticsId } from "../tools/useAnalyticsId";
2121

2222
export type PasswordInputProps = Omit<
2323
InputProps.Common,
24-
"state" | "stateRelatedMessage" | "iconId" | "classes" | "addon"
24+
"state" | "stateRelatedMessage" | "iconId" | "classes" | "addon" | "action"
2525
> & {
2626
classes?: Partial<Record<"root" | "input" | "label" | "checkbox", string>>;
2727
/** Default "Your password must contain:", if empty string the hint wont be displayed */

stories/Input.stories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,8 @@ export const WithButtonAddon = getStory({
144144
"label": "Label champs de saisie",
145145
"addon": <Button>Valider</Button>
146146
});
147+
148+
export const WithButtonAction = getStory({
149+
"label": "Label champs de saisie",
150+
"addon": <Button title="Supprimer le champ" iconId="fr-icon-delete-line" priority="secondary" />
151+
});

0 commit comments

Comments
 (0)