-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: export Locale as named exports (#219)
- allow to import a single Locale via named imports
- Loading branch information
1 parent
38d3142
commit 6eb57ce
Showing
26 changed files
with
188 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"editor.defaultFormatter": "biomejs.biome", | ||
"editor.formatOnSave": true, | ||
"editor.formatOnPaste": false | ||
"editor.formatOnPaste": false, | ||
"typescript.tsdk": "node_modules\\typescript\\lib" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,52 @@ | ||
import { MultipleSelectInstance, multipleSelect } from 'multiple-select-vanilla'; | ||
import { type LocaleKey, type MultipleSelectInstance, multipleSelect } from 'multiple-select-vanilla'; | ||
|
||
// 1. load every locale individually | ||
// import 'multiple-select-vanilla/dist/locales/multiple-select-fr-FR'; | ||
// import 'multiple-select-vanilla/dist/locales/multiple-select-es-ES'; | ||
// 1. load every locale individually, it could be import in 2 ways (named import OR import on window object) | ||
import { Spanish } from 'multiple-select-vanilla/dist/locales/multiple-select-es-ES'; // named import | ||
// import 'multiple-select-vanilla/dist/locales/multiple-select-es-ES'; // locale on window object | ||
|
||
// 2. or load all locales at once | ||
import 'multiple-select-vanilla/dist/locales/multiple-select-all-locales'; | ||
|
||
export default class Example { | ||
ms0?: MultipleSelectInstance; | ||
ms1?: MultipleSelectInstance; | ||
ms2?: MultipleSelectInstance; | ||
|
||
mount() { | ||
const elm = document.querySelector('#locale') as HTMLSelectElement; | ||
elm.addEventListener('change', ((event: KeyboardEvent & { target: HTMLSelectElement }) => { | ||
this.updateLocale(event.target.value); | ||
this.updateLocale(event.target.value as LocaleKey); | ||
}) as EventListener); | ||
|
||
this.ms1 = multipleSelect(elm) as MultipleSelectInstance; | ||
this.ms2 = multipleSelect('#select', { | ||
this.ms0 = multipleSelect(elm) as MultipleSelectInstance; | ||
this.ms1 = multipleSelect('#dynamic-select', { | ||
filter: true, | ||
showOkButton: true, | ||
dataTest: 'select1', | ||
}) as MultipleSelectInstance; | ||
|
||
this.ms2 = multipleSelect('#fixed-import', { | ||
filter: true, | ||
showOkButton: true, | ||
dataTest: 'select2', | ||
|
||
// when using named import | ||
locale: Spanish, | ||
}) as MultipleSelectInstance; | ||
} | ||
|
||
unmount() { | ||
// destroy ms instance(s) to avoid DOM leaks | ||
this.ms0?.destroy(); | ||
this.ms1?.destroy(); | ||
this.ms2?.destroy(); | ||
this.ms0 = undefined; | ||
this.ms1 = undefined; | ||
this.ms2 = undefined; | ||
} | ||
|
||
updateLocale(locale: string) { | ||
this.ms2?.destroy(); | ||
this.ms2?.refreshOptions({ locale }); | ||
updateLocale(locale: LocaleKey) { | ||
this.ms1?.destroy(); | ||
this.ms1?.refreshOptions({ locale }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './interfaces'; | ||
export * from './locale.interface'; | ||
export * from './multipleSelectOption.interface'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/multiple-select-vanilla/src/interfaces/locale.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** Locale I18N key (string) that currently exists in the project */ | ||
export type LocaleKey = | ||
| 'cz-CS' | ||
| 'da-DK' | ||
| 'en-US' | ||
| 'es-ES' | ||
| 'fr-FR' | ||
| 'hu-HU' | ||
| 'it-IT' | ||
| 'ja-JP' | ||
| 'pt-BR' | ||
| 'ru-RU' | ||
| 'vi-VN' | ||
| 'zh-CN' | ||
| 'zh-TW'; | ||
|
||
export interface MultipleSelectLocale { | ||
/** Customize the formatted text "All Selected" when using custom locale. */ | ||
formatAllSelected(): string; | ||
|
||
/** Customize the formatted text "x of y selected" when using custom locale. */ | ||
formatCountSelected(selectedCount: number, totalCount: number): string; | ||
|
||
/** For the "No Matches Found" text when nothing is found while filtering the dropdown */ | ||
formatNoMatchesFound(): string; | ||
|
||
/** Customize the formatted text "OK" showing at the bottom of the drop. */ | ||
formatOkButton(): string; | ||
|
||
/** For the "Select All" checkbox text */ | ||
formatSelectAll(): string; | ||
} | ||
|
||
export type MultipleSelectLocales = Record<LocaleKey, MultipleSelectLocale>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,15 @@ | |
* Author: Matej Puhony<[email protected]> | ||
*/ | ||
|
||
import { MultipleSelectInstance } from '../MultipleSelectInstance'; | ||
import { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces'; | ||
|
||
const ms = window.multipleSelect; | ||
const ms = | ||
typeof window !== 'undefined' && window.multipleSelect !== undefined | ||
? window.multipleSelect | ||
: ({ locales: {} as MultipleSelectLocales } as Partial<MultipleSelectInstance>); | ||
|
||
(ms.locales as MultipleSelectLocales)['cz-CS'] = { | ||
export const Czech = { | ||
formatSelectAll() { | ||
return '[Vybrat vše]'; | ||
}, | ||
|
@@ -25,4 +29,6 @@ const ms = window.multipleSelect; | |
}, | ||
} as MultipleSelectLocale; | ||
|
||
(ms.locales as MultipleSelectLocales)['cz-CS'] = Czech; | ||
|
||
export default ms.locales; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,15 @@ | |
* Author: HThuren<[email protected]> | ||
*/ | ||
|
||
import { MultipleSelectInstance } from '../MultipleSelectInstance'; | ||
import { MultipleSelectLocale, MultipleSelectLocales } from '../interfaces'; | ||
|
||
const ms = window.multipleSelect; | ||
const ms = | ||
typeof window !== 'undefined' && window.multipleSelect !== undefined | ||
? window.multipleSelect | ||
: ({ locales: {} as MultipleSelectLocales } as Partial<MultipleSelectInstance>); | ||
|
||
(ms.locales as MultipleSelectLocales)['da-DK'] = { | ||
export const Danish = { | ||
formatSelectAll() { | ||
return '[Vælg alle]'; | ||
}, | ||
|
@@ -25,4 +29,6 @@ const ms = window.multipleSelect; | |
}, | ||
} as MultipleSelectLocale; | ||
|
||
(ms.locales as MultipleSelectLocales)['da-DK'] = Danish; | ||
|
||
export default ms.locales; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.