2017-10-04 1 views
0

특히,

한 번 구현할 수있게하고 싶습니다. 모든 구성 요소 SCSS 파일에 여러 개의 테마 및 참조 $primary-dark이 있어야합니다.

내가 지시를 사용하는 솔루션을 찾고하지 오전 Theming your Angular Material app

에서 여러 테마를 구현합니다.

나는 그럴 수 없다고 말하고 있습니다.

+0

"구성 요소 SCSS 파일"에 대한 정의는 무엇입니까? '$ primary-dark' (테마 X의 어두운 기본 색상이나 "어두운"또는 ect 같은 테마의 기본 색상)의 정의는 무엇입니까? –

+0

모든 테마에 속하는 색상 변수입니다. – ttugates

답변

1

*이 *

당신은 즉시 그들을 교환하려는 경우, 당신은 여전히 ​​당신의 site.scss 파일 내부의 다른 테마를 모두 정의 할 필요가 있기 때문에 코멘트 업데이트되었습니다.

@import '[email protected]/material/theming'; 
// 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: mat-palette($mat-indigo); 
$candy-app-accent: mat-palette($mat-pink, A200, A100, A400); 
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent); 

// Include the default theme styles. 
@include angular-material-theme($candy-app-theme); 

// Define an alternate dark theme. 
$dark-primary: mat-palette($mat-blue-grey); 
$dark-accent: mat-palette($mat-amber, A200, A100, A400); 
$dark-warn: mat-palette($mat-deep-orange); 
$dark-theme: mat-dark-theme($dark-primary, $dark-accent, $dark-warn); 

// 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); 
} 

당신이 테마 싶은 구성 요소에 .unicorn-dark-theme 클래스를 추가해야합니다.

저는 실제로 동적 테마를 작성하지는 않았지만 ng-class을 루트 레벨에 놓고 필요에 따라 토글 할 수 있기를 바랍니다.

해당 링크의 오른쪽 상단에있는 작은 페인트 통 아이콘을 클릭하면 원래 또한

을 게시 @ttugates 테마 조성 링크에서 여러 테마라는 제목의 섹션이 있습니다, 당신은 4 가지 테마 옵션을 볼 수 있습니다 .

일부 데모 코드로 재생하려면 material2 repo를 로컬로 복제하고 종속성을 설치 한 다음 npm run demo-app을 실행하십시오. 몇 가지 실제 예와 함께 놀 수있는 좋은 방법입니다.

* ORIGINAL 답변 *

우리가 사용해야하는 다른 .scss 파일로 site.scss 파일을 가져 같은 그런

$grey-color: mat-color(mat-palette($mat-grey)); 

으로 우리는 우리의 모든 변수를 선언하는 site.scss 파일이 그것. 당신이 제공 한 링크를 말한다처럼 우리는 그래서 우리는 스타일을 포함 빌드 우리에 대한 각-CLI 사용하는

@import '../../../styles/site.scss'; 

.set-for-deletion { 
    text-decoration: line-through; 
    color: $grey-color; 
} 

.angular-cli.json 파일에 파일.

Angular CLI를 사용하는 경우 Sass to css를 컴파일하도록 지원됩니다. 테마 파일 (예 : unicorn-app-theme.scss)을 가리키는 angular-cli.json의 'styles'목록에 새 항목을 추가하기 만하면됩니다.

+0

고마워요, 저는이 점을 css/angular 방법을 알고있는 제 동료가 실행하고 있습니다. SCSS를 런타임에 바꾸어 테마를 선택하는 방식으로 작동하는지 확인하는 것이 좋습니다. 내가 의견을받을 때 질문이나 마크를 답변으로 후속 조치 할 것입니다. – ttugates

+0

우리는'scss'를 런타임에 바꾸기 때문에 사용자가 새로운 테마를 선택할 때이 접근법이 작동하지 않는다고 들었습니다. 나는 우리가 모든 주제를 가져 오지 않는다는 특이성을 가지고 나의 질문을 업데이트하는 것이 적절하다면, 실행시에'scss' 파일을 바꾼다는 것을 모른다. 또는 답을 수락하고 질문을 다시 게시하십시오. – ttugates

+0

'site.scss'에서 특별히'$ grey-color' 파일을 가져 오는데, 어떻게하면'$ primary' 파일을 런타임에 변경되는 x 파일에서 가져올 수 있습니까? –

관련 문제