@leabankab/component-library 8.10.0 → 8.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/component-library.es.js +1247 -1225
- package/dist/component-library.es.js.map +1 -1
- package/dist/component-library.umd.js +2 -2
- package/dist/component-library.umd.js.map +1 -1
- package/dist/components/animations/index.d.ts +5 -2
- package/dist/components/animations/loader/loader.d.ts +43 -0
- package/dist/components/animations/pulse-animation/pulse-animation.d.ts +21 -0
- package/dist/components/animations/{illustrations → status-animation}/status-animation.d.ts +7 -6
- package/dist/components/feedback/alert-parts.d.ts +1 -1
- package/dist/i18n/languages.d.ts +34 -0
- package/dist/index.css +1 -1
- package/dist/next-intl/index.d.ts +21 -0
- package/dist/next-intl/lea-intl-provider.d.ts +35 -0
- package/dist/next-intl/server.d.ts +24 -0
- package/dist/next-intl/texts.d.ts +77 -0
- package/dist/next-intl/use-texts.d.ts +28 -0
- package/dist/next-intl-server.mjs +11 -0
- package/dist/next-intl-server.mjs.map +1 -0
- package/dist/next-intl-texts-De3tiuSm.mjs +25 -0
- package/dist/next-intl-texts-De3tiuSm.mjs.map +1 -0
- package/dist/next-intl.mjs +37 -0
- package/dist/next-intl.mjs.map +1 -0
- package/dist/theme/tokens/text-styles.d.ts +1 -1
- package/package.json +15 -2
- package/dist/components/animations/icons/index.d.ts +0 -1
- package/dist/components/animations/illustrations/index.d.ts +0 -3
- package/dist/components/animations/illustrations/pulse-animation.d.ts +0 -16
- /package/dist/components/animations/{illustrations → check-animation}/check-animation.d.ts +0 -0
- /package/dist/components/animations/{icons → status-icon}/status-icon.d.ts +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@leabankab/component-library/next-intl` entry: the library in an app
|
|
3
|
+
* that uses next-intl. `LeaIntlProvider` sets the library's language and
|
|
4
|
+
* country from next-intl's locale, and `useTexts` reads the app's own texts
|
|
5
|
+
* in that language, with every language of the app's locales required.
|
|
6
|
+
* Server components use `@leabankab/component-library/next-intl/server`.
|
|
7
|
+
*
|
|
8
|
+
* It is an entry of its own so that next-intl stays an optional peer: the
|
|
9
|
+
* main entry never imports it. Two rules for the files in this folder, both
|
|
10
|
+
* checked by tests/entries.test.tsx:
|
|
11
|
+
*
|
|
12
|
+
* - What they share with the main entry at run time (`LeaProvider`,
|
|
13
|
+
* `CountryProvider`) they import from "../index". The build leaves that
|
|
14
|
+
* module out and points the import at the main bundle, so the language
|
|
15
|
+
* reaches the app's copy of the components.
|
|
16
|
+
* - Anything else they import from `src/` is bundled in, so it has to be
|
|
17
|
+
* plain data or a helper without state: `toLanguage`.
|
|
18
|
+
*/
|
|
19
|
+
export { LeaIntlProvider, type LeaIntlProviderProps, } from './lea-intl-provider';
|
|
20
|
+
export { useTexts } from './use-texts';
|
|
21
|
+
export type { AppLanguage, LanguagesOf, TextFunction, Texts, TextsResult, TextValue, TranslatedText, } from './texts';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Locale } from 'next-intl';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { Country } from '../index';
|
|
4
|
+
import { UnsupportedLocaleKey } from './texts';
|
|
5
|
+
export type LeaIntlProviderProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The country of the formatting hooks (`useFormatCurrency` and the rest).
|
|
8
|
+
* Give it where the country is not the locale's. By default it is the
|
|
9
|
+
* locale's region when that is a Lea Bank country (`sv-FI`), or else the
|
|
10
|
+
* country of its language.
|
|
11
|
+
*/
|
|
12
|
+
country?: Country;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
} & {
|
|
15
|
+
[K in UnsupportedLocaleKey<Locale>]: never;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Sets the library's language and country from next-intl's locale: what
|
|
19
|
+
* `LeaProvider` and `CountryProvider` do, with no map from locale to
|
|
20
|
+
* language in the app. Put it inside `NextIntlClientProvider`, once:
|
|
21
|
+
*
|
|
22
|
+
* ```tsx
|
|
23
|
+
* // app/[locale]/layout.tsx
|
|
24
|
+
* import { NextIntlClientProvider } from "next-intl";
|
|
25
|
+
* import { LeaIntlProvider } from "@leabankab/component-library/next-intl";
|
|
26
|
+
*
|
|
27
|
+
* <NextIntlClientProvider>
|
|
28
|
+
* <LeaIntlProvider>{children}</LeaIntlProvider>
|
|
29
|
+
* </NextIntlClientProvider>
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* The library's components then speak the locale's language, and the
|
|
33
|
+
* formatting hooks format for its country.
|
|
34
|
+
*/
|
|
35
|
+
export declare function LeaIntlProvider({ country, children }: LeaIntlProviderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Locale } from 'next-intl';
|
|
2
|
+
import { AppLanguage, TextsResult } from './texts';
|
|
3
|
+
export type GetTextsOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* The locale, where next-intl can't tell it: in `generateMetadata` of a
|
|
6
|
+
* page that is rendered statically. By default, next-intl's `getLocale()`.
|
|
7
|
+
*/
|
|
8
|
+
locale?: Locale;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Texts in the language of next-intl's locale, for a server component. The
|
|
12
|
+
* texts are the same `satisfies Texts` objects that `useTexts` reads:
|
|
13
|
+
*
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { getTexts } from "@leabankab/component-library/next-intl/server";
|
|
16
|
+
*
|
|
17
|
+
* export default async function Page() {
|
|
18
|
+
* const { t } = await getTexts();
|
|
19
|
+
* return <h1>{t(texts.title)}</h1>;
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function getTexts<L extends AppLanguage = AppLanguage>(options?: GetTextsOptions): Promise<TextsResult<L>>;
|
|
24
|
+
export type { AppLanguage, LanguagesOf, TextFunction, Texts, TextsResult, TextValue, TranslatedText, } from './texts';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Locale } from 'next-intl';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
import { Language, LanguageOfLocale } from '../i18n/languages';
|
|
4
|
+
/**
|
|
5
|
+
* What a text can be in one language: a string, or an element for a text
|
|
6
|
+
* with markup in it (a link, a bold word).
|
|
7
|
+
*/
|
|
8
|
+
export type TextValue = string | ReactElement;
|
|
9
|
+
/** The locales in `L` that stand for no language of the library. */
|
|
10
|
+
type UnsupportedLocale<L extends string> = L extends string ? [LanguageOfLocale<L>] extends [never] ? L : never : never;
|
|
11
|
+
/**
|
|
12
|
+
* The guard on the app's locales. For each locale the library has no
|
|
13
|
+
* language for, a key that every text is then missing, so the error names
|
|
14
|
+
* the locale. `never` when every locale has a language.
|
|
15
|
+
*/
|
|
16
|
+
export type UnsupportedLocaleKey<L extends string> = string extends L ? never : `No library language for locale "${UnsupportedLocale<L>}"`;
|
|
17
|
+
/**
|
|
18
|
+
* The languages that texts for the locales `L` must have: the language of
|
|
19
|
+
* each locale, by `LanguageOfLocale`. `"sv" | "fi" | "nb"` gives
|
|
20
|
+
* `"se" | "fi" | "no"`. Without a list of locales (`string`), all four.
|
|
21
|
+
*/
|
|
22
|
+
export type LanguagesOf<L extends string> = string extends L ? Language : LanguageOfLocale<L> | UnsupportedLocaleKey<L>;
|
|
23
|
+
/**
|
|
24
|
+
* The languages every text in the app must have: one for each locale the app
|
|
25
|
+
* declares to next-intl. With
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* declare module "next-intl" {
|
|
29
|
+
* interface AppConfig {
|
|
30
|
+
* Locale: "sv" | "fi" | "nb";
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* it is `"se" | "fi" | "no"`. An app that declares no `Locale` needs all
|
|
36
|
+
* four.
|
|
37
|
+
*/
|
|
38
|
+
export type AppLanguage = LanguagesOf<Locale>;
|
|
39
|
+
/** One text, in every language of `L`. */
|
|
40
|
+
export type TranslatedText<L extends string = AppLanguage> = {
|
|
41
|
+
readonly [K in L]: TextValue;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The texts of a component or a page: texts, functions that take what goes
|
|
45
|
+
* into a text and return it, and groups of either. Check the object with
|
|
46
|
+
* `satisfies Texts`, so a text that lacks one of the app's languages is a
|
|
47
|
+
* type error:
|
|
48
|
+
*
|
|
49
|
+
* ```tsx
|
|
50
|
+
* const texts = {
|
|
51
|
+
* title: { se: "Ditt lån", no: "Ditt lån", fi: "Lainasi" },
|
|
52
|
+
* greeting: (name: string) => ({ se: `Hej ${name}`, no: `Hei ${name}`, fi: `Hei ${name}` }),
|
|
53
|
+
* } satisfies Texts;
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* `Texts<"se">` is for a feature that only some markets have. Read its texts
|
|
57
|
+
* with `useTexts<"se">()`.
|
|
58
|
+
*/
|
|
59
|
+
export type Texts<L extends string = AppLanguage> = {
|
|
60
|
+
readonly [key: string]: TranslatedText<L> | ((...args: never[]) => TranslatedText<L>) | Texts<L>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* `t`: a text in the current language. A string text gives a string, an
|
|
64
|
+
* element an element. Where `L` leaves out some of the app's languages, the
|
|
65
|
+
* text may have none for the current one, so the result can be `undefined`.
|
|
66
|
+
*/
|
|
67
|
+
export type TextFunction<L extends string = AppLanguage> = <T extends TranslatedText<L>>(text: T) => [AppLanguage] extends [L] ? T[L] : T[L] | undefined;
|
|
68
|
+
/** What `useTexts` and `getTexts` give. */
|
|
69
|
+
export type TextsResult<L extends string = AppLanguage> = {
|
|
70
|
+
/** A text in the current language. */
|
|
71
|
+
t: TextFunction<L>;
|
|
72
|
+
/** The current language, from next-intl's locale. */
|
|
73
|
+
language: AppLanguage;
|
|
74
|
+
};
|
|
75
|
+
/** The `t` and `language` for a language. Shared by the hook and the server. */
|
|
76
|
+
export declare function createTexts<L extends string>(language: Language): TextsResult<L>;
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AppLanguage, TextsResult } from './texts';
|
|
2
|
+
/**
|
|
3
|
+
* Texts in the language of next-intl's locale, for a client component. Keep
|
|
4
|
+
* the texts beside the component and check them with `satisfies Texts`:
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* "use client";
|
|
8
|
+
* import { useTexts, type Texts } from "@leabankab/component-library/next-intl";
|
|
9
|
+
*
|
|
10
|
+
* const texts = {
|
|
11
|
+
* title: { se: "Ditt lån", no: "Ditt lån", fi: "Lainasi" },
|
|
12
|
+
* greeting: (name: string) => ({ se: `Hej ${name}`, no: `Hei ${name}`, fi: `Hei ${name}` }),
|
|
13
|
+
* } satisfies Texts;
|
|
14
|
+
*
|
|
15
|
+
* function LoanHeader({ name }: { name: string }) {
|
|
16
|
+
* const { t } = useTexts();
|
|
17
|
+
* return <h1>{t(texts.title)}, {t(texts.greeting(name))}</h1>;
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* It reads the locale from `NextIntlClientProvider`, so it needs no provider
|
|
22
|
+
* of the library's. In a server component, use `getTexts` from
|
|
23
|
+
* `@leabankab/component-library/next-intl/server`.
|
|
24
|
+
*
|
|
25
|
+
* `useTexts<"se">()` reads texts that only some markets have (`Texts<"se">`).
|
|
26
|
+
* `t` then gives `undefined` in a language the text doesn't have.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useTexts<L extends AppLanguage = AppLanguage>(): TextsResult<L>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { n as e, t } from "./next-intl-texts-De3tiuSm.mjs";
|
|
2
|
+
import { getLocale as n } from "next-intl/server";
|
|
3
|
+
//#region src/next-intl/server.ts
|
|
4
|
+
async function r(r = {}) {
|
|
5
|
+
let i = r.locale ?? await n();
|
|
6
|
+
return t(e(i));
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { r as getTexts };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=next-intl-server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-intl-server.mjs","names":[],"sources":["../src/next-intl/server.ts"],"sourcesContent":["/**\n * The `@leabankab/component-library/next-intl/server` entry: `getTexts`,\n * the server component's `useTexts`.\n *\n * It is apart from `next-intl` because that one is a client module, and a\n * server component can't call a function from a client module. For the same\n * reason nothing here imports from \"../index\", the main bundle, which is a\n * client module too. tests/entries.test.tsx checks both.\n */\nimport type { Locale } from \"next-intl\";\nimport { getLocale } from \"next-intl/server\";\n\nimport { toLanguage } from \"../i18n/languages\";\nimport { type AppLanguage, createTexts, type TextsResult } from \"./texts\";\n\nexport type GetTextsOptions = {\n /**\n * The locale, where next-intl can't tell it: in `generateMetadata` of a\n * page that is rendered statically. By default, next-intl's `getLocale()`.\n */\n locale?: Locale;\n};\n\n/**\n * Texts in the language of next-intl's locale, for a server component. The\n * texts are the same `satisfies Texts` objects that `useTexts` reads:\n *\n * ```tsx\n * import { getTexts } from \"@leabankab/component-library/next-intl/server\";\n *\n * export default async function Page() {\n * const { t } = await getTexts();\n * return <h1>{t(texts.title)}</h1>;\n * }\n * ```\n */\nexport async function getTexts<L extends AppLanguage = AppLanguage>(\n options: GetTextsOptions = {},\n): Promise<TextsResult<L>> {\n const locale = options.locale ?? (await getLocale());\n return createTexts<L>(toLanguage(locale));\n}\n\nexport type {\n AppLanguage,\n LanguagesOf,\n TextFunction,\n Texts,\n TextsResult,\n TextValue,\n TranslatedText,\n} from \"./texts\";\n"],"mappings":";;;AAoCA,eAAsB,EACpB,IAA2B,CAAC,GACH;CACzB,IAAM,IAAS,EAAQ,UAAW,MAAM,EAAU;CAClD,OAAO,EAAe,EAAW,CAAM,CAAC;AAC1C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var e = {
|
|
2
|
+
no: "no",
|
|
3
|
+
nb: "no",
|
|
4
|
+
nn: "no",
|
|
5
|
+
sv: "se",
|
|
6
|
+
se: "se",
|
|
7
|
+
fi: "fi",
|
|
8
|
+
es: "es"
|
|
9
|
+
};
|
|
10
|
+
function t(t) {
|
|
11
|
+
let n = t.toLowerCase().split("-")[0];
|
|
12
|
+
return Object.hasOwn(e, n) ? e[n] : "no";
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/next-intl/texts.ts
|
|
16
|
+
function n(e) {
|
|
17
|
+
return {
|
|
18
|
+
t: (t) => t[e],
|
|
19
|
+
language: e
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { t as n, n as t };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=next-intl-texts-De3tiuSm.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-intl-texts-De3tiuSm.mjs","names":[],"sources":["../src/i18n/languages.ts","../src/next-intl/texts.ts"],"sourcesContent":["/**\n * Languages supported by the component library's built-in translations. The\n * consumer selects one via `LeaProvider`'s `language` prop; components read it\n * with `useLanguage` (usually through `createTranslation`).\n */\nexport const LANGUAGES = [\"no\", \"se\", \"fi\", \"es\"] as const;\n\nexport type Language = (typeof LANGUAGES)[number];\n\n/** Fallback language used when no provider is present or a key is missing. */\nexport const DEFAULT_LANGUAGE = \"no\" satisfies Language;\n\n/**\n * The language each first part of a locale code stands for. Bokmål, Nynorsk\n * and Norwegian are all `no`. Swedish is `se`, the library's name for it,\n * which some apps also use as their locale.\n */\nconst LANGUAGE_BY_SUBTAG = {\n no: \"no\",\n nb: \"no\",\n nn: \"no\",\n sv: \"se\",\n se: \"se\",\n fi: \"fi\",\n es: \"es\",\n} as const satisfies Record<string, Language>;\n\ntype LanguageSubtag = keyof typeof LANGUAGE_BY_SUBTAG;\n\n/**\n * The library language a locale code stands for, read from its first part:\n * `nb`, `nb-NO`, `nn` and `no` are `\"no\"`; `sv`, `sv-SE` and `se` are `\"se\"`;\n * `fi-FI` is `\"fi\"` and `es-ES` is `\"es\"`. `never` for a code the library has\n * no language for, such as `en`. The type of what `toLanguage` returns.\n */\nexport type LanguageOfLocale<L extends string> =\n L extends `${infer Subtag}-${string}`\n ? Subtag extends LanguageSubtag\n ? (typeof LANGUAGE_BY_SUBTAG)[Subtag]\n : never\n : L extends LanguageSubtag\n ? (typeof LANGUAGE_BY_SUBTAG)[L]\n : never;\n\n/**\n * The library language for a locale code as an app writes it for next-intl\n * or `Intl`, by the rules of `LanguageOfLocale`, in upper or lower case. A\n * code the library has no language for gives `DEFAULT_LANGUAGE`.\n *\n * ```tsx\n * toLanguage(\"nb\"); // \"no\"\n * toLanguage(\"sv-SE\"); // \"se\"\n * ```\n */\nexport function toLanguage(locale: string): Language {\n const subtag = locale.toLowerCase().split(\"-\")[0];\n return Object.hasOwn(LANGUAGE_BY_SUBTAG, subtag)\n ? LANGUAGE_BY_SUBTAG[subtag as LanguageSubtag]\n : DEFAULT_LANGUAGE;\n}\n","import type { Locale } from \"next-intl\";\nimport type { ReactElement } from \"react\";\n\nimport type { Language, LanguageOfLocale } from \"../i18n/languages\";\n\n/**\n * What a text can be in one language: a string, or an element for a text\n * with markup in it (a link, a bold word).\n */\nexport type TextValue = string | ReactElement;\n\n/** The locales in `L` that stand for no language of the library. */\ntype UnsupportedLocale<L extends string> = L extends string\n ? [LanguageOfLocale<L>] extends [never]\n ? L\n : never\n : never;\n\n/**\n * The guard on the app's locales. For each locale the library has no\n * language for, a key that every text is then missing, so the error names\n * the locale. `never` when every locale has a language.\n */\nexport type UnsupportedLocaleKey<L extends string> = string extends L\n ? never\n : `No library language for locale \"${UnsupportedLocale<L>}\"`;\n\n/**\n * The languages that texts for the locales `L` must have: the language of\n * each locale, by `LanguageOfLocale`. `\"sv\" | \"fi\" | \"nb\"` gives\n * `\"se\" | \"fi\" | \"no\"`. Without a list of locales (`string`), all four.\n */\nexport type LanguagesOf<L extends string> = string extends L\n ? Language\n : LanguageOfLocale<L> | UnsupportedLocaleKey<L>;\n\n/**\n * The languages every text in the app must have: one for each locale the app\n * declares to next-intl. With\n *\n * ```ts\n * declare module \"next-intl\" {\n * interface AppConfig {\n * Locale: \"sv\" | \"fi\" | \"nb\";\n * }\n * }\n * ```\n *\n * it is `\"se\" | \"fi\" | \"no\"`. An app that declares no `Locale` needs all\n * four.\n */\nexport type AppLanguage = LanguagesOf<Locale>;\n\n/** One text, in every language of `L`. */\nexport type TranslatedText<L extends string = AppLanguage> = {\n readonly [K in L]: TextValue;\n};\n\n/**\n * The texts of a component or a page: texts, functions that take what goes\n * into a text and return it, and groups of either. Check the object with\n * `satisfies Texts`, so a text that lacks one of the app's languages is a\n * type error:\n *\n * ```tsx\n * const texts = {\n * title: { se: \"Ditt lån\", no: \"Ditt lån\", fi: \"Lainasi\" },\n * greeting: (name: string) => ({ se: `Hej ${name}`, no: `Hei ${name}`, fi: `Hei ${name}` }),\n * } satisfies Texts;\n * ```\n *\n * `Texts<\"se\">` is for a feature that only some markets have. Read its texts\n * with `useTexts<\"se\">()`.\n */\nexport type Texts<L extends string = AppLanguage> = {\n readonly [key: string]:\n | TranslatedText<L>\n | ((...args: never[]) => TranslatedText<L>)\n | Texts<L>;\n};\n\n/**\n * `t`: a text in the current language. A string text gives a string, an\n * element an element. Where `L` leaves out some of the app's languages, the\n * text may have none for the current one, so the result can be `undefined`.\n */\nexport type TextFunction<L extends string = AppLanguage> = <\n T extends TranslatedText<L>,\n>(\n text: T,\n) => [AppLanguage] extends [L] ? T[L] : T[L] | undefined;\n\n/** What `useTexts` and `getTexts` give. */\nexport type TextsResult<L extends string = AppLanguage> = {\n /** A text in the current language. */\n t: TextFunction<L>;\n /** The current language, from next-intl's locale. */\n language: AppLanguage;\n};\n\n/** The `t` and `language` for a language. Shared by the hook and the server. */\nexport function createTexts<L extends string>(\n language: Language,\n): TextsResult<L> {\n const t = (text: Partial<Record<Language, TextValue>>) => text[language];\n return {\n t: t as TextFunction<L>,\n language: language as AppLanguage,\n };\n}\n"],"mappings":"AAiBA,IAAM,IAAqB;CACzB,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AA6BA,SAAgB,EAAW,GAA0B;CACnD,IAAM,IAAS,EAAO,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;CAC/C,OAAO,OAAO,OAAO,GAAoB,CAAM,IAC3C,EAAmB,KAAA;AAEzB;;;AC0CA,SAAgB,EACd,GACgB;CAEhB,OAAO;EACF,IAFM,MAA+C,EAAK;EAGnD;CACZ;AACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { n as e, t } from "./next-intl-texts-De3tiuSm.mjs";
|
|
3
|
+
import { useLocale as n } from "next-intl";
|
|
4
|
+
import { COUNTRIES as r, CountryProvider as i, LeaProvider as a } from "./component-library.es.js";
|
|
5
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
6
|
+
import { useMemo as s } from "react";
|
|
7
|
+
//#region src/next-intl/lea-intl-provider.tsx
|
|
8
|
+
var c = {
|
|
9
|
+
no: "NO",
|
|
10
|
+
se: "SE",
|
|
11
|
+
fi: "FI",
|
|
12
|
+
es: "ES"
|
|
13
|
+
};
|
|
14
|
+
function l(t) {
|
|
15
|
+
let n = t.split("-")[1]?.toUpperCase();
|
|
16
|
+
return n !== void 0 && Object.hasOwn(r, n) ? n : c[e(t)];
|
|
17
|
+
}
|
|
18
|
+
function u({ country: t, children: r }) {
|
|
19
|
+
let s = n();
|
|
20
|
+
return /* @__PURE__ */ o(a, {
|
|
21
|
+
language: e(s),
|
|
22
|
+
children: /* @__PURE__ */ o(i, {
|
|
23
|
+
country: t ?? l(s),
|
|
24
|
+
children: r
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/next-intl/use-texts.ts
|
|
30
|
+
function d() {
|
|
31
|
+
let r = n();
|
|
32
|
+
return s(() => t(e(r)), [r]);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { u as LeaIntlProvider, d as useTexts };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=next-intl.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-intl.mjs","names":[],"sources":["../src/next-intl/lea-intl-provider.tsx","../src/next-intl/use-texts.ts"],"sourcesContent":["\"use client\";\n\nimport { type Locale, useLocale } from \"next-intl\";\nimport { type ReactNode } from \"react\";\n\nimport { type Language, toLanguage } from \"../i18n/languages\";\nimport { COUNTRIES, type Country, CountryProvider, LeaProvider } from \"../index\";\nimport type { UnsupportedLocaleKey } from \"./texts\";\n\n/** The country whose language each language is. */\nconst COUNTRY_OF_LANGUAGE = {\n no: \"NO\",\n se: \"SE\",\n fi: \"FI\",\n es: \"ES\",\n} as const satisfies Record<Language, Country>;\n\n/**\n * The country of a locale: its region, when that is one of Lea Bank's\n * countries (`sv-FI` is Finland), or else the country of its language.\n */\nfunction countryOf(locale: string): Country {\n const region = locale.split(\"-\")[1]?.toUpperCase();\n return region !== undefined && Object.hasOwn(COUNTRIES, region)\n ? (region as Country)\n : COUNTRY_OF_LANGUAGE[toLanguage(locale)];\n}\n\nexport type LeaIntlProviderProps = {\n /**\n * The country of the formatting hooks (`useFormatCurrency` and the rest).\n * Give it where the country is not the locale's. By default it is the\n * locale's region when that is a Lea Bank country (`sv-FI`), or else the\n * country of its language.\n */\n country?: Country;\n children: ReactNode;\n} & {\n // The guard on the app's locales: a locale the library has no language for\n // makes this a prop that can't be given, and the error names the locale.\n [K in UnsupportedLocaleKey<Locale>]: never;\n};\n\n/**\n * Sets the library's language and country from next-intl's locale: what\n * `LeaProvider` and `CountryProvider` do, with no map from locale to\n * language in the app. Put it inside `NextIntlClientProvider`, once:\n *\n * ```tsx\n * // app/[locale]/layout.tsx\n * import { NextIntlClientProvider } from \"next-intl\";\n * import { LeaIntlProvider } from \"@leabankab/component-library/next-intl\";\n *\n * <NextIntlClientProvider>\n * <LeaIntlProvider>{children}</LeaIntlProvider>\n * </NextIntlClientProvider>\n * ```\n *\n * The library's components then speak the locale's language, and the\n * formatting hooks format for its country.\n */\nexport function LeaIntlProvider({ country, children }: LeaIntlProviderProps) {\n const locale = useLocale();\n return (\n <LeaProvider language={toLanguage(locale)}>\n <CountryProvider country={country ?? countryOf(locale)}>\n {children}\n </CountryProvider>\n </LeaProvider>\n );\n}\n","\"use client\";\n\nimport { useLocale } from \"next-intl\";\nimport { useMemo } from \"react\";\n\nimport { toLanguage } from \"../i18n/languages\";\nimport { type AppLanguage, createTexts, type TextsResult } from \"./texts\";\n\n/**\n * Texts in the language of next-intl's locale, for a client component. Keep\n * the texts beside the component and check them with `satisfies Texts`:\n *\n * ```tsx\n * \"use client\";\n * import { useTexts, type Texts } from \"@leabankab/component-library/next-intl\";\n *\n * const texts = {\n * title: { se: \"Ditt lån\", no: \"Ditt lån\", fi: \"Lainasi\" },\n * greeting: (name: string) => ({ se: `Hej ${name}`, no: `Hei ${name}`, fi: `Hei ${name}` }),\n * } satisfies Texts;\n *\n * function LoanHeader({ name }: { name: string }) {\n * const { t } = useTexts();\n * return <h1>{t(texts.title)}, {t(texts.greeting(name))}</h1>;\n * }\n * ```\n *\n * It reads the locale from `NextIntlClientProvider`, so it needs no provider\n * of the library's. In a server component, use `getTexts` from\n * `@leabankab/component-library/next-intl/server`.\n *\n * `useTexts<\"se\">()` reads texts that only some markets have (`Texts<\"se\">`).\n * `t` then gives `undefined` in a language the text doesn't have.\n */\nexport function useTexts<\n L extends AppLanguage = AppLanguage,\n>(): TextsResult<L> {\n const locale = useLocale();\n return useMemo(() => createTexts<L>(toLanguage(locale)), [locale]);\n}\n"],"mappings":";;;;;;;AAUA,IAAM,IAAsB;CAC1B,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAMA,SAAS,EAAU,GAAyB;CAC1C,IAAM,IAAS,EAAO,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,YAAY;CACjD,OAAO,MAAW,KAAA,KAAa,OAAO,OAAO,GAAW,CAAM,IACzD,IACD,EAAoB,EAAW,CAAM;AAC3C;AAmCA,SAAgB,EAAgB,EAAE,YAAS,eAAkC;CAC3E,IAAM,IAAS,EAAU;CACzB,OACE,kBAAC,GAAD;EAAa,UAAU,EAAW,CAAM;EACtC,UAAA,kBAAC,GAAD;GAAiB,SAAS,KAAW,EAAU,CAAM;GAClD;EACc,CAAA;CACN,CAAA;AAEjB;;;ACpCA,SAAgB,IAEI;CAClB,IAAM,IAAS,EAAU;CACzB,OAAO,QAAc,EAAe,EAAW,CAAM,CAAC,GAAG,CAAC,CAAM,CAAC;AACnE"}
|
|
@@ -63,7 +63,7 @@ export declare const textStyleEntries: (readonly [TextStyleToken, TextStyleDefin
|
|
|
63
63
|
export declare const resolveTextStyle: (name: TextStyleToken) => {
|
|
64
64
|
fontSize: string;
|
|
65
65
|
fontWeight: 200 | 300 | 400 | 500 | 600 | 700 | 800;
|
|
66
|
-
lineHeight: 1 | 1.25 | 1.
|
|
66
|
+
lineHeight: 1 | 1.25 | 1.4 | 1.5;
|
|
67
67
|
letterSpacing: string;
|
|
68
68
|
};
|
|
69
69
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leabankab/component-library",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.12.0",
|
|
4
4
|
"description": "@leabankab/component-library — Lea Bank's React component library.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20"
|
|
@@ -46,6 +46,14 @@
|
|
|
46
46
|
"import": "./dist/website.mjs",
|
|
47
47
|
"require": "./dist/website.cjs"
|
|
48
48
|
},
|
|
49
|
+
"./next-intl": {
|
|
50
|
+
"types": "./dist/next-intl/index.d.ts",
|
|
51
|
+
"import": "./dist/next-intl.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./next-intl/server": {
|
|
54
|
+
"types": "./dist/next-intl/server.d.ts",
|
|
55
|
+
"import": "./dist/next-intl-server.mjs"
|
|
56
|
+
},
|
|
49
57
|
"./cookie-consent.css": "./dist/cookie-consent.css",
|
|
50
58
|
"./styles.css": "./dist/index.css",
|
|
51
59
|
"./tailwind.css": "./dist/tailwind.css",
|
|
@@ -77,6 +85,7 @@
|
|
|
77
85
|
"@mui/system": "^9.0.0",
|
|
78
86
|
"@mui/x-date-pickers": "^9.0.0",
|
|
79
87
|
"date-fns": "^4.0.0",
|
|
88
|
+
"next-intl": "^4.0.0",
|
|
80
89
|
"react": "^19.0.0",
|
|
81
90
|
"react-dom": "^19.0.0",
|
|
82
91
|
"react-hook-form": "^7.56.0",
|
|
@@ -101,6 +110,9 @@
|
|
|
101
110
|
"date-fns": {
|
|
102
111
|
"optional": true
|
|
103
112
|
},
|
|
113
|
+
"next-intl": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
104
116
|
"react-hook-form": {
|
|
105
117
|
"optional": true
|
|
106
118
|
},
|
|
@@ -138,6 +150,7 @@
|
|
|
138
150
|
"eslint-plugin-storybook": "^10.5.5",
|
|
139
151
|
"husky": "^9.1.7",
|
|
140
152
|
"jsdom": "^29.1.1",
|
|
153
|
+
"next-intl": "^4.14.9",
|
|
141
154
|
"playwright": "^1.62.1",
|
|
142
155
|
"postcss": "^8.5.25",
|
|
143
156
|
"react": "^19.2.8",
|
|
@@ -157,7 +170,7 @@
|
|
|
157
170
|
"scripts": {
|
|
158
171
|
"preinstall": "npx only-allow pnpm",
|
|
159
172
|
"dev": "storybook dev -p 6006",
|
|
160
|
-
"build": "cross-env NODE_OPTIONS=--max-old-space-size=4096 vite build && vite build -c vite.cookie-consent.config.ts && vite build -c vite.react-hook-form.config.ts && vite build -c vite.date-picker.config.ts && vite build -c vite.dev-panel.config.ts && vite build -c vite.website.config.ts",
|
|
173
|
+
"build": "cross-env NODE_OPTIONS=--max-old-space-size=4096 vite build && vite build -c vite.cookie-consent.config.ts && vite build -c vite.react-hook-form.config.ts && vite build -c vite.date-picker.config.ts && vite build -c vite.dev-panel.config.ts && vite build -c vite.website.config.ts && vite build -c vite.next-intl.config.ts",
|
|
161
174
|
"watch": "cross-env NODE_OPTIONS=--max-old-space-size=4096 vite build --watch",
|
|
162
175
|
"watch:all": "cross-env NODE_OPTIONS=--max-old-space-size=4096 node scripts/watch-all.mjs",
|
|
163
176
|
"storybook": "storybook dev -p 6006",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './status-icon';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AnimationSize } from '../shared';
|
|
2
|
-
type PulseAnimationProps = {
|
|
3
|
-
/**
|
|
4
|
-
* `"sm"` is 90px, `"lg"` 150px.
|
|
5
|
-
* @default "lg"
|
|
6
|
-
*/
|
|
7
|
-
size?: AnimationSize;
|
|
8
|
-
/**
|
|
9
|
-
* Accessible name for the spinner; defaults to the translated word for
|
|
10
|
-
* "loading" in the `LeaProvider` language. `StatusAnimation` hides the pulse
|
|
11
|
-
* from assistive tech and announces its own status text instead.
|
|
12
|
-
*/
|
|
13
|
-
label?: string;
|
|
14
|
-
};
|
|
15
|
-
export declare const PulseAnimation: ({ size, label }: PulseAnimationProps) => import("react").JSX.Element;
|
|
16
|
-
export {};
|
|
File without changes
|
|
File without changes
|