数値コントロールでは、スライダー入力を有効にする場合の入力フィールドの非表示を設定できます。
入力フィールドの非表示
入力フィールドの非表示を有効にするには、sliderConfigプロパティのreplaceEditorオプションをtrueに設定します。
また、keyboardプロパティを設定することでキーボードでスライダーを操作できるようにを変更します。keyStepプロパティでキーボードでスライダーを操作する時の増分値を設定できます。
次のサンプルコードは、数値コントロールに入力フィールドの非表示のスライダーを追加することを示しています。
注意事項
検証機能を利用する際に、通知をコントロールの状態に設定しても無効になります。検証結果を通知する方法を「ツールチップ」または「アイコン」に設定する場合、スライダーの外側に検証通知が表示されます。
スピン機能やフォーカス移動など一部の機能が使用できません。
import '@mescius/inputman/CSS/gc.inputman-js.css';
import { InputMan } from '@mescius/inputman';
import './styles.css';
InputMan.appearanceStyle = InputMan.AppearanceStyle.Modern;
const numberConfig = {
width: 400,
minValue: 0,
maxValue: 255,
value: 128,
sliderConfig: {
visible: true,
replaceEditor: true,
marks: [0, 128, 255],
showMarkLabel: true,
showMarkTip: true,
tooltipShowMode: 'always',
},
};
const gcNumberR = new InputMan.GcNumber(document.getElementById('gcNumberR'),
numberConfig
);
const gcNumberG = new InputMan.GcNumber(document.getElementById('gcNumberG'),
numberConfig
);
const gcNumberB = new InputMan.GcNumber(document.getElementById('gcNumberB'),
numberConfig
);
document.getElementById('replaceEditor').addEventListener('change', (e) => {
gcNumberR.slider.replaceEditor = !e.target.checked;
gcNumberG.slider.replaceEditor = !e.target.checked;
gcNumberB.slider.replaceEditor = !e.target.checked;
});
[gcNumberR, gcNumberG, gcNumberB].forEach((control) =>
control.onInput(updateColor)
);
function updateColor() {
const color = [gcNumberR, gcNumberG, gcNumberB]
.map((control) => control.value.toString(16).padStart(2, '0'))
.reduce((result, v) => result + v, '#');
document.getElementById('showColor').style.backgroundColor = color;
}
updateColor();
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>数値コントロール - 入力フィールドの非表示</title>
<!-- SystemJS -->
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
window.onload = function () {
System.import('./src/app');
}
</script>
</head>
<body>
<div id="showColor"></div>
<br />
<br />
<div class="color-picker">
<label>R:</label>
<input type="number" id="gcNumberR" min="0" max="255" />
<br />
<label>G:</label>
<input type="number" id="gcNumberG" min="0" max="255" />
<br />
<label>B:</label>
<input type="number" id="gcNumberB" min="0" max="255" />
</div>
<table class="sample">
<tr>
<th>入力フィールド</th>
<td>
<label><input type="checkbox" id="replaceEditor" />表示する</label>
</td>
</tr>
</table>
</body>
</html>
body {
padding-bottom: 10rem;
}
.color-picker {
display: grid;
grid-template-columns: 20px 300px 50px;
gap: 10px;
align-items: center;
}
#showColor {
width: 300px;
height: 100px;
border: 0.5px solid #000;
}
body {
padding-bottom: 10rem;
}
.color-picker {
display: grid;
grid-template-columns: 20px 300px 50px;
gap: 10px;
align-items: center;
}
#showColor {
width: 300px;
height: 100px;
border: 0.5px solid #000;
}
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: {
'@mescius/inputman': 'npm:@mescius/inputman/index.js',
'@mescius/inputman/CSS': 'npm:@mescius/inputman/CSS',
'@mescius/inputman.richtexteditor': 'npm:@mescius/inputman.richtexteditor/index.js',
"@mescius/inputman.richtexteditor/CSS": "npm:@mescius/inputman.richtexteditor/CSS",
'@mescius/inputman.richtexteditor/JS/plugins/advlist': 'npm:@mescius/inputman.richtexteditor/JS/plugins/advlist/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/all': 'npm:@mescius/inputman.richtexteditor/JS/plugins/all/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/autosave': 'npm:@mescius/inputman.richtexteditor/JS/plugins/autosave/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/charmap': 'npm:@mescius/inputman.richtexteditor/JS/plugins/charmap/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/directionality': 'npm:@mescius/inputman.richtexteditor/JS/plugins/directionality/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/emoticons': 'npm:@mescius/inputman.richtexteditor/JS/plugins/emoticons/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/fullscreen': 'npm:@mescius/inputman.richtexteditor/JS/plugins/fullscreen/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/htmlcode': 'npm:@mescius/inputman.richtexteditor/JS/plugins/htmlcode/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/image': 'npm:@mescius/inputman.richtexteditor/JS/plugins/image/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/link': 'npm:@mescius/inputman.richtexteditor/JS/plugins/link/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/lists': 'npm:@mescius/inputman.richtexteditor/JS/plugins/lists/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/media': 'npm:@mescius/inputman.richtexteditor/JS/plugins/media/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/pagebreak': 'npm:@mescius/inputman.richtexteditor/JS/plugins/pagebreak/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/preview': 'npm:@mescius/inputman.richtexteditor/JS/plugins/preview/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/save': 'npm:@mescius/inputman.richtexteditor/JS/plugins/save/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/searchreplace': 'npm:@mescius/inputman.richtexteditor/JS/plugins/searchreplace/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/table': 'npm:@mescius/inputman.richtexteditor/JS/plugins/table/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/template': 'npm:@mescius/inputman.richtexteditor/JS/plugins/template/plugin.js',
'@mescius/inputman.richtexteditor/JS/plugins/wordcount': 'npm:@mescius/inputman.richtexteditor/JS/plugins/wordcount/plugin.js',
'@mescius/inputman.comment': 'npm:@mescius/inputman.comment/index.js',
'@mescius/inputman.comment/CSS': 'npm:@mescius/inputman.comment/CSS',
'@mescius/wijmo': 'npm:@mescius/wijmo/index.js',
'@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles',
'@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures',
'@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js',
'@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js',
'@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/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',
'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'
},
}
});