mirror of
https://github.com/bitwarden/browser
synced 2026-02-24 08:33:29 +00:00
use client abstraction pattern; add settings toggle; use observable instead of signal due to state provider
This commit is contained in:
@@ -30,7 +30,7 @@ export * from "./radio-button";
|
||||
export * from "./search";
|
||||
export * from "./section";
|
||||
export * from "./select";
|
||||
export * from "./shared/design-system.service";
|
||||
export * from "./shared/compact-mode.service";
|
||||
export * from "./table";
|
||||
export * from "./tabs";
|
||||
export * from "./toast";
|
||||
|
||||
11
libs/components/src/shared/compact-mode.service.ts
Normal file
11
libs/components/src/shared/compact-mode.service.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
/** Global config for the Bitwarden Design System */
|
||||
export abstract class CompactModeService {
|
||||
/**
|
||||
* When true, enables "compact mode".
|
||||
*
|
||||
* Component authors can also hook into compact mode with the `bit-compact:` Tailwind variant.
|
||||
**/
|
||||
enabled$: Observable<boolean>;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { effect, Injectable, signal, WritableSignal } from "@angular/core";
|
||||
|
||||
/** Global config for the Bitwarden Design System */
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class DesignSystemService {
|
||||
/**
|
||||
* When true, enables "compact mode".
|
||||
*
|
||||
* Component authors can hook into compact mode with the `bit-compact:` Tailwind variant.
|
||||
**/
|
||||
compactMode: WritableSignal<boolean> = signal(false);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
this.compactMode()
|
||||
? document.body.classList.add("tw-bit-compact")
|
||||
: document.body.classList.remove("tw-bit-compact");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,8 @@ following example, the paragraph's padding is reduced when compact mode is enabl
|
||||
|
||||
## Service
|
||||
|
||||
To get/set compact mode in TypeScript, the `DesignSystemService` exposes a `compactMode` signal.
|
||||
However, using the Tailwind variant should be preferred as it is more performant.
|
||||
To get/set compact mode in TypeScript, the `CompactModeService` exposes a `enabled$` observable.
|
||||
However, styling with the Tailwind variant should be used when possible as it is more performant.
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
Reference in New Issue
Block a user