@juice-js/layout 2.5.0-alpha.5 → 3.0.0-alpha.2

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/MIGRATION.md ADDED
@@ -0,0 +1,113 @@
1
+ # Migrating from @juice-js/layout 2.x to 3.0
2
+
3
+ Layout 3 drops Angular Material. The shell is built on the Angular CDK, `@juice-js/ui` primitives, `@juice-js/icons` (lucide) and the
4
+ `@juice-js/design-tokens` CSS variables, with the theme state in `ThemeService` (`@juice-js/ui/theme`). Routes, menus
5
+ (`MenuService`), counts (`MenuBadgeService`), the page switcher, the toolbar search (`SearchablePage`), `DevGuard`, `PageComponent` and
6
+ `PageNotfoundComponent` work as before.
7
+
8
+ 2.x stays maintained on the `2.x` release line (npm dist-tag `2.x`). Apps that keep Material, like Observability, Pro, Agent, the
9
+ Notifications consoles and juice-tenants, can stay on `@juice-js/layout@2.4.x` and adopt the tokens with the Material bridge first.
10
+
11
+ ## Breaking changes
12
+
13
+ 1. **No Material.** Layout 3 neither imports nor peers `@angular/material`. The shell no longer brings `MatToolbar`, `MatSidenav`,
14
+ `MatDialog`, `MatMenu`, `MatTooltip`, `MatIcon` or the Material icon font. An app whose own pages use Material keeps it as its own
15
+ dependency.
16
+ 2. **`layout.theme()` is removed**, together with `layout-component-themes()`, `layout-component-colors()`, `scale()`, `tokens()` and
17
+ the `$teal` and `$indigo` M3 palettes. `@use '@juice-js/layout'` now emits the design tokens and the layout's global styles itself.
18
+ No mixin call is needed.
19
+ 3. **New peer dependencies:** `@angular/cdk`, `@juice-js/design-tokens`, `@juice-js/icons`, `@juice-js/ui`, `lucide`,
20
+ `@ngx-translate/core` and `angular-oauth2-oidc`. The `@juice-js/localize` peer is dropped, because layout never imported it.
21
+ 4. **Menu icons are lucide icons by registered name**, not Material font ligatures. `menuIcon: 'home'` draws the icon registered as
22
+ `home` with `provideJuiceIcons()`. An unregistered name draws nothing and logs a dev-mode warning. `MATERIAL_ICON_ALIASES` maps the
23
+ common Material names (home, dashboard, security, notifications, inbox, settings, tune, account_circle, alternate_email, edit_note,
24
+ search, manage_search) to lucide icons.
25
+ 5. **Palettes are the tokens' accents.** `LAYOUT_PALETTES` is now indigo, teal and violet (it was teal and indigo), and **indigo is the
26
+ default** (it was teal). `LayoutService.palette()` always names an accent (it was `null` for "the stylesheet's default"), and
27
+ `setPalette(null)` goes back to `LayoutConfig.defaultPalette` instead of forgetting the choice. A custom palette id needs a matching
28
+ `:root[data-accent=<id>]` block in the app's CSS, setting `--juice-ref-accent-*`. `LayoutConfig.palettes` no longer takes M3 palettes.
29
+ 6. **The theme lives in `ThemeService`.** `LayoutService.getThemeMode()`, `toggleDarkMode()` and `setPalette()` delegate to it. It
30
+ writes `data-theme`, `data-accent` and `data-density` on `<html>`, and in legacy mode (the default) it also writes `body.dark` and
31
+ `data-juice-palette`. Its record is `localStorage['juice.theme']`. `IS_DARK_MODE` and `JUICE_PALETTE` are still read and written,
32
+ so a 2.x app on the same origin shows the same theme. `LayoutModule.forRoot()` configures it from `LayoutConfig` (`defaultThemeMode`,
33
+ `defaultPalette`, `palettes`). An app that calls `provideJuiceTheme()` itself configures it there.
34
+ 7. **Components are standalone.** `NavMenuComponent`, `ExpandableMenuComponent`, `MenuBadgeComponent`, `PageSwitcherComponent`,
35
+ `PageNotfoundComponent` and `PageComponent` are standalone, so they go in `imports`, not `declarations`. `LayoutModule` still
36
+ exports `PageComponent` and `RouterModule`.
37
+ 8. **`PageComponent`'s selector is `juice-standard-workspace`** (`app-page` still matches). The routed host element is
38
+ `<juice-standard-workspace>`. Global CSS that targeted `app-page > .container`, `.mat-toolbar` or `.mat-sidenav` inside the shell
39
+ no longer matches. Style the shell with the tier 3 tokens instead (`--juice-header-*`, `--juice-sidebar-*`).
40
+ 9. **`ProfileDialogService` uses the CDK `Dialog`.** It is `AsyncDialog<unknown, string, unknown, Dialog, DialogRef>`. A subclass
41
+ injects `Dialog` from `@angular/cdk/dialog`, passes it to `super()`, and resolves `open()` to a CDK `DialogRef`. The built-in
42
+ dialog component's selector is `juice-user-profile-dialog` (it was `app-user-profile`).
43
+ 10. **The folded menu no longer unfolds on hover.** It shows icons, with each label as a tooltip and for screen readers. The fold
44
+ toggle moved to the sidebar's foot and sets `IS_MENU_OPEN` as before. `NavMenuComponent.mouseEnter()` and `mouseLeave()` are gone,
45
+ and `isExpanded` is an input.
46
+ 11. **No `@angular/animations`.** The shell no longer needs `BrowserAnimationsModule` or `provideAnimations()`, though an app's own
47
+ Material pages may still need it.
48
+ 12. **The DOM and classes changed.** The toolbar is `<juice-header>`, the sidebar `<juice-sidebar>`, the page switcher panel a
49
+ `.cdk-dialog-container` with `.juice-page-switcher-panel`, and menu rows `.juice-nav__item` (`.active`, `aria-current="page"`).
50
+ `data-testid="page-switcher-open"` and `data-testid="palette-switch"` are kept.
51
+
52
+ Unchanged: `LayoutConfig` fields, `LAYOUT_TOOLBAR_ITEMS`, `LAYOUT_PALETTES` (the name), `MenuBadgeService`, `PageSwitcherService`,
53
+ `SearchService` (with the deprecated `enable()`), `SearchablePage`, `DevGuard`, `IS_PRODUCTION`, the `[tooltip]` directive and
54
+ `TooltipModule`, `jc-page-header` (also `juice-page-header` now) with `@juice-js/layout/page-header`, the storage keys
55
+ `IS_DARK_MODE`, `JUICE_PALETTE` and `IS_MENU_OPEN`, the skip link and the `#main-content` target.
56
+
57
+ ## Steps
58
+
59
+ 1. **Dependencies.**
60
+ ```sh
61
+ npm i @juice-js/layout@^3 @juice-js/ui @juice-js/icons @juice-js/design-tokens lucide @angular/cdk
62
+ npm i @fontsource-variable/inter @fontsource-variable/jetbrains-mono # self-hosted fonts the tokens name
63
+ ```
64
+ Re-pin `@juice-js/auth` and `@juice-js/tenant` to the alphas that peer layout 3. They still use Material until M2, so keep
65
+ `@angular/material` while you use them.
66
+ 2. **Global styles.** Replace the theme with the layout entry:
67
+ ```scss
68
+ // before
69
+ @use '@juice-js/layout' as layout;
70
+ @include layout.theme((default: indigo, density: -1));
71
+
72
+ // after
73
+ @use '@juice-js/layout';
74
+ @use '@fontsource-variable/inter';
75
+ @use '@fontsource-variable/jetbrains-mono';
76
+ ```
77
+ If the app still has Material pages, add the bridge so they follow the tokens:
78
+ ```scss
79
+ @use '@juice-js/design-tokens' as tokens;
80
+ @include tokens.material-bridge();
81
+ ```
82
+ Remove the Roboto and Material Icons `<link>`s from `index.html` unless your own pages need them, and the `mat-typography` class.
83
+ 3. **Icons for your menu.** Register the icons your routes name:
84
+ ```ts
85
+ import { provideJuiceIcons } from '@juice-js/icons';
86
+ import { MATERIAL_ICON_ALIASES } from '@juice-js/layout';
87
+ import { Rocket } from 'lucide';
88
+ providers: [provideJuiceIcons(MATERIAL_ICON_ALIASES), provideJuiceIcons({ launches: Rocket })]
89
+ ```
90
+ 4. **Bootstrap.** `LayoutModule.forRoot(production, config)` keeps working. Standalone apps use
91
+ `provideJuiceLayout(production, config)` and, for the built-in profile dialog, `provideUserProfileDialog()`.
92
+ 5. **Palettes.** If you passed `palettes` or `defaultPalette`, use accent ids the tokens define (`indigo`, `teal`, `violet`) or add
93
+ your own `[data-accent=<id>]` CSS. Drop custom M3 palette maps.
94
+ 6. **A custom profile dialog.** Switch it from `MatDialog` to the CDK `Dialog`:
95
+ ```ts
96
+ @Injectable()
97
+ export class MyProfileDialog extends ProfileDialogService {
98
+ constructor(dialog: Dialog) { super(dialog); }
99
+ async open(imageUrl: string) { return this.matDialog.open(MyProfileComponent, { ariaModal: true }); }
100
+ }
101
+ ```
102
+ 7. **Shell CSS overrides.** Replace selectors on `.mat-toolbar`, `.mat-sidenav`, `.mat-mdc-list-item` and `app-page > .container`
103
+ with token overrides, for example `:root { --juice-sidebar-width: 15rem; --juice-header-height: 3rem; }`.
104
+ 8. **Tests.** Specs that declared layout components move them to `imports`. Specs that found menu rows by `mat-list-item` use
105
+ `.juice-nav__item`.
106
+
107
+ ## New in 3.0
108
+
109
+ - Shell parts for your own layouts: `<juice-shell>` (skip link, `[juiceShellHeader]`, `[juiceShellSidebar]`, main content),
110
+ `<juice-header>`, `<juice-sidebar [(collapsed)]>`, `<juice-content>`, `<juice-side-panel [(open)] side="start|end">` (modal, focus
111
+ trap, Escape, focus return), `<juice-split-panel orientation [(sizes)] storageKey>` (keyboard-resizable separator, bounded, remembered).
112
+ - Primitives: `<juice-stack gap>`, `<juice-cluster gap>`, `<juice-page-header title>`.
113
+ - `<juice-standard-workspace>` is the preset (`PageComponent`).
package/README.md CHANGED
@@ -1,123 +1,105 @@
1
- # Layout
1
+ # @juice-js/layout
2
2
 
3
- This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 16.1.0.
3
+ The Juice app shell, Material-free since 3.0: a header, a side menu, a page switcher, the routed page, and layout primitives. It is
4
+ built on the Angular CDK, `@juice-js/ui`, `@juice-js/icons` (lucide) and the `@juice-js/design-tokens` CSS variables. Moving from
5
+ 2.x? See [MIGRATION.md](./MIGRATION.md). 2.x stays on the `2.x` release line.
4
6
 
5
- ## Theme and palettes
7
+ ## Setup
6
8
 
7
- The layout owns the app's colours, so the shell and every Juice page package (notifications, audit, observability…)
8
- show the same palette, light and dark. With Material 3, include the theme once in the app's global styles:
9
-
10
- ```scss
11
- @use '@juice-js/layout' as layout;
12
-
13
- @include layout.theme(); // teal (default) and indigo
14
- @include layout.theme((default: indigo, density: -1)); // another default, denser
15
- @include layout.theme((palettes: (brand: $brand))); // add your own, beside the built-in ones
9
+ ```sh
10
+ npm i @juice-js/layout @juice-js/ui @juice-js/icons @juice-js/design-tokens @juice-js/core lucide @angular/cdk
11
+ npm i @fontsource-variable/inter @fontsource-variable/jetbrains-mono
16
12
  ```
17
13
 
18
- `theme()` emits:
19
- - **Material 3:** `mat.theme()` for the default palette, and again under `[data-juice-palette="<name>"]` for each one. The colours are `light-dark()` pairs; the dark mode switch puts `.dark` (`color-scheme: dark`) on `body`.
20
- - **The layout's components:** toolbar, sidenav, menus and scrollbars, from Material's system colours.
21
- - **Shared tokens** for the page packages, on the same elements: `--juice-bg`, `--juice-surface`, `--juice-border`, `--juice-text`, `--juice-muted`, `--juice-accent`, `--juice-on-accent`, `--juice-select`, and the tones `--juice-ok`, `--juice-warn`, `--juice-bad`, `--juice-info`, `--juice-none`, each with a `-bg` tint. A package reads them with its own fallback: `var(--juice-accent, …)`.
14
+ Global styles: the tokens and the layout's styles, plus the self-hosted fonts.
22
15
 
23
- - **The type and radius scale** of the Juice Consoles (since 2.4.3), under a zero-specificity `:where(:root)`: `--jc-font-xs` 11px, `-sm` 12, `-md` 13, `-lg` 14, `-xl` 16, `-2xl` 20, `-fig` 24; `--jc-radius-sm` 4px, `--jc-radius` 8, `--jc-radius-pill` 999. An app's own values win.
24
- - **A keyboard focus ring** on the shell's toolbar, menu and skip link: 2px of `--juice-focus` (the primary colour) on `:focus-visible`.
16
+ ```scss
17
+ @use '@juice-js/layout';
18
+ @use '@fontsource-variable/inter';
19
+ @use '@fontsource-variable/jetbrains-mono';
20
+ ```
25
21
 
26
- Options: `default` (the palette before the viewer picks one), `palettes` (name → `(primary: …, tertiary: …)` M3 palettes, as `ng generate @angular/material:theme-color` writes them; a built-in name replaces that palette), `typography` (Roboto) and `density` (0).
22
+ `@use '@juice-js/layout/shell'` gives the layout's global styles without the tokens, and `@use '@juice-js/layout/page-header'` gives
23
+ the page header classes alone. An app with Material pages adds the bridge: `@use '@juice-js/design-tokens' as tokens; @include tokens.material-bridge();`.
27
24
 
28
- At runtime the viewer picks a palette with the palette button beside the dark mode switch. `LayoutService.setPalette(id)` sets `data-juice-palette` on `<html>` and remembers it in the browser; `palette()` is the current one. Configure what the button offers in `LayoutModule.forRoot`:
25
+ Providers:
29
26
 
30
27
  ```ts
31
- LayoutModule.forRoot(production, {
32
- brand: 'Acme',
33
- defaultPalette: 'indigo', // match layout.theme((default: …)), so the menu marks the right one
34
- palettes: [...LAYOUT_PALETTES, { id: 'brand', name: 'Brand', color: '#c2410c' }],
35
- }),
28
+ // NgModule apps
29
+ LayoutModule.forRoot(production, { brand: 'Acme', defaultPalette: 'indigo' }),
30
+ UserProfileDialogModule,
31
+ // standalone apps
32
+ provideJuiceLayout(production, { brand: 'Acme' }), provideUserProfileDialog(),
33
+ // the icons your menu names (menuIcon: 'home'), as lucide icons
34
+ provideJuiceIcons(MATERIAL_ICON_ALIASES), provideJuiceIcons({ launches: Rocket }),
36
35
  ```
37
36
 
38
- With one palette there is no button. The Material 2 mixins of 1.x (`layout-component-themes`, `layout-component-colors`) still work for apps not on Material 3 yet; they get no palettes and no `--juice-*` tokens.
37
+ Routes use the standard workspace as their component: `{ path: '', component: PageComponent, children: [...] }`. Its host is
38
+ `<juice-standard-workspace>`.
39
39
 
40
- ## Page header: `jc-page-header`
40
+ ## Theme
41
41
 
42
- The header the Juice Consoles share, for a page that isn't about one environment or time range: the way back, the title as the
43
- page's `h1`, a line under it, and the page's actions (and filters) projected in on the right.
42
+ `ThemeService` (`@juice-js/ui/theme`) owns the theme. It writes `data-theme`, `data-accent` and `data-density` on `<html>`, and it
43
+ remembers the choice under `juice.theme`. In legacy mode (the default) it also mirrors `body.dark` and `data-juice-palette`, and reads
44
+ and writes `IS_DARK_MODE` and `JUICE_PALETTE`, so a 2.x app on the same origin agrees. `LayoutModule.forRoot()` configures it from
45
+ `LayoutConfig`:
44
46
 
45
- ```ts
46
- import { PageHeader } from '@juice-js/layout';
47
- // <jc-page-header title="Routes" subtitle="Who gets what" [crumbs]="[{ label: 'Alerts', link: ['/alerts'] }, { label: 'Notifications' }]">
48
- // <button mat-flat-button>New route</button>
49
- // </jc-page-header>
50
- ```
47
+ - `defaultThemeMode` (Auto follows the system)
48
+ - `defaultPalette` (indigo by default)
49
+ - `palettes`: the accents the palette button offers, by default `LAYOUT_PALETTES` (indigo, teal and violet)
51
50
 
52
- Its styles are plain CSS, with or without `theme()`: `@use '@juice-js/layout/page-header';` once in the global styles. Classes:
53
- `.jc-page-header`, `.jc-page-title`, `.jc-page-subtitle`, `.jc-crumb`, `.jc-crumb-sep`, `.jc-spacer`, and `.jc-sr-only` (visually
54
- hidden, for a screen reader only). It reads `--jc-border` and `--jc-muted` (else `--juice-border` and `--juice-muted`), and the scale's
55
- `--jc-font-2xl` and `--jc-font-md`, each with a fallback.
51
+ `LayoutService.setPalette(id)`, `palette()`, `getThemeMode()` and `toggleDarkMode()` are the 2.x API over it.
56
52
 
57
- ## Toolbar search: `SearchablePage`
53
+ ## The shell's parts
58
54
 
59
- The shell's toolbar hosts one search box, shared by every page. It appears only while the
60
- displayed page implements `SearchablePage`, and disappears otherwise.
55
+ | Part | Use |
56
+ |---|---|
57
+ | `<juice-shell>` | skip link (first tab stop, focuses the content), `[juiceShellHeader]`, `[juiceShellSidebar]`, main content (`#main-content`, `role=main` unless `mainLandmark` is false) |
58
+ | `<juice-header>` | the top bar; `.juice-header__spacer` pushes the rest to the end |
59
+ | `<juice-sidebar [(collapsed)]>` | the menu column; the fold toggle at its foot has `aria-expanded`; `[juiceSidebarFooter]` content goes beside it |
60
+ | `<juice-content>` | padded page area |
61
+ | `<juice-side-panel [(open)] side="start\|end" label (closed)>` | a modal panel over the page: focus trap, Escape and backdrop close, focus returns |
62
+ | `<juice-split-panel orientation [(sizes)] storageKey min step>` | two panes (`[juiceSplitStart]`, `[juiceSplitEnd]`) with a `role=separator` resized by drag or arrow keys, Home and End, bounded by `min`, remembered under `storageKey` (an invalid stored value is ignored) |
63
+ | `<juice-stack gap>`, `<juice-cluster gap>` | column and wrapping row, `gap` a step of the spacing scale |
64
+ | `<juice-page-header title subtitle [crumbs]>` | the page's h1 and actions (also `jc-page-header`) |
65
+ | `<juice-standard-workspace>` | the preset: all of the above wired to the menu, search, page switcher, accent, theme and profile (`PageComponent`) |
61
66
 
62
- ```ts
63
- import { SearchablePage } from '@juice-js/layout';
67
+ Styling: each part reads the tier 3 tokens, such as `--juice-header-height`, `--juice-header-bg`, `--juice-sidebar-width`,
68
+ `--juice-sidebar-collapsed-width`, `--juice-sidebar-item-active-bg` and `--juice-panel-*`. Override them on `:root`.
64
69
 
65
- @Component({ /* ... */ })
66
- export class OrdersComponent implements SearchablePage {
67
- onSearch(query: string): void {
68
- this.filter = query; // '' means the box was cleared — show everything
69
- }
70
- }
71
- ```
70
+ ## Side menu
72
71
 
73
- That is the whole opt-in: no service to inject, no constructor wiring, no route config.
74
- A page that supports no search implements nothing — the box is absent by default.
72
+ The menu comes from `MenuService` (`@juice-js/core`). Groups open on their pages, also pages kept out of the menu (`inMenu: false`),
73
+ and the most specific entry gets `aria-current="page"`. `MenuBadgeService.set(id, count)` puts a count on an entry: beside the label
74
+ when unfolded, on the icon when folded, and summed on a closed group's header. Folded, entries show their icon and keep the label
75
+ as a tooltip and for screen readers. The fold state is remembered under `IS_MENU_OPEN`. On a phone the menu opens in a side panel.
75
76
 
76
- Implementing `onSearch` *is* the declaration, so a page cannot claim search without
77
- serving it. The shell binds the active page from its own router outlet, which means the
78
- box survives a cancelled navigation and a tenant switch that reuses the page component.
77
+ ## Page switcher
79
78
 
80
- Notes:
79
+ Ctrl+K or ⌘K (or the header button) opens a CDK dialog over the menu's pages, with a focus trap. Escape closes it and gives the focus
80
+ back. Go-to keys (`shortcut: 'g s'` on a menu item) jump straight to a page. `LayoutConfig.pageSwitcher: false` turns both off.
81
81
 
82
- - `onSearch` fires on every keystroke. The shell does not debounce, impose a minimum
83
- length, or wait for Enter — a page that wants any of those owns them.
84
- - Clearing the box calls `onSearch('')`, which is different from the box being absent
85
- (which calls nothing).
86
-
87
- ### Migrating from `SearchService.enable()`
82
+ ## Toolbar search: `SearchablePage`
88
83
 
89
- `enable()` and `disable()` are deprecated but still functional; they will be removed in
90
- the next major.
84
+ The header hosts one search box, shared by every page. It appears only while the page on display implements `SearchablePage`:
91
85
 
92
86
  ```ts
93
- // Before
94
- constructor(searchService: SearchService) {
95
- searchService.enable((text: string, event: Event) => { /* ... */ });
96
- }
97
-
98
- // After
99
- export class DashboardComponent implements SearchablePage {
100
- onSearch(query: string): void { /* ... */ }
87
+ export class OrdersComponent implements SearchablePage {
88
+ onSearch(query: string): void { this.filter = query; } // '' means cleared
101
89
  }
102
90
  ```
103
91
 
104
- ## Code scaffolding
105
-
106
- Run `ng generate component component-name --project layout` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project layout`.
107
- > Note: Don't forget to add `--project layout` or else it will be added to the default project in your `angular.json` file.
92
+ `onSearch` fires on every keystroke. Clearing the box calls `onSearch('')`. `SearchService.enable()` and `disable()` are deprecated.
108
93
 
109
- ## Build
94
+ ## Toolbar items
110
95
 
111
- Run `ng build layout` to build the project. The build artifacts will be stored in the `dist/` directory.
96
+ `{ provide: LAYOUT_TOOLBAR_ITEMS, useValue: NotificationBellComponent, multi: true }` adds a component to the header, before the
97
+ accent and theme buttons.
112
98
 
113
- ## Publishing
99
+ ## Build and test
114
100
 
115
- After building your library with `ng build layout`, go to the dist folder `cd dist/layout` and run `npm publish`.
116
-
117
- ## Running unit tests
118
-
119
- Run `ng test layout` to execute the unit tests via [Karma](https://karma-runner.github.io).
120
-
121
- ## Further help
122
-
123
- To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
101
+ ```sh
102
+ npx ng build @juice-js/layout # needs core, design-tokens, icons and ui built first
103
+ npx ng test @juice-js/layout --watch=false --browsers=ChromeHeadless
104
+ node tools/check-no-material.mjs # layout and everything it imports stay Material-free
105
+ ```