Files
aurora-admin/frameworks/ButtonGroup.html
T

44 lines
1.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Aurora Admin · ButtonGroup(普通 H5)</title>
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css" />
<link rel="stylesheet" href="ButtonGroup.css" />
<style>body{margin:0;padding:24px;background:#F5F7FA;display:flex;flex-direction:column;gap:16px;}</style>
</head>
<body>
<div class="aa-btngroup" id="single"></div>
<div class="aa-btngroup" id="multi"></div>
<script>
function paint(el, options, selected, multiple) {
el.innerHTML = options.map(function (o) {
var on = multiple ? selected.indexOf(o.value) >= 0 : selected === o.value;
var cls = 'aa-btngroup-btn' + (on ? ' is-selected' : '') + (o.disabled ? ' is-disabled' : '');
return '<button class="' + cls + '" data-value="' + o.value + '" ' + (o.disabled ? 'disabled' : '') + '>' + o.label + '</button>';
}).join('');
el.querySelectorAll('button').forEach(function (b) {
b.addEventListener('click', function () {
var v = b.dataset.value;
if (multiple) {
var i = selected.indexOf(v);
if (i >= 0) selected.splice(i, 1); else selected.push(v);
} else {
selected = v;
}
paint(el, options, selected, multiple);
});
});
}
paint(document.getElementById('single'),
[{ label: '日', value: 'day' }, { label: '周', value: 'week' }, { label: '月', value: 'month' }], 'week', false);
paint(document.getElementById('multi'),
[{ label: '红', value: 'r' }, { label: '绿', value: 'g' }, { label: '蓝', value: 'b', disabled: true }], ['r'], true);
</script>
</body>
</html>