@besaitech/ng-design-system 0.0.58 → 0.0.60
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 +44 -0
- package/fesm2022/besaitech-ng-design-system.mjs +1250 -195
- package/fesm2022/besaitech-ng-design-system.mjs.map +1 -1
- package/index.d.ts +346 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -203,6 +203,50 @@ Import names are the `Sl…` classes; the markup selectors are `sds-…`.
|
|
|
203
203
|
| `SdsTopbar` | `<sds-topbar>` | `appName`, `user`, `(logout)`; `[sdsLogo]` slot |
|
|
204
204
|
| `SdsSidebar` + `SdsNavGroup` + `SdsNavItem` | `<sds-sidebar>` … | Collapsible nav rail; collapse state via root-provided `SidebarStore`; items render `routerLink` or `<button>` |
|
|
205
205
|
|
|
206
|
+
## Theme & cross-app preferences
|
|
207
|
+
|
|
208
|
+
`SdsThemeService` holds the person's **mode** — `'system' | 'light' | 'dark'`, persisted to `localStorage`
|
|
209
|
+
under `sds-theme` — and resolves it to the painted **theme** (`light`/`dark`); `system` follows the OS live.
|
|
210
|
+
`toggle()` / `setTheme()` set an explicit theme, `setMode('system')` goes back to following the OS.
|
|
211
|
+
|
|
212
|
+
Apps of one product can carry the person's language and theme in the URL when they link to each other, so the
|
|
213
|
+
page that opens matches. Sending side:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import { appendUiPrefs } from '@besaitech/ng-design-system';
|
|
217
|
+
|
|
218
|
+
appendUiPrefs('https://auth.example/continue#token=abc', { lang: translate.getCurrentLang(), theme: theme.mode() });
|
|
219
|
+
// → https://auth.example/continue?lang=fr&theme=dark#token=abc
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Never put them inside a nested redirect a server matches exactly (`return_to`, `redirect_uri`) — append them to
|
|
223
|
+
the outer URL. Receiving side: an inline script in `<head>` of `index.html` applies, persists and strips them
|
|
224
|
+
**before first paint** (no flash, and no import of this library at the root). `LANG_KEY` is the app's own
|
|
225
|
+
language storage key; keep `LANGS` in step with the app's languages. `readUiPrefs` / `stripUiPrefs` are the same
|
|
226
|
+
logic for code and tests.
|
|
227
|
+
|
|
228
|
+
```html
|
|
229
|
+
<script>
|
|
230
|
+
(function () {
|
|
231
|
+
var LANG_KEY = 'app.lang', LANGS = ['en', 'fr', 'nl'], THEME_KEY = 'sds-theme', MODES = ['system', 'light', 'dark'];
|
|
232
|
+
var url = new URL(location.href), q = url.searchParams, lang = q.get('lang'), mode = q.get('theme');
|
|
233
|
+
try {
|
|
234
|
+
if (LANGS.indexOf(lang) >= 0) localStorage.setItem(LANG_KEY, lang);
|
|
235
|
+
if (MODES.indexOf(mode) >= 0) localStorage.setItem(THEME_KEY, mode);
|
|
236
|
+
} catch (e) {}
|
|
237
|
+
try { lang = localStorage.getItem(LANG_KEY) || lang; mode = localStorage.getItem(THEME_KEY) || mode; } catch (e) {}
|
|
238
|
+
if (LANGS.indexOf(lang) >= 0) document.documentElement.lang = lang;
|
|
239
|
+
var dark = mode === 'dark' || (mode !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches);
|
|
240
|
+
document.documentElement.classList.toggle('dark', dark);
|
|
241
|
+
document.documentElement.style.colorScheme = dark ? 'dark' : 'light';
|
|
242
|
+
if (q.has('lang') || q.has('theme')) {
|
|
243
|
+
q.delete('lang'); q.delete('theme');
|
|
244
|
+
history.replaceState(history.state, '', url.pathname + url.search + url.hash);
|
|
245
|
+
}
|
|
246
|
+
})();
|
|
247
|
+
</script>
|
|
248
|
+
```
|
|
249
|
+
|
|
206
250
|
## Labels & languages
|
|
207
251
|
|
|
208
252
|
The library ships **no translations of its own**. Every visible or spoken string — placeholders,
|