clase:daw:diw:1eval:tema02
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Próxima revisión | Revisión previa | ||
| clase:daw:diw:1eval:tema02 [2025/11/03 11:37] – creado - editor externo 127.0.0.1 | clase:daw:diw:1eval:tema02 [2026/10/23 23:04] (actual) – Reorganización del módulo: contenido movido a las páginas nuevas de clase:daw:diw claude | ||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| - | ====== 2. Introducción a los componentes visuales ====== | ||
| - | |||
| - | |||
| - | |||
| - | ===== Crear una aplicación de Angular ===== | ||
| - | * Instala Angular CLI v20 | ||
| - | |||
| - | <sxh bash> | ||
| - | npm install | ||
| - | </ | ||
| - | |||
| - | * Crea una aplicación de Angular | ||
| - | |||
| - | <sxh bash> | ||
| - | ng new prueba | ||
| - | </ | ||
| - | |||
| - | Las preguntas que hacen se response de la siguiente forma: | ||
| - | * '' | ||
| - | * '' | ||
| - | (SSG/ | ||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | ===== Ejecutar la App ===== | ||
| - | |||
| - | * Dentro de la carpeta del proyecto, ejecutar | ||
| - | |||
| - | <sxh bash> | ||
| - | ng serve | ||
| - | </ | ||
| - | |||
| - | |||
| - | * Navegar a [[http:// | ||
| - | |||
| - | ===== Modificar la página de inicio ===== | ||
| - | |||
| - | * Modifica el fichero '' | ||
| - | |||
| - | <sxh html> | ||
| - | < | ||
| - | </ | ||
| - | |||
| - | <h1 >Hola mundo</ | ||
| - | |||
| - | <button > | ||
| - | Aceptar | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | </ | ||
| - | |||
| - | |||
| - | Los dos ficheros importantes son: | ||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | |||
| - | * Vamos a dejar el componente de '' | ||
| - | |||
| - | <sxh typescript; | ||
| - | import { Component, signal } from ' | ||
| - | import { RouterOutlet } from ' | ||
| - | |||
| - | |||
| - | @Component({ | ||
| - | selector: ' | ||
| - | imports: [RouterOutlet], | ||
| - | templateUrl: | ||
| - | styleUrl: ' | ||
| - | }) | ||
| - | export class App { | ||
| - | protected readonly title = signal(' | ||
| - | |||
| - | |||
| - | } | ||
| - | </ | ||
| - | |||
| - | <sxh html; | ||
| - | < | ||
| - | </ | ||
| - | |||
| - | <h1 >Hola mundo</ | ||
| - | |||
| - | <button > | ||
| - | Aceptar | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | </ | ||
| - | |||
| - | |||
| - | ===== Añadir Angular Material ===== | ||
| - | La librería que vamos a usar en este módulo es [[https:// | ||
| - | |||
| - | * Para añadirla al proyecto se usa: | ||
| - | |||
| - | <sxh bash> | ||
| - | ng add @angular/ | ||
| - | </ | ||
| - | |||
| - | Las preguntas que hacen se response de la siguiente forma: | ||
| - | * '' | ||
| - | |||
| - | ===== Usar Angular Material ===== | ||
| - | Para usar un componente, | ||
| - | |||
| - | Lo primero es buscar el componente en [[https:// | ||
| - | |||
| - | Veamos el ejemplo con el componente [[https:// | ||
| - | |||
| - | * Navega a [[https:// | ||
| - | |||
| - | <sxh ts> | ||
| - | import {MatButtonModule} from ' | ||
| - | </ | ||
| - | |||
| - | |||
| - | * Ves al fichero '' | ||
| - | |||
| - | |||
| - | * En el array de '' | ||
| - | |||
| - | <sxh ts> | ||
| - | imports: [RouterOutlet, | ||
| - | </ | ||
| - | |||
| - | |||
| - | El fichero '' | ||
| - | |||
| - | <sxh typescript; | ||
| - | import { Component, signal } from ' | ||
| - | import { RouterOutlet } from ' | ||
| - | import {MatButtonModule} from ' | ||
| - | |||
| - | @Component({ | ||
| - | selector: ' | ||
| - | imports: [RouterOutlet, | ||
| - | templateUrl: | ||
| - | styleUrl: ' | ||
| - | }) | ||
| - | export class App { | ||
| - | protected readonly title = signal(' | ||
| - | |||
| - | |||
| - | |||
| - | } | ||
| - | </ | ||
| - | |||
| - | |||
| - | * Ahora ya puedes transformar un botón " | ||
| - | |||
| - | <sxh html; | ||
| - | < | ||
| - | </ | ||
| - | |||
| - | <h1 >Hola mundo</ | ||
| - | |||
| - | <button matButton> | ||
| - | Aceptar | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | </ | ||
| - | |||
| - | |||
| - | ===== Personalizar componentes ===== | ||
| - | |||
| - | * Cambia para que sea '' | ||
| - | |||
| - | <sxh html; | ||
| - | < | ||
| - | </ | ||
| - | |||
| - | <h1 >Hola mundo</ | ||
| - | |||
| - | <button matButton=" | ||
| - | Aceptar | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | </ | ||
| - | |||
| - | |||
| - | Vuelve a los ejemplos que hay en [[https:// | ||
| - | |||
| - | Prueba ahora a añadir un icono de Angular Material para ello ves a [[https:// | ||
| - | |||
| - | Y fíjate que ahora ya no se añade un atributo a una etiqueta HTML sino que directamente es la etiqueta '' | ||
| - | |||
| - | |||
| - | ===== Design Tokens ===== | ||
| - | Vamos a ver como personalizar los componentes de Angular Material. Para personalizarlo se usa el concepto llamado " | ||
| - | |||
| - | El la documentación del componente '' | ||
| - | |||
| - | Para el componente '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | Para cada grupo ('' | ||
| - | |||
| - | * '' | ||
| - | * '' | ||
| - | * | ||
| - | |||
| - | |||
| - | ¿Como cambiamos entonces esos valores? Pues creamos una clase CSS en SASS con lo siguiente: | ||
| - | |||
| - | <sxh sass> | ||
| - | @use ' | ||
| - | |||
| - | .botones-grandes { | ||
| - | @include mat.button-overrides(( | ||
| - | filled-label-text-size: | ||
| - | outlined-label-text-size: | ||
| - | )); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | |||
| - | Si queremos que sea para todos los componentes no hay más que hacer: | ||
| - | |||
| - | <sxh sass> | ||
| - | @use ' | ||
| - | |||
| - | html { | ||
| - | @include mat.button-overrides(( | ||
| - | filled-label-text-size: | ||
| - | outlined-label-text-size: | ||
| - | )); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | |||
| - | Actualmente en Angular Material 20, todos esos Tokens de diseño realmente se transforman en variables CSS | ||
| - | |||
| - | Veamos algunos ejemplos: | ||
| - | |||
| - | * Para botones '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * Para botones '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * Para botones '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | | ||
| - | Propiedades CSS | ||
| - | |||
| - | * Para botones '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * Para botones '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * Para botones '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | | ||
| - | | ||
| - | ===== System Tokens ===== | ||
| - | Resulta que si vemos el código CSS que usa Angular Material para los Design Tokens, podemos comprobar que es de la siguiente forma: | ||
| - | | ||
| - | <sxh css; | ||
| - | background-color: | ||
| - | color: var(--mat-button-filled-label-text-color, | ||
| - | border-radius: | ||
| - | padding: 0 var(--mat-button-filled-horizontal-padding, | ||
| - | font-size: var(--mat-button-filled-label-text-size, | ||
| - | </ | ||
| - | <sxh css; | ||
| - | color: var(--mat-button-outlined-label-text-color, | ||
| - | border-color: | ||
| - | background-color: | ||
| - | border-radius: | ||
| - | padding: 0 var(--mat-button-outlined-horizontal-padding, | ||
| - | font-size: var(--mat-button-outlined-label-text-size, | ||
| - | </ | ||
| - | <sxh css; | ||
| - | color: var(--mat-button-text-label-text-color, | ||
| - | background-color: | ||
| - | border-radius: | ||
| - | padding: 0 var(--mat-button-text-horizontal-padding, | ||
| - | font-size: var(--mat-button-text-label-text-size, | ||
| - | </ | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | Es decir que hay una serie de variable CSS globales que afectan a todo Angular Material. Esas variables CSS globales se llaman **System Tokens**. Y que como vemos empieza por '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | ¿Como podemos saber el listado completo de variables globales (System Tokens)? Creando una paleta nueva [[https:// | ||
| - | |||
| - | |||
| - | <note important> | ||
| - | |||
| - | |||
| - | logongas@beren: | ||
| - | ✔ What HEX color should be used to generate the M3 theme? It will represent your primary color palette. (ex. #ffffff) #1979E6 | ||
| - | ✔ What HEX color should be used represent the secondary color palette? (Leave blank to use generated colors from Material) #E67519 | ||
| - | ✔ What HEX color should be used represent the tertiary color palette? (Leave blank to use generated colors from Material) | ||
| - | ✔ What HEX color should be used represent the neutral color palette? (Leave blank to use generated colors from Material) | ||
| - | ✔ What HEX color should be used represent the neutral variant palette? (Leave blank to use generated colors from Material) | ||
| - | ✔ What HEX color should be used represent the error palette? (Leave blank to use generated colors from Material) | ||
| - | ✔ Do you want to generate high contrast value override mixins for your themes?. Providing a high contrast version of your theme when a user specifies helps increase the accesibility of your application. No | ||
| - | ✔ What is the directory you want to place the generated theme file in? (Enter the relative path such as ' | ||
| - | ✔ Do you want the generated file to be a scss file? This is the recommended way of setting up theming in your application. If not, a CSS file will be generated with all the system variables defined. (Leave blank to generate a scss file) No | ||
| - | CREATE src/ | ||
| - | |||
| - | Y generará un fichero CSS con todas las variables (System Tokens) , un ejemplo es este fichero: {{ : | ||
| - | |||
| - | Pero para modificar los System Tokens no deberíamos modificar directamente las variables de ese fichero sino usando el mixing de crear un tema '' | ||
| - | |||
| - | Al añadir Angular Material se añade el siguiente código en '' | ||
| - | |||
| - | <sxh sass; | ||
| - | html { | ||
| - | @include mat.theme(( | ||
| - | color: ( | ||
| - | primary: mat.$azure-palette, | ||
| - | tertiary: mat.$blue-palette | ||
| - | ), | ||
| - | typography: Roboto, | ||
| - | density: 0, | ||
| - | )); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | Pues si queremos definir algún System Tokens no tenemos que añadir más que un map con los System Tokens y sus nuevos valores | ||
| - | |||
| - | |||
| - | <sxh sass; | ||
| - | html { | ||
| - | @include mat.theme(( | ||
| - | color: ( | ||
| - | primary: mat.$azure-palette, | ||
| - | tertiary: mat.$blue-palette | ||
| - | ), | ||
| - | typography: Roboto, | ||
| - | density: 0, | ||
| - | ),( | ||
| - | corner-full: | ||
| - | label-large-size: | ||
| - | )); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | |||
| - | |||
| - | Vemos en el ejemplo que ahora el '' | ||
| - | mientras que el tipo de letra grande ahora sería de '' | ||
| - | |||
| - | |||
| - | ===== Paletas de colores ===== | ||
| - | Para terminar nuestra personalización de Angular Material, nos hace falta definir los colores. | ||
| - | |||
| - | En Angular Material hay 5 tipos de colores pero los importantes son: | ||
| - | * '' | ||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | Para generar nuestra paleta de colores tenemos que volver a usar el comando '' | ||
| - | |||
| - | |||
| - | ng generate @angular/ | ||
| - | ✔ What HEX color should be used to generate the M3 theme? It will represent your primary color palette. (ex. #ffffff) #57BF40 | ||
| - | ✔ What HEX color should be used represent the secondary color palette? (Leave blank to use generated colors from Material) #A840BF | ||
| - | ✔ What HEX color should be used represent the tertiary color palette? (Leave blank to use generated colors from Material) #40BDBF | ||
| - | ✔ What HEX color should be used represent the neutral color palette? (Leave blank to use generated colors from Material) | ||
| - | ✔ What HEX color should be used represent the neutral variant palette? (Leave blank to use generated colors from Material) | ||
| - | ✔ What HEX color should be used represent the error palette? (Leave blank to use generated colors from Material) | ||
| - | ✔ Do you want to generate high contrast value override mixins for your themes?. Providing a high contrast version of your theme when a user specifies helps increase the accesibility of your application. No | ||
| - | ✔ What is the directory you want to place the generated theme file in? (Enter the relative path such as ' | ||
| - | ✔ Do you want the generated file to be a scss file? This is the recommended way of setting up theming in your application. If not, a CSS file will be generated with all the system variables defined. (Leave blank to generate a scss file) Yes | ||
| - | CREATE src/ | ||
| - | |||
| - | |||
| - | En el ejemplo se ha creado el fichero {{ : | ||
| - | |||
| - | <sxh sass; | ||
| - | // This file was generated by running 'ng generate @angular/ | ||
| - | // Proceed with caution if making changes to this file. | ||
| - | |||
| - | @use ' | ||
| - | @use ' | ||
| - | |||
| - | // Note: Color palettes are generated from primary: #4084BF, secondary: #B5BF40, tertiary: #BF4040, neutral: #74808B, neutral variant: #B7C5D2, error: #BE4141 | ||
| - | $_palettes: ( | ||
| - | primary: (0: #000000,10: #001d34,20: #003355,25: #003e66,30: #004a78,35: #00568b,40: #0d629b,50: #367bb6,60: #5495d2,70: #70b0ee,80: #99cbff,90: #cfe5ff,95: #e8f1ff,98: #f7f9ff,99: # | ||
| - | secondary: (0: #000000,10: #1b1d00,20: #2f3300,25: #3a3f00,30: #454a00,35: #515700,40: #5c6300,50: #757d00,60: #8e9718,70: #a9b334,80: #c4ce4e,90: #e0eb67,95: #effa74,98: #faffb0,99: # | ||
| - | tertiary: (0: #000000,10: #410005,20: #68000d,25: #7a0a15,30: #8b191f,35: #9b2629,40: #ac3233,50: #cd4a49,60: #ef6360,70: #ff8984,80: #ffb3af,90: #ffdad7,95: #ffedeb,98: #fff8f7,99: # | ||
| - | neutral: (0: #000000,10: #111d26,20: #26323b,25: #313d46,30: #3c4852,35: #48545e,40: #54606a,50: #6d7883,60: #86929d,70: #a0adb8,80: #bcc8d4,90: #d8e4f0,95: #e6f2ff,98: #f6faff,99: # | ||
| - | neutral-variant: | ||
| - | error: (0: #000000,10: #410005,20: #68000d,25: #790c16,30: #8a1a20,35: #9a272a,40: #ab3334,50: #cc4b4a,60: #ee6462,70: #ff8984,80: #ffb3af,90: #ffdad7,95: #ffedeb,98: #fff8f7,99: # | ||
| - | ); | ||
| - | |||
| - | $_rest: ( | ||
| - | secondary: map.get($_palettes, | ||
| - | neutral: map.get($_palettes, | ||
| - | neutral-variant: | ||
| - | error: map.get($_palettes, | ||
| - | ); | ||
| - | |||
| - | $primary-palette: | ||
| - | $tertiary-palette: | ||
| - | </ | ||
| - | |||
| - | Este fichero crea las variables SASS con las paletas de colores. | ||
| - | * '' | ||
| - | * '' | ||
| - | |||
| - | Cada paleta (variable de SASS) ya incluye además los colores '' | ||
| - | |||
| - | |||
| - | Y ahora ya podemos usarlos para crear nuestro tema con nuestros colores y nuestros System Tokens | ||
| - | |||
| - | <sxh sass; | ||
| - | html { | ||
| - | @include mat.theme(( | ||
| - | color: ( | ||
| - | primary: $primary-palette, | ||
| - | tertiary: $tertiary-palette | ||
| - | ), | ||
| - | typography: Roboto, | ||
| - | density: 0, | ||
| - | ),( | ||
| - | corner-full: | ||
| - | label-large-size: | ||
| - | )); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | El ejemplo completo con todo el código se puede ver en GitHub en [[https:// | ||
| - | |||
| - | |||
| - | | ||
| - | Más información | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
| - | |||
clase/daw/diw/1eval/tema02.1762166241.txt.gz · Última modificación: por 127.0.0.1
