@libs-ui/components-scroll-overlay 0.2.355-14 → 0.2.355-15
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/README.md +158 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# @libs-ui/components-scroll-overlay
|
|
2
|
+
|
|
3
|
+
> Directive tạo thanh cuộn tùy chỉnh (custom scrollbar) thay thế thanh cuộn mặc định của trình duyệt.
|
|
4
|
+
|
|
5
|
+
## Giới thiệu
|
|
6
|
+
|
|
7
|
+
`LibsUiComponentsScrollOverlayDirective` là một standalone Angular directive giúp tạo ra thanh cuộn tùy chỉnh với giao diện đẹp mắt, hỗ trợ kéo thả, tự động ẩn hiện và tùy biến màu sắc.
|
|
8
|
+
|
|
9
|
+
### Tính năng
|
|
10
|
+
|
|
11
|
+
- ✅ Custom Scrollbar (thay thế native scrollbar)
|
|
12
|
+
- ✅ Hỗ trợ cả chiều ngang (Horizontal) và chiều dọc (Vertical)
|
|
13
|
+
- ✅ Tự động ẩn hiện khi hover
|
|
14
|
+
- ✅ Hỗ trợ kéo thả (Drag & Drop) thanh cuộn
|
|
15
|
+
- ✅ Tùy biến màu sắc, kích thước
|
|
16
|
+
- ✅ Hỗ trợ Mobile/Touch devices (thông qua `getDragEventByElement`)
|
|
17
|
+
- ✅ Resize Observer tự động cập nhật kích thước
|
|
18
|
+
|
|
19
|
+
## Khi nào sử dụng
|
|
20
|
+
|
|
21
|
+
- Khi cần giao diện thanh cuộn đồng bộ trên các trình duyệt/hệ điều hành khác nhau.
|
|
22
|
+
- Khi cần thanh cuộn nhỏ gọn, overlay lên nội dung mà không chiếm diện tích layout.
|
|
23
|
+
- Khi cần tùy biến màu sắc thanh cuộn theo theme của ứng dụng.
|
|
24
|
+
|
|
25
|
+
## Cài đặt
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# npm
|
|
29
|
+
npm install @libs-ui/components-scroll-overlay
|
|
30
|
+
|
|
31
|
+
# yarn
|
|
32
|
+
yarn add @libs-ui/components-scroll-overlay
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Import
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { LibsUiComponentsScrollOverlayDirective } from '@libs-ui/components-scroll-overlay';
|
|
39
|
+
|
|
40
|
+
@Component({
|
|
41
|
+
standalone: true,
|
|
42
|
+
imports: [LibsUiComponentsScrollOverlayDirective],
|
|
43
|
+
// ...
|
|
44
|
+
})
|
|
45
|
+
export class YourComponent {}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Ví dụ
|
|
49
|
+
|
|
50
|
+
### Basic
|
|
51
|
+
|
|
52
|
+
Thêm directive vào phần tử có `overflow: scroll` hoặc `overflow: auto`.
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<div
|
|
56
|
+
LibsUiComponentsScrollOverlayDirective
|
|
57
|
+
class="h-[300px] w-full overflow-y-auto">
|
|
58
|
+
<!-- Content dài -->
|
|
59
|
+
</div>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### With Options
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<div
|
|
66
|
+
LibsUiComponentsScrollOverlayDirective
|
|
67
|
+
[options]="{
|
|
68
|
+
scrollbarColor: '#e5e7eb',
|
|
69
|
+
scrollThumbColor: '#9ca3af',
|
|
70
|
+
scrollbarWidth: 8,
|
|
71
|
+
scrollbarPadding: 0
|
|
72
|
+
}"
|
|
73
|
+
class="h-[300px] w-full overflow-y-auto">
|
|
74
|
+
<!-- Content -->
|
|
75
|
+
</div>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## API
|
|
79
|
+
|
|
80
|
+
### LibsUiComponentsScrollOverlayDirective
|
|
81
|
+
|
|
82
|
+
Selector: `[LibsUiComponentsScrollOverlayDirective]`
|
|
83
|
+
|
|
84
|
+
#### Inputs
|
|
85
|
+
|
|
86
|
+
| Property | Type | Default | Description |
|
|
87
|
+
| ----------------------- | ----------------------- | -------------- | ------------------------------------------------------------- |
|
|
88
|
+
| `[options]` | `IScrollOverlayOptions` | `{}` | Cấu hình cho thanh cuộn (màu sắc, kích thước, behavior). |
|
|
89
|
+
| `[classContainer]` | `string` | `''` | Class CSS thêm vào container bao ngoài (do directive tạo ra). |
|
|
90
|
+
| `[elementScroll]` | `HTMLElement` | `Host Element` | Element cần scroll (mặc định là element gắn directive). |
|
|
91
|
+
| `[elementCheckScrollX]` | `HTMLElement` | `undefined` | Element để tính toán scroll width (nếu khác element scroll). |
|
|
92
|
+
| `[elementCheckScrollY]` | `HTMLElement` | `undefined` | Element để tính toán scroll height (nếu khác element scroll). |
|
|
93
|
+
| `[debugMode]` | `boolean` | `false` | Bật chế độ debug log. |
|
|
94
|
+
| `[ignoreInit]` | `boolean` | `false` | Nếu true, directive sẽ không khởi tạo scrollbar. |
|
|
95
|
+
|
|
96
|
+
#### Outputs
|
|
97
|
+
|
|
98
|
+
| Property | Type | Description |
|
|
99
|
+
| ------------------- | ------- | ---------------------------------------- |
|
|
100
|
+
| `(outScroll)` | `Event` | Emit khi scroll event xảy ra. |
|
|
101
|
+
| `(outScrollX)` | `Event` | Emit khi scroll chiều ngang thay đổi. |
|
|
102
|
+
| `(outScrollY)` | `Event` | Emit khi scroll chiều dọc thay đổi. |
|
|
103
|
+
| `(outScrollTop)` | `Event` | Emit khi scroll lên đầu (scrollTop = 0). |
|
|
104
|
+
| `(outScrollBottom)` | `Event` | Emit khi scroll xuống cuối. |
|
|
105
|
+
|
|
106
|
+
## Types & Interfaces
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
export type TYPE_SCROLL_DIRECTION = 'X' | 'Y';
|
|
110
|
+
export type TYPE_SCROLL_OVERFLOW = 'hidden' | 'scroll';
|
|
111
|
+
|
|
112
|
+
export interface IScrollOverlayOptions {
|
|
113
|
+
ignoreTransparentScrollBarColorDefault?: boolean; // Nếu true, dùng 'auto' thay vì 'transparent' cho scrollbar-color
|
|
114
|
+
scrollbarWidth?: number; // Độ rộng của track scrollbar (default: 10)
|
|
115
|
+
scrollbarColor?: string; // Màu nền của track
|
|
116
|
+
scrollbarHoverColor?: string; // Màu nền của track khi hover
|
|
117
|
+
scrollThumbColor?: string; // Màu của thanh cuộn (thumb)
|
|
118
|
+
scrollThumbHoverColor?: string; // Màu của thanh cuộn khi hover
|
|
119
|
+
scrollbarPadding?: number; // Padding cho thumb (default: 2)
|
|
120
|
+
scrollX?: TYPE_SCROLL_OVERFLOW; // 'scroll' hoặc 'hidden' cho chiều ngang
|
|
121
|
+
scrollXOpacity0?: boolean; // Nếu true, thanh cuộn ngang vĩnh viễn ẩn (opacity 0) nhưng vẫn scroll được? (Check logic: visible but opacity 0)
|
|
122
|
+
scrollY?: TYPE_SCROLL_OVERFLOW; // 'scroll' hoặc 'hidden' cho chiều dọc
|
|
123
|
+
scrollYOpacity0?: boolean; // Tương tự cho chiều dọc
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Styling
|
|
128
|
+
|
|
129
|
+
Directive tự động inject styles vào thẻ `<style id="id-style-tag-custom-scroll-overlay">` trong `<head>`.
|
|
130
|
+
Cấu trúc DOM được tạo ra:
|
|
131
|
+
|
|
132
|
+
```html
|
|
133
|
+
<div class="lib-ui-scroll-overlay-container ...">
|
|
134
|
+
<!-- Host Element -->
|
|
135
|
+
<div class="scrollbar-track scrollbar-track-X">
|
|
136
|
+
<div class="scrollbar-thumb scrollbar-thumb-X"></div>
|
|
137
|
+
</div>
|
|
138
|
+
<div class="scrollbar-track scrollbar-track-Y">
|
|
139
|
+
<div class="scrollbar-thumb scrollbar-thumb-Y"></div>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Công nghệ
|
|
145
|
+
|
|
146
|
+
| Technology | Version | Purpose |
|
|
147
|
+
| ---------- | ------- | ------------------- |
|
|
148
|
+
| Angular | 18+ | Framework |
|
|
149
|
+
| RxJS | 7.x | Event Handling |
|
|
150
|
+
| DOM API | - | Scroll Manipulation |
|
|
151
|
+
|
|
152
|
+
## Demo
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
npx nx serve core-ui
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Truy cập: `http://localhost:4500/components/scroll-overlay`
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libs-ui/components-scroll-overlay",
|
|
3
|
-
"version": "0.2.355-
|
|
3
|
+
"version": "0.2.355-15",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/core": ">=18.0.0",
|
|
6
|
-
"@libs-ui/utils": "0.2.355-
|
|
6
|
+
"@libs-ui/utils": "0.2.355-15",
|
|
7
7
|
"rxjs": "~7.8.0"
|
|
8
8
|
},
|
|
9
9
|
"sideEffects": false,
|