ng-magary 0.0.1 → 0.0.3
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/LICENSE.md +21 -0
- package/README.md +166 -32
- package/bun.lock +290 -0
- package/ng-package.json +7 -0
- package/package.json +11 -12
- package/src/lib/Button/button/button.html +29 -0
- package/src/lib/Button/button/button.module.ts +9 -0
- package/src/lib/Button/button/button.scss +196 -0
- package/src/lib/Button/button/button.spec.ts +18 -0
- package/src/lib/Button/button/button.ts +72 -0
- package/src/lib/Button/speed-dial/speed-dial-item.interface.ts +9 -0
- package/src/lib/Button/speed-dial/speed-dial.html +57 -0
- package/src/lib/Button/speed-dial/speed-dial.module.ts +8 -0
- package/src/lib/Button/speed-dial/speed-dial.scss +247 -0
- package/src/lib/Button/speed-dial/speed-dial.spec.ts +18 -0
- package/src/lib/Button/speed-dial/speed-dial.ts +106 -0
- package/src/lib/Form/cascade-select/cascade-select.html +1 -0
- package/src/lib/Form/cascade-select/cascade-select.module.ts +8 -0
- package/src/lib/Form/cascade-select/cascade-select.scss +0 -0
- package/src/lib/Form/cascade-select/cascade-select.spec.ts +18 -0
- package/src/lib/Form/cascade-select/cascade-select.ts +9 -0
- package/src/lib/Form/input/input.html +66 -0
- package/src/lib/Form/input/input.module.ts +9 -0
- package/src/lib/Form/input/input.scss +193 -0
- package/src/lib/Form/input/input.spec.ts +22 -0
- package/src/lib/Form/input/input.ts +132 -0
- package/src/lib/Menu/panelmenu/panelmenu.html +259 -0
- package/src/lib/Menu/panelmenu/panelmenu.interface.ts +13 -0
- package/src/lib/Menu/panelmenu/panelmenu.module.ts +9 -0
- package/src/lib/Menu/panelmenu/panelmenu.scss +177 -0
- package/src/lib/Menu/panelmenu/panelmenu.spec.ts +18 -0
- package/src/lib/Menu/panelmenu/panelmenu.ts +134 -0
- package/src/lib/Menu/sidebar/sidebar.html +85 -0
- package/src/lib/Menu/sidebar/sidebar.module.ts +9 -0
- package/src/lib/Menu/sidebar/sidebar.scss +153 -0
- package/src/lib/Menu/sidebar/sidebar.spec.ts +18 -0
- package/src/lib/Menu/sidebar/sidebar.ts +64 -0
- package/src/lib/Misc/avatar/avatar.html +44 -0
- package/src/lib/Misc/avatar/avatar.module.ts +9 -0
- package/src/lib/Misc/avatar/avatar.scss +167 -0
- package/src/lib/Misc/avatar/avatar.spec.ts +18 -0
- package/src/lib/Misc/avatar/avatar.ts +93 -0
- package/src/lib/Panel/card/card.html +58 -0
- package/src/lib/Panel/card/card.module.ts +9 -0
- package/src/lib/Panel/card/card.scss +290 -0
- package/src/lib/Panel/card/card.spec.ts +18 -0
- package/src/lib/Panel/card/card.ts +126 -0
- package/src/lib/Panel/tabs/tab/tab.spec.ts +18 -0
- package/src/lib/Panel/tabs/tab/tab.ts +12 -0
- package/src/lib/Panel/tabs/tabs.html +26 -0
- package/src/lib/Panel/tabs/tabs.module.ts +10 -0
- package/src/lib/Panel/tabs/tabs.scss +58 -0
- package/src/lib/Panel/tabs/tabs.spec.ts +18 -0
- package/src/lib/Panel/tabs/tabs.ts +57 -0
- package/src/lib/ng-magary.spec.ts +18 -0
- package/src/lib/ng-magary.ts +43 -0
- package/src/public-api.ts +5 -0
- package/tsconfig.lib.json +22 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +14 -0
- package/fesm2022/ng-magary.mjs +0 -811
- package/fesm2022/ng-magary.mjs.map +0 -1
- package/index.d.ts +0 -422
- package/index.d.ts.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import {
|
|
3
|
+
Component,
|
|
4
|
+
computed,
|
|
5
|
+
input,
|
|
6
|
+
output,
|
|
7
|
+
signal,
|
|
8
|
+
ElementRef,
|
|
9
|
+
HostListener,
|
|
10
|
+
inject,
|
|
11
|
+
} from '@angular/core';
|
|
12
|
+
import { SpeedDialItem } from './speed-dial-item.interface';
|
|
13
|
+
type SpeedDialType = 'linear' | 'circle' | 'semicircle' | 'quartercircle';
|
|
14
|
+
type SpeedDialDirection =
|
|
15
|
+
| 'up'
|
|
16
|
+
| 'down'
|
|
17
|
+
| 'left'
|
|
18
|
+
| 'right'
|
|
19
|
+
| 'up-left'
|
|
20
|
+
| 'up-right'
|
|
21
|
+
| 'down-left'
|
|
22
|
+
| 'down-right';
|
|
23
|
+
@Component({
|
|
24
|
+
selector: 'magary-speed-dial',
|
|
25
|
+
imports: [CommonModule],
|
|
26
|
+
templateUrl: './speed-dial.html',
|
|
27
|
+
styleUrl: './speed-dial.scss',
|
|
28
|
+
})
|
|
29
|
+
export class MagarySpeedDial {
|
|
30
|
+
private readonly elementRef = inject(ElementRef);
|
|
31
|
+
readonly items = input.required<SpeedDialItem[]>();
|
|
32
|
+
readonly icon = input<string>('fas fa-plus');
|
|
33
|
+
readonly activeIcon = input<string>('fas fa-times');
|
|
34
|
+
readonly type = input<SpeedDialType>('linear');
|
|
35
|
+
readonly direction = input<SpeedDialDirection>();
|
|
36
|
+
readonly radius = input<number>(80);
|
|
37
|
+
readonly showMask = input<boolean>(false);
|
|
38
|
+
readonly background = input<string>('#007bff');
|
|
39
|
+
readonly ariaLabel = input<string>('Speed dial menu');
|
|
40
|
+
readonly isOpen = signal(false);
|
|
41
|
+
readonly speedDialToggle = output<boolean>();
|
|
42
|
+
readonly itemSelect = output<{ item: SpeedDialItem; event: Event }>();
|
|
43
|
+
readonly itemCount = computed(() => this.items().length);
|
|
44
|
+
readonly containerClasses = computed(() =>
|
|
45
|
+
[
|
|
46
|
+
'speed-dial-container',
|
|
47
|
+
this.isOpen() ? 'is-open' : '',
|
|
48
|
+
`type-${this.type()}`,
|
|
49
|
+
this.direction() ? `direction-${this.direction()}` : '',
|
|
50
|
+
].filter(Boolean),
|
|
51
|
+
);
|
|
52
|
+
readonly triggerStyles = computed(() => ({
|
|
53
|
+
'--trigger-bg': this.background(),
|
|
54
|
+
}));
|
|
55
|
+
readonly itemsStyles = computed(() => ({
|
|
56
|
+
'--item-count': this.itemCount().toString(),
|
|
57
|
+
'--radius': `${this.radius()}px`,
|
|
58
|
+
}));
|
|
59
|
+
readonly currentIcon = computed(() =>
|
|
60
|
+
this.isOpen() ? this.activeIcon() : this.icon(),
|
|
61
|
+
);
|
|
62
|
+
toggleSpeedDial(event: Event): void {
|
|
63
|
+
event.stopPropagation();
|
|
64
|
+
const newState = !this.isOpen();
|
|
65
|
+
this.isOpen.set(newState);
|
|
66
|
+
this.speedDialToggle.emit(newState);
|
|
67
|
+
}
|
|
68
|
+
onItemClick(event: Event, item: SpeedDialItem): void {
|
|
69
|
+
event.stopPropagation();
|
|
70
|
+
if (item.disabled) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.itemSelect.emit({ item, event });
|
|
74
|
+
if (item.command) {
|
|
75
|
+
item.command(event);
|
|
76
|
+
}
|
|
77
|
+
this.isOpen.set(false);
|
|
78
|
+
this.speedDialToggle.emit(false);
|
|
79
|
+
}
|
|
80
|
+
closeMask(): void {
|
|
81
|
+
this.isOpen.set(false);
|
|
82
|
+
this.speedDialToggle.emit(false);
|
|
83
|
+
}
|
|
84
|
+
trackByItem(index: number, item: SpeedDialItem): string {
|
|
85
|
+
return item.id || `${item.icon}-${index}`;
|
|
86
|
+
}
|
|
87
|
+
@HostListener('document:click', ['$event'])
|
|
88
|
+
onDocumentClick(event: Event): void {
|
|
89
|
+
if (!this.isOpen()) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const target = event.target as HTMLElement;
|
|
93
|
+
const componentElement = this.elementRef.nativeElement;
|
|
94
|
+
if (!componentElement.contains(target)) {
|
|
95
|
+
this.isOpen.set(false);
|
|
96
|
+
this.speedDialToggle.emit(false);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
@HostListener('document:keydown.escape')
|
|
100
|
+
onEscapeKeydown(): void {
|
|
101
|
+
if (this.isOpen()) {
|
|
102
|
+
this.isOpen.set(false);
|
|
103
|
+
this.speedDialToggle.emit(false);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<p>cascade-select works!</p>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { CascadeSelect } from './cascade-select';
|
|
4
|
+
@NgModule({
|
|
5
|
+
imports: [CommonModule, CascadeSelect],
|
|
6
|
+
exports: [CascadeSelect],
|
|
7
|
+
})
|
|
8
|
+
export class CascadeSelectModule { }
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { CascadeSelect } from './cascade-select';
|
|
3
|
+
describe('CascadeSelect', () => {
|
|
4
|
+
let component: CascadeSelect;
|
|
5
|
+
let fixture: ComponentFixture<CascadeSelect>;
|
|
6
|
+
beforeEach(async () => {
|
|
7
|
+
await TestBed.configureTestingModule({
|
|
8
|
+
imports: [CascadeSelect]
|
|
9
|
+
})
|
|
10
|
+
.compileComponents();
|
|
11
|
+
fixture = TestBed.createComponent(CascadeSelect);
|
|
12
|
+
component = fixture.componentInstance;
|
|
13
|
+
fixture.detectChanges();
|
|
14
|
+
});
|
|
15
|
+
it('should create', () => {
|
|
16
|
+
expect(component).toBeTruthy();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<div [ngClass]="containerClasses()" [ngStyle]="inputStyles()">
|
|
2
|
+
@if (label()) {
|
|
3
|
+
<label [for]="getId()" class="input-label">
|
|
4
|
+
{{ label() }}
|
|
5
|
+
@if (required()) {
|
|
6
|
+
<span class="required-asterisk">*</span>
|
|
7
|
+
}
|
|
8
|
+
</label>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
<div class="input-wrapper">
|
|
12
|
+
@if (prefixIcon()) {
|
|
13
|
+
<i
|
|
14
|
+
[class]="prefixIcon()"
|
|
15
|
+
class="prefix-icon"
|
|
16
|
+
(click)="onPrefixIconClick()"
|
|
17
|
+
[class.clickable]="!disabled()"
|
|
18
|
+
></i>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
<input
|
|
22
|
+
[id]="getId()"
|
|
23
|
+
[ngClass]="inputClasses()"
|
|
24
|
+
[type]="actualType()"
|
|
25
|
+
[value]="value()"
|
|
26
|
+
[placeholder]="placeholder()"
|
|
27
|
+
[disabled]="disabled()"
|
|
28
|
+
[readonly]="readonly()"
|
|
29
|
+
[required]="required()"
|
|
30
|
+
attr.maxlength="{{ maxLength() }}"
|
|
31
|
+
(input)="onInput($event)"
|
|
32
|
+
(focus)="onFocus($event)"
|
|
33
|
+
(blur)="onBlur($event)"
|
|
34
|
+
/>
|
|
35
|
+
|
|
36
|
+
@if (loading()) {
|
|
37
|
+
<i class="fas fa-spinner fa-spin suffix-icon loading-icon"></i>
|
|
38
|
+
} @else if (type() === "password") {
|
|
39
|
+
<i
|
|
40
|
+
[class]="passwordIcon()"
|
|
41
|
+
class="suffix-icon password-toggle"
|
|
42
|
+
(click)="togglePasswordVisibility()"
|
|
43
|
+
></i>
|
|
44
|
+
} @else if (suffixIcon()) {
|
|
45
|
+
<i
|
|
46
|
+
[class]="suffixIcon()"
|
|
47
|
+
class="suffix-icon"
|
|
48
|
+
(click)="onSuffixIconClick()"
|
|
49
|
+
[class.clickable]="!disabled()"
|
|
50
|
+
></i>
|
|
51
|
+
}
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
@if (error() || helpText()) {
|
|
55
|
+
<div class="input-message">
|
|
56
|
+
@if (error()) {
|
|
57
|
+
<span class="error-message">
|
|
58
|
+
<i class="fas fa-exclamation-circle"></i>
|
|
59
|
+
{{ error() }}
|
|
60
|
+
</span>
|
|
61
|
+
} @else if (helpText()) {
|
|
62
|
+
<span class="help-message">{{ helpText() }}</span>
|
|
63
|
+
}
|
|
64
|
+
</div>
|
|
65
|
+
}
|
|
66
|
+
</div>
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
--input-primary: #007bff;
|
|
3
|
+
--input-success: #28a745;
|
|
4
|
+
--input-error: #dc3545;
|
|
5
|
+
--input-border: #ced4da;
|
|
6
|
+
--input-bg: #ffffff;
|
|
7
|
+
--input-text: #495057;
|
|
8
|
+
--input-placeholder: #6c757d;
|
|
9
|
+
--input-radius: 6px;
|
|
10
|
+
--input-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.magary-input-container {
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
gap: 6px;
|
|
17
|
+
font-family: inherit;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.input-label {
|
|
21
|
+
font-weight: 500;
|
|
22
|
+
color: var(--input-text);
|
|
23
|
+
font-size: 0.875rem;
|
|
24
|
+
margin-bottom: 2px;
|
|
25
|
+
|
|
26
|
+
.required-asterisk {
|
|
27
|
+
color: var(--input-error);
|
|
28
|
+
margin-left: 2px;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.input-wrapper {
|
|
33
|
+
position: relative;
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.magary-input-field {
|
|
39
|
+
width: 100%;
|
|
40
|
+
border: 1px solid var(--input-border);
|
|
41
|
+
border-radius: var(--input-radius);
|
|
42
|
+
background: var(--input-bg);
|
|
43
|
+
color: var(--input-text);
|
|
44
|
+
font-size: 1rem;
|
|
45
|
+
transition: all 0.15s ease-in-out;
|
|
46
|
+
outline: none;
|
|
47
|
+
|
|
48
|
+
&::placeholder {
|
|
49
|
+
color: var(--input-placeholder);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&:focus {
|
|
53
|
+
border-color: var(--input-primary);
|
|
54
|
+
box-shadow: var(--input-shadow);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&.input-small {
|
|
58
|
+
padding: 6px 12px;
|
|
59
|
+
font-size: 0.875rem;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&.input-normal {
|
|
63
|
+
padding: 8px 16px;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&.input-large {
|
|
67
|
+
padding: 12px 20px;
|
|
68
|
+
font-size: 1.125rem;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
&.input-outlined {
|
|
72
|
+
border: 2px solid var(--input-border);
|
|
73
|
+
background: var(--input-bg);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&.input-filled {
|
|
77
|
+
border: none;
|
|
78
|
+
background: #f8f9fa;
|
|
79
|
+
border-bottom: 2px solid var(--input-border);
|
|
80
|
+
border-radius: var(--input-radius) var(--input-radius) 0 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
&.input-underlined {
|
|
84
|
+
border: none;
|
|
85
|
+
border-bottom: 1px solid var(--input-border);
|
|
86
|
+
border-radius: 0;
|
|
87
|
+
background: transparent;
|
|
88
|
+
|
|
89
|
+
&:focus {
|
|
90
|
+
border-bottom: 2px solid var(--input-primary);
|
|
91
|
+
box-shadow: none;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&.input-error {
|
|
96
|
+
border-color: var(--input-error);
|
|
97
|
+
|
|
98
|
+
&:focus {
|
|
99
|
+
border-color: var(--input-error);
|
|
100
|
+
box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
&.input-success {
|
|
105
|
+
border-color: var(--input-success);
|
|
106
|
+
|
|
107
|
+
&:focus {
|
|
108
|
+
border-color: var(--input-success);
|
|
109
|
+
box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
&.input-disabled {
|
|
114
|
+
background: #e9ecef;
|
|
115
|
+
color: #6c757d;
|
|
116
|
+
cursor: not-allowed;
|
|
117
|
+
opacity: 0.6;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&.input-readonly {
|
|
121
|
+
background: #f8f9fa;
|
|
122
|
+
cursor: default;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.has-prefix .magary-input-field {
|
|
127
|
+
padding-left: 40px;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.has-suffix .magary-input-field {
|
|
131
|
+
padding-right: 40px;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.prefix-icon,
|
|
135
|
+
.suffix-icon {
|
|
136
|
+
position: absolute;
|
|
137
|
+
color: var(--input-placeholder);
|
|
138
|
+
transition: color 0.15s ease-in-out;
|
|
139
|
+
|
|
140
|
+
&.clickable {
|
|
141
|
+
cursor: pointer;
|
|
142
|
+
|
|
143
|
+
&:hover {
|
|
144
|
+
color: var(--input-primary);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.prefix-icon {
|
|
150
|
+
left: 12px;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.suffix-icon {
|
|
154
|
+
right: 12px;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.password-toggle {
|
|
158
|
+
cursor: pointer;
|
|
159
|
+
|
|
160
|
+
&:hover {
|
|
161
|
+
color: var(--input-primary);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.loading-icon {
|
|
166
|
+
color: var(--input-primary);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.input-message {
|
|
170
|
+
margin-top: 4px;
|
|
171
|
+
font-size: 0.875rem;
|
|
172
|
+
|
|
173
|
+
.error-message {
|
|
174
|
+
color: var(--input-error);
|
|
175
|
+
display: flex;
|
|
176
|
+
align-items: center;
|
|
177
|
+
gap: 4px;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.help-message {
|
|
181
|
+
color: var(--input-placeholder);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@media (max-width: 480px) {
|
|
186
|
+
.magary-input-field {
|
|
187
|
+
font-size: 16px;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.input-label {
|
|
191
|
+
font-size: 14px;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { MagaryInput } from './input';
|
|
4
|
+
|
|
5
|
+
describe('Input', () => {
|
|
6
|
+
let component: MagaryInput;
|
|
7
|
+
let fixture: ComponentFixture<MagaryInput>;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await TestBed.configureTestingModule({
|
|
11
|
+
imports: [MagaryInput],
|
|
12
|
+
}).compileComponents();
|
|
13
|
+
|
|
14
|
+
fixture = TestBed.createComponent(MagaryInput);
|
|
15
|
+
component = fixture.componentInstance;
|
|
16
|
+
fixture.detectChanges();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should create', () => {
|
|
20
|
+
expect(component).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Component, computed, input, output, signal } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { FormsModule } from '@angular/forms';
|
|
4
|
+
|
|
5
|
+
export type InputType =
|
|
6
|
+
| 'text'
|
|
7
|
+
| 'email'
|
|
8
|
+
| 'password'
|
|
9
|
+
| 'number'
|
|
10
|
+
| 'tel'
|
|
11
|
+
| 'url'
|
|
12
|
+
| 'search';
|
|
13
|
+
|
|
14
|
+
export type InputSize = 'small' | 'normal' | 'large';
|
|
15
|
+
|
|
16
|
+
export type InputVariant = 'filled' | 'outlined' | 'underlined';
|
|
17
|
+
|
|
18
|
+
@Component({
|
|
19
|
+
selector: 'magary-input',
|
|
20
|
+
imports: [CommonModule, FormsModule],
|
|
21
|
+
templateUrl: './input.html',
|
|
22
|
+
styleUrl: './input.scss',
|
|
23
|
+
})
|
|
24
|
+
export class MagaryInput {
|
|
25
|
+
value = input<string>('');
|
|
26
|
+
placeholder = input<string>('');
|
|
27
|
+
type = input<InputType>('text');
|
|
28
|
+
size = input<InputSize>('normal');
|
|
29
|
+
variant = input<InputVariant>('outlined');
|
|
30
|
+
|
|
31
|
+
disabled = input<boolean>(false);
|
|
32
|
+
readonly = input<boolean>(false);
|
|
33
|
+
required = input<boolean>(false);
|
|
34
|
+
loading = input<boolean>(false);
|
|
35
|
+
|
|
36
|
+
error = input<string>('');
|
|
37
|
+
success = input<boolean>(false);
|
|
38
|
+
|
|
39
|
+
label = input<string>('');
|
|
40
|
+
helpText = input<string>('');
|
|
41
|
+
|
|
42
|
+
prefixIcon = input<string>('');
|
|
43
|
+
suffixIcon = input<string>('');
|
|
44
|
+
|
|
45
|
+
width = input<string>('100%');
|
|
46
|
+
maxLength = input<number | undefined>(undefined);
|
|
47
|
+
|
|
48
|
+
valueChange = output<string>();
|
|
49
|
+
inputFocus = output<Event>();
|
|
50
|
+
inputBlur = output<Event>();
|
|
51
|
+
iconClick = output<'prefix' | 'suffix'>();
|
|
52
|
+
|
|
53
|
+
private focused = signal(false);
|
|
54
|
+
private showPassword = signal(false);
|
|
55
|
+
private readonly uniqueId = `magary-input-${Math.random().toString(36).substr(2, 9)}`;
|
|
56
|
+
|
|
57
|
+
inputClasses = computed(() => {
|
|
58
|
+
const classes = ['magary-input-field'];
|
|
59
|
+
classes.push(`input-${this.variant()}`);
|
|
60
|
+
classes.push(`input-${this.size()}`);
|
|
61
|
+
|
|
62
|
+
if (this.disabled()) classes.push('input-disabled');
|
|
63
|
+
if (this.readonly()) classes.push('input-readonly');
|
|
64
|
+
if (this.error()) classes.push('input-error');
|
|
65
|
+
if (this.success()) classes.push('input-success');
|
|
66
|
+
if (this.focused()) classes.push('input-focused');
|
|
67
|
+
if (this.loading()) classes.push('input-loading');
|
|
68
|
+
|
|
69
|
+
return classes.join(' ');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
containerClasses = computed(() => {
|
|
73
|
+
const classes = ['magary-input-container'];
|
|
74
|
+
if (this.label()) classes.push('has-label');
|
|
75
|
+
if (this.prefixIcon()) classes.push('has-prefix');
|
|
76
|
+
if (this.suffixIcon() || this.type() === 'password')
|
|
77
|
+
classes.push('has-suffix');
|
|
78
|
+
return classes.join(' ');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
inputStyles = computed(() => ({
|
|
82
|
+
width: this.width(),
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
actualType = computed(() => {
|
|
86
|
+
if (this.type() === 'password') {
|
|
87
|
+
return this.showPassword() ? 'text' : 'password';
|
|
88
|
+
}
|
|
89
|
+
return this.type();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
passwordIcon = computed(() => {
|
|
93
|
+
return this.showPassword() ? 'fas fa-eye-slash' : 'fas fa-eye';
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
onInput(event: Event): void {
|
|
97
|
+
const target = event.target as HTMLInputElement;
|
|
98
|
+
this.valueChange.emit(target.value);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
onFocus(event: Event): void {
|
|
102
|
+
this.focused.set(true);
|
|
103
|
+
this.inputFocus.emit(event);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
onBlur(event: Event): void {
|
|
107
|
+
this.focused.set(false);
|
|
108
|
+
this.inputBlur.emit(event);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
onPrefixIconClick(): void {
|
|
112
|
+
if (!this.disabled()) {
|
|
113
|
+
this.iconClick.emit('prefix');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
onSuffixIconClick(): void {
|
|
118
|
+
if (!this.disabled()) {
|
|
119
|
+
this.iconClick.emit('suffix');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
togglePasswordVisibility(): void {
|
|
124
|
+
if (this.type() === 'password') {
|
|
125
|
+
this.showPassword.set(!this.showPassword());
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getId(): string {
|
|
130
|
+
return this.uniqueId;
|
|
131
|
+
}
|
|
132
|
+
}
|