core升级到1.4.0版

master
yutent 2023-03-16 13:56:32 +08:00
parent 069eb5fc9c
commit 8ea85ba562
3 changed files with 217 additions and 181 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.3.0/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.4.0/index.js"}}</script>
<style></style>
</head>
<body>

View File

@ -9,19 +9,22 @@ import '../icon/index.js'
class Button extends Component {
static props = {
type: 'primary',
icon: '',
autofocus: '',
size: 'l',
autofocus: false,
loading: false,
disabled: false,
lazy: 0 // 并发拦截时间, 单位毫秒
}
static styles = css`
static styles = [
// 基础样式
css`
:host {
overflow: hidden;
display: inline-flex;
min-width: 128px;
height: 36px;
border: 0;
border-radius: 3px;
user-select: none;
-moz-user-select: none;
@ -32,13 +35,14 @@ class Button extends Component {
button {
display: flex;
justify-content: space-evenly;
justify-content: center;
align-items: center;
width: 100%;
min-width: 1px;
height: inherit;
padding: var(--padding, 0 14px);
padding: var(--button-padding, 0 4px);
line-height: 1;
border: 1px solid var(--color-grey-2);
border: 1px solid transparent;
border-radius: inherit;
white-space: nowrap;
background: #fff;
@ -56,75 +60,82 @@ class Button extends Component {
.icon {
--size: var(--icon-size, 18px);
margin-right: 4px;
}
}
:host(:focus-within) {
box-shadow: 0 0 0 2px var(--color-plain-a);
}
`,
// 尺寸
css`
@use 'sass:map';
$sizes: (
s: (
w: 52px,
h: 20px,
f: 12px
),
m: (
w: 72px,
h: 24px,
f: 12px
),
l: (
w: 108px,
h: 32px,
f: 14px
),
xl: (
w: 132px,
h: 36px,
f: 14px
),
xxl: (
w: 160px,
h: 44px,
f: 14px
),
xxxl: (
w: 192px,
h: 52px,
f: 16px
),
xxxxl: (
w: 212px,
h: 64px,
f: 18px
)
);
:host([size='large']) {
min-width: 212px;
height: 52px;
font-size: 18px;
button {
padding: 0 24px;
}
@loop $s, $v in $sizes {
:host([size='#{$s}']) {
min-width: map.get($v, 'w');
height: map.get($v, 'h');
font-size: map.get($v, 'f');
.icon {
--size: 26px;
--size: #{map.get($v, 'f')};
}
}
:host([size='large'][circle]) {
min-width: 52px;
width: 52px;
height: 52px;
:host([size='#{$s}'][circle]) {
width: map.get($v, 'h');
height: map.get($v, 'h');
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([dashed]) button {
border-style: dashed;
}
:host([round]) {
border-radius: 26px;
border-radius: 32px;
}
:host([circle]) {
min-width: 36px;
width: 36px;
min-width: 0;
border-radius: 50%;
button {
padding: 0;
@ -137,11 +148,9 @@ class Button extends Component {
display: none;
}
}
:host(:focus-within) {
box-shadow: 0 0 0 2px var(--color-plain-a);
}
`,
// 配色
css`
$colors: (
primary: 'teal',
info: 'blue',
@ -156,7 +165,7 @@ class Button extends Component {
:host([type='#{$t}']) {
button {
color: var(--color-#{$c}-2);
border: 1px solid var(--color-#{$c}-2);
border-color: var(--color-#{$c}-2);
&:hover {
color: var(--color-#{$c}-1);
@ -192,19 +201,46 @@ class Button extends Component {
}
}
}
`,
// 状态
css`
:host([loading]),
:host([disabled]) {
cursor: not-allowed;
opacity: 0.6;
}
`
]
created() {
this.stamp = 0
this.$on(
'click',
ev => {
let { loading, disabled, lazy } = this
let now = Date.now()
if (loading || disabled) {
return ev.stopPropagation()
}
// 并发拦截
if (lazy > 0 && now - this.stamp < lazy) {
return ev.stopPropagation()
}
this.stamp = now
},
true
)
}
render() {
return html`<button>
return html`
<button disabled=${this.disabled}>
<wc-icon class="icon" is="${this.icon}"></wc-icon>
<slot />
</button>`
</button>
`
}
}

View File

@ -4,7 +4,7 @@
> 主题功能, 暂时由根样式定义来实现, 所以, 组件内的样式, 尽可能避免过多的私有配色。
2. 组件几种配色样式, 暂时同大多数组件一致
- `type=primary` 青色
- `type=primary` 青色 (默认值)
- `type=secondary` 暗色
- `type=info` 蓝色
- `type=success` 绿色