@cahyo-dimas/freeday 3.16.1 → 3.17.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 +55 -0
- package/COMPONENTS.md +28 -0
- package/README.id.md +1 -1
- package/README.md +1 -1
- package/adapters/blazor/freeday-blazor.js +13 -4
- package/adapters/react/index.d.ts +26 -0
- package/adapters/react/index.js +1 -0
- package/adapters/react/useTheme.js +35 -0
- package/adapters/vue/index.d.ts +26 -0
- package/adapters/vue/index.js +1 -0
- package/adapters/vue/useTheme.js +47 -0
- package/dist/freeday-theme.js +115 -0
- package/dist/freeday.js +116 -0
- package/docs/getting-started.md +4 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,61 @@ benar. Perubahan seperti itu ditulis di bawah `### Changed: BREAKING (types)`
|
|
|
9
9
|
lama → tipe baru, dan cara menyempitkannya — bukan di bawah `### Added`, betapapun aditifnya dari
|
|
10
10
|
sisi kit.
|
|
11
11
|
|
|
12
|
+
## [3.17.0] - 2026-11-05
|
|
13
|
+
|
|
14
|
+
**Pengalih tema terang/gelap, siap pakai di semua stack.** Setiap app sebelumnya menulis sendiri
|
|
15
|
+
penyimpanan pilihan, pembacaan `prefers-color-scheme`, dan pemasangan `data-theme`, sambil menebak
|
|
16
|
+
kontrak kit dari dokumen (`CATATAN-FREEDAY.md` §23). Catatan itu menyebut Blazor sudah punya.
|
|
17
|
+
Sebenarnya `FreedayBlazor.toggleTheme()` hanya pembantu demo: ia membalik atribut di `<html>`,
|
|
18
|
+
tidak menyimpan apa pun, dan tidak bisa kembali ke "ikuti sistem". Jadi tidak ada satu stack pun
|
|
19
|
+
yang punya.
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- **`freeday-theme.js` → `window.FreedayTheme`** (`#113`), ikut di `freeday.js`:
|
|
23
|
+
- `get()`, `resolved()`, `set(theme)`, `toggle()`, `attach(el)`, dan event `fdy-theme-change`
|
|
24
|
+
di `document` dengan detail `{ theme, resolved }`.
|
|
25
|
+
- Satu pilihan per perangkat: `'light'`, `'dark'`, atau `'system'`, disimpan di `localStorage`
|
|
26
|
+
dan diterapkan ke `<html>`. Nilai lain ditolak dengan `TypeError`.
|
|
27
|
+
- `'system'` **mencabut** `data-theme`, tidak menghitung nilainya. Token sudah mengikuti OS
|
|
28
|
+
selama tidak ada `data-theme`, jadi pergantian OS langsung terlihat tanpa listener yang
|
|
29
|
+
memutuskan apa pun. Event tetap dikirim supaya ikon tombol ikut berganti.
|
|
30
|
+
- `toggle()` membalik yang **tampil** di layar, bukan pilihannya. Di OS gelap dengan pilihan
|
|
31
|
+
`'system'`, tekan pertama menuju terang.
|
|
32
|
+
- `attach(el)` menyerahkan wilayah yang `data-theme`-nya ditulis tetap di markup kepada pilihan
|
|
33
|
+
pengguna, dan mengembalikan fungsi pelepas. Tanpa itu, atribut subtree selalu menang atas
|
|
34
|
+
atribut dokumen.
|
|
35
|
+
- Pilihan yang tersimpan diterapkan saat dimuat. Kalau tidak ada yang tersimpan, tidak ada yang
|
|
36
|
+
disentuh, jadi markup yang membawa `data-theme` sendiri tetap utuh.
|
|
37
|
+
- **`useTheme(rootRef?)` di Vue dan React**, mengembalikan `theme`, `resolved`, `setTheme`, dan
|
|
38
|
+
`toggleTheme`. Kedua adapter memuat inti yang sama sendiri, jadi tidak perlu impor akar, dan
|
|
39
|
+
inti hanya terdaftar sekali walaupun dimuat dari dua jalur. Semua pemanggil di satu halaman
|
|
40
|
+
tetap sinkron. Ref yang diberikan di-`attach` saat mount dan dilepas saat unmount.
|
|
41
|
+
- **Blazor:** `FreedayBlazor.setTheme`, `getTheme`, dan `getResolvedTheme`. `toggleTheme()` kini
|
|
42
|
+
memakai inti yang sama, jadi ikut menyimpan dan mengenal `'system'`.
|
|
43
|
+
- **Cuplikan satu baris untuk `<head>`** di `COMPONENTS.md`, untuk menerapkan pilihan sebelum paint
|
|
44
|
+
pertama. Gate baru di `test/docs.test.mjs` memastikan cuplikan itu membaca kunci yang ditulis inti,
|
|
45
|
+
dan fixture uji menjalankan cuplikan yang persis sama.
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
- `FreedayBlazor.toggleTheme()` kini **menyimpan** pilihannya di `localStorage` dan membutuhkan
|
|
49
|
+
`freeday.js` sudah dimuat. Tanpa itu ia melempar `Error` yang menyebut berkas yang kurang.
|
|
50
|
+
Sebelumnya ia hanya membalik atribut di `<html>`.
|
|
51
|
+
|
|
52
|
+
### Catatan
|
|
53
|
+
- Uji baru `browser/theme-pref.mjs` (6 uji) memeriksa atribut, nilai tersimpan, dan **warna kartu
|
|
54
|
+
yang benar-benar dicat**, dicocokkan dengan kartu acuan terang dan gelap. Pengaturan OS diemulasi
|
|
55
|
+
sebagai fitur media sungguhan lewat CDP, bukan `matchMedia` palsu. Sembilan mutasi (system
|
|
56
|
+
menghitung nilai, tanpa listener OS, toggle membalik pilihan, tanpa penerapan saat dimuat, root
|
|
57
|
+
diabaikan, tanpa validasi, dan dua adapter tanpa pelepas atau tanpa listener) semuanya merah.
|
|
58
|
+
- Harness mendapat `setColorScheme()`. Event `change` dari `MediaQueryList` dikirim pada langkah
|
|
59
|
+
rendering, dan polling lewat CDP tidak pernah menjalankan langkah itu. Tanpa menunggu dua frame,
|
|
60
|
+
listener tetap diam: terukur tanpa event selama 4 detik polling, lalu satu event sesudah dua
|
|
61
|
+
frame.
|
|
62
|
+
- Gate string `#016` kini juga melewati pesan `throw new …Error(…)`, dengan alasan yang sama seperti
|
|
63
|
+
`console.warn`: teks itu untuk devtools pengembang, tidak pernah masuk DOM.
|
|
64
|
+
- `examples/vue-faktur` berhenti menulis pengalih temanya sendiri dan memakai `useTheme()`.
|
|
65
|
+
- Sinkronisasi antar-tab sengaja tidak dibuat. Tab lain mengikuti pilihan baru saat dimuat ulang.
|
|
66
|
+
|
|
12
67
|
## [3.16.1] - 2026-11-04
|
|
13
68
|
|
|
14
69
|
**Slot teks kit di atas `<p>` tidak lagi membawa margin bawaan peramban.** `<p>` punya margin 1em
|
package/COMPONENTS.md
CHANGED
|
@@ -126,6 +126,7 @@ element is fine. Events are bubbling
|
|
|
126
126
|
| — (imperative, returns `Promise<boolean>`) | `freeday-confirm.js` | `Freeday.confirm()` | — |
|
|
127
127
|
| — (stamps `<html data-breakpoint>`) | `freeday-breakpoint.js` | `FreedayBreakpoint` | `fdy-breakpoint-change` |
|
|
128
128
|
| — (internal positioning) | `freeday-popover.js` | `FreedayPopover` | — |
|
|
129
|
+
| — (theme preference, see below) | `freeday-theme.js` | `FreedayTheme` | `fdy-theme-change` (on `document`) |
|
|
129
130
|
|
|
130
131
|
**Shared conventions across the select-type widgets** (combo, cascade, datepicker, daterange,
|
|
131
132
|
timepicker, autocomplete, cfl): `data-value` seeds the value, `data-placeholder` the empty text,
|
|
@@ -497,6 +498,33 @@ lightness that a panel four times more transparent still passed. So glass here i
|
|
|
497
498
|
the effect people actually see comes from the blur, not from the alpha. Put a photo or a gradient
|
|
498
499
|
behind a panel and the promise still holds; that is what "over any ground" buys.
|
|
499
500
|
|
|
501
|
+
**Theme preference: `FreedayTheme` / `useTheme()`.** The light/dark switch, ready made. One choice
|
|
502
|
+
per device, `'light'`, `'dark'` or `'system'`, stored in `localStorage` and applied to `<html>`.
|
|
503
|
+
`'system'` removes `data-theme`, so the tokens follow the OS and an OS switch repaints the page
|
|
504
|
+
without a reload.
|
|
505
|
+
|
|
506
|
+
| | Vue / React | Blazor | Anything else |
|
|
507
|
+
|---|---|---|---|
|
|
508
|
+
| read | `useTheme()` → `theme`, `resolved` | `FreedayBlazor.getTheme()`, `getResolvedTheme()` | `FreedayTheme.get()`, `.resolved()` |
|
|
509
|
+
| change | `setTheme(t)`, `toggleTheme()` | `FreedayBlazor.setTheme(t)`, `toggleTheme()` | `FreedayTheme.set(t)`, `.toggle()` |
|
|
510
|
+
|
|
511
|
+
- **Label the button from `resolved`, not `theme`.** `resolved` is what is on screen; `theme` is
|
|
512
|
+
`'system'` until someone chooses. `toggle` flips what is on screen, so the first press always
|
|
513
|
+
changes it.
|
|
514
|
+
- **Every caller shares one preference.** Two toggles in two shells stay in step, through
|
|
515
|
+
`fdy-theme-change` (detail `{ theme, resolved }`).
|
|
516
|
+
- **A region with its own `data-theme` in markup keeps it**, because a subtree's attribute beats the
|
|
517
|
+
document's. To hand it to the preference, pass its ref (`useTheme(regionRef)`) or call
|
|
518
|
+
`FreedayTheme.attach(el)`, which returns a detacher. Under `'system'` that removes the fixed value.
|
|
519
|
+
- `useTheme()` loads the core itself; no `import '@cahyo-dimas/freeday'` is needed for it.
|
|
520
|
+
- **Apply the stored choice before first paint** with this line as the first script in `<head>`.
|
|
521
|
+
Without it the kit still applies the choice once it loads, but the page shows the default for a
|
|
522
|
+
moment first:
|
|
523
|
+
|
|
524
|
+
```html
|
|
525
|
+
<script>try{var t=localStorage.getItem('fdy-theme');if(t==='light'||t==='dark')document.documentElement.setAttribute('data-theme',t)}catch(e){}</script>
|
|
526
|
+
```
|
|
527
|
+
|
|
500
528
|
**Primary palette: `data-primary`.** 18 options — `azure` (the default, and what you get with no
|
|
501
529
|
attribute) · `sky` `blue` `indigo` `violet` `purple` `fuchsia` `pink` `rose` · `orange` `amber`
|
|
502
530
|
`yellow` `lime` `green` `emerald` `teal` `cyan` · `noir`. Set it anywhere `data-theme` works,
|
package/README.id.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> **Lebih banyak _free day_ buat dev. UI kit-nya sudah siap pakai.**
|
|
6
6
|
|
|
7
7
|
[](https://cahyo-dimas.github.io/freeday-ui-kit/)
|
|
8
|
-
[](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.17.0)
|
|
9
9
|
|
|
10
10
|
UI KIT yang token-driven & framework-agnostic. Satu sumber kebenaran untuk warna, tipografi,
|
|
11
11
|
spasi, dan komponen. Blueprint: `docs/superpowers/specs/2026-07-21-freeday-ui-kit-design.md`.
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> **More free days for devs. The UI kit is ready to use.**
|
|
6
6
|
|
|
7
7
|
[](https://cahyo-dimas.github.io/freeday-ui-kit/)
|
|
8
|
-
[](https://github.com/cahyo-dimas/freeday-ui-kit/tree/v3.17.0)
|
|
9
9
|
|
|
10
10
|
A token-driven, framework-agnostic UI kit. One source of truth for color, typography,
|
|
11
11
|
spacing, and components. Blueprint: `docs/superpowers/specs/2026-07-21-freeday-ui-kit-design.md`.
|
|
@@ -175,14 +175,23 @@
|
|
|
175
175
|
if (element) element.indeterminate = !!value;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
// The device's theme preference, through the same core Vue and React use (freeday-theme.js, in
|
|
179
|
+
// freeday.js): stored per device, 'system' follows the OS, and every toggle on the page agrees.
|
|
180
|
+
function themeCore() {
|
|
181
|
+
if (!window.FreedayTheme) {
|
|
182
|
+
throw new Error('FreedayBlazor: window.FreedayTheme is missing. Load freeday.js (which includes '
|
|
183
|
+
+ 'freeday-theme.js) before freeday-blazor.js.');
|
|
184
|
+
}
|
|
185
|
+
return window.FreedayTheme;
|
|
182
186
|
}
|
|
187
|
+
function toggleTheme() { themeCore().toggle(); }
|
|
188
|
+
function setTheme(theme) { themeCore().set(theme); }
|
|
189
|
+
function getTheme() { return themeCore().get(); }
|
|
190
|
+
function getResolvedTheme() { return themeCore().resolved(); }
|
|
183
191
|
|
|
184
192
|
window.FreedayBlazor = {
|
|
185
193
|
initAll: initAll, on: on, off: off, onOutside: onOutside, toast: toast, toggleTheme: toggleTheme,
|
|
194
|
+
setTheme: setTheme, getTheme: getTheme, getResolvedTheme: getResolvedTheme,
|
|
186
195
|
comboSetValue: comboSetValue, dateRangeOn: dateRangeOn, chartUpdate: chartUpdate,
|
|
187
196
|
setIndeterminate: setIndeterminate,
|
|
188
197
|
dialogInit: dialogInit, dialogShow: dialogShow, dialogClose: dialogClose, dialogDispose: dialogDispose,
|
|
@@ -13,6 +13,32 @@ export interface UseFreedayReturn {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function useFreeday(rootRef?: RefObject<HTMLElement | null>): UseFreedayReturn;
|
|
15
15
|
|
|
16
|
+
/** A theme preference. `'system'` removes `data-theme`, so the tokens follow the OS, live. */
|
|
17
|
+
export type FdyTheme = 'light' | 'dark' | 'system';
|
|
18
|
+
/** What is actually on screen once `'system'` is resolved against the OS. */
|
|
19
|
+
export type FdyResolvedTheme = 'light' | 'dark';
|
|
20
|
+
/** `event.detail` of `fdy-theme-change`, fired on `document`. */
|
|
21
|
+
export interface FdyThemeChangeDetail { theme: FdyTheme; resolved: FdyResolvedTheme }
|
|
22
|
+
|
|
23
|
+
export interface UseThemeReturn {
|
|
24
|
+
/** The stored preference, per device; `'system'` until one is chosen. */
|
|
25
|
+
theme: FdyTheme;
|
|
26
|
+
/** The theme on screen. Use it for the toggle's icon and label, not `theme`. */
|
|
27
|
+
resolved: FdyResolvedTheme;
|
|
28
|
+
/** Store and apply a preference. Throws a TypeError for any other value. */
|
|
29
|
+
setTheme: (theme: FdyTheme) => void;
|
|
30
|
+
/** Switch to the opposite of what is on screen, so the first press always changes it. */
|
|
31
|
+
toggleTheme: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The device's light/dark preference, applied to `<html>`, kept in `localStorage` and shared by
|
|
36
|
+
* every caller on the page. Pass a ref to also apply it to that element, for a region whose markup
|
|
37
|
+
* fixes its own `data-theme`. Loads the theme core itself: no `import '@cahyo-dimas/freeday'`
|
|
38
|
+
* needed. Apply the stored value before first paint with the `<head>` snippet in COMPONENTS.md.
|
|
39
|
+
*/
|
|
40
|
+
export declare function useTheme(rootRef?: RefObject<HTMLElement | null>): UseThemeReturn;
|
|
41
|
+
|
|
16
42
|
/** `event.detail` shapes for the bubbling `fdy-*` CustomEvents. */
|
|
17
43
|
export interface FdyChangeDetail { value: string }
|
|
18
44
|
export interface FdyAutocompleteSelectDetail { value: string }
|
package/adapters/react/index.js
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* Freeday. React theme preference (CATATAN-FREEDAY §23). A thin view over window.FreedayTheme,
|
|
2
|
+
* which this file loads itself, so it needs no `import 'freeday'` first and a page still has one
|
|
3
|
+
* preference if the root import is there too (the core registers once).
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* const { theme, resolved, setTheme, toggleTheme } = useTheme();
|
|
7
|
+
* // <button onClick={toggleTheme} aria-label={resolved === 'dark' ? 'Light theme' : 'Dark theme'}>
|
|
8
|
+
*
|
|
9
|
+
* Pass a ref to also put the preference on that element, for a region whose markup fixes its own
|
|
10
|
+
* data-theme. Every instance reads the same store through useSyncExternalStore, so two toggles on
|
|
11
|
+
* one page never disagree.
|
|
12
|
+
*/
|
|
13
|
+
import { useEffect, useSyncExternalStore } from 'react';
|
|
14
|
+
import '../../dist/freeday-theme.js';
|
|
15
|
+
|
|
16
|
+
function subscribe(onChange) {
|
|
17
|
+
document.addEventListener('fdy-theme-change', onChange);
|
|
18
|
+
return function () { document.removeEventListener('fdy-theme-change', onChange); };
|
|
19
|
+
}
|
|
20
|
+
function getTheme() { return window.FreedayTheme.get(); }
|
|
21
|
+
function getResolved() { return window.FreedayTheme.resolved(); }
|
|
22
|
+
function serverTheme() { return 'system'; }
|
|
23
|
+
function serverResolved() { return 'light'; }
|
|
24
|
+
function setTheme(next) { window.FreedayTheme.set(next); }
|
|
25
|
+
function toggleTheme() { window.FreedayTheme.toggle(); }
|
|
26
|
+
|
|
27
|
+
export function useTheme(rootRef) {
|
|
28
|
+
var theme = useSyncExternalStore(subscribe, getTheme, serverTheme);
|
|
29
|
+
var resolved = useSyncExternalStore(subscribe, getResolved, serverResolved);
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
if (rootRef && rootRef.current) return window.FreedayTheme.attach(rootRef.current);
|
|
32
|
+
return undefined;
|
|
33
|
+
}, [rootRef]);
|
|
34
|
+
return { theme: theme, resolved: resolved, setTheme: setTheme, toggleTheme: toggleTheme };
|
|
35
|
+
}
|
package/adapters/vue/index.d.ts
CHANGED
|
@@ -13,6 +13,32 @@ export interface UseFreedayReturn {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function useFreeday(rootRef?: Ref<HTMLElement | null>): UseFreedayReturn;
|
|
15
15
|
|
|
16
|
+
/** A theme preference. `'system'` removes `data-theme`, so the tokens follow the OS, live. */
|
|
17
|
+
export type FdyTheme = 'light' | 'dark' | 'system';
|
|
18
|
+
/** What is actually on screen once `'system'` is resolved against the OS. */
|
|
19
|
+
export type FdyResolvedTheme = 'light' | 'dark';
|
|
20
|
+
/** `event.detail` of `fdy-theme-change`, fired on `document`. */
|
|
21
|
+
export interface FdyThemeChangeDetail { theme: FdyTheme; resolved: FdyResolvedTheme }
|
|
22
|
+
|
|
23
|
+
export interface UseThemeReturn {
|
|
24
|
+
/** The stored preference, per device; `'system'` until one is chosen. */
|
|
25
|
+
theme: Readonly<Ref<FdyTheme>>;
|
|
26
|
+
/** The theme on screen. Use it for the toggle's icon and label, not `theme`. */
|
|
27
|
+
resolved: Readonly<Ref<FdyResolvedTheme>>;
|
|
28
|
+
/** Store and apply a preference. Throws a TypeError for any other value. */
|
|
29
|
+
setTheme: (theme: FdyTheme) => void;
|
|
30
|
+
/** Switch to the opposite of what is on screen, so the first press always changes it. */
|
|
31
|
+
toggleTheme: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The device's light/dark preference, applied to `<html>`, kept in `localStorage` and shared by
|
|
36
|
+
* every caller on the page. Pass a ref to also apply it to that element, for a region whose markup
|
|
37
|
+
* fixes its own `data-theme`. Loads the theme core itself: no `import '@cahyo-dimas/freeday'`
|
|
38
|
+
* needed. Apply the stored value before first paint with the `<head>` snippet in COMPONENTS.md.
|
|
39
|
+
*/
|
|
40
|
+
export declare function useTheme(rootRef?: Ref<HTMLElement | null>): UseThemeReturn;
|
|
41
|
+
|
|
16
42
|
/**
|
|
17
43
|
* Which of the panel's edges lines up with the trigger's. `'start'` (the default) puts the panel's
|
|
18
44
|
* LEFT edge on the trigger's left edge, right for an input-shaped dropdown; `'end'` puts its RIGHT
|
package/adapters/vue/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useFreeday } from './useFreeday.js';
|
|
2
|
+
export { useTheme } from './useTheme.js';
|
|
2
3
|
export { usePopover } from './usePopover.ts';
|
|
3
4
|
export { default as FdyCombo } from './components/FdyCombo.vue';
|
|
4
5
|
export { default as FdyDatepicker } from './components/FdyDatepicker.vue';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* Freeday. Vue 3 theme preference (CATATAN-FREEDAY §23). A thin view over window.FreedayTheme,
|
|
2
|
+
* which this file loads itself, so it needs no `import 'freeday'` first and a page still has one
|
|
3
|
+
* preference if the root import is there too (the core registers once).
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* const { theme, resolved, setTheme, toggleTheme } = useTheme();
|
|
7
|
+
* // <button @click="toggleTheme" :aria-label="resolved === 'dark' ? 'Light theme' : 'Dark theme'">
|
|
8
|
+
*
|
|
9
|
+
* Pass a template ref to also put the preference on that element, for a region whose markup fixes
|
|
10
|
+
* its own data-theme. Every instance stays in step through the core's fdy-theme-change event.
|
|
11
|
+
*/
|
|
12
|
+
import { onBeforeUnmount, onMounted, readonly, ref } from 'vue';
|
|
13
|
+
import '../../dist/freeday-theme.js';
|
|
14
|
+
|
|
15
|
+
function core() {
|
|
16
|
+
return typeof window === 'undefined' ? null : window.FreedayTheme;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useTheme(rootRef) {
|
|
20
|
+
var api = core();
|
|
21
|
+
var theme = ref(api ? api.get() : 'system');
|
|
22
|
+
var resolved = ref(api ? api.resolved() : 'light');
|
|
23
|
+
var detach = null;
|
|
24
|
+
|
|
25
|
+
function sync(e) {
|
|
26
|
+
theme.value = e.detail.theme;
|
|
27
|
+
resolved.value = e.detail.resolved;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onMounted(function () {
|
|
31
|
+
if (rootRef && rootRef.value) detach = api.attach(rootRef.value);
|
|
32
|
+
theme.value = api.get();
|
|
33
|
+
resolved.value = api.resolved();
|
|
34
|
+
document.addEventListener('fdy-theme-change', sync);
|
|
35
|
+
});
|
|
36
|
+
onBeforeUnmount(function () {
|
|
37
|
+
document.removeEventListener('fdy-theme-change', sync);
|
|
38
|
+
if (detach) detach();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
theme: readonly(theme),
|
|
43
|
+
resolved: readonly(resolved),
|
|
44
|
+
setTheme: function (next) { core().set(next); },
|
|
45
|
+
toggleTheme: function () { core().toggle(); }
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* Freeday, theme preference (optional, zero-dependency, no markup of its own).
|
|
2
|
+
* The light/dark switch every app needs and each one used to write for itself, guessing the kit's
|
|
3
|
+
* contract from the docs (CATATAN-FREEDAY §23). One preference per device: 'light', 'dark' or
|
|
4
|
+
* 'system'.
|
|
5
|
+
*
|
|
6
|
+
* 'system' REMOVES data-theme instead of computing one. The tokens already follow
|
|
7
|
+
* prefers-color-scheme whenever no data-theme says otherwise, so the page tracks an OS switch live,
|
|
8
|
+
* with no listener deciding anything.
|
|
9
|
+
*
|
|
10
|
+
* The preference always lands on <html>. attach(el) adds another root that gets it too: a region
|
|
11
|
+
* that carries its own data-theme in markup (a dark kiosk shell inside a light app) would otherwise
|
|
12
|
+
* keep that fixed value, because a subtree's attribute wins over the document's. Attaching hands the
|
|
13
|
+
* region to the user: with the preference at 'system' its fixed value is removed and it follows the
|
|
14
|
+
* OS like the rest of the page.
|
|
15
|
+
*
|
|
16
|
+
* Every change fires "fdy-theme-change" on document, detail {theme, resolved}; so does an OS switch
|
|
17
|
+
* while the preference is 'system', since `resolved` (what is actually shown) moved. The Vue and
|
|
18
|
+
* React useTheme() import this same file, so a page has one preference whichever way it loaded.
|
|
19
|
+
*
|
|
20
|
+
* Only a script in <head> can apply the stored value before the first paint; this file runs too
|
|
21
|
+
* late for that, and catches up on load. COMPONENTS.md has the one-line snippet. Exposes
|
|
22
|
+
* window.FreedayTheme.
|
|
23
|
+
*/
|
|
24
|
+
(function () {
|
|
25
|
+
'use strict';
|
|
26
|
+
if (typeof window === 'undefined' || window.FreedayTheme) return;
|
|
27
|
+
|
|
28
|
+
var KEY = 'fdy-theme';
|
|
29
|
+
var THEMES = ['light', 'dark', 'system'];
|
|
30
|
+
var roots = [];
|
|
31
|
+
var memory = null;
|
|
32
|
+
var media = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null;
|
|
33
|
+
|
|
34
|
+
function valid(theme) {
|
|
35
|
+
return THEMES.indexOf(theme) !== -1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* Storage can throw (private mode, a blocked origin); the preference then lasts the page. */
|
|
39
|
+
function read() {
|
|
40
|
+
try {
|
|
41
|
+
var stored = window.localStorage.getItem(KEY);
|
|
42
|
+
if (valid(stored)) return stored;
|
|
43
|
+
} catch (e) { /* fall through to the in-memory value */ }
|
|
44
|
+
return memory !== null ? memory : 'system';
|
|
45
|
+
}
|
|
46
|
+
function write(theme) {
|
|
47
|
+
memory = theme;
|
|
48
|
+
try {
|
|
49
|
+
if (theme === 'system') window.localStorage.removeItem(KEY);
|
|
50
|
+
else window.localStorage.setItem(KEY, theme);
|
|
51
|
+
} catch (e) { /* kept in memory only */ }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function applyTo(el, theme) {
|
|
55
|
+
if (theme === 'system') el.removeAttribute('data-theme');
|
|
56
|
+
else el.setAttribute('data-theme', theme);
|
|
57
|
+
}
|
|
58
|
+
function targets() {
|
|
59
|
+
return [document.documentElement].concat(roots);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* What <html> shows: its own attribute if it has one, the OS otherwise. Read from the DOM, not
|
|
63
|
+
from the preference, so markup that ships data-theme="light" before anything is stored is
|
|
64
|
+
reported as light, which is what the user sees. */
|
|
65
|
+
function resolved() {
|
|
66
|
+
var own = document.documentElement.getAttribute('data-theme');
|
|
67
|
+
if (own === 'light' || own === 'dark') return own;
|
|
68
|
+
return media && media.matches ? 'dark' : 'light';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function emit() {
|
|
72
|
+
document.dispatchEvent(new CustomEvent('fdy-theme-change', { detail: { theme: read(), resolved: resolved() } }));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function set(theme) {
|
|
76
|
+
if (!valid(theme)) {
|
|
77
|
+
throw new TypeError('FreedayTheme.set: theme must be one of ' + THEMES.join(', ') + ', got ' + JSON.stringify(theme));
|
|
78
|
+
}
|
|
79
|
+
write(theme);
|
|
80
|
+
targets().forEach(function (el) { applyTo(el, theme); });
|
|
81
|
+
emit();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* Flips what is SHOWN, so the first press always changes the screen, even from 'system'. */
|
|
85
|
+
function toggle() {
|
|
86
|
+
set(resolved() === 'dark' ? 'light' : 'dark');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function attach(el) {
|
|
90
|
+
if (!el || roots.indexOf(el) !== -1) return detacher(el);
|
|
91
|
+
roots.push(el);
|
|
92
|
+
applyTo(el, read());
|
|
93
|
+
return detacher(el);
|
|
94
|
+
}
|
|
95
|
+
function detacher(el) {
|
|
96
|
+
return function () {
|
|
97
|
+
var i = roots.indexOf(el);
|
|
98
|
+
if (i !== -1) roots.splice(i, 1);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* A stored choice is applied on load as well. The <head> snippet does it before first paint;
|
|
103
|
+
without it the page shows the CSS default for a moment, and then still ends up right. Nothing
|
|
104
|
+
stored means nothing is touched, so markup that ships its own data-theme keeps it. */
|
|
105
|
+
var initial = read();
|
|
106
|
+
if (initial !== 'system') applyTo(document.documentElement, initial);
|
|
107
|
+
|
|
108
|
+
if (media) {
|
|
109
|
+
var onOs = function () { if (read() === 'system') emit(); };
|
|
110
|
+
if (media.addEventListener) media.addEventListener('change', onOs);
|
|
111
|
+
else if (media.addListener) media.addListener(onOs);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
window.FreedayTheme = { get: read, resolved: resolved, set: set, toggle: toggle, attach: attach };
|
|
115
|
+
})();
|
package/dist/freeday.js
CHANGED
|
@@ -5221,6 +5221,122 @@
|
|
|
5221
5221
|
window.FreedayTabs = { init: initTabs, initAll: initAll };
|
|
5222
5222
|
})();
|
|
5223
5223
|
|
|
5224
|
+
/* Freeday, theme preference (optional, zero-dependency, no markup of its own).
|
|
5225
|
+
* The light/dark switch every app needs and each one used to write for itself, guessing the kit's
|
|
5226
|
+
* contract from the docs (CATATAN-FREEDAY §23). One preference per device: 'light', 'dark' or
|
|
5227
|
+
* 'system'.
|
|
5228
|
+
*
|
|
5229
|
+
* 'system' REMOVES data-theme instead of computing one. The tokens already follow
|
|
5230
|
+
* prefers-color-scheme whenever no data-theme says otherwise, so the page tracks an OS switch live,
|
|
5231
|
+
* with no listener deciding anything.
|
|
5232
|
+
*
|
|
5233
|
+
* The preference always lands on <html>. attach(el) adds another root that gets it too: a region
|
|
5234
|
+
* that carries its own data-theme in markup (a dark kiosk shell inside a light app) would otherwise
|
|
5235
|
+
* keep that fixed value, because a subtree's attribute wins over the document's. Attaching hands the
|
|
5236
|
+
* region to the user: with the preference at 'system' its fixed value is removed and it follows the
|
|
5237
|
+
* OS like the rest of the page.
|
|
5238
|
+
*
|
|
5239
|
+
* Every change fires "fdy-theme-change" on document, detail {theme, resolved}; so does an OS switch
|
|
5240
|
+
* while the preference is 'system', since `resolved` (what is actually shown) moved. The Vue and
|
|
5241
|
+
* React useTheme() import this same file, so a page has one preference whichever way it loaded.
|
|
5242
|
+
*
|
|
5243
|
+
* Only a script in <head> can apply the stored value before the first paint; this file runs too
|
|
5244
|
+
* late for that, and catches up on load. COMPONENTS.md has the one-line snippet. Exposes
|
|
5245
|
+
* window.FreedayTheme.
|
|
5246
|
+
*/
|
|
5247
|
+
(function () {
|
|
5248
|
+
'use strict';
|
|
5249
|
+
if (typeof window === 'undefined' || window.FreedayTheme) return;
|
|
5250
|
+
|
|
5251
|
+
var KEY = 'fdy-theme';
|
|
5252
|
+
var THEMES = ['light', 'dark', 'system'];
|
|
5253
|
+
var roots = [];
|
|
5254
|
+
var memory = null;
|
|
5255
|
+
var media = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null;
|
|
5256
|
+
|
|
5257
|
+
function valid(theme) {
|
|
5258
|
+
return THEMES.indexOf(theme) !== -1;
|
|
5259
|
+
}
|
|
5260
|
+
|
|
5261
|
+
/* Storage can throw (private mode, a blocked origin); the preference then lasts the page. */
|
|
5262
|
+
function read() {
|
|
5263
|
+
try {
|
|
5264
|
+
var stored = window.localStorage.getItem(KEY);
|
|
5265
|
+
if (valid(stored)) return stored;
|
|
5266
|
+
} catch (e) { /* fall through to the in-memory value */ }
|
|
5267
|
+
return memory !== null ? memory : 'system';
|
|
5268
|
+
}
|
|
5269
|
+
function write(theme) {
|
|
5270
|
+
memory = theme;
|
|
5271
|
+
try {
|
|
5272
|
+
if (theme === 'system') window.localStorage.removeItem(KEY);
|
|
5273
|
+
else window.localStorage.setItem(KEY, theme);
|
|
5274
|
+
} catch (e) { /* kept in memory only */ }
|
|
5275
|
+
}
|
|
5276
|
+
|
|
5277
|
+
function applyTo(el, theme) {
|
|
5278
|
+
if (theme === 'system') el.removeAttribute('data-theme');
|
|
5279
|
+
else el.setAttribute('data-theme', theme);
|
|
5280
|
+
}
|
|
5281
|
+
function targets() {
|
|
5282
|
+
return [document.documentElement].concat(roots);
|
|
5283
|
+
}
|
|
5284
|
+
|
|
5285
|
+
/* What <html> shows: its own attribute if it has one, the OS otherwise. Read from the DOM, not
|
|
5286
|
+
from the preference, so markup that ships data-theme="light" before anything is stored is
|
|
5287
|
+
reported as light, which is what the user sees. */
|
|
5288
|
+
function resolved() {
|
|
5289
|
+
var own = document.documentElement.getAttribute('data-theme');
|
|
5290
|
+
if (own === 'light' || own === 'dark') return own;
|
|
5291
|
+
return media && media.matches ? 'dark' : 'light';
|
|
5292
|
+
}
|
|
5293
|
+
|
|
5294
|
+
function emit() {
|
|
5295
|
+
document.dispatchEvent(new CustomEvent('fdy-theme-change', { detail: { theme: read(), resolved: resolved() } }));
|
|
5296
|
+
}
|
|
5297
|
+
|
|
5298
|
+
function set(theme) {
|
|
5299
|
+
if (!valid(theme)) {
|
|
5300
|
+
throw new TypeError('FreedayTheme.set: theme must be one of ' + THEMES.join(', ') + ', got ' + JSON.stringify(theme));
|
|
5301
|
+
}
|
|
5302
|
+
write(theme);
|
|
5303
|
+
targets().forEach(function (el) { applyTo(el, theme); });
|
|
5304
|
+
emit();
|
|
5305
|
+
}
|
|
5306
|
+
|
|
5307
|
+
/* Flips what is SHOWN, so the first press always changes the screen, even from 'system'. */
|
|
5308
|
+
function toggle() {
|
|
5309
|
+
set(resolved() === 'dark' ? 'light' : 'dark');
|
|
5310
|
+
}
|
|
5311
|
+
|
|
5312
|
+
function attach(el) {
|
|
5313
|
+
if (!el || roots.indexOf(el) !== -1) return detacher(el);
|
|
5314
|
+
roots.push(el);
|
|
5315
|
+
applyTo(el, read());
|
|
5316
|
+
return detacher(el);
|
|
5317
|
+
}
|
|
5318
|
+
function detacher(el) {
|
|
5319
|
+
return function () {
|
|
5320
|
+
var i = roots.indexOf(el);
|
|
5321
|
+
if (i !== -1) roots.splice(i, 1);
|
|
5322
|
+
};
|
|
5323
|
+
}
|
|
5324
|
+
|
|
5325
|
+
/* A stored choice is applied on load as well. The <head> snippet does it before first paint;
|
|
5326
|
+
without it the page shows the CSS default for a moment, and then still ends up right. Nothing
|
|
5327
|
+
stored means nothing is touched, so markup that ships its own data-theme keeps it. */
|
|
5328
|
+
var initial = read();
|
|
5329
|
+
if (initial !== 'system') applyTo(document.documentElement, initial);
|
|
5330
|
+
|
|
5331
|
+
if (media) {
|
|
5332
|
+
var onOs = function () { if (read() === 'system') emit(); };
|
|
5333
|
+
if (media.addEventListener) media.addEventListener('change', onOs);
|
|
5334
|
+
else if (media.addListener) media.addListener(onOs);
|
|
5335
|
+
}
|
|
5336
|
+
|
|
5337
|
+
window.FreedayTheme = { get: read, resolved: resolved, set: set, toggle: toggle, attach: attach };
|
|
5338
|
+
})();
|
|
5339
|
+
|
|
5224
5340
|
/* Freeday, time picker enhancer (optional, zero-dependency).
|
|
5225
5341
|
* Builds an input-styled trigger + scrollable time-list popover (WAI-ARIA listbox)
|
|
5226
5342
|
* from an empty [data-fdy-timepicker] wrapper. 24h HH:MM. Options run from
|
package/docs/getting-started.md
CHANGED
|
@@ -198,7 +198,7 @@ live docs also have a copy button per component.
|
|
|
198
198
|
```bash
|
|
199
199
|
npm i @cahyo-dimas/freeday
|
|
200
200
|
```
|
|
201
|
-
Lands in `package.json` as `"@cahyo-dimas/freeday": "^3.
|
|
201
|
+
Lands in `package.json` as `"@cahyo-dimas/freeday": "^3.17.0"` (public npm package). `dist/` is
|
|
202
202
|
committed and published → no build step; `npm ci` runs without auth.
|
|
203
203
|
|
|
204
204
|
### 2. Import the CSS + enhancers **once** in your entry (`src/main.ts`)
|
|
@@ -424,8 +424,9 @@ public partial class Panel : ComponentBase, IAsyncDisposable
|
|
|
424
424
|
<div data-fdy-datepicker></div>
|
|
425
425
|
</div>
|
|
426
426
|
```
|
|
427
|
-
Extras: `FreedayBlazor.toast(new { variant, title, message })` for toasts; `FreedayBlazor.toggleTheme()
|
|
428
|
-
|
|
427
|
+
Extras: `FreedayBlazor.toast(new { variant, title, message })` for toasts; `FreedayBlazor.toggleTheme()`,
|
|
428
|
+
`setTheme("light" | "dark" | "system")`, `getTheme()` and `getResolvedTheme()` for the stored theme
|
|
429
|
+
preference (COMPONENTS.md, "Theme preference"). Event DTOs are deserialized case-insensitively by Blazor.
|
|
429
430
|
|
|
430
431
|
### 4. Recommended: native typed components (`Freeday.Blazor` RCL)
|
|
431
432
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cahyo-dimas/freeday",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.0",
|
|
4
4
|
"description": "Freeday: token-driven, framework-agnostic UI KIT (design source-of-truth).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"scripts": {
|
|
98
98
|
"build": "node tokens/build.mjs",
|
|
99
99
|
"test": "node --test",
|
|
100
|
-
"test:browser": "node --test --test-concurrency=3 browser/color-mix.mjs browser/vanilla.mjs browser/adapter.mjs browser/layout.mjs browser/theme.mjs browser/state.mjs browser/root-init.mjs browser/upload-states.mjs browser/number.mjs browser/card-stretch.mjs browser/stretch-warn.mjs browser/hidden-attr.mjs browser/form-grid-rows.mjs browser/text-override.mjs browser/control-heights.mjs browser/field-width.mjs browser/cfl-multi.mjs browser/cfl-dialog-only.mjs browser/crowding.mjs browser/over-dialog.mjs browser/chart-scale.mjs browser/overlay-stack.mjs browser/chart-a11y.mjs browser/app-shell.mjs browser/bottom-nav.mjs browser/picker-states.mjs browser/tabs-strip.mjs browser/tabs-vertical.mjs browser/menu-align.mjs browser/cfl-narrow.mjs browser/form-reveal.mjs browser/confirm-search-copy.mjs browser/daterange-settled.mjs browser/display-parts.mjs browser/table-empty.mjs browser/table-footer-text.mjs browser/month-mode.mjs browser/monthpicker.mjs browser/page-columns.mjs browser/table-hover.mjs browser/typed-popover.mjs browser/filter-parity.mjs browser/filter-wrap.mjs browser/filter-stack.mjs browser/timepicker.mjs browser/form-kit-required.mjs browser/picker-in-modal.mjs browser/harness-contract.mjs browser/app-owned.mjs browser/sortable.mjs browser/modal-phone.mjs browser/empty-ref.mjs browser/stack-standalone.mjs",
|
|
100
|
+
"test:browser": "node --test --test-concurrency=3 browser/color-mix.mjs browser/vanilla.mjs browser/adapter.mjs browser/layout.mjs browser/theme.mjs browser/state.mjs browser/root-init.mjs browser/upload-states.mjs browser/number.mjs browser/card-stretch.mjs browser/stretch-warn.mjs browser/hidden-attr.mjs browser/form-grid-rows.mjs browser/theme-pref.mjs browser/text-override.mjs browser/control-heights.mjs browser/field-width.mjs browser/cfl-multi.mjs browser/cfl-dialog-only.mjs browser/crowding.mjs browser/over-dialog.mjs browser/chart-scale.mjs browser/overlay-stack.mjs browser/chart-a11y.mjs browser/app-shell.mjs browser/bottom-nav.mjs browser/picker-states.mjs browser/tabs-strip.mjs browser/tabs-vertical.mjs browser/menu-align.mjs browser/cfl-narrow.mjs browser/form-reveal.mjs browser/confirm-search-copy.mjs browser/daterange-settled.mjs browser/display-parts.mjs browser/table-empty.mjs browser/table-footer-text.mjs browser/month-mode.mjs browser/monthpicker.mjs browser/page-columns.mjs browser/table-hover.mjs browser/typed-popover.mjs browser/filter-parity.mjs browser/filter-wrap.mjs browser/filter-stack.mjs browser/timepicker.mjs browser/form-kit-required.mjs browser/picker-in-modal.mjs browser/harness-contract.mjs browser/app-owned.mjs browser/sortable.mjs browser/modal-phone.mjs browser/empty-ref.mjs browser/stack-standalone.mjs",
|
|
101
101
|
"prepack": "node tokens/build.mjs",
|
|
102
102
|
"version": "node tokens/build.mjs && git add dist",
|
|
103
103
|
"typecheck:react": "tsc -p adapters/react/tsconfig.json --noEmit",
|