feat(config): add shared browser cookie policy
This commit is contained in:
@@ -166,6 +166,35 @@ theme: {
|
||||
|
||||
The client runtime (`renderThemeRuntime`) exposes `window.wrnTheme` with `{ get, set, toggle, bind, themes }`, connects up any `[data-wrn-theme-toggle]` and `[data-wrn-theme-set]` elements on load, and persists the choice to the `wrn-theme` cookie (`max-age` 1 year, `samesite=lax`). `toggle()` cycles through the configured theme names in order.
|
||||
|
||||
### Shared browser cookies
|
||||
|
||||
Set one cookie policy for theme, accent, language, and application cookies:
|
||||
|
||||
```ts
|
||||
export default {
|
||||
cookies: {
|
||||
defaults: {
|
||||
domain: "example.com",
|
||||
path: "/",
|
||||
maxAge: 31_536_000,
|
||||
sameSite: "Lax",
|
||||
secure: true,
|
||||
},
|
||||
language: { maxAge: 2_592_000 },
|
||||
},
|
||||
} satisfies AppConfig;
|
||||
```
|
||||
|
||||
The theme, accent, and language switchers use this policy automatically. Client
|
||||
functions can use the same resolved policy for other values:
|
||||
|
||||
```ts
|
||||
window.wrnCookies.set("dashboard-view", "compact");
|
||||
window.wrnCookies.set("locale-preview", "hi", "language");
|
||||
const value = window.wrnCookies.get("dashboard-view");
|
||||
window.wrnCookies.remove("dashboard-view");
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### `wrnexus.config.ts`
|
||||
|
||||
Reference in New Issue
Block a user