#GWC UI Library : ToolButton

웹 UI 라이브러리인 GWC에서 제공하는 Select 컴포넌트에 대한 예제 코드입니다.

먼저 DOM 구성은 다음과 같습니다.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<div class="center">
<gwc-label id="label" content="상태 변경 이벤트"></gwc-label>
<div>
<gwc-toolbutton id="toolbutton1" icon="images/icon1.png"></gwc-toolbutton>
<gwc-toolbutton id="toolbutton2" icon="images/icon2.png" pressed="true"></gwc-toolbutton>
<gwc-toolbutton id="toolbutton3" icon="images/icon3.png"></gwc-toolbutton>
</div>
</div>
<div class="center"> <gwc-label id="label" content="상태 변경 이벤트"></gwc-label> <div> <gwc-toolbutton id="toolbutton1" icon="images/icon1.png"></gwc-toolbutton> <gwc-toolbutton id="toolbutton2" icon="images/icon2.png" pressed="true"></gwc-toolbutton> <gwc-toolbutton id="toolbutton3" icon="images/icon3.png"></gwc-toolbutton> </div> </div>

그리고 CSS 구성은 다음과 같구요.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
.center {
display: flex;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 1em;
}
.center > div {
display: flex;
gap: 1em;
}
.center { display: flex; width: 100%; height: 100%; justify-content: center; align-items: center; flex-direction: column; gap: 1em; } .center > div { display: flex; gap: 1em; }
.center {
    display: flex;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 1em;
}

.center > div {
    display: flex;
    gap: 1em;
}

js 코드는 다음과 같습니다.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
window.onload = () => {
toolbutton1.addEventListener("click", () => {
gwcMessage("안녕하세요! GWC 라이브러리입니다.");
});
toolbutton2.addEventListener("statechange", (event) => {
const tb = event.target;
label.content = `${tb.id}${tb.pressed?"DOWN":"UP"}된 상태입니다.`;
});
toolbutton2.addEventListener("click", () => {
toolbutton2.pressed = !toolbutton2.pressed;
});
toolbutton3.addEventListener("click", () => {
toolbutton3.disabled = true;
});
};
window.onload = () => { toolbutton1.addEventListener("click", () => { gwcMessage("안녕하세요! GWC 라이브러리입니다."); }); toolbutton2.addEventListener("statechange", (event) => { const tb = event.target; label.content = `${tb.id}가 ${tb.pressed?"DOWN":"UP"}된 상태입니다.`; }); toolbutton2.addEventListener("click", () => { toolbutton2.pressed = !toolbutton2.pressed; }); toolbutton3.addEventListener("click", () => { toolbutton3.disabled = true; }); };
window.onload = () => {
    toolbutton1.addEventListener("click", () => { 
        gwcMessage("안녕하세요! GWC 라이브러리입니다.");
    });

    toolbutton2.addEventListener("statechange", (event) => {
        const tb = event.target;
        label.content = `${tb.id}가 ${tb.pressed?"DOWN":"UP"}된 상태입니다.`;
    });

    toolbutton2.addEventListener("click", () => {
        toolbutton2.pressed = !toolbutton2.pressed;
    });

    toolbutton3.addEventListener("click", () => {
        toolbutton3.disabled = true;
    });
};

실행 결과는 다음과 같습니다.

title 속성으로 간단한 툴팁을 표현할 수 있습니다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다