スタイルの設定

このサンプルではテキストコントロールの背景色や幅、高さなどのスタイルをCSSに設定する場合のソースコードを確認することができます。

本製品ではコントロールの高さや幅などのサイズのほか、背景色や文字色などを含め、コントロールの外観はすべてCSS(Cascading Style Sheet)により設定します。 コントロールで使用されるCSSクラスの詳細については、以下の製品ヘルプをご参照ください。 コントロールの外観設定 入力コントロールのCSS 新しいスタイルの設定方法 InputManJSは2種類のデザインを提供しています。appearanceStyleプロパティを設定することで、従来のデザインまたは新しいデザインを適用できます。すべてのコントロールを初期化する前に設定する必要があります。 appearanceStyleプロパティの設定できる値は次のとおりで、既定値はClassicです。 値 説明 Classic 従来のデザイン Modern 新しいデザイン
<template> <div> <div class="flexbox"> <div> 通常の状態<br> <GcTextBoxComponent text="テキスト"></GcTextBoxComponent> </div> <div> 無効な状態<br> <GcTextBoxComponent text="テキスト" :enabled="false"></GcTextBoxComponent> </div> <div> ウォーターマーク<br> <GcTextBoxComponent watermark-display-null-text="氏名" watermark-null-text="全角で入力してください"></GcTextBoxComponent> </div> </div> <div class="peoperty-header">コントロール全般のスタイル</div> <div class="peoperty-panel"> <label><input type="checkbox" value=".gcim,width">コントロールの幅</label> <label><input type="checkbox" value=".gcim,height">コントロールの高さ</label> <label><input type="checkbox" value=".gcim,backgroundColor">背景色</label> <label><input type="checkbox" value=".gcim,borderColor">境界線の色</label> <label><input type="checkbox" value=".gcim,borderWidth">境界線の幅</label> <label><input type="checkbox" value=".gcim,borderStyle">境界線のスタイル</label> <label><input type="checkbox" value=".gcim,borderRadius">境界線の角丸</label> <label><input type="checkbox" value=".gcim__input,cursor">カーソルの形</label> <label><input type="checkbox" value=".gcim,boxShadow">コントロールの影</label> </div> <div class="peoperty-header">テキストのスタイル</div> <div class="peoperty-panel"> <label><input type="checkbox" value=".gcim,color">文字色</label> <label><input type="checkbox" value=".gcim__input,fontSize">フォントのサイズ</label> <label><input type="checkbox" value=".gcim__input,fontWeight">フォントの太さ</label> <label><input type="checkbox" value=".gcim__input,fontStyle">フォントのスタイル</label> <label><input type="checkbox" value=".gcim__input,fontFamily">フォントの種類</label> <label><input type="checkbox" value=".gcim__input,textAlign">水平方向の位置</label> <label><input type="checkbox" value=".gcim__input,textShadow">テキストの影</label> </div> <div class="peoperty-header">コントロール無効時のスタイル</div> <div class="peoperty-panel"> <label><input type="checkbox" value=".gcim__input:disabled,backgroundColor">背景色</label> <label><input type="checkbox" value=".gcim__input:disabled,color">文字色</label> </div> <div class="peoperty-header">フォーカス時のスタイル</div> <div class="peoperty-panel"> <label><input type="checkbox" value=".gcim_focused,backgroundColor">背景色</label> <label><input type="checkbox" value=".gcim_focused,borderColor">境界線の色</label> <label><input type="checkbox" value=".gcim_focused,color">文字色</label> </div> <div class="peoperty-header">ウォーターマークのスタイル</div> <div class="peoperty-panel"> <label><input type="checkbox" value=".gcim_watermark_null,backgroundColor">背景色</label> <label><input type="checkbox" value=".gcim_watermark_null,borderColor">境界線の色</label> <label><input type="checkbox" value=".gcim_watermark_null,color">文字色</label> </div> <div class="peoperty-header">ウォーターマークのフォーカス時のスタイル</div> <div class="peoperty-panel"> <label><input type="checkbox" value=".gcim_focused.gcim_watermark_null,backgroundColor">背景色</label> <label><input type="checkbox" value=".gcim_focused.gcim_watermark_null,borderColor">境界線の色</label> <label><input type="checkbox" value=".gcim_focused.gcim_watermark_null,color">文字色</label> </div> <button id="copyStyle">CSSコードをコピー</button><br> <textarea id="style" cols="60" rows="10"></textarea> </div> </template> <script setup> import '@mescius/inputman/CSS/gc.inputman-js.css'; import {onMounted} from 'vue'; import '@mescius/inputman.vue'; import { InputMan } from '@mescius/inputman'; import {GcTextBoxComponent} from '@mescius/inputman.vue'; InputMan.appearanceStyle = InputMan.AppearanceStyle.Modern; var styleSheet; var indices = []; const styles = { '.gcim': { width: '200px', height: '40px', backgroundColor: '#ddffdd', borderColor: '#009900', borderWidth: '2px', borderStyle: 'dashed', borderRadius: '12px', boxShadow: '5px 5px 5px rgba(0,0,0,0.5)', color: '#009900' }, '.gcim__input': { cursor: 'crosshair', fontSize: '20px', fontWeight: 'bold', fontStyle: 'italic', fontFamily: 'serif', textAlign: 'right', textShadow: '1px 1px 1px rgba(0,0,0,0.5)' }, '.gcim__input:disabled': { backgroundColor: '#666666', color: '#cccccc', cursor: 'wait' }, '.gcim_focused': { backgroundColor: '#ddddff', borderColor: '#0000ff', color: '#0000ff' }, '.gcim_watermark_null': { backgroundColor: '#ffdddd', borderColor: '#ff0000', color: '#ff0000' }, '.gcim_focused.gcim_watermark_null': { backgroundColor: '#ffddff', borderColor: '#990099', color: '#990099' }, }; const createInitialStyles = function() { const element = document.createElement('style'); document.head.appendChild(element); styleSheet = element.sheet; var i = 0; for (const styleName in styles) { styleSheet.insertRule(getRulePrefix() + styleName + '{}', i); indices[styleName] = i; i++; } } const updateStyle = function(event) { console.log(event); var element = event.target; if (element.tagName == 'INPUT') { var values = element.value.split(','); var styleName = values[0]; var propertyName = values[1]; styleSheet.cssRules[indices[styleName]].style[propertyName] = element.checked ? styles[styleName][propertyName] : ''; } var style = ''; for (var i = 0; i < styleSheet.cssRules.length; i++) { if (styleSheet.cssRules[i].style.length > 0) { style += styleSheet.cssRules[i].cssText.replace(/{/g, '{\n ').replace(/;/g, ';\n ').replace(/ }/g, '}') + '\n'; } } document.getElementById('style').value = style; } const copyStyle = function() { document.getElementById('style').select(); document.execCommand('copy'); } const getRulePrefix = function() { return InputMan.appearanceStyle === InputMan.AppearanceStyle.Modern? '[gcim-control-appearance="modern"] ' : ''; } onMounted(() => { createInitialStyles(); var panels = document.getElementsByClassName('peoperty-panel'); for (var i = 0; i < panels.length; i++) { panels[i].addEventListener('click', updateStyle); } document.getElementById('copyStyle').addEventListener('click', copyStyle); }) </script>
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>テキストコントロール - スタイルの設定</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script src="compiler.js" type="module"></script> <script> window.onload = function() { var System = SystemJS; System.import("./src/app.js"); } </script> </head> <body> <div id="app"></div> </body> </html>
(function (global) { SystemJS.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, packageConfigPaths: [ './node_modules/*/package.json', "./node_modules/@mescius/*/package.json", "./node_modules/@babel/*/package.json", "./node_modules/@vue/*/package.json" ], map: { 'vue': "npm:vue/dist/vue.esm-browser.js", 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', "systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js", "@mescius/inputman": 'npm:@mescius/inputman/index.js', "@mescius/inputman.vue": 'npm:@mescius/inputman.vue/lib/gc.inputman.plugin.vue.js', "@mescius/inputman/CSS": "npm:@mescius/inputman/CSS", "@mescius/inputman.richtexteditor": "npm:@mescius/inputman.richtexteditor/index.js", "@mescius/inputman.richtexteditor.vue": "npm:/@mescius/inputman.richtexteditor.vue/lib/gc.inputman.richtexteditor.plugin.vue.js", "@mescius/inputman.richtexteditor/CSS": "npm:@mescius/inputman.richtexteditor/CSS", '@mescius/wijmo': 'npm:@mescius/wijmo/index.js', '@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles', '@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures/wijmo.culture.ja.js', '@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/index.js', '@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js', '@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js', '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-ja': 'npm:@mescius/spread-sheets-resources-ja/index.js', '@mescius/spread-sheets/styles': 'npm:@mescius/spread-sheets/styles', 'css': 'npm:systemjs-plugin-css/css.js', }, meta: { '*.css': { loader: 'css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);