Skip to content

Commit 299ca24

Browse files
authored
fjern readonly ikon fra checkbox (#3907)
* fjern readonly ikon fra checkbox * gjør noen småendringer i props på Rhf komponentene * fiks fler props
1 parent cf36e1c commit 299ca24

File tree

11 files changed

+39
-30
lines changed

11 files changed

+39
-30
lines changed

packages/form-hooks/src/RhfCheckbox/RhfCheckbox.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { type ReactNode, useMemo } from 'react';
22
import { type FieldValues, useController, type UseControllerProps, useFormContext } from 'react-hook-form';
33

44
import { Checkbox, type CheckboxProps, ErrorMessage } from '@navikt/ds-react';
5+
import classnames from 'classnames';
56

67
import { getError, getValidationRules, type ValidationReturnType } from '../formUtils';
78

9+
import styles from '../readOnlyIcon.module.css';
10+
811
type Props<T extends FieldValues> = {
912
label: ReactNode;
1013
validate?: Array<(value: string) => ValidationReturnType>;
11-
readOnly?: boolean;
1214
onChange?: (isChecked: boolean) => void;
1315
onClick?: () => void;
1416
control: UseControllerProps<T>['control'];
@@ -19,13 +21,12 @@ type Props<T extends FieldValues> = {
1921
export const RhfCheckbox = <T extends FieldValues>({
2022
label,
2123
validate = [],
22-
readOnly = false,
2324
onChange,
2425
onClick,
2526
size = 'small',
2627
name,
2728
control,
28-
disabled,
29+
className,
2930
...rest
3031
}: Props<T>) => {
3132
const {
@@ -46,7 +47,6 @@ export const RhfCheckbox = <T extends FieldValues>({
4647
<>
4748
<Checkbox
4849
size={size}
49-
disabled={disabled || readOnly}
5050
checked={field.value === true}
5151
error={!!error}
5252
{...field}
@@ -61,6 +61,7 @@ export const RhfCheckbox = <T extends FieldValues>({
6161
onClick();
6262
}
6363
}}
64+
className={classnames(className, styles.noReadOnlyIcon)}
6465
{...rest}
6566
>
6667
{label}

packages/form-hooks/src/RhfCheckboxGroup/RhfCheckboxGroup.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { type ReactElement, type ReactNode, useMemo } from 'react';
22
import { type FieldValues, useController, type UseControllerProps, useFormContext } from 'react-hook-form';
33

44
import { Checkbox, CheckboxGroup, type CheckboxGroupProps, HStack } from '@navikt/ds-react';
5+
import classnames from 'classnames';
56

67
import { EditedIcon } from '@navikt/ft-ui-komponenter';
78

89
import { getError, getValidationRules, type ValidationReturnType } from '../formUtils';
910

11+
import styles from '../readOnlyIcon.module.css';
12+
1013
export interface CheckboxProps {
1114
value: string;
1215
label: string | ReactNode;
@@ -29,13 +32,13 @@ export const RhfCheckboxGroup = <T extends FieldValues>({
2932
legend,
3033
validate = [],
3134
onChange,
32-
readOnly = false,
33-
hideLegend = false,
34-
isEdited = false,
35+
readOnly,
36+
isEdited,
3537
size = 'small',
3638
children,
3739
name,
3840
control,
41+
className,
3942
...rest
4043
}: Props<T>) => {
4144
const {
@@ -67,8 +70,9 @@ export const RhfCheckboxGroup = <T extends FieldValues>({
6770
{readOnly && isEdited && <EditedIcon />}
6871
</HStack>
6972
}
73+
readOnly={readOnly}
7074
error={getError(errors, name)}
71-
hideLegend={hideLegend}
75+
className={classnames(className, styles.noReadOnlyIcon)}
7276
{...rest}
7377
>
7478
{children}

packages/form-hooks/src/RhfDatepicker/RhfDatepicker.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export const RhfDatepicker = <T extends FieldValues>({
3232
label,
3333
description,
3434
validate = [],
35-
hideLabel = false,
36-
readOnly = false,
35+
hideLabel,
36+
readOnly,
3737
size = 'small',
3838
onChange,
3939
disabledDays,

packages/form-hooks/src/RhfNumericField/RhfNumericField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const RhfNumericField = <T extends FieldValues>({
2424
label,
2525
hideLabel,
2626
validate = [],
27-
readOnly = false,
27+
readOnly,
2828
description,
2929
isEdited,
3030
forceTwoDecimalDigits = false,
@@ -51,7 +51,7 @@ export const RhfNumericField = <T extends FieldValues>({
5151
});
5252

5353
if (readOnly) {
54-
return <ReadOnlyField label={label} value={field.value} isEdited={isEdited} hideLabel={hideLabel} />;
54+
return <ReadOnlyField label={label} value={field.value} isEdited={isEdited} hideLabel={hideLabel} size={size} />;
5555
}
5656

5757
const regex = forceTwoDecimalDigits ? TWO_DECIMALS_REGEXP : DECIMAL_REGEXP;

packages/form-hooks/src/RhfRadioGroup/RhfRadioGroup.stories.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const meta = {
88
component: RhfRadioGroup,
99
tags: ['autodocs'],
1010
args: {
11-
readOnly: false,
12-
isEdited: false,
1311
control: undefined, // This will be provided by the decorator
1412
},
1513
decorators: rhfDecorator({ radiopre: 'no' }),

packages/form-hooks/src/RhfRadioGroup/RhfRadioGroup.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { EditedIcon } from '@navikt/ft-ui-komponenter';
88

99
import { getError, getValidationRules, type ValidationReturnType } from '../formUtils';
1010

11-
import styles from './rhfRadioGroup.module.css';
11+
import styles from '../readOnlyIcon.module.css';
1212

1313
type Props<T extends FieldValues> = {
1414
isEdited?: boolean;
@@ -26,9 +26,9 @@ export const RhfRadioGroup = <T extends FieldValues>({
2626
onChange,
2727
children,
2828
className,
29-
readOnly = false,
29+
readOnly,
3030
size = 'small',
31-
isEdited = false,
31+
isEdited,
3232
name,
3333
control,
3434
...rest

packages/form-hooks/src/RhfRadioGroup/rhfRadioGroup.module.css

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/form-hooks/src/RhfRangepicker/RhfRangepicker.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const RhfRangepicker = ({
3838
fromDate,
3939
toDate,
4040
isEdited,
41+
size = 'small',
4142
}: Props) => {
4243
const {
4344
formState: { errors },
@@ -115,7 +116,7 @@ export const RhfRangepicker = ({
115116
if (isReadOnly) {
116117
const fom = fomField.value ? dayjs(fomField.value, ISO_DATE_FORMAT, true).format(DDMMYYYY_DATE_FORMAT) : undefined;
117118
const tom = tomField.value ? dayjs(tomField.value, ISO_DATE_FORMAT, true).format(DDMMYYYY_DATE_FORMAT) : undefined;
118-
return <ReadOnlyField label={label} value={`${fom} - ${tom || ''}`} isEdited={isEdited} />;
119+
return <ReadOnlyField label={label} value={`${fom} - ${tom || ''}`} isEdited={isEdited} size={size} />;
119120
}
120121

121122
const dpProps = {
@@ -133,7 +134,7 @@ export const RhfRangepicker = ({
133134
{...fromInputProps}
134135
onChange={onChangeInputFom}
135136
value={fieldValueFom}
136-
size="small"
137+
size={size}
137138
hideLabel
138139
label=""
139140
aria-label="Fra dato"
@@ -144,7 +145,7 @@ export const RhfRangepicker = ({
144145
{...toInputProps}
145146
onChange={onChangeInputTom}
146147
value={fieldValueTom}
147-
size="small"
148+
size={size}
148149
label=""
149150
aria-label="Til dato"
150151
hideLabel

packages/form-hooks/src/RhfTextField/RhfTextField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export const RhfTextField = <T extends FieldValues>({
2727
name,
2828
control,
2929
label,
30+
hideLabel,
3031
validate = [],
31-
readOnly = false,
32+
readOnly,
3233
type,
3334
shouldValidateOnBlur = false,
3435
onBlur,
@@ -38,7 +39,6 @@ export const RhfTextField = <T extends FieldValues>({
3839
normalizeOnBlur,
3940
isEdited,
4041
autoComplete = 'off',
41-
hideLabel,
4242
size = 'small',
4343
...props
4444
}: Props<T>) => {

packages/form-hooks/src/RhfTextarea/RhfTextarea.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ export const RhfTextarea = <T extends FieldValues>({
2828
name,
2929
control,
3030
label,
31+
hideLabel,
3132
readOnly,
3233
badges,
3334
validate = [],
3435
parse = value => value,
3536
isEdited,
37+
autoComplete = 'off',
3638
size = 'small',
3739
...props
3840
}: Props<T>) => {
@@ -56,7 +58,7 @@ export const RhfTextarea = <T extends FieldValues>({
5658
value={field.value}
5759
type="textarea"
5860
isEdited={isEdited}
59-
hideLabel={props.hideLabel}
61+
hideLabel={hideLabel}
6062
/>
6163
);
6264
}
@@ -75,7 +77,8 @@ export const RhfTextarea = <T extends FieldValues>({
7577
<Textarea
7678
size={size}
7779
label={label}
78-
autoComplete="off"
80+
hideLabel={hideLabel}
81+
autoComplete={autoComplete}
7982
{...field}
8083
onChange={event => field.onChange(event.currentTarget.value !== '' ? parse(event.currentTarget.value) : null)}
8184
value={field.value ? field.value : ''}

0 commit comments

Comments
 (0)