문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| angular:material [2019/01/20 11:56] – [사용자 theme 정의하기] taekgu | angular:material [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| ===== Angular Material ===== | ===== Angular Material ===== | ||
| + | * [[https:// | ||
| ==== ng CLI 사용 ==== | ==== ng CLI 사용 ==== | ||
| [[study: | [[study: | ||
| 줄 40: | 줄 41: | ||
| - theme data structure를 여러 팔레트의 구성으로 정의합니다. 이 객체는 mat-light-theme 함수 또는 mat-dark-theme 함수로 만들 수 있습니다. 이 함수의 출력은 angle-material-theme mixin으로 전달되며, | - theme data structure를 여러 팔레트의 구성으로 정의합니다. 이 객체는 mat-light-theme 함수 또는 mat-dark-theme 함수로 만들 수 있습니다. 이 함수의 출력은 angle-material-theme mixin으로 전달되며, | ||
| A typical theme file will look something like this: | A typical theme file will look something like this: | ||
| + | <code css> | ||
| + | @import ' | ||
| + | // Plus imports for other components in your app. | ||
| + | // Include the common styles for Angular Material. We include this here so that you only | ||
| + | // have to load a single css file for Angular Material in your app. | ||
| + | // Be sure that you only ever include this mixin once! | ||
| + | @include mat-core(); | ||
| + | // Define the palettes for your theme using the Material Design palettes available in palette.scss | ||
| + | // (imported above). For each palette, you can optionally specify a default, lighter, and darker | ||
| + | // hue. Available color palettes: https:// | ||
| + | $candy-app-primary: | ||
| + | $candy-app-accent: | ||
| + | |||
| + | // The warn palette is optional (defaults to red). | ||
| + | $candy-app-warn: | ||
| + | |||
| + | // Create the theme object (a Sass map containing all of the palettes). | ||
| + | $candy-app-theme: | ||
| + | |||
| + | // Include theme styles for core and each component used in your app. | ||
| + | // Alternatively, | ||
| + | // that you are using. | ||
| + | @include angular-material-theme($candy-app-theme); | ||
| + | </ | ||
| + | Example of defining multiple themes: | ||
| + | <code css> | ||
| + | @import ' | ||
| + | // Plus imports for other components in your app. | ||
| + | |||
| + | // Include the common styles for Angular Material. We include this here so that you only | ||
| + | // have to load a single css file for Angular Material in your app. | ||
| + | // **Be sure that you only ever include this mixin once!** | ||
| + | @include mat-core(); | ||
| + | |||
| + | // Define the default theme (same as the example above). | ||
| + | $candy-app-primary: | ||
| + | $candy-app-accent: | ||
| + | $candy-app-theme: | ||
| + | |||
| + | // Include the default theme styles. | ||
| + | @include angular-material-theme($candy-app-theme); | ||
| + | |||
| + | |||
| + | // Define an alternate dark theme. | ||
| + | $dark-primary: | ||
| + | $dark-accent: | ||
| + | $dark-warn: | ||
| + | $dark-theme: | ||
| + | |||
| + | // Include the alternative theme styles inside of a block with a CSS class. You can make this | ||
| + | // CSS class whatever you want. In this example, any component inside of an element with | ||
| + | // `.unicorn-dark-theme` will be affected by this alternate dark theme instead of the default theme. | ||
| + | .unicorn-dark-theme { | ||
| + | @include angular-material-theme($dark-theme); | ||
| + | } | ||
| + | </ | ||
| + | === Multiple themes and overlay-based components === | ||
| + | 특정 구성 요소 (예 : 메뉴, 선택, 대화 상자 등)는 전역 오버레이 컨테이너 안에 있기 때문에 위의 예에서 테마의 CSS 클래스 선택기 (.unicorn-dark-theme)의 영향을받는 구성 요소에 대한 추가 단계가 필요합니다. ). | ||
| + | |||
| + | 이렇게하려면 전역 오버레이 컨테이너에 적절한 클래스를 추가 할 수 있습니다. 위의 예제에서는 다음과 같습니다. | ||
| + | <code javascript> | ||
| + | import {OverlayContainer} from ' | ||
| + | |||
| + | @NgModule({ | ||
| + | // ... | ||
| + | }) | ||
| + | export class UnicornCandyAppModule { | ||
| + | constructor(overlayContainer: | ||
| + | overlayContainer.getContainerElement().classList.add(' | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | overlayContainer에서 class삭제 | ||
| + | <code javascript> | ||
| + | |||
| + | onThemeChange(_$event) { | ||
| + | // console.log(" | ||
| + | // this.overlayContainer.getContainerElement().classList.remove(); | ||
| + | // this.overlayContainer.getContainerElement().classList.add(this.theme); | ||
| + | // if (this.theme === " | ||
| + | // | ||
| + | // } else { | ||
| + | // | ||
| + | // } | ||
| + | const overlayContainerClasses = this.overlayContainer.getContainerElement().classList; | ||
| + | const themeClassesToRemove = Array.from(overlayContainerClasses).filter((item: | ||
| + | if (themeClassesToRemove.length) { | ||
| + | overlayContainerClasses.remove(...themeClassesToRemove); | ||
| + | } | ||
| + | overlayContainerClasses.add(this.theme); | ||
| + | } | ||
| + | </ | ||
| + | === Theming only certain components === | ||
| + | |||
| + | The angular-material-theme mixin will output styles for all components in the library. If you are only using a subset of the components (or if you want to change the theme for specific components), | ||
| + | <code css> | ||
| + | @import ' | ||
| + | // Plus imports for other components in your app. | ||
| + | |||
| + | // Include the common styles for Angular Material. We include this here so that you only | ||
| + | // have to load a single css file for Angular Material in your app. | ||
| + | // **Be sure that you only ever include this mixin once!** | ||
| + | @include mat-core(); | ||
| + | |||
| + | // Define the theme. | ||
| + | $candy-app-primary: | ||
| + | $candy-app-accent: | ||
| + | $candy-app-theme: | ||
| + | |||
| + | // Include the theme styles for only specified components. | ||
| + | @include mat-core-theme($candy-app-theme); | ||
| + | @include mat-button-theme($candy-app-theme); | ||
| + | @include mat-checkbox-theme($candy-app-theme); | ||
| + | </ | ||
| ==== 참조 ==== | ==== 참조 ==== | ||
| icon | icon | ||
| https:// | https:// | ||
| css grid | css grid | ||