Skip to content

Commit

Permalink
fix(ui): button原型完成
Browse files Browse the repository at this point in the history
affects: @varlet/ui
  • Loading branch information
haoziqaq committed Dec 1, 2020
1 parent 41bfdab commit cdf32e5
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 21 deletions.
6 changes: 5 additions & 1 deletion packages/varlet-ui/src/button/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
:disabled="disabled"
@click="trigger"
>
<varlet-loading v-if="loading"></varlet-loading>
<varlet-loading
:type="loadingType"
:size="loadingSize"
v-if="loading"
/>
<slot v-else/>
</button>
</template>
Expand Down
167 changes: 151 additions & 16 deletions packages/varlet-ui/src/button/example/index.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
<template>
<div class="example">
<varlet-button class="example__button" type="plain" size="large">测试</varlet-button>

<varlet-button class="example__button" type="primary" size="large">测试</varlet-button>
<varlet-button class="example__button" type="primary" size="normal">测试</varlet-button>
<varlet-button class="example__button" type="primary" size="small">测试</varlet-button>
<varlet-button class="example__button" type="primary" size="mini">测试</varlet-button>

<varlet-button class="example__button" type="danger" size="large">测试</varlet-button>
<varlet-button class="example__button" type="danger">测试</varlet-button>
<varlet-button class="example__button" type="danger" size="small">测试</varlet-button>
<varlet-button class="example__button" type="danger" size="mini">测试</varlet-button>

<varlet-button class="example__button" type="info" size="normal" block>测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试</varlet-button>
<varlet-button class="example__button" type="warning" size="large" block>测试</varlet-button>

<varlet-button
class="example__button"
round
Expand All @@ -36,14 +21,164 @@
<varlet-button class="example__button" type="primary" @click="trigger">切换状态</varlet-button>
<varlet-button class="example__button" type="plain" size="large" :disabled="disabled">{{ disabled ? '禁用' : '启用' }}</varlet-button>

<varlet-button
class="example__button"
type="primary"
size="large"
v-model:loading="loading"
@click="trigger"
>
Large
</varlet-button>
<varlet-button
class="example__button"
type="primary"
size="normal"
v-model:loading="loading"
@click="trigger"
>
Normal
</varlet-button>
<varlet-button
class="example__button"
type="primary"
size="small"
v-model:loading="loading"
@click="trigger"
>
Small
</varlet-button>
<varlet-button
class="example__button"
type="primary"
size="mini"
v-model:loading="loading"
@click="trigger"
>
Mini
</varlet-button>

<varlet-button
class="example__button"
type="danger"
loading-type="cube"
size="large"
v-model:loading="loading"
@click="trigger"
>
Large
</varlet-button>
<varlet-button
class="example__button"
type="danger"
loading-type="cube"
size="normal"
v-model:loading="loading"
@click="trigger"
>
Normal
</varlet-button>
<varlet-button
class="example__button"
type="danger"
loading-type="cube"
size="small"
v-model:loading="loading"
@click="trigger"
>
Small
</varlet-button>
<varlet-button
class="example__button"
type="danger"
loading-type="cube"
size="mini"
v-model:loading="loading"
@click="trigger"
>
Mini
</varlet-button>

<varlet-button
class="example__button"
type="warning"
loading-type="rect"
size="large"
v-model:loading="loading"
@click="trigger"
>
Large
</varlet-button>
<varlet-button
class="example__button"
type="warning"
loading-type="rect"
size="normal"
v-model:loading="loading"
@click="trigger"
>
Normal
</varlet-button>
<varlet-button
class="example__button"
type="warning"
loading-type="rect"
size="small"
v-model:loading="loading"
@click="trigger"
>
Small
</varlet-button>
<varlet-button
class="example__button"
type="warning"
loading-type="rect"
size="mini"
v-model:loading="loading"
@click="trigger"
>
Mini
</varlet-button>

<varlet-button
class="example__button"
type="success"
loading-type="disappear"
size="large"
v-model:loading="loading"
@click="trigger"
>
给老子转!
Large
</varlet-button>
<varlet-button
class="example__button"
type="success"
loading-type="disappear"
size="normal"
v-model:loading="loading"
@click="trigger"
>
Normal
</varlet-button>
<varlet-button
class="example__button"
type="success"
loading-type="disappear"
size="small"
v-model:loading="loading"
@click="trigger"
>
Small
</varlet-button>
<varlet-button
class="example__button"
type="success"
loading-type="disappear"
size="mini"
v-model:loading="loading"
@click="trigger"
>
Mini
</varlet-button>
</div>
</template>
Expand Down
18 changes: 18 additions & 0 deletions packages/varlet-ui/src/button/propsEmits.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
typeValidator as loadingTypeValidator,
sizeValidator as loadingSizeValidator,
getTypeDefault as getLoadingTypeDefault
} from '../loading/propsEmits'

function typeValidator(type: string): boolean {
const validTypes = ['plain', 'primary', 'info', 'success', 'warning', 'danger']

Expand Down Expand Up @@ -28,6 +34,18 @@ export const props = {
type: Boolean,
default: false
},
// 加载动画类型
loadingType: {
type: String,
default: getLoadingTypeDefault,
validator: loadingTypeValidator
},
// 加载动画尺寸
loadingSize: {
type: String,
default: (props: any) => props.size,
validator: loadingSizeValidator
},
// 原型按钮
round: {
type: Boolean,
Expand Down
12 changes: 8 additions & 4 deletions packages/varlet-ui/src/loading/propsEmits.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
function typeValidator(type: string): boolean {
export function typeValidator(type: string): boolean {
const validTypes = ['wave', 'cube', 'rect', 'disappear']
return validTypes.includes(type)
}

function sizeValidator(size: string): boolean {
export function sizeValidator(size: string): boolean {
const validSizes = ['normal', 'mini', 'small', 'large']

return validSizes.includes(size)
}

export const getTypeDefault = () => 'wave'

export const getSizeDefault = () => 'normal'

export const props = {
// loading类型
type: {
type: String,
default: 'wave',
default: getTypeDefault,
validator: typeValidator,
},
// loading尺寸
size: {
type: String,
default: 'normal',
default: getSizeDefault,
validator: sizeValidator,
},
// loading颜色
Expand Down

0 comments on commit cdf32e5

Please sign in to comment.