Wijmo 리본

Wijmo 5에는 Ribbon 컨트롤이 없지만, TabPanel 컨트롤과 Wijmo 입력 모듈의 컨트롤을 사용하여 리본을 간편하게 만들 수 있습니다.

이 예제는 사용자 정의 리본을 사용하여 간단한 텍스트 편집기를 빌드하는 방법을 보여 줍니다.

리본 요소는 TabPanel입니다. 탭 페이지에는 컨트롤 그룹이 행과 열에 정렬되어 있습니다. 그룹의 컨트롤은 Material 아이콘을 사용하며, 각 컨트롤에 할당된 aria-label 특성에 따라 도구 설명이 자동으로 생성됩니다.

탭 헤더 옆에 있는 빈 영역을 두 번 클릭하면 리본 콘텐츠 표시 여부를 토글할 수 있습니다.

Wijmo 알아보기 | TabPanel API Reference

import 'bootstrap.css'; import '@mescius/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wjCore from '@mescius/wijmo'; import * as wjInput from '@mescius/wijmo.input'; import * as wjNav from '@mescius/wijmo.nav'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // initialize editor element let editor = document.querySelector('#editor'); execCommand('styleWithCSS', true); // if (localStorage.editorContent) { editor.innerHTML = localStorage.editorContent; } // // create ribbon let ribbon = new wjNav.TabPanel('#ribbon'); // // toggle ribbon content visibility on double-clicks, restore on clicks document.querySelector('.wj-tabheaders').addEventListener('dblclick', e => { if (!wjCore.hasClass(e.target, 'wj-tabheader')) { wjCore.toggleClass(ribbon.hostElement, 'hide-content'); } }); document.querySelector('.wj-tabheaders').addEventListener('click', e => { if (wjCore.hasClass(e.target, 'wj-tabheader')) { wjCore.toggleClass(ribbon.hostElement, 'hide-content', false); } }); // // set up combos let fontFace = new wjInput.ComboBox('#font-face', { itemsSource: ['Arial', 'Courier New', 'Garamond', 'Tahoma', 'Times', 'Verdana', 'WingDings'], textChanged: (sender) => execCommand('fontName', sender.text) }); let fontSize = new wjInput.ComboBox('#font-size', { itemsSource: ['Very Small', 'Smaller', 'Small', 'Medium', 'Large', 'Larger', 'Very Large'], selectedIndex: 3, textChanged: (sender) => execCommand('fontSize', sender.selectedIndex + 1) }); // // set up color pickers let clrBack = createColorPicker(sender => execCommand('backColor', sender.value)); document.querySelector('#background').addEventListener('click', e => { wjCore.showPopup(clrBack.hostElement, e.target, false, true, false); clrBack.focus(); }); let clrFore = createColorPicker(sender => execCommand('foreColor', sender.value)); document.querySelector('#color').addEventListener('click', e => { wjCore.showPopup(clrFore.hostElement, e.target, false, true, false); clrFore.focus(); }); // // add tooltips (based on aria-label attribute) addTooltips(ribbon); // // execute commands ribbon.hostElement.addEventListener('click', e => { switch (e.target.id) { // format group case 'save': localStorage.editorContent = editor.innerHTML; alert('Document Saved to Local Storage.'); break; case 'undo': case 'redo': case 'preview': case 'removeFormat': case 'cut': case 'copy': case 'paste': case 'selectAll': execCommand(e.target.id); break; // // font group case 'bold': case 'italic': case 'underline': case 'strikethrough': case 'subscript': case 'superscript': execCommand(e.target.id); break; // case 'click-me': alert('Wijmo Ribbon Sample'); } }); // // execute editor commands function execCommand(cmd, parm) { editor.focus(); document.execCommand(cmd, false, parm); } // // save/restore editor selection on focus changes let selection = null; editor.addEventListener('keyup', () => selection = saveSelection()); editor.addEventListener('mouseup', () => selection = saveSelection()); editor.addEventListener('focus', () => restoreSelection(selection)); // function saveSelection() { let sel = window.getSelection(); return sel && sel.rangeCount ? sel.getRangeAt(0) : null; } // function restoreSelection(range) { if (range) { let sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range); } } // // add tooltips based on the element's aria-label attribute function addTooltips(ctl) { let tt = new wjCore.Tooltip(); let els = ctl.hostElement.querySelectorAll('[aria-label]'); for (let i = 0; i < els.length; i++) { tt.setTooltip(els[i], els[i].getAttribute('aria-label')); } } // // create an auto-hiding color picker control function createColorPicker(valueChanged) { // create color picker let host = wjCore.createElement('<div class="wj-dropdown-panel"></div>'); let picker = new wjInput.ColorPicker(host, { lostFocus: function (s) { valueChanged(picker); wjCore.hidePopup(s.hostElement); } }); // done return picker; } }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>MESCIUS Wijmo TabPanel Ribbon</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.21.5/system.src.js" integrity="sha512-skZbMyvYdNoZfLmiGn5ii6KmklM82rYX2uWctBhzaXPxJgiv4XBwJnFGr5k8s+6tE1pcR1nuTKghozJHyzMcoA==" crossorigin="anonymous"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div id="ribbon"> <!-- Format tab --> <div> <div>Format</div> <div> <div class="wj-group"> <div class="wj-content"> <div class="wj-column"> <button id="save" class="wj-btn wj-btn-large"> <i class="material-icons">save</i> <br /> Save </button> </div> <div class="wj-column"> <div class="wj-row"> <button id="undo" class="wj-btn" aria-label="Undo"> <i class="material-icons">undo</i> </button> <button id="redo" class="wj-btn" aria-label="Redo"> <i class="material-icons">redo</i> </button> <button id="preview" class="wj-btn" aria-label="Preview"> <i class="material-icons">pageview</i> </button> <button id="removeFormat" class="wj-btn" aria-label="Remove Format"> <i class="material-icons">format_clear</i> </button> </div> <div class="wj-row"> <button id="cut" class="wj-btn" aria-label="Cut"> <i class="material-icons">&#x2702;</i> </button> <button id="copy" class="wj-btn" aria-label="Copy"> <i class="material-icons">&#xE14D;</i> </button> <button id="paste" class="wj-btn" aria-label="Paste"> <i class="material-icons">&#xE85D;</i> </button> <button id="selectAll" class="wj-btn" aria-label="Select All"> <i class="material-icons">select_all</i> </button> </div> </div> </div> <div class="wj-header">Actions</div> </div> <div class="wj-group"> <div class="wj-content"> <div class="wj-row"> <div id="font-face" aria-label="Font Face"></div> <div id="font-size" aria-label="Font Size"></div> <button id="background" class="wj-btn" aria-label="Background Color"> <i class="material-icons">format_color_fill</i> </button> <button id="color" class="wj-btn" aria-label="Text Color"> <i class="material-icons">format_color_text</i> </button> </div> <div class="wj-row"> <button id="bold" class="wj-btn" aria-label="Bold"> <i class="material-icons">format_bold</i> </button> <button id="italic" class="wj-btn" aria-label="Italic"> <i class="material-icons">format_italic</i> </button> <button id="underline" class="wj-btn" aria-label="Underline"> <i class="material-icons">format_underline</i> </button> <button id="strikethrough" class="wj-btn" aria-label="Strikethrough"> <i class="material-icons">format_strikethrough</i> </button> <button id="subscript" class="wj-btn" aria-label="Subscript"> <i class="material-icons">vertical_align_bottom</i> </button> <button id="superscript" class="wj-btn" aria-label="Superscript"> <i class="material-icons">vertical_align_top</i> </button> </div> </div> <div class="wj-header">Font</div> </div> </div> </div> <!-- Custom Tab --> <div> <div>Custom Tab</div> <div> <div class="wj-group"> <div class="wj-content"> <div class="wj-column"> <button id="click-me" class="wj-btn wj-btn-large"> Click Me </button> </div> </div> <div class="wj-header">Custom Group</div> </div> </div> </div> </div> <div id="editor" contenteditable="true"> <b>Lorem Ipsum</b> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. </div> </div> </body> </html>
@import url('https://fonts.googleapis.com/icon?family=Material+Icons'); .wj-tabpane { white-space: nowrap; /* keep groups on a single line */ } .wj-group { display: inline-block; border-right: 1px solid #eee; padding: 3px 6px 0 3px; } .wj-group >.wj-header { text-align: center; background: transparent; font-weight: normal; font-size: 80%; margin-top: 6px; } .wj-group >.wj-content { border: none; height: 5.5em; overflow: visible; } .wj-group .wj-column { display: inline-block; vertical-align: top; } .wj-group .wj-row { margin-bottom: 2px; } .wj-control .wj-group .wj-content .wj-btn { font-weight: normal; padding: 5px 12px; } .wj-group .wj-content .wj-btn.wj-btn-large { padding: 2em 1.5em; } .wj-group .material-icons { font-size: 110%; padding-top: 2px; pointer-events: none; } .wj-group .wj-dropdown { width: 10em; border: none; background: #eee; } /* hide ribbon content */ .wj-tabpanel.hide-content .wj-tabpanes { height: 0; transition: height linear 400ms; } #editor { height: 300px; overflow: auto; padding: 12px; background: #ffe; border: 1px solid #ccc; } body { margin-bottom: 36pt; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { 'jszip': 'npm:jszip/dist/jszip.js', '@mescius/wijmo': 'npm:@mescius/wijmo/index.js', '@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js', '@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles', '@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures', '@mescius/wijmo.chart': 'npm:@mescius/wijmo.chart/index.js', '@mescius/wijmo.chart.analytics': 'npm:@mescius/wijmo.chart.analytics/index.js', '@mescius/wijmo.chart.animation': 'npm:@mescius/wijmo.chart.animation/index.js', '@mescius/wijmo.chart.annotation': 'npm:@mescius/wijmo.chart.annotation/index.js', '@mescius/wijmo.chart.finance': 'npm:@mescius/wijmo.chart.finance/index.js', '@mescius/wijmo.chart.finance.analytics': 'npm:@mescius/wijmo.chart.finance.analytics/index.js', '@mescius/wijmo.chart.hierarchical': 'npm:@mescius/wijmo.chart.hierarchical/index.js', '@mescius/wijmo.chart.interaction': 'npm:@mescius/wijmo.chart.interaction/index.js', '@mescius/wijmo.chart.radar': 'npm:@mescius/wijmo.chart.radar/index.js', '@mescius/wijmo.chart.render': 'npm:@mescius/wijmo.chart.render/index.js', '@mescius/wijmo.chart.webgl': 'npm:@mescius/wijmo.chart.webgl/index.js', '@mescius/wijmo.chart.map': 'npm:@mescius/wijmo.chart.map/index.js', '@mescius/wijmo.gauge': 'npm:@mescius/wijmo.gauge/index.js', '@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js', '@mescius/wijmo.grid.detail': 'npm:@mescius/wijmo.grid.detail/index.js', '@mescius/wijmo.grid.filter': 'npm:@mescius/wijmo.grid.filter/index.js', '@mescius/wijmo.grid.search': 'npm:@mescius/wijmo.grid.search/index.js', '@mescius/wijmo.grid.grouppanel': 'npm:@mescius/wijmo.grid.grouppanel/index.js', '@mescius/wijmo.grid.multirow': 'npm:@mescius/wijmo.grid.multirow/index.js', '@mescius/wijmo.grid.transposed': 'npm:@mescius/wijmo.grid.transposed/index.js', '@mescius/wijmo.grid.transposedmultirow': 'npm:@mescius/wijmo.grid.transposedmultirow/index.js', '@mescius/wijmo.grid.pdf': 'npm:@mescius/wijmo.grid.pdf/index.js', '@mescius/wijmo.grid.sheet': 'npm:@mescius/wijmo.grid.sheet/index.js', '@mescius/wijmo.grid.xlsx': 'npm:@mescius/wijmo.grid.xlsx/index.js', '@mescius/wijmo.grid.selector': 'npm:@mescius/wijmo.grid.selector/index.js', '@mescius/wijmo.grid.cellmaker': 'npm:@mescius/wijmo.grid.cellmaker/index.js', '@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/index.js', '@mescius/wijmo.odata': 'npm:@mescius/wijmo.odata/index.js', '@mescius/wijmo.olap': 'npm:@mescius/wijmo.olap/index.js', '@mescius/wijmo.rest': 'npm:@mescius/wijmo.rest/index.js', '@mescius/wijmo.pdf': 'npm:@mescius/wijmo.pdf/index.js', '@mescius/wijmo.pdf.security': 'npm:@mescius/wijmo.pdf.security/index.js', '@mescius/wijmo.viewer': 'npm:@mescius/wijmo.viewer/index.js', '@mescius/wijmo.xlsx': 'npm:@mescius/wijmo.xlsx/index.js', '@mescius/wijmo.undo': 'npm:@mescius/wijmo.undo/index.js', '@mescius/wijmo.interop.grid': 'npm:@mescius/wijmo.interop.grid/index.js', '@mescius/wijmo.touch': 'npm:@mescius/wijmo.touch/index.js', '@mescius/wijmo.cloud': 'npm:@mescius/wijmo.cloud/index.js', '@mescius/wijmo.barcode': 'npm:@mescius/wijmo.barcode/index.js', '@mescius/wijmo.barcode.common': 'npm:@mescius/wijmo.barcode.common/index.js', '@mescius/wijmo.barcode.composite': 'npm:@mescius/wijmo.barcode.composite/index.js', '@mescius/wijmo.barcode.specialized': 'npm:@mescius/wijmo.barcode.specialized/index.js', 'jszip': 'npm:jszip/dist/jszip.js', 'bootstrap.css': 'npm:bootstrap/dist/css/bootstrap.min.css', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);