웹 UI 라이브러리인 GWC에서 제공하는 Tab 컴포넌트에 대한 예제 코드입니다.
먼저 DOM 구성은 다음과 같습니다.
<div class="vcenter">
<gwc-label id="label" content="Tab 변경 이벤트"></gwc-label>
<gwc-tab id="tab" selected-tab=4>
<tabs>
<tab title="텍스트">
<div class="vcenter">
<h2>안녕하세요. GWC 라이브러리입니다.</h2>
<gwc-button id="button1" title="다운로드"></gwc-button>
</div>
</tab>
<tab title="툴버튼">
<div class="center">
<gwc-toolbutton class="toolbutton09" icon="images/icon2.png"></gwc-toolbutton>
<gwc-toolbutton icon="images/icon3.png"></gwc-toolbutton>
<gwc-toolbutton icon="images/icon1.png"></gwc-toolbutton>
</div>
</tab>
<tab title="탭1">
<div class="vcenter">
<div>
<gwc-checkbox title="사과"></gwc-checkbox>
<gwc-checkbox title="토마토"></gwc-checkbox>
<gwc-checkbox title="귤"></gwc-checkbox>
<gwc-checkbox title="당근"></gwc-checkbox>
<gwc-checkbox title="바나나"></gwc-checkbox>
</div>
<gwc-slider label="볼륨" unit="dB" to-fixed=1 min=0 max=100 value=45></gwc-slider>
</div>
</tab>
<tab title="탭2">
<div class="vcenter">
<gwc-radiogroup>
<items>
<item>CSS</item>
<item>JS</item>
<item>HTML</item>
</items>
</gwc-radiogroup>
<div>
<gwc-label content="DOWNLOADING" outline-type="concave"></gwc-label><gwc-progress auto="true"></gwc-progress>
</div>
</div>
</tab>
<tab title="수직스크롤뷰">
<div class="vcenter">
<gwc-vscrollview>
<content>
<p>01. 인간은 말이 아닌 행위로 정의된다.</p>
<p>02. 인간은 말이 아닌 행위로 정의된다.</p>
<p>03. 인간은 말이 아닌 행위로 정의된다.</p>
<p>04. 인간은 말이 아닌 행위로 정의된다.</p>
<p>05. 인간은 말이 아닌 행위로 정의된다.</p>
<p>06. 인간은 말이 아닌 행위로 정의된다.</p>
<p>07. 인간은 말이 아닌 행위로 정의된다.</p>
<p>08. 인간은 말이 아닌 행위로 정의된다.</p>
<p>09. 인간은 말이 아닌 행위로 정의된다.</p>
<p>10. 인간은 말이 아닌 행위로 정의된다.</p>
<p>11. 인간은 말이 아닌 행위로 정의된다.</p>
<p>12. 인간은 말이 아닌 행위로 정의된다.</p>
<p>13. 인간은 말이 아닌 행위로 정의된다.</p>
<p>14. 인간은 말이 아닌 행위로 정의된다.</p>
<p>15. 인간은 말이 아닌 행위로 정의된다.</p>
<p>16. 인간은 말이 아닌 행위로 정의된다.</p>
<p>17. 인간은 말이 아닌 행위로 정의된다.</p>
<p>18. 인간은 말이 아닌 행위로 정의된다.</p>
<p>19. 인간은 말이 아닌 행위로 정의된다.</p>
<p>20. 인간은 말이 아닌 행위로 정의된다.</p>
</content>
</gwc-vscrollview>
</div>
</tab>
</tabs>
</gwc-tab>
<gwc-button id="button2" title="세번째 탭으로 변경"></gwc-button>
</div>
그리고 CSS 구성은 다음과 같구요.
.center {
display: flex;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
gap: 0.5em;
}
.vcenter {
display: flex;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 2em;
}
gwc-tab {
width: 35em;
height: 13em;
}
gwc-vscrollview {
width: 25em;
height: 9em;
}
gwc-slider {
width: 18em;
}
gwc-progress {
width: 20em;
}
gwc-label {
margin-right: 0.5em;
}
div, h2 {
color: white;
}
p:nth-child(2n) {
color: greenyellow;
font-size: 1.2em;
}
p:nth-child(2n+1) {
color: yellow;
}
js 코드는 다음과 같습니다.
window.onload = () => {
button1.onclick = () => {
gwcMessage("GitHub에서 다운로드 가능합니다.");
}
tab.addEventListener("change", (event) => {
label.content = `${event.detail.previousTab}번 탭에서 ${event.detail.currentTab}번 탭으로 변경 되었습니다.`; ;
});
button2.onclick = () => tab.selectedTab = 3;
GeoServiceWebComponentManager.instance.update();
};
실행 결과는 다음과 같습니다.
