ngx-kit 6.0.1 → 6.1.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/angle-selector/README.md +11 -11
- package/box-shadow/README.md +10 -10
- package/color-picker/README.md +20 -23
- package/data-table/README.md +34 -41
- package/date-picker/README.md +21 -26
- package/dialog/README.md +31 -33
- package/drawer-menu/README.md +51 -50
- package/dropzone/README.md +395 -32
- package/fesm2022/ngx-kit-box-shadow.mjs +2 -2
- package/fesm2022/ngx-kit-box-shadow.mjs.map +1 -1
- package/fesm2022/ngx-kit-color-picker.mjs +2 -2
- package/fesm2022/ngx-kit-color-picker.mjs.map +1 -1
- package/fesm2022/ngx-kit-data-table.mjs +68 -26
- package/fesm2022/ngx-kit-data-table.mjs.map +1 -1
- package/fesm2022/ngx-kit-dropzone.mjs +274 -29
- package/fesm2022/ngx-kit-dropzone.mjs.map +1 -1
- package/fesm2022/ngx-kit-form-field.mjs +129 -64
- package/fesm2022/ngx-kit-form-field.mjs.map +1 -1
- package/fesm2022/ngx-kit-gallery.mjs +2 -2
- package/fesm2022/ngx-kit-gallery.mjs.map +1 -1
- package/fesm2022/ngx-kit-gradient-picker.mjs +2 -2
- package/fesm2022/ngx-kit-gradient-picker.mjs.map +1 -1
- package/fesm2022/ngx-kit-image-editor.mjs +33 -10
- package/fesm2022/ngx-kit-image-editor.mjs.map +1 -1
- package/fesm2022/ngx-kit-message.mjs +5 -0
- package/fesm2022/ngx-kit-message.mjs.map +1 -1
- package/fesm2022/ngx-kit-time-picker.mjs +17 -4
- package/fesm2022/ngx-kit-time-picker.mjs.map +1 -1
- package/gallery/README.md +29 -29
- package/gradient-picker/README.md +16 -16
- package/image-editor/README.md +19 -19
- package/menu/README.md +27 -27
- package/message/README.md +34 -34
- package/notify/README.md +25 -23
- package/package.json +1 -1
- package/shared/README.md +32 -32
- package/time-picker/README.md +95 -0
- package/types/ngx-kit-data-table.d.ts +25 -5
- package/types/ngx-kit-dropzone.d.ts +129 -18
- package/types/ngx-kit-form-field.d.ts +65 -27
- package/types/ngx-kit-image-editor.d.ts +23 -3
- package/types/ngx-kit-time-picker.d.ts +19 -14
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
# ngx-kit/gradient-picker
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A linear/radial gradient picker with multiple draggable color stops, outputting a ready-to-use CSS string.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install ngx-kit
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
13
|
```html
|
|
14
14
|
<ngx-input-gradient [(ngModel)]="gradientCss"></ngx-input-gradient>
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Or as a directive on a plain input:
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
20
|
<input type="text" [ngxInputGradient]="gradientCss" (change)="gradientCss = $event" />
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
The output is a valid CSS string like `linear-gradient(90deg, #ff0000 0%, #0000ff 100%)`, ready to use directly in `background`/`background-image`.
|
|
24
24
|
|
|
25
25
|
## API
|
|
26
26
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
| `theme`
|
|
30
|
-
| `setInputBackground`
|
|
31
|
-
| `change`
|
|
27
|
+
| Input | Type | Default | Description |
|
|
28
|
+
| --- | --- | --- | --- |
|
|
29
|
+
| `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | Panel theme |
|
|
30
|
+
| `setInputBackground` *(directive)* | `boolean` | `true` | Sets the input's background to the selected gradient |
|
|
31
|
+
| `change` *(directive)* | `EventEmitter<string>` | | The new gradient string |
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## UI notes
|
|
34
34
|
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
35
|
+
- Add a color stop by clicking on the gradient bar; drag to move it.
|
|
36
|
+
- Double-click a stop to remove it (or use the delete button if shown).
|
|
37
|
+
- Each stop's color is edited with the same `ngx-kit/color-picker` panel (this package depends on it).
|
|
38
38
|
|
|
39
|
-
##
|
|
39
|
+
## Dark mode and RTL
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Supported automatically.
|
package/image-editor/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# ngx-kit/image-editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An image editor built on raw Canvas: crop with draggable corner handles, rotation (quick 90° and free), brightness/contrast/saturation, built-in filters (grayscale, sepia, invert), a **real cartoon filter** (posterize + Sobel edge detection, hand-implemented since there's no native equivalent), and output compression with adjustable quality.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install ngx-kit
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
13
|
```html
|
|
14
14
|
<ngx-image-editor [source]="selectedFile" (saved)="onSaved($event)" (cancelled)="onCancelled()" />
|
|
@@ -16,29 +16,29 @@ npm install ngx-kit
|
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
onSaved(result: NgxImageEditorResult) {
|
|
19
|
-
// result.blob (
|
|
19
|
+
// result.blob (for uploading), result.dataUrl (for an instant preview), result.width/height
|
|
20
20
|
}
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## API
|
|
24
24
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
| `source`
|
|
28
|
-
| `aspectRatio`
|
|
29
|
-
| `outputMaxWidth` / `outputMaxHeight` | `number`
|
|
30
|
-
| `outputType`
|
|
31
|
-
| `displayMaxWidth`
|
|
25
|
+
| Input | Type | Default | Description |
|
|
26
|
+
| --- | --- | --- | --- |
|
|
27
|
+
| `source` | `File \| Blob \| string \| null` **(required)** | | The source file/blob/data URL |
|
|
28
|
+
| `aspectRatio` | `number` | free | Lock the crop's aspect ratio (e.g. `1` for a square avatar) |
|
|
29
|
+
| `outputMaxWidth` / `outputMaxHeight` | `number` | unlimited | Resize the final output's dimensions |
|
|
30
|
+
| `outputType` | `'image/jpeg' \| 'image/png' \| 'image/webp'` | `'image/jpeg'` | |
|
|
31
|
+
| `displayMaxWidth` | `number` | `420` | Max display width for the crop area on screen |
|
|
32
32
|
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
| `saved`
|
|
36
|
-
| `cancelled` | `void`
|
|
33
|
+
| Output | Type | Description |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| `saved` | `NgxImageEditorResult` (`{ blob, dataUrl, width, height }`) | |
|
|
36
|
+
| `cancelled` | `void` | |
|
|
37
37
|
|
|
38
|
-
##
|
|
38
|
+
## Internal architecture (why it's fast)
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
All live interaction (rotating, moving/resizing the crop box, previewing filters including cartoon) happens on a downscaled copy of the image (max 1200px) — only when you call `save()` is the final render done from the full-resolution original. `brightness`/`contrast`/`saturate`/`grayscale`/`sepia`/`invert` are all implemented with Canvas 2D's native `ctx.filter` (browser-accelerated); only the cartoon filter (which has no native equivalent) is done with separate pixel processing.
|
|
41
41
|
|
|
42
|
-
##
|
|
42
|
+
## Dark mode and RTL
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
Supported automatically.
|
package/menu/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# ngx-kit/menu
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Dropdown menu and context (right-click) menu, with smart positioning relative to an anchor (via `ngx-kit/shared`'s `OverlayService`).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install ngx-kit
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Basic usage (dropdown menu)
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
import { NgxMenuModule } from 'ngx-kit/menu';
|
|
@@ -17,57 +17,57 @@ import { NgxMenuModule } from 'ngx-kit/menu';
|
|
|
17
17
|
standalone: true,
|
|
18
18
|
imports: [NgxMenuModule],
|
|
19
19
|
template: `
|
|
20
|
-
<button [ngxMenu]="userMenu"
|
|
20
|
+
<button [ngxMenu]="userMenu">Open menu</button>
|
|
21
21
|
|
|
22
22
|
<ngx-menu #userMenu="ngxMenu">
|
|
23
|
-
<ngx-menu-item (click)="editProfile()"
|
|
24
|
-
<ngx-menu-item (click)="logout()"
|
|
23
|
+
<ngx-menu-item (click)="editProfile()">Edit profile</ngx-menu-item>
|
|
24
|
+
<ngx-menu-item (click)="logout()">Sign out</ngx-menu-item>
|
|
25
25
|
<ngx-menu-divider></ngx-menu-divider>
|
|
26
|
-
<ngx-menu-item [ngxMenu]="subMenu"
|
|
26
|
+
<ngx-menu-item [ngxMenu]="subMenu">More settings ›</ngx-menu-item>
|
|
27
27
|
</ngx-menu>
|
|
28
28
|
|
|
29
29
|
<ngx-menu #subMenu="ngxMenu">
|
|
30
|
-
<ngx-menu-item
|
|
31
|
-
<ngx-menu-item
|
|
30
|
+
<ngx-menu-item>Option A</ngx-menu-item>
|
|
31
|
+
<ngx-menu-item>Option B</ngx-menu-item>
|
|
32
32
|
</ngx-menu>
|
|
33
33
|
`,
|
|
34
34
|
})
|
|
35
35
|
export class MyComponent {}
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
Important: `<ngx-menu>`'s content isn't rendered until it's triggered via `[ngxMenu]` (or `[ngxContextMenu]`) — so you can't use `<ngx-menu>` directly, without a trigger, as an always-visible list (like a sidebar). For that, use a regular list styled similarly.
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
Nested menus (submenus) work exactly as shown above, just by putting `[ngxMenu]` on the `<ngx-menu-item>` itself.
|
|
41
41
|
|
|
42
|
-
##
|
|
42
|
+
## Right-click (context) menu
|
|
43
43
|
|
|
44
44
|
```html
|
|
45
|
-
<div [ngxContextMenu]="rightClickMenu"
|
|
45
|
+
<div [ngxContextMenu]="rightClickMenu">Right-click me</div>
|
|
46
46
|
|
|
47
47
|
<ngx-menu #rightClickMenu="ngxMenu">
|
|
48
|
-
<ngx-menu-item
|
|
49
|
-
<ngx-menu-item
|
|
48
|
+
<ngx-menu-item>Copy</ngx-menu-item>
|
|
49
|
+
<ngx-menu-item>Paste</ngx-menu-item>
|
|
50
50
|
</ngx-menu>
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
## API
|
|
54
54
|
|
|
55
|
-
###
|
|
55
|
+
### `[ngxMenu]` directive
|
|
56
56
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
| `ngxMenu`
|
|
60
|
-
| `placement` | `'top' \| 'bottom' \| 'auto'` |
|
|
57
|
+
| Input | Type | Description |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| `ngxMenu` | `NgxMenu \| TemplateRef` | Reference to the menu to open |
|
|
60
|
+
| `placement` | `'top' \| 'bottom' \| 'auto'` | Opening direction; defaults to `'auto'` (picked automatically if there isn't enough room) |
|
|
61
61
|
|
|
62
62
|
### `<ngx-menu>`
|
|
63
63
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
| `class` | `string` |
|
|
64
|
+
| Input | Type | Description |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| `class` | `string` | Extra CSS class on the panel |
|
|
67
67
|
|
|
68
|
-
###
|
|
68
|
+
### Styling
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
Via CSS custom properties:
|
|
71
71
|
|
|
72
72
|
```css
|
|
73
73
|
ngx-menu {
|
|
@@ -80,6 +80,6 @@ ngx-menu {
|
|
|
80
80
|
}
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
##
|
|
83
|
+
## Dark mode and RTL
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
Both are supported automatically (via `ngx-kit/shared`'s `OverlayService`/`DirectionService` and `light-dark()`); no extra work needed.
|
package/message/README.md
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
1
|
# ngx-kit/message
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Alert/confirm dialogs (SweetAlert-style), with a static API callable from anywhere in the app.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install ngx-kit
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Setup
|
|
12
12
|
|
|
13
|
-
```
|
|
13
|
+
```ts
|
|
14
14
|
// app.config.ts
|
|
15
15
|
import { provideMessage } from 'ngx-kit/message';
|
|
16
16
|
|
|
17
17
|
export const appConfig: ApplicationConfig = {
|
|
18
|
-
providers: [provideMessage({ confirmButtonText: '
|
|
18
|
+
providers: [provideMessage({ confirmButtonText: 'OK' /* global defaults */ })],
|
|
19
19
|
};
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Usage
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
25
|
import { MSG } from 'ngx-kit/message';
|
|
26
26
|
|
|
27
|
-
MSG.success('
|
|
28
|
-
MSG.error('
|
|
29
|
-
MSG.warning('
|
|
30
|
-
MSG.info('
|
|
31
|
-
MSG.question('
|
|
32
|
-
MSG.loading('
|
|
27
|
+
MSG.success('Saved!', 'Your changes were saved successfully.');
|
|
28
|
+
MSG.error('Error', 'Something went wrong.');
|
|
29
|
+
MSG.warning('Warning', 'Are you sure?');
|
|
30
|
+
MSG.info('Heads up', 'This is an informational message.');
|
|
31
|
+
MSG.question('Question', 'Continue?');
|
|
32
|
+
MSG.loading('Processing…');
|
|
33
33
|
|
|
34
|
-
//
|
|
34
|
+
// full control over options:
|
|
35
35
|
const result = MSG.show({
|
|
36
|
-
title: '
|
|
37
|
-
text: '
|
|
36
|
+
title: 'Delete this?',
|
|
37
|
+
text: 'This action cannot be undone.',
|
|
38
38
|
showCancelButton: true,
|
|
39
39
|
showDenyButton: true,
|
|
40
|
-
confirmButtonText: '
|
|
40
|
+
confirmButtonText: 'Yes, delete it',
|
|
41
41
|
});
|
|
42
42
|
result.afterClose.subscribe((r) => console.log(r));
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
## API
|
|
46
46
|
|
|
47
|
-
### `MSG` (
|
|
47
|
+
### `MSG` (and its alias `Modal`)
|
|
48
48
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
| `show(options?)`
|
|
52
|
-
| `info` / `success` / `warning` / `error` / `question` / `loading` | `(title, text?, options?)` |
|
|
49
|
+
| Method | Signature | Description |
|
|
50
|
+
| --- | --- | --- |
|
|
51
|
+
| `show(options?)` | `IMessageOptions` | Full control |
|
|
52
|
+
| `info` / `success` / `warning` / `error` / `question` / `loading` | `(title, text?, options?)` | Common shortcuts |
|
|
53
53
|
|
|
54
|
-
### `IMessageOptions` (
|
|
54
|
+
### `IMessageOptions` (key fields)
|
|
55
55
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
| `title` / `text` / `html`
|
|
59
|
-
| `icon`
|
|
60
|
-
| `showConfirmButton` / `showDenyButton` / `showCancelButton` | `boolean`
|
|
61
|
-
| `confirmButtonText` / `denyButtonText` / `cancelButtonText` | `string`
|
|
62
|
-
| `allowOutsideClick` / `allowEscapeKey` / `allowEnterKey`
|
|
63
|
-
| `showCloseButton`
|
|
64
|
-
| `useOverlay`
|
|
56
|
+
| Field | Type | Default | Description |
|
|
57
|
+
| --- | --- | --- | --- |
|
|
58
|
+
| `title` / `text` / `html` | `string` | | Content (`html` is not sanitized — escaping is your responsibility) |
|
|
59
|
+
| `icon` | `MessageIcon` | | Icon shown |
|
|
60
|
+
| `showConfirmButton` / `showDenyButton` / `showCancelButton` | `boolean` | `true` / `false` / `false` | |
|
|
61
|
+
| `confirmButtonText` / `denyButtonText` / `cancelButtonText` | `string` | `'OK'` / `'No'` / `'Cancel'` | |
|
|
62
|
+
| `allowOutsideClick` / `allowEscapeKey` / `allowEnterKey` | `boolean` | `true` | How the message can be dismissed |
|
|
63
|
+
| `showCloseButton` | `boolean` | `false` | The ✕ button |
|
|
64
|
+
| `useOverlay` | `boolean` | | For when it's used inside another dialog (e.g. Angular Material), raises the display layer to the top |
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
If several messages are open at once, Escape/Enter only affect the **last (topmost) message**, not all of them.
|
|
67
67
|
|
|
68
|
-
##
|
|
68
|
+
## Dark mode and RTL
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
Supported automatically.
|
package/notify/README.md
CHANGED
|
@@ -1,56 +1,58 @@
|
|
|
1
1
|
# ngx-kit/notify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Corner toast notifications, with a static API, automatic queueing (once the visible count exceeds the limit), and the timer pausing on hover.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install ngx-kit
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Setup
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
// app.config.ts
|
|
15
15
|
import { provideNotify } from 'ngx-kit/notify';
|
|
16
16
|
|
|
17
17
|
export const appConfig: ApplicationConfig = {
|
|
18
|
-
providers: [
|
|
18
|
+
providers: [
|
|
19
|
+
provideNotify({ timeout: 4000, position: 'top-center', dismissible: true }),
|
|
20
|
+
],
|
|
19
21
|
};
|
|
20
22
|
```
|
|
21
23
|
|
|
22
|
-
##
|
|
24
|
+
## Usage
|
|
23
25
|
|
|
24
26
|
```ts
|
|
25
27
|
import { Notify } from 'ngx-kit/notify';
|
|
26
28
|
|
|
27
|
-
Notify.success('
|
|
28
|
-
Notify.error('
|
|
29
|
-
Notify.warning('
|
|
30
|
-
Notify.info('
|
|
29
|
+
Notify.success('Saved');
|
|
30
|
+
Notify.error('We couldn\'t send your message', 'Try again');
|
|
31
|
+
Notify.warning('Weak connection');
|
|
32
|
+
Notify.info('A new version is available', undefined, { timeout: 8000 });
|
|
31
33
|
```
|
|
32
34
|
|
|
33
35
|
## API
|
|
34
36
|
|
|
35
37
|
### `Notify`
|
|
36
38
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
+
| Method | Signature |
|
|
40
|
+
| --- | --- |
|
|
39
41
|
| `show(type, message, description?, options?)` | `type: 'info' \| 'success' \| 'warning' \| 'error'` |
|
|
40
|
-
| `info` / `success` / `warning` / `error`
|
|
42
|
+
| `info` / `success` / `warning` / `error` | `(message, description?, options?)` |
|
|
41
43
|
|
|
42
44
|
### `NgxNotifyOptions`
|
|
43
45
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
| `timeout`
|
|
47
|
-
| `position`
|
|
48
|
-
| `maxVisible`
|
|
49
|
-
| `allowHtml`
|
|
50
|
-
| `pauseOnHover` | `boolean`
|
|
51
|
-
| `dismissible`
|
|
52
|
-
| `closeOnTap`
|
|
46
|
+
| Field | Type | Default | Description |
|
|
47
|
+
| --- | --- | --- | --- |
|
|
48
|
+
| `timeout` | `number` (ms) | `3000` | How long it's shown before auto-dismissing |
|
|
49
|
+
| `position` | `NgxNotifyPositionType` | `'top-center'` | Corner/center to display in |
|
|
50
|
+
| `maxVisible` | `number` | `10` | Beyond this count, notifications queue instead of overlapping |
|
|
51
|
+
| `allowHtml` | `boolean` | `false` | If `true`, the message is rendered as HTML (not sanitized) |
|
|
52
|
+
| `pauseOnHover` | `boolean` | `true` | The timer pauses while the mouse hovers |
|
|
53
|
+
| `dismissible` | `boolean` | `true` | Show a close button |
|
|
54
|
+
| `closeOnTap` | `boolean` | `true` | Clicking the notification itself closes it |
|
|
53
55
|
|
|
54
|
-
##
|
|
56
|
+
## Dark mode and RTL
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
Supported automatically.
|
package/package.json
CHANGED
package/shared/README.md
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
# ngx-kit/shared
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared utilities and services that the rest of the `ngx-kit` packages are built on: overlay/dialog management, page-direction (RTL/LTR) detection, browser-preference detection, and a few reusable base components (slider, range slider, color-saturation panel).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
You usually won't need this package directly — the other packages depend on it automatically. But if you're building a custom component that should stay consistent with the rest of the library (dark mode, RTL, drag performance), use these same utilities.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm install ngx-kit
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Import the base styles (which enable dark mode via `color-scheme`) once, app-wide:
|
|
14
14
|
|
|
15
15
|
```scss
|
|
16
16
|
// styles.scss
|
|
17
17
|
@import 'ngx-kit/styles/all.css';
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Services
|
|
21
21
|
|
|
22
22
|
### `OverlayService`
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
The engine behind everything floating in the library (menus, dialogs, the color/gradient/angle picker popups). Renders an Angular component inside a native `<dialog>` (`showModal()`) and positions it relative to an anchor.
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
27
|
import { OverlayService } from 'ngx-kit/shared';
|
|
@@ -38,20 +38,20 @@ const ref = overlay.open({
|
|
|
38
38
|
margin: 8,
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
ref.close(); // OverlayRef.close()
|
|
41
|
+
ref.close(); // OverlayRef.close() takes no argument and has no afterClosed; for that (return value, afterClosed) use ngx-kit/dialog, which is built on top of this service
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
What's handled for you automatically:
|
|
45
45
|
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
- **RTL
|
|
46
|
+
- **Smart positioning**: if there isn't enough room below the anchor, it flips above (`placement: 'auto'`).
|
|
47
|
+
- **Click-outside dismissal**: detected via the backdrop click, not a global `document` listener.
|
|
48
|
+
- **Correct stacking**: multiple simultaneous overlays (e.g. a menu with a submenu) work correctly; Escape only closes the last (topmost) overlay.
|
|
49
|
+
- **Focus restoration**: after closing, focus returns to whatever had focus before the overlay opened (accessibility).
|
|
50
|
+
- **Automatic RTL**: alignment and placement are computed against the page's actual direction (not a fixed assumption).
|
|
51
51
|
|
|
52
52
|
### `DirectionService`
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
A signal (`isRtl(): boolean`) that watches the `<html>` element's `dir` attribute with a `MutationObserver` and updates reactively the moment it changes — so if your app switches languages at runtime, everything stays in sync automatically.
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
57
|
const direction = inject(DirectionService);
|
|
@@ -62,14 +62,14 @@ direction.isRtl(); // signal<boolean>
|
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
64
|
const browser = inject(BrowserService);
|
|
65
|
-
browser.prefersDarkMode; // boolean —
|
|
65
|
+
browser.prefersDarkMode; // boolean — read once at service construction time
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
##
|
|
68
|
+
## Utilities
|
|
69
69
|
|
|
70
70
|
### `startDragSession(callbacks)`
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
Replaces the problematic `@HostListener('document:mousemove', ...)` pattern, which keeps a listener attached to `document` for the entire lifetime of the component — even when nothing is being dragged (a real performance issue on pages with many simultaneous instances). This function only adds a listener for the duration of an actual drag and removes it itself; `touchmove` is handled with `{passive: false}`, so dragging on mobile doesn't also scroll the page.
|
|
73
73
|
|
|
74
74
|
```ts
|
|
75
75
|
import { startDragSession } from 'ngx-kit/shared';
|
|
@@ -80,7 +80,7 @@ function onPointerDown(ev: MouseEvent | TouchEvent) {
|
|
|
80
80
|
stop?.();
|
|
81
81
|
stop = startDragSession({
|
|
82
82
|
onMove: (ev) => {
|
|
83
|
-
/*
|
|
83
|
+
/* update position */
|
|
84
84
|
},
|
|
85
85
|
onEnd: () => {
|
|
86
86
|
stop = undefined;
|
|
@@ -89,29 +89,29 @@ function onPointerDown(ev: MouseEvent | TouchEvent) {
|
|
|
89
89
|
}
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
>
|
|
92
|
+
> If your component is `OnPush` and uses `startDragSession` (instead of `@HostListener`), make sure to call `ChangeDetectorRef.markForCheck()` inside `onMove`/`onEnd` yourself — unlike `@HostListener`, which automatically marks the view dirty, a manual `addEventListener` does not.
|
|
93
93
|
|
|
94
94
|
### `getOffsetPosition(event, element)`
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
Returns the pointer/touch position relative to an element's top-left corner; used to implement drag-based components (sliders, color pickers, etc.).
|
|
97
97
|
|
|
98
98
|
### `mergeConfig(base, override)`
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
Deep-merges two config objects (for the `provideXxx({...})` pattern used throughout the library).
|
|
101
101
|
|
|
102
|
-
##
|
|
102
|
+
## Base components
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
These can be used directly, but they're mostly designed as building blocks for other components (like `color-picker`, `box-shadow`):
|
|
105
105
|
|
|
106
|
-
|
|
|
107
|
-
|
|
|
108
|
-
| `SliderComponent`
|
|
109
|
-
| `RangeSliderComponent` | `range-slider`
|
|
110
|
-
| `SaturationComponent`
|
|
106
|
+
| Component | Selector | Description |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| `SliderComponent` | `slider` | Single-value slider, `ControlValueAccessor`, `[min]`/`[max]`/`[step]` |
|
|
109
|
+
| `RangeSliderComponent` | `range-slider` | Range slider (two thumbs) |
|
|
110
|
+
| `SaturationComponent` | internal (color-picker) | 2D saturation/lightness picker panel |
|
|
111
111
|
|
|
112
|
-
##
|
|
112
|
+
## Dark mode and RTL
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
Both rely directly on `ngx-kit/shared`:
|
|
115
115
|
|
|
116
|
-
-
|
|
117
|
-
- **RTL**:
|
|
116
|
+
- **Dark mode**: uses the native CSS `light-dark()` function. For it to work, `color-scheme: light dark` (or `only light`/`only dark` to force it manually) must be set on `:root` — this happens automatically when you import `ngx-kit/styles/all.css`. To force a theme manually (independent of the OS's `prefers-color-scheme`), set `data-ngx-theme="dark"` or `"light"` on `<html>`/`<body>`.
|
|
117
|
+
- **RTL**: enabled via `dir="rtl"` on `<html>`; the whole library uses CSS logical properties (`inset-inline-start`, etc.), so no separate styling is needed.
|