@enonic/ui 1.2.1 → 1.4.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/README.md +39 -5
- package/dist/enonic-ui.cjs +1 -1
- package/dist/enonic-ui.es.js +126 -119
- package/dist/style.cjs +1 -1
- package/dist/style.es.js +1 -1
- package/dist/styles/style.css +1 -1
- package/dist/types/components/combobox/combobox.phrases.d.ts +3 -0
- package/dist/types/components/date-picker/date-picker.phrases.d.ts +10 -0
- package/dist/types/components/dialog/dialog.phrases.d.ts +3 -0
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/search-field/search-field.phrases.d.ts +5 -0
- package/dist/types/components/stepper/stepper.phrases.d.ts +4 -0
- package/dist/types/components/tag/index.d.ts +1 -0
- package/dist/types/components/tag/tag.d.ts +42 -0
- package/dist/types/components/time-picker/time-picker.phrases.d.ts +6 -0
- package/dist/types/components/toast/toast.phrases.d.ts +3 -0
- package/dist/types/components/tree-list/tree-list.phrases.d.ts +9 -0
- package/dist/types/i18n/index.d.ts +2 -0
- package/dist/types/i18n/phrases.d.ts +41 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/providers/combobox-provider.d.ts +2 -1
- package/dist/types/providers/i18n-provider.d.ts +26 -0
- package/dist/types/providers/index.d.ts +2 -0
- package/dist/types/providers/tag-provider.d.ts +13 -0
- package/dist/types/providers/tree-list-provider.d.ts +1 -1
- package/dist/types/providers/virtualized-tree-list-provider.d.ts +1 -0
- package/dist/types/types/i18n.d.ts +15 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/utils/phrase.d.ts +7 -0
- package/package.json +24 -15
package/README.md
CHANGED
|
@@ -154,11 +154,45 @@ The `icon` prop accepts either package.
|
|
|
154
154
|
|
|
155
155
|
Optional peers, needed per feature:
|
|
156
156
|
|
|
157
|
-
| Package
|
|
158
|
-
|
|
|
159
|
-
| `
|
|
160
|
-
| `
|
|
161
|
-
|
|
157
|
+
| Package | Needed for |
|
|
158
|
+
| ---------------- | ------------------------------------------------- |
|
|
159
|
+
| `react-virtuoso` | `VirtualizedTreeList` and other virtualized lists |
|
|
160
|
+
| `tw-animate-css` | Component animations on the `preset.css` path |
|
|
161
|
+
|
|
162
|
+
## Localization
|
|
163
|
+
|
|
164
|
+
Every label a component renders on its own — the close button of a `Dialog`, the placeholder of a
|
|
165
|
+
`SearchField`, the month navigation of a `DatePicker` — is English by default and keyed
|
|
166
|
+
`enonic.ui.<component>.<name>`. To render them in the application's words, hand `I18nProvider` one
|
|
167
|
+
function at the root. It receives the key and the library's English for it, and answers the
|
|
168
|
+
application's text or the English it was given:
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { I18nProvider, type Translate } from '@enonic/ui';
|
|
172
|
+
|
|
173
|
+
const translate: Translate = (key, { defaultValue, values = [] }) => {
|
|
174
|
+
const phrase = phrases[key];
|
|
175
|
+
if (phrase === undefined) return defaultValue;
|
|
176
|
+
|
|
177
|
+
return phrase.replace(/\{(\d+)\}/g, (placeholder, i) => String(values[Number(i)] ?? placeholder));
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
<I18nProvider translate={translate}>
|
|
181
|
+
<App />
|
|
182
|
+
</I18nProvider>;
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
A phrase the application supplies still carries the library's `{0}` placeholders, so fill them with
|
|
186
|
+
`values` — returning `phrases[key]` unformatted renders `Go to step {0}` verbatim. On a miss, return
|
|
187
|
+
`defaultValue`: never an empty string and never the key, or the `aria-label`s go blank.
|
|
188
|
+
|
|
189
|
+
`translate`'s identity is the only thing that re-renders the labels. Hoisting it out of the render is
|
|
190
|
+
right for a phrase bundle fixed at load; where the locale switches or the bundle arrives later, put
|
|
191
|
+
it in a `useMemo` keyed on that instead, or the labels keep their first wording.
|
|
192
|
+
|
|
193
|
+
`uiPhrases` lists every key with its English, for the application to add to its own phrase files
|
|
194
|
+
and check its bundle against. Texts the application supplies through props — a dialog title, an
|
|
195
|
+
item name — never pass through the provider.
|
|
162
196
|
|
|
163
197
|
## What's exported
|
|
164
198
|
|