Upgrade: Angular 18, Ionic 8, Capacitor 6
Modernizacion completa del frontend: - Angular 8 -> 18.2.14 - Ionic 4 -> 8.7.17 - Capacitor 6.x (migracion desde Cordova/@ionic-native) - TypeScript 5.4.5 - Swiper 11 con Web Components API Cambios principales: - Migrar NativeStorage a @capacitor/preferences - Migrar InAppBrowser a @capacitor/browser - Migrar Camera a @capacitor/camera - Migrar Geolocation a @capacitor/geolocation - Migrar StatusBar/SplashScreen a Capacitor - Migrar Facebook/Google login a plugins Capacitor - Actualizar lazy loading syntax (Angular 12+) - Configurar buildOptimizer: false para Ionic 8 - Limpiar package.json de dependencias obsoletas - Agregar README con guia de instalacion Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
85
src/app/components/rating/rating.component.ts
Normal file
85
src/app/components/rating/rating.component.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { Component, Input, Output, EventEmitter, forwardRef } from '@angular/core';
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'rating',
|
||||
template: `
|
||||
<div class="rating-container" [class.readonly]="readonly === 'true'">
|
||||
<ion-icon
|
||||
*ngFor="let star of stars; let i = index"
|
||||
[name]="i < value ? 'star' : 'star-outline'"
|
||||
[class.selected]="i < value"
|
||||
[class.large]="size === 'large'"
|
||||
(click)="onStarClick(i + 1)">
|
||||
</ion-icon>
|
||||
</div>
|
||||
`,
|
||||
styles: [`
|
||||
.rating-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
ion-icon {
|
||||
font-size: 24px;
|
||||
color: #ffc107;
|
||||
cursor: pointer;
|
||||
}
|
||||
ion-icon.large {
|
||||
font-size: 36px;
|
||||
}
|
||||
ion-icon.selected {
|
||||
color: #ffc107;
|
||||
}
|
||||
ion-icon:not(.selected) {
|
||||
color: #ccc;
|
||||
}
|
||||
.readonly ion-icon {
|
||||
cursor: default;
|
||||
}
|
||||
`],
|
||||
providers: [
|
||||
{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
useExisting: forwardRef(() => RatingComponent),
|
||||
multi: true
|
||||
}
|
||||
]
|
||||
})
|
||||
export class RatingComponent implements ControlValueAccessor {
|
||||
@Input() readonly: string = 'false';
|
||||
@Input() size: string = 'default';
|
||||
@Input() max: number = 5;
|
||||
@Output() rateChange = new EventEmitter<number>();
|
||||
|
||||
value: number = 0;
|
||||
stars: number[] = [];
|
||||
|
||||
private onChange: (value: number) => void = () => {};
|
||||
private onTouched: () => void = () => {};
|
||||
|
||||
ngOnInit() {
|
||||
this.stars = Array(this.max).fill(0);
|
||||
}
|
||||
|
||||
onStarClick(rating: number) {
|
||||
if (this.readonly !== 'true') {
|
||||
this.value = rating;
|
||||
this.onChange(this.value);
|
||||
this.onTouched();
|
||||
this.rateChange.emit(this.value);
|
||||
}
|
||||
}
|
||||
|
||||
writeValue(value: number): void {
|
||||
this.value = value || 0;
|
||||
}
|
||||
|
||||
registerOnChange(fn: (value: number) => void): void {
|
||||
this.onChange = fn;
|
||||
}
|
||||
|
||||
registerOnTouched(fn: () => void): void {
|
||||
this.onTouched = fn;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user