Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cspell.words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ aria-valuenow
uppercased
llms
sitemapindex
prerenders
prerenders
wordmark
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export default [
}
},
rules: {
'better-tailwindcss/no-unknown-classes': 'warn',
// .light and .dark of ui fix the mode of an element, plain css in its base layer, which the plugin doesn't see
'better-tailwindcss/no-unknown-classes': ['warn', { ignore: ['^light$', '^dark$'] }],
'better-tailwindcss/no-concatenated-classes': 'warn',
'better-tailwindcss/enforce-consistent-line-wrapping': ['warn', { printWidth: 140, indent: 4, preferSingleLine: true }],
'better-tailwindcss/no-restricted-classes': [
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@service-soft/ngx-auth",
"version": "22.3.1",
"version": "22.3.2",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -24,7 +24,7 @@
"@angular/localize": "^22.2.0",
"@angular/router": "^22.2.0",
"@fortawesome/free-solid-svg-icons": "^7.3.1",
"@service-soft/ui": "^22.3.1",
"@service-soft/ui": "^22.3.2",
"tailwindcss": "^4.3.3",
"uqr": "^0.1.3",
"zibri-contract": "^3.2.0"
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-change-sets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@service-soft/ngx-change-sets",
"version": "22.3.1",
"version": "22.3.2",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -23,7 +23,7 @@
"@angular/core": "^22.2.0",
"@angular/localize": "^22.2.0",
"@fortawesome/free-solid-svg-icons": "^7.3.1",
"@service-soft/ui": "^22.3.1",
"@service-soft/ui": "^22.3.2",
"tailwindcss": "^4.3.3",
"zibri-contract": "^3.1.0"
},
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-ecommerce/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@service-soft/ngx-ecommerce",
"version": "22.3.1",
"version": "22.3.2",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -23,7 +23,7 @@
"@angular/core": "^22.2.0",
"@angular/localize": "^22.2.0",
"@fortawesome/free-solid-svg-icons": "^7.3.1",
"@service-soft/ui": "^22.3.1",
"@service-soft/ui": "^22.3.2",
"tailwindcss": "^4.3.3"
},
"sideEffects": false
Expand Down
8 changes: 4 additions & 4 deletions projects/ngx-entity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@service-soft/ngx-entity",
"version": "22.3.1",
"version": "22.3.2",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -23,9 +23,9 @@
"@angular/core": "^22.2.0",
"@angular/localize": "^22.2.0",
"@angular/router": "^22.2.0",
"@service-soft/ngx-error-handling": "^22.3.1",
"@service-soft/ngx-pwa": "^22.3.1",
"@service-soft/ui": "^22.3.1",
"@service-soft/ngx-error-handling": "^22.3.2",
"@service-soft/ngx-pwa": "^22.3.2",
"@service-soft/ui": "^22.3.2",
"tailwindcss": "^4.3.3",
"zibri-contract": "^3.1.0"
},
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-error-handling/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@service-soft/ngx-error-handling",
"version": "22.3.1",
"version": "22.3.2",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -22,7 +22,7 @@
"@angular/common": "^22.2.0",
"@angular/core": "^22.2.0",
"@angular/localize": "^22.2.0",
"@service-soft/ui": "^22.3.1",
"@service-soft/ui": "^22.3.2",
"tailwindcss": "^4.3.3",
"zibri-contract": "^3.1.0"
},
Expand Down
14 changes: 9 additions & 5 deletions projects/ngx-navigation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Your Tailwind generates the css. Add both packages to your global stylesheet:
@import "@service-soft/ngx-navigation";
```

A title is drawn in the font of the token `--font-nav-title`, the font of headings by default. Set it in your `@theme` when your name has a font of its own, like the one of your wordmark: `--font-nav-title: "Orbitron", var(--font-heading);`.

Every part lives in its own entry point, so a page only loads what it uses: `@service-soft/ngx-navigation/navbar`, `/footer`, `/anchors`, `/breadcrumbs`, `/secondary-nav`, `/language-switcher`, `/not-found`, and one for the component of each type of element, like `/nav-link`. The models and `NavigationUtilities` are in `/navigation`.

# The navbar
Expand Down Expand Up @@ -93,7 +95,7 @@ The navbar is a `<header>` with a `<nav>` inside, labelled "Navigation". Each ro
|---|---|---|---|
| `title` | the name of the app, linked when it has a `link` | `title`, `icon?`, `link?` | `NavTitleComponent` of `/nav-title` |
| `image` | an image like the logo, linked when it has a `link`, shown with `NgOptimizedImage` | `url`, `alt`, `width`, `height`, `link?` | `NavImageComponent` of `/nav-image` |
| `link` | a link, to a route of the app with `route`, or to another site with `url` | `name`, `icon?`, `route` or `url`, `fragment?`, `openInNewTab?` | `NavLinkComponent` of `/nav-link` |
| `link` | a link, to a route of the app with `route`, or to another site with `url` | `name`, `icon?`, `route` or `url`, `fragment?`, `openInNewTab?`, `variant?` and `color?` (of `ui-button`: drawn as a button in a row, like a call to action; a link in the drawer and in menus) | `NavLinkComponent` of `/nav-link` |
| `button` | a button that runs an action | `name`, `icon?`, `variant?` (of `ui-button`, `'text'` by default), `action` | `NavButtonComponent` of `/nav-button` |
| `menu` | links, buttons, menus and custom components under one name; a menu inside opens beside it | `name`, `icon?`, `elements` | `NavMenuComponent` of `/nav-menu` |
| `text` | plain text, like the copyright in the footer | `text` | `NavTextComponent` of `/nav-text` |
Expand All @@ -104,7 +106,7 @@ A `link` of a title or an image is `{ route }` or `{ url }`, like the fields of
## Components of the elements
The navbar and the footer import none of the components of the elements: `components` brings the ones their rows need, so a navbar with only a title and links never ships the code of images, menus or buttons. A menu shows the links, buttons and menus inside of it itself, so only its own type counts.

A `custom` component inside a menu shows in the menu, and in the drawer once the menu collapsed. `inject(MenuComponent, { optional: true })` of `@service-soft/ui/menu` tells it where it is, so it shows its actions as `ui-menu-item` or `ui-menu-link` in the menu, like the other items, and as buttons or links in the drawer.
A `custom` component inside a menu shows in the menu, and in the drawer once the menu collapsed. `inject(MenuComponent, { optional: true })` of `@service-soft/ui/menu` tells it where it is, so it shows its actions as `ui-menu-item` or `ui-menu-link` in the menu, like the other items, and as buttons or links in the drawer. In the drawer, `inject(IS_IN_DRAWER)` of `@service-soft/ui/drawer` is true, like for a button that is only an icon in the row and has the room for its text in the drawer, as the [theme switcher](https://www.npmjs.com/package/@service-soft/ui#theme-switcher) and the [language switcher](#language-switcher) do.

Development builds throw when a type of the rows has no component, and when there is a component for a type no element has, as it would only make the bundle bigger. An element whose `condition` hides it still counts, as it may show later. Production builds leave the check out, and an element without a component shows nothing.

Expand Down Expand Up @@ -246,14 +248,15 @@ protected readonly languages: LanguageSwitcherLanguage[] = [

```html
<ngx-language-switcher [languages]="languages" />
<ngx-language-switcher appearance="icon" [languages]="languages" />
<ngx-language-switcher appearance="list" [languages]="languages" />
```

| Input | Values | Default |
|---|---|---|
| `languages` | `LanguageSwitcherLanguage[]` | required — `code`, `label`, `subPath`, the path its build is served below, its code when it has none, and `href`, a fixed address or a function of the url of the current page; the `href` of the config when it has none |
| `current` | `string` | the `LOCALE_ID` of the app — the code of the language of the page; `en` counts for `en-US` when no code is the same |
| `appearance` | `'menu'` \| `'list'` | `'menu'` — a button with a globe and the current language that opens a [menu](https://www.npmjs.com/package/@service-soft/ui#menu) of all of them, or a row of links |
| `appearance` | `'menu'` \| `'icon'` \| `'list'` | `'menu'` — a button with the icon of languages and the current language that opens a [menu](https://www.npmjs.com/package/@service-soft/ui#menu) of all of them, the same button with only the icon, like the theme switcher beside it, or a row of links. Inside of a `ui-drawer`, like the drawer of the navbar, the button of `'menu'` and `'icon'` is a row of the drawer with the current language |
| `label` | `string` | `'Language'` — what screen readers call it; the button is named "Language: English" |

The link to the current page in a language has its code as `hreflang` and `lang`, so search engines know the page in that language, and screen readers read its name in it. The one of the current language is marked with a check in the menu, underlined in the row, and tells screen readers that it is the current page. The links are plain hrefs, which load the page in the other language. By default they go to `/<subPath><url>`, like `/de/orders?page=2`, where Angular's i18n puts the build of every language. Give a language whose path isn't its code its `subPath`, like `{ code: 'de-CH', label: 'Deutsch', subPath: 'de' }`, the same as the `subPath` of its [SEO locale](#several-languages). Change the links for all languages with `provideLanguageSwitcherConfig({ href: (url, code, subPath) => … })`, and the `label`, the `icon` and the `appearance` there as well. Inside of a `ui-menu`, like a menu of the navbar as a `custom` element, its links are items of that menu.
Expand Down Expand Up @@ -361,14 +364,15 @@ Every part reads its defaults and texts from a config, which `provideXConfig` ch

| Provider | Option | Default |
|---|---|---|
| `provideNavbarConfig` | `collapse` | `'sm'` — for the elements without a collapse of their own |
| `provideNavbarConfig` | `color` | `'surface'` — or `'primary'` / `'secondary'`, a [colored surface](../ui/README.md#colored-surfaces) of ui, like the brand color behind a white wordmark. Also the input `color` of `ngx-navbar`. A colored navbar looks the same in both modes and takes the shadow of dark mode, which also shows on a section of its color below it, like a hero. The drawer keeps the colors of the page |
| | `collapse` | `'sm'` — for the elements without a collapse of their own |
| | `menuIcon` | `faBars` — the icon of the button that opens the drawer |
| | `labels` | `navigation: 'Navigation'`, `openNavigation: 'Open the navigation'` |
| `provideNavigationConfig` | `labels` | `home: 'Home'` — the first step of the breadcrumbs, `anchors: 'On this page'` — what screen readers call the links to the sections |
| | `routeCondition` | every link shows — see [conditions and actions](#conditions-and-actions) |
| `provideSeoConfig` | `origin`, `defaultImage`, `locales` | required, none, `[]` — see [SEO](#seo) |
| `provideNotFoundConfig` | `title`, `message`, `homeLabel`, `homeRoute`, `icon` | `'Page not found'`, a sentence, `'Back to the start page'`, `'/'`, `faSignsPost` |
| `provideLanguageSwitcherConfig` | `appearance`, `label`, `icon`, `href` | `'menu'`, `'Language'`, `faGlobe`, `(url, code, subPath) => '/' + subPath + url` |
| `provideLanguageSwitcherConfig` | `appearance`, `label`, `icon`, `href` | `'menu'`, `'Language'`, `faLanguage`, `(url, code, subPath) => '/' + subPath + url` |
| `provideBreadcrumbsConfig` of `@service-soft/ui/breadcrumbs` | `label` | `'Breadcrumbs'` — what screen readers call the breadcrumbs |
| `provideDrawerConfig` of `@service-soft/ui/drawer` | `side` | `'start'` — the edge the drawer slides in from |

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* How the language switcher shows the languages: in a menu behind a button with the current one, or as a row of links.
* How the language switcher shows the languages: in a menu behind a button with the current one, in a menu behind a
* button with only the icon, or as a row of links.
*/
export type LanguageSwitcherAppearance = 'menu' | 'list';
export type LanguageSwitcherAppearance = 'menu' | 'icon' | 'list';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, InjectionToken, Provider } from '@angular/core';
import { faGlobe } from '@fortawesome/free-solid-svg-icons';
import { faLanguage } from '@fortawesome/free-solid-svg-icons';

import { LanguageSwitcherConfig } from './language-switcher-config.model';

Expand All @@ -12,7 +12,9 @@ function getDefaultLanguageSwitcherConfig(): LanguageSwitcherConfig {
return {
appearance: 'menu',
label: $localize`:@@ngx-navigation.language-switcher.label:Language`,
icon: faGlobe,
// characters of two scripts, the sign of language and translation, which a globe, the sign of a region or of
// the web, is not
icon: faLanguage,
// a build for every language under its own path, like Angular's i18n makes them: /de/orders and /en/orders.
href: (url, code, subPath) => `/${subPath}${url}`
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
@if (isInMenu) {
<ngx-language-menu-items [items]="items()" />
} @else if (appearance() === 'menu') {
<!-- named by the label and the current language, which it shows, so a voice command with what it shows hits it -->
<button ui-button type="button" variant="text" [uiMenuTrigger]="menu">
<ui-icon [icon]="icon" />
@if (currentItem(); as current) {
<!-- the space inside, Angular drops the ones between elements -->
<span class="sr-only">{{ label() }}: </span><span [lang]="current.code">{{ current.label }}</span>
} @else {
{{ label() }}
}
</button>
<ui-menu #menu>
<ngx-language-menu-items [items]="items()" />
</ui-menu>
} @else {
} @else if (appearance() === 'list') {
<nav [attr.aria-label]="label()">
<ul class="flex flex-wrap gap-1">
@for (item of items(); track item.code) {
Expand All @@ -33,4 +19,35 @@
}
</ul>
</nav>
} @else {
@if (isInDrawer) {
<!-- a row of the drawer, like its links, which has the room for the current language as an icon does too -->
<button ui-link appearance="nav" block type="button" [uiMenuTrigger]="menu">
<ui-icon [icon]="icon" />
<span><ng-container [ngTemplateOutlet]="name" /></span>
</button>
} @else if (appearance() === 'icon') {
<!-- like the theme switcher beside it: the label and the current language only for screen readers -->
<button ui-button type="button" variant="text" iconOnly [attr.aria-label]="buttonLabel()" [uiMenuTrigger]="menu">
<ui-icon [icon]="icon" />
</button>
} @else {
<!-- named by the label and the current language, which it shows, so a voice command with what it shows hits it -->
<button ui-button type="button" variant="text" [uiMenuTrigger]="menu">
<ui-icon [icon]="icon" />
<ng-container [ngTemplateOutlet]="name" />
</button>
}
<ui-menu #menu>
<ngx-language-menu-items [items]="items()" />
</ui-menu>
}

<ng-template #name>
@if (currentItem(); as current) {
<!-- the space inside, Angular drops the ones between elements -->
<span class="sr-only">{{ label() }}: </span><span [lang]="current.code">{{ current.label }}</span>
} @else {
{{ label() }}
}
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, LOCALE_ID } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { provideRouter } from '@angular/router';
import { RouterTestingHarness } from '@angular/router/testing';
import { DrawerComponent } from '@service-soft/ui/drawer';
import { MenuComponent } from '@service-soft/ui/menu';
import { describe, expect, test } from 'vitest';

Expand Down Expand Up @@ -39,6 +40,17 @@ class RegionalPageComponent {
];
}

// the switcher as an icon, like in a navbar: in its row, and in its drawer
@Component({
selector: 'ngx-icon-page',
template: `<div><ngx-language-switcher appearance="icon" [languages]="languages" /></div>
<div><ui-drawer label="Navigation"><ngx-language-switcher appearance="icon" [languages]="languages" /></ui-drawer></div>`,
imports: [LanguageSwitcherComponent, DrawerComponent]
})
class IconPageComponent {
readonly languages: LanguageSwitcherLanguage[] = LANGUAGES;
}

// the text, the href, the hreflang, the lang and the aria-current of a link.
type LinkAttributes = [string, ...(string | undefined)[]];

Expand Down Expand Up @@ -116,4 +128,20 @@ describe('LanguageSwitcherComponent', () => {
'https://fr.example.ch/orders?page=2#fr-CH'
]);
});

test('shows only the icon, named by the current language, and in a drawer a row of it with the language', async () => {
TestBed.configureTestingModule({ providers: [provideRouter([{ path: '**', component: IconPageComponent }])] });
const [row, drawer] = await render();

const iconButton: HTMLButtonElement | null | undefined = row?.querySelector('button[ui-button]');
expect(iconButton?.getAttribute('aria-label')).toBe('Language: English');
expect(iconButton?.textContent.trim()).toBe('');
expect(findLinks(row).map(([text]) => text)).toEqual(['Deutsch', 'English', 'Français', 'Nederlands']);

// a row like the links of the drawer, not a button of its own
const drawerButton: HTMLButtonElement | null | undefined = drawer?.querySelector('button[ui-link]');
expect(drawerButton?.getAttribute('aria-label')).toBeNull();
expect(drawerButton?.textContent.replaceAll(/\s+/g, ' ').trim()).toBe('Language: English');
expect(drawerButton?.querySelector('[lang="en"]')).not.toBeNull();
});
});
Loading
Loading