refactor: move libs

This commit is contained in:
thomas
2024-05-11 21:27:33 +02:00
parent 4a3c7f23e0
commit 001d35731a
659 changed files with 775 additions and 1573 deletions

View File

@@ -0,0 +1,16 @@
import { Component } from '@angular/core';
import { FeedbackFormComponent } from './feedback-form/feedback-form.component';
@Component({
standalone: true,
imports: [FeedbackFormComponent],
selector: 'app-root',
template: `
<app-feedback-form (feedBackSubmit)="apiCall($event)"></app-feedback-form>
`,
})
export class AppComponent {
apiCall(event: Record<string, string | null>): void {
console.log(event);
}
}

View File

@@ -0,0 +1,29 @@
<form
[formGroup]="feedbackForm"
class="feedback-form"
(ngSubmit)="submitForm()">
<legend class="feedback-form-title">Tell us what you think</legend>
<input
class="feedback-form-control"
[formControl]="feedbackForm.controls.name"
placeholder="Name"
type="text" />
<input
class="feedback-form-control"
[formControl]="feedbackForm.controls.email"
placeholder="Email"
type="email" />
<app-rating-control (ratingUpdated)="rating = $event"></app-rating-control>
<textarea
class="feedback-form-control"
[formControl]="feedbackForm.controls.comment"
placeholder="Сomment text"></textarea>
<button
class="feedback-form-submit"
type="submit"
[disabled]="
!feedbackForm.touched || rating === null || feedbackForm.invalid
">
Submit
</button>
</form>

View File

@@ -0,0 +1,50 @@
* {
box-sizing: border-box;
}
:host {
display: block;
padding: 20px;
}
.feedback-form {
display: flex;
flex-direction: column;
width: 500px;
padding: 20px;
border: 1px solid #000000;
}
.feedback-form-title {
margin-bottom: 20px;
font-size: 24px;
}
.feedback-form-control {
max-height: 200px;
margin-bottom: 20px;
padding: 12px 12px 12px 20px;
border-radius: 0;
background-color: #fbfbfb;
color: #3c3c3c;
font-size: 18px;
&:focus {
padding: 10px 10px 10px 18px;
border: 2px solid #054ada;
outline: none;
background: #fff;
}
}
.feedback-form-submit {
padding: 10px;
background-color: #054ada;
color: #ffffff;
font-size: 18px;
&[disabled] {
background-color: #cccccc;
color: #ffffff;
}
}

View File

@@ -0,0 +1,42 @@
import { Component, EventEmitter, Output } from '@angular/core';
import {
FormControl,
FormGroup,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import { RatingControlComponent } from '../rating-control/rating-control.component';
@Component({
standalone: true,
imports: [RatingControlComponent, ReactiveFormsModule],
selector: 'app-feedback-form',
templateUrl: 'feedback-form.component.html',
styleUrls: ['feedback-form.component.scss'],
})
export class FeedbackFormComponent {
@Output()
readonly feedBackSubmit: EventEmitter<Record<string, string | null>> =
new EventEmitter<Record<string, string | null>>();
readonly feedbackForm = new FormGroup({
name: new FormControl('', {
validators: Validators.required,
}),
email: new FormControl('', {
validators: Validators.required,
}),
comment: new FormControl(),
});
rating: string | null = null;
submitForm(): void {
this.feedBackSubmit.emit({
...this.feedbackForm.value,
rating: this.rating,
});
this.feedbackForm.reset();
}
}

View File

@@ -0,0 +1,16 @@
<svg width="0" height="0" xmlns="http://www.w3.org/2000/svg">
<symbol id="star" width="50" height="50" xmlns="http://www.w3.org/2000/svg">
<path
d="M31.77 11.857H19.74L15.99.5l-3.782 11.357H0l9.885 6.903-3.692 11.21 9.736-7.05 9.796 6.962-3.722-11.18 9.766-6.845z" />
</symbol>
</svg>
<div class="rating">
@for (item of [].constructor(5); track item) {
<svg
class="star"
[class.star-active]="isStarActive($index, value)"
(click)="setRating($index)">
<use xlink:href="#star"></use>
</svg>
}
</div>

After

Width:  |  Height:  |  Size: 547 B

View File

@@ -0,0 +1,26 @@
.rating {
display: flex;
justify-content: center;
padding: 0 10px;
&:hover {
.star {
fill: #ffd055;
}
}
}
.star {
width: 50px;
height: 50px;
fill: #cccccc;
cursor: pointer;
&:hover ~ .star {
fill: #d8d8d8;
}
}
.star-active {
fill: #ffd055 !important;
}

View File

@@ -0,0 +1,23 @@
import { Component, EventEmitter, Output } from '@angular/core';
@Component({
standalone: true,
selector: 'app-rating-control',
templateUrl: 'rating-control.component.html',
styleUrls: ['rating-control.component.scss'],
})
export class RatingControlComponent {
@Output()
readonly ratingUpdated: EventEmitter<string> = new EventEmitter<string>();
value: number | null = null;
setRating(index: number): void {
this.value = index + 1;
this.ratingUpdated.emit(`${this.value}`);
}
isStarActive(index: number, value: number | null): boolean {
return value ? index < value : false;
}
}