Skip to content

Commit

Permalink
Translations for ReadOnlyIcon (#3311)
Browse files Browse the repository at this point in the history
  • Loading branch information
HalvorHaugan authored Oct 31, 2024
1 parent 5ce8ec6 commit c200f58
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 43 deletions.
2 changes: 1 addition & 1 deletion @navikt/core/react/src/date/parts/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const DateInput = forwardRef<HTMLInputElement, DateInputProps>((props, ref) => {
"navds-sr-only": hideLabel,
})}
>
<ReadOnlyIcon readOnly={readOnly} />
{readOnly && <ReadOnlyIcon />}
{label}
</Label>
{!!description && (
Expand Down
31 changes: 14 additions & 17 deletions @navikt/core/react/src/form/ReadOnlyIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import React from "react";
import { PadlockLockedFillIcon } from "@navikt/aksel-icons";
import { useI18n } from "../util/i18n/i18n.context";

export const ReadOnlyIcon = ({
readOnly,
nativeReadOnly = true,
}: {
readOnly?: boolean;
nativeReadOnly?: boolean;
}) => {
if (readOnly) {
return (
<PadlockLockedFillIcon
{...(nativeReadOnly ? { "aria-hidden": true } : { title: "readonly" })}
className="navds-form-field__readonly-icon"
/>
);
}
return null;
};
export const ReadOnlyIcon = () => (
<PadlockLockedFillIcon
aria-hidden
className="navds-form-field__readonly-icon"
/>
);

export const ReadOnlyIconWithTitle = () => (
<PadlockLockedFillIcon
title={useI18n("global")("readOnly")}
className="navds-form-field__readonly-icon"
/>
);
6 changes: 2 additions & 4 deletions @navikt/core/react/src/form/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { forwardRef } from "react";
import { BodyShort } from "../../typography";
import { omit } from "../../util";
import { useId } from "../../util/hooks";
import { ReadOnlyIcon } from "../ReadOnlyIcon";
import { ReadOnlyIconWithTitle } from "../ReadOnlyIcon";
import { CheckboxProps } from "./types";
import useCheckbox from "./useCheckbox";

Expand Down Expand Up @@ -90,9 +90,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
className="navds-checkbox__label-text"
aria-hidden
>
{!nested && (
<ReadOnlyIcon readOnly={readOnly} nativeReadOnly={false} />
)}
{!nested && readOnly && <ReadOnlyIconWithTitle />}
{props.children}
</BodyShort>
{props.description && (
Expand Down
4 changes: 2 additions & 2 deletions @navikt/core/react/src/form/combobox/Combobox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cl from "clsx";
import React, { forwardRef } from "react";
import { BodyShort, ErrorMessage, Label } from "../../typography";
import { ReadOnlyIcon } from "../ReadOnlyIcon";
import { ReadOnlyIconWithTitle } from "../ReadOnlyIcon";
import ComboboxWrapper from "./ComboboxWrapper";
import FilteredOptions from "./FilteredOptions/FilteredOptions";
import { useFilteredOptionsContext } from "./FilteredOptions/filteredOptionsContext";
Expand Down Expand Up @@ -46,7 +46,7 @@ export const Combobox = forwardRef<
"navds-sr-only": hideLabel,
})}
>
<ReadOnlyIcon nativeReadOnly={false} readOnly={readOnly} />
{readOnly && <ReadOnlyIconWithTitle />}
{label}
</Label>
{!!description && (
Expand Down
5 changes: 3 additions & 2 deletions @navikt/core/react/src/form/fieldset/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cl from "clsx";
import React, { FieldsetHTMLAttributes, forwardRef, useContext } from "react";
import { BodyShort, ErrorMessage, Label } from "../../typography";
import { omit } from "../../util";
import { ReadOnlyIcon } from "../ReadOnlyIcon";
import { ReadOnlyIcon, ReadOnlyIconWithTitle } from "../ReadOnlyIcon";
import { FormFieldProps } from "../useFormField";
import { FieldsetContext } from "./context";
import { useFieldset } from "./useFieldset";
Expand Down Expand Up @@ -89,7 +89,8 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
"navds-sr-only": !!hideLegend,
})}
>
<ReadOnlyIcon readOnly={readOnly} nativeReadOnly={nativeReadOnly} />
{readOnly &&
(nativeReadOnly ? <ReadOnlyIcon /> : <ReadOnlyIconWithTitle />)}
{legend}
</Label>
{!!description && (
Expand Down
4 changes: 2 additions & 2 deletions @navikt/core/react/src/form/select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { SelectHTMLAttributes, forwardRef } from "react";
import { ChevronDownIcon } from "@navikt/aksel-icons";
import { BodyShort, ErrorMessage, Label } from "../../typography";
import { omit } from "../../util";
import { ReadOnlyIcon } from "../ReadOnlyIcon";
import { ReadOnlyIconWithTitle } from "../ReadOnlyIcon";
import { FormFieldProps, useFormField } from "../useFormField";

export interface SelectProps
Expand Down Expand Up @@ -112,7 +112,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
"navds-sr-only": hideLabel,
})}
>
<ReadOnlyIcon readOnly={readOnly} nativeReadOnly={false} />
{readOnly && <ReadOnlyIconWithTitle />}
{label}
</Label>
{!!description && (
Expand Down
19 changes: 9 additions & 10 deletions @navikt/core/react/src/form/switch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
import { Loader } from "../../loader";
import { BodyShort } from "../../typography";
import { omit } from "../../util";
import { ReadOnlyIcon } from "../ReadOnlyIcon";
import { ReadOnlyIconWithTitle } from "../ReadOnlyIcon";
import { FormFieldProps, useFormField } from "../useFormField";

const SelectedIcon = () => (
Expand All @@ -21,7 +21,6 @@ const SelectedIcon = () => (
focusable={false}
role="img"
aria-hidden
aria-label="Deaktiver valg"
>
<path
fillRule="evenodd"
Expand Down Expand Up @@ -117,19 +116,19 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
defaultChecked={defaultChecked}
ref={ref}
type="checkbox"
onChange={(e) => {
onChange={(event) => {
if (readOnly) {
return;
}
setChecked(e.target.checked);
props.onChange?.(e);
setChecked(event.target.checked);
props.onChange?.(event);
}}
onClick={(e) => {
onClick={(event) => {
if (readOnly) {
e.preventDefault();
event.preventDefault();
return;
}
props?.onClick?.(e);
props.onClick?.(event);
}}
className={cl(className, "navds-switch__input")}
/>
Expand All @@ -150,11 +149,11 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
<div
className={cl("navds-switch__content", {
"navds-sr-only": hideLabel,
"navds-switch--with-description": !!description && !hideLabel,
"navds-switch--with-description": description && !hideLabel,
})}
>
<BodyShort as="div" size={size} className="navds-switch__label">
<ReadOnlyIcon readOnly={readOnly} nativeReadOnly={false} />
{readOnly && <ReadOnlyIconWithTitle />}
{children}
</BodyShort>
{description && (
Expand Down
5 changes: 1 addition & 4 deletions @navikt/core/react/src/form/textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import { ReadOnlyIcon } from "../ReadOnlyIcon";
import { FormFieldProps, useFormField } from "./../useFormField";
import Counter from "./TextareaCounter";

/**
* TODO: Mulighet for lokalisering av sr-only/counter text
*/
export interface TextareaProps
extends FormFieldProps,
React.TextareaHTMLAttributes<HTMLTextAreaElement> {
Expand Down Expand Up @@ -144,7 +141,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
"navds-sr-only": hideLabel,
})}
>
<ReadOnlyIcon readOnly={readOnly} />
{readOnly && <ReadOnlyIcon />}
{label}
</Label>
{!!description && (
Expand Down
2 changes: 1 addition & 1 deletion @navikt/core/react/src/form/textfield/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
"navds-sr-only": hideLabel,
})}
>
<ReadOnlyIcon readOnly={readOnly} />
{readOnly && <ReadOnlyIcon />}
{label}
</Label>

Expand Down
1 change: 1 addition & 0 deletions @navikt/core/react/src/util/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default {
global: {
showMore: "Show more",
showLess: "Show less",
readOnly: "Read-only",
},

FileUpload: {
Expand Down
1 change: 1 addition & 0 deletions @navikt/core/react/src/util/i18n/locales/nb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
global: {
showMore: "Vis mer",
showLess: "Vis mindre",
readOnly: "Skrivebeskyttet",
},

FileUpload: {
Expand Down
1 change: 1 addition & 0 deletions @navikt/core/react/src/util/i18n/locales/nn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default {
global: {
showMore: "Vis meir",
showLess: "Vis mindre",
readOnly: "Skrivebeskytta",
},

FileUpload: {
Expand Down

0 comments on commit c200f58

Please sign in to comment.