Skip to content

Commit

Permalink
Ny prop: useLanguageSelector (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehansen2 authored Apr 24, 2024
1 parent faa9d7a commit 0bbee9f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-goats-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/sif-common-soknad-ds": patch
---

Utvide med prop for om språkvelger skal brukes eller ikke.
16 changes: 13 additions & 3 deletions packages/sif-common-soknad-ds/src/setup/SoknadApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ interface Props {
publicPath: string;
/** Locale messages */
intlMessages: MessageFileFormat;
/** Toggle on/off languageselector in decorator */
useLanguageSelector?: boolean;
/** If amplitude logging is active or not - default true*/
useAmplitude?: boolean;
/** Config for connecting to the appStatus sanity project */
Expand All @@ -47,12 +49,20 @@ interface Props {
const localeFromSessionStorage = getLocaleFromSessionStorage();
dayjs.locale(localeFromSessionStorage);

const SoknadApplication = ({ intlMessages, appStatus, publicPath, appKey, useAmplitude = true, children }: Props) => {
const SoknadApplication = ({
intlMessages,
appStatus,
publicPath,
appKey,
useAmplitude = true,
useLanguageSelector,
children,
}: Props) => {
const [locale, setLocale] = React.useState<Locale>(localeFromSessionStorage);
const localeMessages = intlMessages[locale] || intlMessages['nb'];
const locales = Object.keys(intlMessages) as any;
const locales = useLanguageSelector ? (Object.keys(intlMessages) as any) : [];

useDecoratorLanguageSelector([locales], (locale: any) => {
useDecoratorLanguageSelector(locales, (locale: any) => {
setLocaleInSessionStorage(locale);
setLocale(locale);
});
Expand Down

0 comments on commit 0bbee9f

Please sign in to comment.