Web Components Banner 개요
Ignite UI for Web Components Banner 구성 요소는 스낵바보다 덜 일시적이고 대화 상자보다 덜 눈에 거슬리는 방식으로 애플리케이션 사용자에게 눈에 띄는 메시지를 쉽게 표시할 수 있는 방법을 제공합니다. 또한 메시지의 컨텍스트에 따라 수행할 작업을 나타낼 수도 있습니다.
Ignite UI for Web Components Banner Example
Usage
먼저 다음 명령을 실행하여 Ignite UI for Web Components 설치해야 합니다.
npm install igniteui-webcomponents
그 다음에는 필요한 CSS를 가져오IgcBannerComponent 고, 그 모듈을 등록해야 합니다. 다음과 같습니다:
import { defineComponents, IgcBannerComponent } from "igniteui-webcomponents";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
defineComponents(IgcBannerComponent);
Ignite UI for Web Components에 대한 완전한 소개는 '시작 주제'를 읽어보세요.
Show Banner
배너 컴포넌트를 표시하려면 그show 메서드를 사용하고 버튼 클릭으로 호출하세요. 배너는 해당 요소가 페이지 템플릿에 삽입된 위치에 대해 기준으로 나타나며, 나머지 모든 콘텐츠를 이동시킵니다. 보통 최소한의 사용자 상호작용만으로도 해산되는 비침해적인 콘텐츠를 보여줍니다.
<igc-button onclick="banner.show()">Show Banner</igc-button>
<igc-banner id="banner">
You are currently offline.
</igc-banner>
[!NOTE] The
IgcBannerComponentincludes a default action buttonOK, which closes the banner.
Examples
이 컴포넌트는IgcBannerComponent 콘텐츠 템플릿을 허용하면서도 머티리얼 디자인 배너 지침을 최대한 준수할 수 있습니다.
Changing the banner message
Configuring the message displayed in the banner is easy - just change the content you are passing to the igc-banner tag. The text will show up in the specified banner area and the banner will use its default template when displaying it. Below, we will change the content of our sample banner to be a bit more descriptive:
<igc-banner id="banner">
You have lost connection to the internet. This app is offline.
</igc-banner>
Adding an icon
AnIgcIconComponent 배너에 표시할 수 있는 것은 배너의prefix 슬롯. 아이콘은 항상 배너 메시지 시작 부분에 위치합니다.
[!NOTE] If several
IgcIconComponentelements are inserted, the banner will try to position all of them at the beginning. It is strongly advised to pass only oneIgcIconComponentdirectly to the banner.
배너로 a를 전달IgcIconComponent 하려면 다음 슬롯을 사용하세요prefix:
<igc-banner id="banner">
<igc-icon slot="prefix" name="signal_wifi_off"></igc-icon>
You have lost connection to the internet. This app is offline.
</igc-banner>
배너 내 메시지를 사용하고IgcIconComponent 싶다면, 배너 내용에 삽입하면 됩니다:
<igc-banner id="banner">
You have lost connection to the internet. This app is offline.
<igc-icon name="signal_wifi_off"></igc-icon>
</igc-banner>
Changing the banner button
이렇게 하면IgcBannerComponent 배너 버튼을 템플릿 넣을 수 있는 슬롯이actions 드러납니다. 이 기능을 통해 기본 배너 버튼(OK)을 덮어쓰고 사용자 정의 커스텀 액션을 추가할 수 있습니다.
<igc-banner id="banner">
<igc-icon slot="prefix" name="signal_wifi_off"></igc-icon>
You have lost connection to the internet. This app is offline.
<div slot="actions">
<igc-button onclick="banner.toggle()">
<igc-ripple></igc-ripple>
Toggle Banner
</igc-button>
</div>
</igc-banner>
Binding to events
배너 구성 요소는 닫힐 때 이벤트Closing를 방출합니다Closed. 이벤트는Closing 취소 가능하며, 인터페이스를 사용하고CustomEvent 방출된 객체의 속성이cancelable true로 설정되어 있습니다. 이벤트를Closing 취소하면 해당 종료 액션과 이벤트가 발동되지 않고, 배너가 닫히지 않고 이벤트가Closed 발동되지 않습니다.
종료 이벤트를 취소하려면 메서드를preventDefault 호출하세요.
<igc-banner id="banner">
...
</igc-banner>
const banner = document.getElementById('banner') as IgcBannerComponent;
banner.addEventListener('igcClosing', (event) => {
event.preventDefault();
});
[!NOTE] If the changes above are applied, the banner will never close, as the closing event is always cancelled.
Advanced Example
알림 해제용과 연결 활성화용 버튼 두 개의 커스텀 버튼이 있는 배너를 만들어봅시다. 우리는 다음 슬롯을 사용하여actions 커스텀 액션 핸들러를 전달할 수 있습니다:
<igc-banner id="banner">
<igc-icon slot="prefix" name="signal_wifi_off"></igc-icon>
You have lost connection to the internet. This app is offline.
<div slot="actions">
<igc-button onclick="banner.hide()">
<igc-ripple></igc-ripple>
Continue Offline
</igc-button>
<igc-button id="button">
<igc-ripple></igc-ripple>
Turn On Wifi
</igc-button>
</div>
</igc-banner>
구글의 머티리얼 디자인 가이드라인에 따르면, 배너에는 최대 2개의 버튼이 있어야 합니다.
IgcBannerComponent슬롯 아래actions요소 수를 명시적으로 제한하지는 않지만, 재료 디자인 지침을 따르려면 최대 2개까지 사용하는 것이 강력히 권장됩니다.
디사이트 옵션(오프라인 계속 진행)은 추가 로직이 필요 없으니 메서드를hide 호출하면 됩니다. 하지만 확인 동작(Turn On Wifi)은 추가 로직이 필요하기 때문에 컴포넌트에서 정의해야 합니다. 그 다음에는 이벤트에 대한click 리스너를 추가할 예정입니다. 마지막 단계는 각 변경 시 메서드를refreshBanner() 호출하는 것으로, 이 메서드는 필요에wifiState 따라 배너를 토글링합니다.
내비게이션바에는 와이파이 아이콘이 있고, 이벤트에 대한click 이벤트 리스너도 추가할 예정입니다.refreshBanner() 메서드가 변경될 때마다 호출되면, 아이콘은 배너를 토글할 뿐만 아니라 연결 상태에 따라 바뀝니다:
<igc-navbar>
<h1>Gallery</h1>
<igc-icon id="icon" slot="end" name="signal_wifi_off"></igc-icon>
</igc-navbar>
<igc-banner id="banner">
...
<div slot="actions">
...
<igc-button id="button">
<igc-ripple></igc-ripple>
Turn On Wifi
</igc-button>
</div>
</igc-banner>
private banner: IgcBannerComponent;
private icon: IgcIconComponent;
private button: IgcButtonComponent;
private wifiState: boolean = false;
constructor() {
this.banner = document.getElementById('banner') as IgcBannerComponent;
this.icon = document.getElementById('icon') as IgcIconComponent;
this.button = document.getElementById('button') as IgcButtonComponent;
this.icon.addEventListener('click', () => this.refreshBanner());
this.button.addEventListener('click', () => this.refreshBanner());
}
public refreshBanner() {
if (!this.wifiState) {
this.icon.name = 'signal_wifi_4_bar';
this.banner.hide();
} else {
this.icon.name = 'signal_wifi_off';
this.banner.show();
}
this.wifiState = !this.wifiState;
}
마지막으로, WiFi 상태에 관한 메시지를 표시하는 aIgcToastComponent를 추가할 예정입니다. 템플릿 배너의 결과는 아래 데모에서 확인할 수 있습니다:
Styling
이 컴포넌트는IgcBannerComponent 스타일을 완전히 제어할 수 있는 여러 CSS 파트를 제공합니다:
| 이름 | 설명 |
|---|---|
base |
배너 구성 요소의 기본 래퍼입니다. |
spacer |
배너 주위의 공간을 설정하는 내부 래퍼입니다. |
message |
텍스트와 일러스트레이션을 담고 있는 부분입니다. |
illustration |
배너 아이콘/일러스트레이션을 보유하는 부분입니다. |
content |
배너 텍스트 콘텐츠를 보유하는 부분입니다. |
actions |
배너 작업 버튼을 보유하는 부분입니다. |
igc-banner::part(spacer) {
background: var(--ig-surface-600);
}
igc-banner::part(illustration) {
color: var(--ig-surface-600-contrast);
}
igc-banner::part(content) {
color: var(--ig-gray-900);
}
API References
IgcBannerComponentIgcCardComponentIgcIconComponentIgcNavbarComponentIgcToastComponentIgcRippleComponentStyling & Themes