优化icon组件, 增加button组件

master
yutent 2023-03-15 19:23:52 +08:00
parent c49296feb8
commit 386d613af7
3 changed files with 213 additions and 2 deletions

View File

@ -18,7 +18,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<link rel="stylesheet" href="/dist/css/reset-basic.css">
<script async src="//jscdn.ink/es-module-shims/1.6.3/es-module-shims.wasm.js"></script>
<script type="importmap">{"imports":{"es.shim":"//jscdn.ink/es.shim/2.1.1/index.js","vue":"//jscdn.ink/vue/3.2.47/vue.runtime.esm-browser.prod.js","vue-router":"//jscdn.ink/@bytedo/vue-router/4.1.6/vue-router.js","fetch":"//jscdn.ink/@bytedo/fetch/2.1.5/next.js","@bd/core":"//jscdn.ink/@bd/core/1.2.2/index.js"}}</script>
<script type="importmap">{"imports":{"es.shim":"//jscdn.ink/es.shim/2.1.1/index.js","vue":"//jscdn.ink/vue/3.2.47/vue.runtime.esm-browser.prod.js","vue-router":"//jscdn.ink/@bytedo/vue-router/4.1.6/vue-router.js","fetch":"//jscdn.ink/@bytedo/fetch/2.1.5/next.js","@bd/core":"//jscdn.ink/@bd/core/1.3.0/index.js"}}</script>
<style></style>
</head>
<body>

203
src/form/button.js Normal file
View File

@ -0,0 +1,203 @@
/**
* {按钮组件}
* @author yutent<yutent.io@gmail.com>
* @date 2023/03/06 15:17:25
*/
import { css, html, Component } from '@bd/core'
import '../icon/index.js'
class Button extends Component {
static props = {
icon: '',
autofocus: '',
loading: false,
disabled: false,
lazy: 0 // 并发拦截时间, 单位毫秒
}
static styles = css`
:host {
overflow: hidden;
display: inline-flex;
min-width: 128px;
height: 36px;
border-radius: 3px;
user-select: none;
-moz-user-select: none;
color: var(--color-dark-1);
font-size: 14px;
cursor: pointer;
transition: box-shadow 0.15s linear;
button {
display: flex;
justify-content: space-evenly;
align-items: center;
width: 100%;
height: inherit;
padding: var(--padding, 0 14px);
line-height: 1;
border: 1px solid var(--color-grey-2);
border-radius: inherit;
white-space: nowrap;
background: #fff;
font-size: inherit;
font-family: inherit;
outline: none;
color: inherit;
cursor: inherit;
transition: background 0.15s linear;
&::-moz-focus-inner {
border: none;
}
}
.icon {
--size: var(--icon-size, 18px);
}
}
:host([size='large']) {
min-width: 212px;
height: 52px;
font-size: 18px;
button {
padding: 0 24px;
}
.icon {
--size: 26px;
}
}
:host([size='large'][circle]) {
min-width: 52px;
width: 52px;
height: 52px;
button {
padding: 0;
}
}
:host([size='medium']) {
min-width: 160px;
height: 44px;
button {
padding: 0 18px;
}
}
:host([size='medium'][circle]) {
min-width: 44px;
width: 44px;
}
:host([size='small']) {
min-width: 96px;
height: 32px;
}
:host([size='small'][circle]) {
min-width: 32px;
width: 32px;
}
:host([size='mini']) {
min-width: 72px;
height: 26px;
font-size: 12px;
button {
padding: 0 6px;
}
.icon {
--size: 14px;
}
}
:host([size='mini'][circle]) {
min-width: 26px;
width: 26px;
}
:host([round]) {
border-radius: 26px;
}
:host([circle]) {
min-width: 36px;
width: 36px;
border-radius: 50%;
button {
padding: 0;
}
.icon {
margin-right: 0;
}
slot {
display: none;
}
}
:host(:focus-within) {
box-shadow: 0 0 0 2px var(--color-plain-a);
}
$colors: 'teal', 'blue', 'green', 'orange', 'red', 'dark', 'grey';
@each $c in $colors {
:host([#{$c}]) {
button {
color: var(--color-#{$c}-2);
border: 1px solid var(--color-#{$c}-2);
&:hover {
color: var(--color-#{$c}-1);
border-color: var(--color-#{$c}-1);
}
&:active {
color: var(--color-#{$c}-3);
}
&:disabled {
color: var(--color-#{$c}-2);
}
}
&:host([solid]) button {
border: 0;
color: #fff;
background: var(--color-#{$c}-2);
&:hover {
background: var(--color-#{$c}-1);
}
&:active {
background: var(--color-#{$c}-3);
}
&:disabled {
background: var(--color-#{$c}-2);
}
}
&:host(:focus-within) {
box-shadow: 0 0 0 2px var(--color-#{$c}-a);
}
}
}
:host([loading]),
:host([disabled]) {
cursor: not-allowed;
opacity: 0.6;
}
`
render() {
return html`<button>
<wc-icon class="icon" is="${this.icon}"></wc-icon>
<slot />
</button>`
}
}
customElements.define('wc-button', Button)

View File

@ -15,7 +15,15 @@ if (window.EXT_SVG_DICT) {
class Icon extends Component {
static props = {
is: ''
is: {
type: String,
default: null,
observer(val) {
if (val === '') {
this.is = null
}
}
}
}
static styles = css`