Skip to content

Commit

Permalink
Merge pull request #1250 from nsbno/phonenumberinput-optional
Browse files Browse the repository at this point in the history
Added the option to display optional phone number
  • Loading branch information
mar2n authored Aug 26, 2024
2 parents 572fc31 + 06f8d91 commit ad91d4f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilled-cheetahs-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vygruppen/spor-react": minor
---

PhoneNumberInput: Added the option to display the input as optional
13 changes: 12 additions & 1 deletion packages/spor-react/src/input/PhoneNumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type PhoneNumberInputProps = Omit<BoxProps, "onChange"> & {
/** The optional value of the country code and phone number */
value?: CountryCodeAndPhoneNumber;
variant?: "base" | "floating";
isOptional?: boolean;
};
/**
* A component for entering phone numbers.
Expand All @@ -51,12 +52,16 @@ export const PhoneNumberInput = forwardRef<PhoneNumberInputProps, As>(
value: externalValue,
onChange: externalOnChange,
variant,
isOptional,
...boxProps
},
ref,
) => {
const { t } = useTranslation();
const label = externalLabel ?? t(texts.phoneNumber);
const label =
externalLabel ?? isOptional
? t(texts.phoneNumberOptional)
: t(texts.phoneNumber);
const [value, onChange] = useControllableState({
value: externalValue,
onChange: externalOnChange,
Expand Down Expand Up @@ -125,6 +130,12 @@ const texts = createTexts({
en: "Phone number",
sv: "Telefonnummer",
},
phoneNumberOptional: {
nb: "Telefonnummer (valgfritt)",
nn: "Telefonnummer (valgfritt)",
en: "Phone number (optional)",
sv: "Telefonnummer (valfritt)",
},
countryCodeLabel: {
nb: "Landskode",
nn: "Landskode",
Expand Down

0 comments on commit ad91d4f

Please sign in to comment.