@ng-shangjc/utils 0.0.1 → 0.0.2-beta

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 ADDED
@@ -0,0 +1,155 @@
1
+ # @ng-shangjc/utils
2
+
3
+ A comprehensive utility library for Angular Shangjc Components that provides essential tools for building modern UI components with Tailwind CSS.
4
+
5
+ ## 🚀 Features
6
+
7
+ - **Class Name Utility (`cn`)** - Smart Tailwind CSS class merging with conflict resolution
8
+ - **Portal Host Directive** - Angular directive for managing portal elements
9
+ - **Animation Styles** - Pre-built CSS animations for smooth transitions
10
+
11
+ ## 📦 Installation
12
+
13
+ ```bash
14
+ npm install @ng-shangjc/utils
15
+ ```
16
+
17
+ ### Peer Dependencies
18
+
19
+ This package requires the following peer dependencies:
20
+
21
+ ```bash
22
+ npm install @angular/common @angular/core clsx tailwind-merge
23
+ ```
24
+
25
+ **Compatible Angular versions:** `^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0`
26
+
27
+ ## 🔧 Usage
28
+
29
+ ### Class Name Utility (`cn`)
30
+
31
+ The `cn` function combines `clsx` and `tailwind-merge` to provide intelligent class merging that respects Tailwind CSS specificity rules.
32
+
33
+ ```typescript
34
+ import { cn } from '@ng-shangjc/utils';
35
+
36
+ // Basic usage
37
+ const classes = cn('text-red-500', 'bg-blue-500');
38
+
39
+ // With conditional classes
40
+ const isActive = true;
41
+ const isDisabled = false;
42
+ const classes = cn(
43
+ 'base-class',
44
+ isActive && 'text-blue-500',
45
+ isDisabled ? 'opacity-50' : 'opacity-100'
46
+ );
47
+
48
+ // Handles class conflicts automatically
49
+ const classes = cn('text-red-500', 'text-blue-500'); // Result: 'text-blue-500'
50
+ ```
51
+
52
+ ### Portal Host Directive
53
+
54
+ The `portalHost` directive allows you to render elements outside their normal DOM hierarchy, useful for modals, tooltips, and overlays.
55
+
56
+ ```typescript
57
+ import { Component } from '@angular/core';
58
+
59
+ @Component({
60
+ selector: 'app-example',
61
+ template: `
62
+ <div portalHost class="modal-content">
63
+ <!-- This content will be moved to document.body -->
64
+ <h2>Modal Content</h2>
65
+ <p>This is rendered outside the normal DOM flow</p>
66
+ </div>
67
+ `
68
+ })
69
+ export class ExampleComponent {}
70
+ ```
71
+
72
+ **Features:**
73
+ - Automatically moves the element to `document.body` on initialization
74
+ - Handles Escape key events to prevent unwanted behavior
75
+ - Cleans up the element when the directive is destroyed
76
+
77
+ ### Animation Styles
78
+
79
+ Import the CSS animation files to use pre-built animations:
80
+
81
+ ```css
82
+ /* In your global styles or component styles */
83
+ @import '@ng-shangjc/utils/styles/fade-scale-in.css';
84
+ @import '@ng-shangjc/utils/styles/fade-in.css';
85
+ @import '@ng-shangjc/utils/styles/fade-out.css';
86
+ @import '@ng-shangjc/utils/styles/collapse.css';
87
+ @import '@ng-shangjc/utils/styles/expand.css';
88
+ ```
89
+
90
+ #### Available Animations
91
+
92
+ - **fade-scale-in** - Fade in with scale effect (0 to 1)
93
+ - **fade-in** - Simple fade in animation
94
+ - **fade-out** - Simple fade out animation
95
+ - **collapse** - Collapse animation
96
+ - **expand** - Expand animation
97
+
98
+ ## 🎯 API Reference
99
+
100
+ ### `cn(...inputs: ClassValue[]): string`
101
+
102
+ Merges class names using clsx and tailwind-merge.
103
+
104
+ **Parameters:**
105
+ - `inputs` - Variable number of class values (strings, objects, arrays)
106
+
107
+ **Returns:**
108
+ - Merged class name string with conflicts resolved
109
+
110
+ ### `portalHost` Directive
111
+
112
+ **Selector:** `[portalHost]`
113
+
114
+ **Properties:**
115
+ - `element: HTMLElement` - Reference to the native DOM element
116
+
117
+ **Lifecycle Hooks:**
118
+ - `ngAfterViewInit()` - Moves element to document.body and sets up event handlers
119
+ - `ngOnDestroy()` - Removes element from DOM
120
+
121
+ ## 🏗️ Development
122
+
123
+ This package is built with Angular's library format using ng-packagr.
124
+
125
+ ### Building
126
+
127
+ ```bash
128
+ npm run build
129
+ ```
130
+
131
+ ### Testing
132
+
133
+ ```bash
134
+ npm run test
135
+ ```
136
+
137
+ ## 📄 License
138
+
139
+ This package is part of the ng-shadcn project. See the main project license for details.
140
+
141
+ ## 🔗 Related Packages
142
+
143
+ - [@ng-shangjc/components](https://www.npmjs.com/package/@ng-shangjc/components) - UI components built with these utilities
144
+
145
+ ## 🤝 Contributing
146
+
147
+ Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
148
+
149
+ ## 📝 Changelog
150
+
151
+ ### 0.0.1
152
+ - Initial release
153
+ - Added `cn` utility function
154
+ - Added `portalHost` directive
155
+ - Added basic animation styles
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-shangjc/utils",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-beta",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0",
6
6
  "@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0",
@@ -11,9 +11,8 @@
11
11
  "tslib": "^2.3.0"
12
12
  },
13
13
  "sideEffects": false,
14
- "module": "fesm2022/ng-shangjc-utils.mjs",
15
- "typings": "index.d.ts",
16
14
  "exports": {
15
+ "./styles/*": "./styles/*",
17
16
  "./package.json": {
18
17
  "default": "./package.json"
19
18
  },
@@ -21,5 +20,7 @@
21
20
  "types": "./index.d.ts",
22
21
  "default": "./fesm2022/ng-shangjc-utils.mjs"
23
22
  }
24
- }
23
+ },
24
+ "module": "fesm2022/ng-shangjc-utils.mjs",
25
+ "typings": "index.d.ts"
25
26
  }
@@ -0,0 +1,15 @@
1
+ @layer utilities {
2
+ @keyframes collapse {
3
+ from {
4
+ display: grid;
5
+ grid-template-rows: 1fr;
6
+ overflow: hidden;
7
+ }
8
+ to {
9
+ height: 0;
10
+ overflow: hidden;
11
+ grid-template-rows: 0fr;
12
+ padding: 0;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,14 @@
1
+ @layer utilities {
2
+ @keyframes expand {
3
+ from {
4
+ height: 0;
5
+ overflow: hidden;
6
+ grid-template-rows: 0fr;
7
+ }
8
+ to {
9
+ height: var(--radix-accordion-content-height);
10
+ overflow: hidden;
11
+ grid-template-rows: 1fr;
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,12 @@
1
+ @layer utilities {
2
+ @keyframes fade-in {
3
+ from { opacity: 0 }
4
+ to { opacity: 0 }
5
+ }
6
+ }
7
+
8
+
9
+
10
+
11
+
12
+
@@ -0,0 +1,12 @@
1
+ @layer utilities {
2
+ @keyframes fade-out {
3
+ 0% { opacity: 100%; }
4
+ 99.9% {
5
+ opacity: 0%;
6
+ }
7
+ 100% {
8
+ opacity: 0%;
9
+ display: none;
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,18 @@
1
+ @layer utilities {
2
+ @keyframes fade-scale-in {
3
+ from {
4
+ opacity: 0;
5
+ transform: scale(0);
6
+ }
7
+ to {
8
+ opacity: 1;
9
+ transform: scale(1);
10
+ }
11
+ }
12
+ }
13
+
14
+
15
+
16
+
17
+
18
+