├── src
├── assets
│ └── .gitkeep
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── app
│ ├── shared
│ │ ├── directives
│ │ │ ├── disable-control
│ │ │ │ ├── disable-control.directive.spec.ts
│ │ │ │ ├── disable-control.module.ts
│ │ │ │ └── disable-control.directive.ts
│ │ │ └── keyboard-manager
│ │ │ │ ├── keyboard-manager.directive.spec.ts
│ │ │ │ ├── keyboard-manager-item.directive.spec.ts
│ │ │ │ ├── keyboard-manager.module.ts
│ │ │ │ ├── keyboard-manager-item.directive.ts
│ │ │ │ └── keyboard-manager.directive.ts
│ │ ├── service
│ │ │ ├── unique-id.service.spec.ts
│ │ │ └── unique-id.service.ts
│ │ └── components
│ │ │ └── si-no-buttons-group
│ │ │ ├── si-no-buttons-group.module.ts
│ │ │ ├── si-no-buttons-group.component.spec.ts
│ │ │ ├── si-no-buttons-group.component.scss
│ │ │ ├── si-no-buttons-group.component.ts
│ │ │ └── si-no-buttons-group.component.html
│ ├── app.component.scss
│ ├── app.component.html
│ ├── app.component.ts
│ ├── app.module.ts
│ └── app.component.spec.ts
├── index.html
├── main.ts
├── styles.scss
├── test.ts
└── polyfills.ts
├── .editorconfig
├── tsconfig.app.json
├── tsconfig.spec.json
├── .browserslistrc
├── .gitignore
├── tsconfig.json
├── README.md
├── package.json
├── karma.conf.js
└── angular.json
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alura-es-cursos/1875-Angular-Diseno-de-componentes-con-accessibilidad/master/src/favicon.ico
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.ts]
12 | quote_type = single
13 |
14 | [*.md]
15 | max_line_length = off
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/src/app/shared/directives/disable-control/disable-control.directive.spec.ts:
--------------------------------------------------------------------------------
1 | import { DisableControlDirective } from './disable-control.directive';
2 |
3 | describe('DisableControlDirective', () => {
4 | it('should create an instance', () => {
5 | const directive = new DisableControlDirective();
6 | expect(directive).toBeTruthy();
7 | });
8 | });
9 |
--------------------------------------------------------------------------------
/src/app/shared/directives/keyboard-manager/keyboard-manager.directive.spec.ts:
--------------------------------------------------------------------------------
1 | import { KeyboardManagerDirective } from './keyboard-manager.directive';
2 |
3 | describe('KeyboardManagerDirective', () => {
4 | it('should create an instance', () => {
5 | const directive = new KeyboardManagerDirective();
6 | expect(directive).toBeTruthy();
7 | });
8 | });
9 |
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Accesibilidad
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/app",
6 | "types": []
7 | },
8 | "files": [
9 | "src/main.ts",
10 | "src/polyfills.ts"
11 | ],
12 | "include": [
13 | "src/**/*.d.ts"
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------
/src/app/shared/directives/keyboard-manager/keyboard-manager-item.directive.spec.ts:
--------------------------------------------------------------------------------
1 | import { KeyboardManagerItemDirective } from './keyboard-manager-item.directive';
2 |
3 | describe('KeyboardManagerItemDirective', () => {
4 | it('should create an instance', () => {
5 | const directive = new KeyboardManagerItemDirective();
6 | expect(directive).toBeTruthy();
7 | });
8 | });
9 |
--------------------------------------------------------------------------------
/src/app/app.component.scss:
--------------------------------------------------------------------------------
1 | main {
2 | height: 100vh;
3 | display: flex;
4 | align-items: center;
5 | justify-content: center;
6 | flex-direction: column;
7 | }
8 |
9 | .btn {
10 | width: 100%;
11 | margin-top: 15px;
12 | padding: 0.5rem;
13 | cursor: pointer;
14 | background-color: var(--secondary-color);
15 | border: none;
16 | border-radius: 5px;
17 | }
18 |
--------------------------------------------------------------------------------
/src/app/shared/directives/disable-control/disable-control.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { DisableControlDirective } from './disable-control.directive';
4 |
5 | @NgModule({
6 | declarations: [DisableControlDirective],
7 | imports: [CommonModule],
8 | exports: [DisableControlDirective],
9 | })
10 | export class DisableControlModule {}
11 |
--------------------------------------------------------------------------------
/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/spec",
6 | "types": [
7 | "jasmine"
8 | ]
9 | },
10 | "files": [
11 | "src/test.ts",
12 | "src/polyfills.ts"
13 | ],
14 | "include": [
15 | "src/**/*.spec.ts",
16 | "src/**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 | Accesibilidad
3 |
11 |
12 | {{ this.form.get("answer")?.value }}
13 |
14 |
--------------------------------------------------------------------------------
/src/app/shared/service/unique-id.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 |
3 | import { UniqueIdService } from './unique-id.service';
4 |
5 | describe('UniqueIdService', () => {
6 | let service: UniqueIdService;
7 |
8 | beforeEach(() => {
9 | TestBed.configureTestingModule({});
10 | service = TestBed.inject(UniqueIdService);
11 | });
12 |
13 | it('should be created', () => {
14 | expect(service).toBeTruthy();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/src/app/shared/service/unique-id.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { v4 as uuidv4 } from 'uuid';
3 |
4 | @Injectable({
5 | providedIn: 'root',
6 | })
7 | export class UniqueIdService {
8 | constructor() {}
9 |
10 | generateUniqueIdWithPrefix(prefix: string): string {
11 | const uniqueId = this.generateUniqueId();
12 | return `${prefix}-${uniqueId}`;
13 | }
14 |
15 | private generateUniqueId(): string {
16 | return uuidv4();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/app/shared/components/si-no-buttons-group/si-no-buttons-group.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { SiNoButtonsGroupComponent } from './si-no-buttons-group.component';
4 | import { KeyboardManagerModule } from '../../directives/keyboard-manager/keyboard-manager.module';
5 |
6 | @NgModule({
7 | declarations: [SiNoButtonsGroupComponent],
8 | imports: [CommonModule, KeyboardManagerModule],
9 | exports: [SiNoButtonsGroupComponent],
10 | })
11 | export class SiNoButtonsGroupModule {}
12 |
--------------------------------------------------------------------------------
/src/app/shared/directives/keyboard-manager/keyboard-manager.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { KeyboardManagerDirective } from './keyboard-manager.directive';
4 | import { KeyboardManagerItemDirective } from './keyboard-manager-item.directive';
5 |
6 | @NgModule({
7 | declarations: [KeyboardManagerDirective, KeyboardManagerItemDirective],
8 | imports: [CommonModule],
9 | exports: [KeyboardManagerDirective, KeyboardManagerItemDirective],
10 | })
11 | export class KeyboardManagerModule {}
12 |
--------------------------------------------------------------------------------
/src/styles.scss:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
3 | * {
4 | box-sizing: border-box;
5 | margin: 0;
6 | padding: 0;
7 | }
8 |
9 | :root {
10 | --primary-color: #4361ee;
11 | --secondary-color: #4cc9f0;
12 | --color-text: #fff;
13 | --background-color: #121212;
14 | --focus-color: #f72585;
15 | }
16 |
17 | body {
18 | font-family: "Open Sans", sans-serif;
19 | color: var(--color-text);
20 | background-color: var(--background-color);
21 | }
22 |
23 | :focus {
24 | outline: 1px solid var(--focus-color);
25 | }
26 |
--------------------------------------------------------------------------------
/src/app/shared/directives/keyboard-manager/keyboard-manager-item.directive.ts:
--------------------------------------------------------------------------------
1 | import { Directive, ElementRef, EventEmitter, Output } from '@angular/core';
2 |
3 | @Directive({
4 | selector: '[appKeyboardManagerItem]',
5 | })
6 | export class KeyboardManagerItemDirective {
7 | @Output() focused = new EventEmitter();
8 |
9 | constructor(private elementRef: ElementRef) {}
10 |
11 | focus(): void {
12 | this.elementRef.nativeElement.focus();
13 | this.focused.emit();
14 | }
15 |
16 | isFocused(): boolean {
17 | return this.elementRef.nativeElement === document.activeElement;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.browserslistrc:
--------------------------------------------------------------------------------
1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 |
5 | # For the full list of supported browsers by the Angular framework, please see:
6 | # https://angular.io/guide/browser-support
7 |
8 | # You can see what browsers were selected by your queries by running:
9 | # npx browserslist
10 |
11 | last 1 Chrome version
12 | last 1 Firefox version
13 | last 2 Edge major versions
14 | last 2 Safari major versions
15 | last 2 iOS major versions
16 | Firefox ESR
17 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { FormBuilder, FormGroup } from '@angular/forms';
3 |
4 | @Component({
5 | selector: 'app-root',
6 | templateUrl: './app.component.html',
7 | styleUrls: ['./app.component.scss'],
8 | })
9 | export class AppComponent {
10 | // answer = 'no';
11 | form!: FormGroup;
12 |
13 | constructor(private formBuilder: FormBuilder) {
14 | this.form = this.formBuilder.group({
15 | answer: [
16 | {
17 | value: 'si',
18 | disabled: false,
19 | },
20 | ],
21 | });
22 | }
23 |
24 | submit(): void {
25 | this.form.get('answer')?.disable();
26 | console.log(this.form.value);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/app/shared/directives/disable-control/disable-control.directive.ts:
--------------------------------------------------------------------------------
1 | import { Directive, Input, OnChanges, SimpleChanges } from '@angular/core';
2 | import { NgControl } from '@angular/forms';
3 |
4 | @Directive({
5 | selector: '[appDisableControl]',
6 | })
7 | export class DisableControlDirective implements OnChanges {
8 | @Input() appDisableControl = false;
9 | constructor(private ngControl: NgControl) {
10 | console.log(this.ngControl);
11 | }
12 |
13 | ngOnChanges(changes: SimpleChanges): void {
14 | console.log(changes);
15 | if (changes['appDisableControl']) {
16 | const action = this.appDisableControl ? 'disable' : 'enable';
17 | this.ngControl.control![action]();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false
7 | };
8 |
9 | /*
10 | * For easier debugging in development mode, you can import the following file
11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
12 | *
13 | * This import should be commented out in production mode because it will have a negative impact
14 | * on performance if an error is thrown.
15 | */
16 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
17 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { FormsModule, ReactiveFormsModule } from '@angular/forms';
3 | import { BrowserModule } from '@angular/platform-browser';
4 |
5 | import { AppComponent } from './app.component';
6 | import { SiNoButtonsGroupModule } from './shared/components/si-no-buttons-group/si-no-buttons-group.module';
7 | import { DisableControlModule } from './shared/directives/disable-control/disable-control.module';
8 |
9 | @NgModule({
10 | declarations: [AppComponent],
11 | imports: [
12 | BrowserModule,
13 | SiNoButtonsGroupModule,
14 | ReactiveFormsModule,
15 | FormsModule,
16 | DisableControlModule,
17 | ],
18 | providers: [],
19 | bootstrap: [AppComponent],
20 | })
21 | export class AppModule {}
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | # Only exists if Bazel was run
8 | /bazel-out
9 |
10 | # dependencies
11 | /node_modules
12 |
13 | # profiling files
14 | chrome-profiler-events*.json
15 |
16 | # IDEs and editors
17 | /.idea
18 | .project
19 | .classpath
20 | .c9/
21 | *.launch
22 | .settings/
23 | *.sublime-workspace
24 |
25 | # IDE - VSCode
26 | .vscode/*
27 | !.vscode/settings.json
28 | !.vscode/tasks.json
29 | !.vscode/launch.json
30 | !.vscode/extensions.json
31 | .history/*
32 |
33 | # misc
34 | /.angular/cache
35 | /.sass-cache
36 | /connect.lock
37 | /coverage
38 | /libpeerconnection.log
39 | npm-debug.log
40 | yarn-error.log
41 | testem.log
42 | /typings
43 |
44 | # System Files
45 | .DS_Store
46 | Thumbs.db
47 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: {
11 | context(path: string, deep?: boolean, filter?: RegExp): {
12 | (id: string): T;
13 | keys(): string[];
14 | };
15 | };
16 |
17 | // First, initialize the Angular testing environment.
18 | getTestBed().initTestEnvironment(
19 | BrowserDynamicTestingModule,
20 | platformBrowserDynamicTesting(),
21 | );
22 |
23 | // Then we find all the tests.
24 | const context = require.context('./', true, /\.spec\.ts$/);
25 | // And load the modules.
26 | context.keys().map(context);
27 |
--------------------------------------------------------------------------------
/src/app/shared/components/si-no-buttons-group/si-no-buttons-group.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { SiNoButtonsGroupComponent } from './si-no-buttons-group.component';
4 |
5 | describe('SiNoButtonsGroupComponent', () => {
6 | let component: SiNoButtonsGroupComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async () => {
10 | await TestBed.configureTestingModule({
11 | declarations: [ SiNoButtonsGroupComponent ]
12 | })
13 | .compileComponents();
14 | });
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(SiNoButtonsGroupComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "compileOnSave": false,
4 | "compilerOptions": {
5 | "baseUrl": "./",
6 | "outDir": "./dist/out-tsc",
7 | "forceConsistentCasingInFileNames": true,
8 | "strict": true,
9 | "noImplicitOverride": true,
10 | "noPropertyAccessFromIndexSignature": true,
11 | "noImplicitReturns": true,
12 | "noFallthroughCasesInSwitch": true,
13 | "sourceMap": true,
14 | "declaration": false,
15 | "downlevelIteration": true,
16 | "experimentalDecorators": true,
17 | "moduleResolution": "node",
18 | "importHelpers": true,
19 | "target": "es2017",
20 | "module": "es2020",
21 | "lib": [
22 | "es2020",
23 | "dom"
24 | ]
25 | },
26 | "angularCompilerOptions": {
27 | "enableI18nLegacyMessageIdFormat": false,
28 | "strictInjectionParameters": true,
29 | "strictInputAccessModifiers": true,
30 | "strictTemplates": true
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 |
4 | describe('AppComponent', () => {
5 | beforeEach(async () => {
6 | await TestBed.configureTestingModule({
7 | declarations: [
8 | AppComponent
9 | ],
10 | }).compileComponents();
11 | });
12 |
13 | it('should create the app', () => {
14 | const fixture = TestBed.createComponent(AppComponent);
15 | const app = fixture.componentInstance;
16 | expect(app).toBeTruthy();
17 | });
18 |
19 | it(`should have as title 'accesibilidad'`, () => {
20 | const fixture = TestBed.createComponent(AppComponent);
21 | const app = fixture.componentInstance;
22 | expect(app.title).toEqual('accesibilidad');
23 | });
24 |
25 | it('should render title', () => {
26 | const fixture = TestBed.createComponent(AppComponent);
27 | fixture.detectChanges();
28 | const compiled = fixture.nativeElement as HTMLElement;
29 | expect(compiled.querySelector('.content span')?.textContent).toContain('accesibilidad app is running!');
30 | });
31 | });
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Accesibilidad
2 |
3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.0.4.
4 |
5 | ## Development server
6 |
7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
8 |
9 | ## Code scaffolding
10 |
11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12 |
13 | ## Build
14 |
15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
16 |
17 | ## Running unit tests
18 |
19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20 |
21 | ## Running end-to-end tests
22 |
23 | Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
24 |
25 | ## Further help
26 |
27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
28 |
--------------------------------------------------------------------------------
/src/app/shared/components/si-no-buttons-group/si-no-buttons-group.component.scss:
--------------------------------------------------------------------------------
1 | .button-group {
2 | .label {
3 | margin-right: 10px;
4 | }
5 |
6 | .button {
7 | background-color: var(--secondary-color);
8 | border: 1px solid var(--secondary-color);
9 | padding: 0.5rem 0.75rem;
10 | margin: 0;
11 | cursor: pointer;
12 |
13 | &.button-yes {
14 | border-radius: 5px 0 0 5px;
15 | }
16 |
17 | &.button-no {
18 | border-radius: 0 5px 5px 0;
19 | }
20 | }
21 |
22 | .button-pressed {
23 | background-color: var(--primary-color);
24 | border-color: var(--primary-color);
25 | box-shadow: inset 0 0 5px 0 rgba(0, 0, 0.2);
26 | }
27 |
28 | .radio {
29 | position: relative;
30 | display: inline-block;
31 |
32 | input {
33 | opacity: 0;
34 | position: absolute;
35 | top: 25%;
36 | left: 25%;
37 | &:focus + label {
38 | outline: solid 1px var(--focus-color);
39 | }
40 | &:checked + label {
41 | @extend .button-pressed;
42 | }
43 | }
44 | label {
45 | display: block;
46 | color: #000;
47 | font-size: 13.33px;
48 | font-family: Arial;
49 | cursor: pointer;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "accesibilidad",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "watch": "ng build --watch --configuration development",
9 | "test": "ng test"
10 | },
11 | "private": true,
12 | "dependencies": {
13 | "@angular/animations": "~13.0.0",
14 | "@angular/common": "~13.0.0",
15 | "@angular/compiler": "~13.0.0",
16 | "@angular/core": "~13.0.0",
17 | "@angular/forms": "~13.0.0",
18 | "@angular/platform-browser": "~13.0.0",
19 | "@angular/platform-browser-dynamic": "~13.0.0",
20 | "@angular/router": "~13.0.0",
21 | "rxjs": "~7.4.0",
22 | "tslib": "^2.3.0",
23 | "uuid": "^8.3.2",
24 | "zone.js": "~0.11.4"
25 | },
26 | "devDependencies": {
27 | "@angular-devkit/build-angular": "~13.0.4",
28 | "@angular/cli": "~13.0.4",
29 | "@angular/compiler-cli": "~13.0.0",
30 | "@types/jasmine": "~3.10.0",
31 | "@types/node": "^12.11.1",
32 | "@types/uuid": "^8.3.4",
33 | "jasmine-core": "~3.10.0",
34 | "karma": "~6.3.0",
35 | "karma-chrome-launcher": "~3.1.0",
36 | "karma-coverage": "~2.0.3",
37 | "karma-jasmine": "~4.0.0",
38 | "karma-jasmine-html-reporter": "~1.7.0",
39 | "typescript": "~4.4.3"
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | jasmine: {
17 | // you can add configuration options for Jasmine here
18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19 | // for example, you can disable the random execution with `random: false`
20 | // or set a specific seed with `seed: 4321`
21 | },
22 | clearContext: false // leave Jasmine Spec Runner output visible in browser
23 | },
24 | jasmineHtmlReporter: {
25 | suppressAll: true // removes the duplicated traces
26 | },
27 | coverageReporter: {
28 | dir: require('path').join(__dirname, './coverage/accesibilidad'),
29 | subdir: '.',
30 | reporters: [
31 | { type: 'html' },
32 | { type: 'text-summary' }
33 | ]
34 | },
35 | reporters: ['progress', 'kjhtml'],
36 | port: 9876,
37 | colors: true,
38 | logLevel: config.LOG_INFO,
39 | autoWatch: true,
40 | browsers: ['Chrome'],
41 | singleRun: false,
42 | restartOnFileChange: true
43 | });
44 | };
45 |
--------------------------------------------------------------------------------
/src/app/shared/directives/keyboard-manager/keyboard-manager.directive.ts:
--------------------------------------------------------------------------------
1 | import {
2 | ContentChildren,
3 | Directive,
4 | HostListener,
5 | QueryList,
6 | } from '@angular/core';
7 | import { KeyboardManagerItemDirective } from './keyboard-manager-item.directive';
8 |
9 | @Directive({
10 | selector: '[appKeyboardManager]',
11 | })
12 | export class KeyboardManagerDirective {
13 | @ContentChildren(KeyboardManagerItemDirective) items!: QueryList;
14 |
15 | @HostListener('keyup', ['$event'])
16 | managekeys(event: KeyboardEvent) {
17 | switch (event.key) {
18 | case 'ArrowRight':
19 | console.log('derecha');
20 | this.moveFocus(ArrowDirection.RIGHT).focus();
21 | break;
22 | case 'ArrowUp':
23 | console.log('arriba');
24 | this.moveFocus(ArrowDirection.RIGHT).focus();
25 | break;
26 | case 'ArrowDown':
27 | console.log('abajo');
28 | this.moveFocus(ArrowDirection.LEFT).focus();
29 | break;
30 | case 'ArrowLeft':
31 | console.log('izquierda');
32 | this.moveFocus(ArrowDirection.LEFT).focus();
33 | break;
34 | }
35 | }
36 | constructor() {}
37 |
38 | moveFocus(direction: ArrowDirection): KeyboardManagerItemDirective {
39 | const items = this.items.toArray();
40 | const currentIndex = items.findIndex((item) => item.isFocused());
41 | console.log(currentIndex);
42 | const targetElement = items[currentIndex + direction];
43 |
44 | if (targetElement) {
45 | return targetElement;
46 | }
47 |
48 | return direction === ArrowDirection.LEFT
49 | ? items[items.length - 1]
50 | : items[0];
51 | }
52 | }
53 |
54 | enum ArrowDirection {
55 | LEFT = -1,
56 | RIGHT = 1,
57 | }
58 |
--------------------------------------------------------------------------------
/src/app/shared/components/si-no-buttons-group/si-no-buttons-group.component.ts:
--------------------------------------------------------------------------------
1 | import {
2 | Component,
3 | EventEmitter,
4 | forwardRef,
5 | Input,
6 | OnInit,
7 | Output,
8 | } from '@angular/core';
9 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
10 | import { v4 as uuidv4 } from 'uuid';
11 | import { UniqueIdService } from '../../service/unique-id.service';
12 | @Component({
13 | selector: 'app-si-no-buttons-group',
14 | templateUrl: './si-no-buttons-group.component.html',
15 | styleUrls: ['./si-no-buttons-group.component.scss'],
16 | providers: [
17 | {
18 | provide: NG_VALUE_ACCESSOR,
19 | multi: true,
20 | useExisting: forwardRef(() => SiNoButtonsGroupComponent),
21 | },
22 | ],
23 | })
24 | export class SiNoButtonsGroupComponent implements OnInit, ControlValueAccessor {
25 | @Input() disabled = false;
26 | @Input() value = '';
27 | @Input() label = '';
28 |
29 | @Output() valueChange = new EventEmitter();
30 |
31 | options = SiNoButtonGroupOptions;
32 |
33 | id = '';
34 |
35 | onChange = (value: string): void => {};
36 | onTouched = () => {};
37 |
38 | constructor(private uniqueIdService: UniqueIdService) {
39 | this.id = this.uniqueIdService.generateUniqueIdWithPrefix(
40 | 'si-no-buttons-group'
41 | );
42 | }
43 |
44 | ngOnInit(): void {}
45 |
46 | writeValue(value: string): void {
47 | this.value = value;
48 | this.onChange(value);
49 | this.valueChange.emit(this.value);
50 | }
51 |
52 | registerOnChange(fn: any): void {
53 | this.onChange = fn;
54 | }
55 |
56 | registerOnTouched(fn: any): void {
57 | this.onTouched = fn;
58 | }
59 |
60 | setDisabledState(isDisabled: boolean): void {
61 | this.disabled = isDisabled;
62 | }
63 |
64 | activate(value: string): void {
65 | this.writeValue(value);
66 | }
67 | }
68 |
69 | enum SiNoButtonGroupOptions {
70 | SI = 'si',
71 | NO = 'no',
72 | }
73 |
--------------------------------------------------------------------------------
/src/app/shared/components/si-no-buttons-group/si-no-buttons-group.component.html:
--------------------------------------------------------------------------------
1 |
37 |
38 |
61 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes recent versions of Safari, Chrome (including
12 | * Opera), Edge on the desktop, and iOS and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /**
22 | * By default, zone.js will patch all possible macroTask and DomEvents
23 | * user can disable parts of macroTask/DomEvents patch by setting following flags
24 | * because those flags need to be set before `zone.js` being loaded, and webpack
25 | * will put import in the top of bundle, so user need to create a separate file
26 | * in this directory (for example: zone-flags.ts), and put the following flags
27 | * into that file, and then add the following code before importing zone.js.
28 | * import './zone-flags';
29 | *
30 | * The flags allowed in zone-flags.ts are listed here.
31 | *
32 | * The following flags will work for all browsers.
33 | *
34 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
35 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
36 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
37 | *
38 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
39 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
40 | *
41 | * (window as any).__Zone_enable_cross_context_check = true;
42 | *
43 | */
44 |
45 | /***************************************************************************************************
46 | * Zone JS is required by default for Angular itself.
47 | */
48 | import 'zone.js'; // Included with Angular CLI.
49 |
50 |
51 | /***************************************************************************************************
52 | * APPLICATION IMPORTS
53 | */
54 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "accesibilidad": {
7 | "projectType": "application",
8 | "schematics": {
9 | "@schematics/angular:component": {
10 | "style": "scss"
11 | },
12 | "@schematics/angular:application": {
13 | "strict": true
14 | }
15 | },
16 | "root": "",
17 | "sourceRoot": "src",
18 | "prefix": "app",
19 | "architect": {
20 | "build": {
21 | "builder": "@angular-devkit/build-angular:browser",
22 | "options": {
23 | "outputPath": "dist/accesibilidad",
24 | "index": "src/index.html",
25 | "main": "src/main.ts",
26 | "polyfills": "src/polyfills.ts",
27 | "tsConfig": "tsconfig.app.json",
28 | "inlineStyleLanguage": "scss",
29 | "assets": [
30 | "src/favicon.ico",
31 | "src/assets"
32 | ],
33 | "styles": [
34 | "src/styles.scss"
35 | ],
36 | "scripts": []
37 | },
38 | "configurations": {
39 | "production": {
40 | "budgets": [
41 | {
42 | "type": "initial",
43 | "maximumWarning": "500kb",
44 | "maximumError": "1mb"
45 | },
46 | {
47 | "type": "anyComponentStyle",
48 | "maximumWarning": "2kb",
49 | "maximumError": "4kb"
50 | }
51 | ],
52 | "fileReplacements": [
53 | {
54 | "replace": "src/environments/environment.ts",
55 | "with": "src/environments/environment.prod.ts"
56 | }
57 | ],
58 | "outputHashing": "all"
59 | },
60 | "development": {
61 | "buildOptimizer": false,
62 | "optimization": false,
63 | "vendorChunk": true,
64 | "extractLicenses": false,
65 | "sourceMap": true,
66 | "namedChunks": true
67 | }
68 | },
69 | "defaultConfiguration": "production"
70 | },
71 | "serve": {
72 | "builder": "@angular-devkit/build-angular:dev-server",
73 | "configurations": {
74 | "production": {
75 | "browserTarget": "accesibilidad:build:production"
76 | },
77 | "development": {
78 | "browserTarget": "accesibilidad:build:development"
79 | }
80 | },
81 | "defaultConfiguration": "development"
82 | },
83 | "extract-i18n": {
84 | "builder": "@angular-devkit/build-angular:extract-i18n",
85 | "options": {
86 | "browserTarget": "accesibilidad:build"
87 | }
88 | },
89 | "test": {
90 | "builder": "@angular-devkit/build-angular:karma",
91 | "options": {
92 | "main": "src/test.ts",
93 | "polyfills": "src/polyfills.ts",
94 | "tsConfig": "tsconfig.spec.json",
95 | "karmaConfig": "karma.conf.js",
96 | "inlineStyleLanguage": "scss",
97 | "assets": [
98 | "src/favicon.ico",
99 | "src/assets"
100 | ],
101 | "styles": [
102 | "src/styles.scss"
103 | ],
104 | "scripts": []
105 | }
106 | }
107 | }
108 | }
109 | },
110 | "defaultProject": "accesibilidad"
111 | }
112 |
--------------------------------------------------------------------------------