Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
feat: add component skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Feb 17, 2022
1 parent 659e24e commit 2b89d31
Show file tree
Hide file tree
Showing 15 changed files with 968 additions and 68 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ pnpm dev
- 组件types类型声明完成
- 组件文档适配Vue2写法

#### 单元测试

```shell
yarn test -w -c skeleton
```

- props -> propsData
- unmount -> destroy
- slots -> scopedSlots(注意:参数default属性值直接为字符串)

#### Todolist

- app-bar
Expand Down
120 changes: 52 additions & 68 deletions packages/varlet-vue2-ui/src/button/docs/zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Button } from '@varlet-vue2/ui'
Vue.use(Button)
```


### 主题色按钮

```html
Expand All @@ -24,8 +23,7 @@ Vue.use(Button)
### 文字按钮

```html
<var-button text outline type="primary">外边框按钮</var-button>
<var-button text type="primary">纯文字按钮</var-button>
<var-button text outline type="primary">外边框按钮</var-button> <var-button text type="primary">纯文字按钮</var-button>
```

### 禁用状态
Expand All @@ -39,21 +37,11 @@ Vue.use(Button)
### 加载状态

```html
<var-button loading type="primary">
加载状态
</var-button>
<var-button loading type="info" loading-type="rect">
加载状态
</var-button>
<var-button loading type="success" loading-type="disappear">
加载状态
</var-button>
<var-button loading type="danger" loading-type="cube">
加载状态
</var-button>
<var-button loading type="warning" loading-type="wave">
加载状态
</var-button>
<var-button loading type="primary"> 加载状态 </var-button>
<var-button loading type="info" loading-type="rect"> 加载状态 </var-button>
<var-button loading type="success" loading-type="disappear"> 加载状态 </var-button>
<var-button loading type="danger" loading-type="cube"> 加载状态 </var-button>
<var-button loading type="warning" loading-type="wave"> 加载状态 </var-button>
```

### 按钮尺寸
Expand All @@ -75,12 +63,7 @@ Vue.use(Button)

```html
<var-button color="#69dbaa" text-color="#eee">背景/文字</var-button>
<var-button
color="linear-gradient(to right, #69dbaa, #3a7afe)"
text-color="#fff"
>
使用渐变
</var-button>
<var-button color="linear-gradient(to right, #69dbaa, #3a7afe)" text-color="#fff"> 使用渐变 </var-button>
```

### 圆形按钮
Expand Down Expand Up @@ -126,66 +109,67 @@ export default {
return new Promise((resolve) => {
setTimeout(resolve, 2000)
})
}
}
},
},
}
```

## API

### 属性

| 参数 | 说明 | 类型 | 默认值 |
|------------------|---------------------------------------------------------------------------------|-----------|-----------|
| `type` | 类型,可选值为 `default` `primary` `info` `success` `warning` `danger` | _string_ | `default` |
| `size` | 尺寸,可选值为 `normal` `mini` `small` `large` | _string_ | `normal` |
| `loading` | 加载状态 | _boolean_ | `false` |
| `loading-radius` | loading 的半径,只作用于 `loading-type="circle"`| _string \| number_ | `12` |
| `loading-type` | loading 的类型,可选值为 `circle` `wave` `cube` `rect` `disappear` | _string_ | `circle` |
| `loading-size` | loading 的尺寸,可选值为 `large` `normal` `small` `mini` 不作用于 `loading-type="circle"`| _string_ | `normal` |
| `auto-loading` | 自动 loading 模式,方便处理异步任务 | _boolean_ | `false` |
| `round` | 是否是圆形按钮 | _boolean_ | `false` |
| `block` | 是否是块级元素 | _boolean_ | `false` |
| `text` | 是否是文字按钮 | _boolean_ | `false` |
| `outline` | 是否使用外边框 | _boolean_ | `false` |
| `disabled` | 禁用状态 | _boolean_ | `false` |
| `ripple` | 是否使用水波纹 | _boolean_ | `true` |
| `text-color` | 文字颜色 | _string_ | `-` |
| `color` | 背景颜色 | _string_ | `-` |
| 参数 | 说明 | 类型 | 默认值 |
| ---------------- | -------------------------------------------------------------------------------------------- | ------------------ | --------- |
| `type` | 类型,可选值为 `default` `primary` `info` `success` `warning` `danger` | _string_ | `default` |
| `size` | 尺寸,可选值为 `normal` `mini` `small` `large` | _string_ | `normal` |
| `loading` | 加载状态 | _boolean_ | `false` |
| `loading-radius` | loading 的半径,只作用于 `loading-type="circle"` | _string \| number_ | `12` |
| `loading-type` | loading 的类型,可选值为 `circle` `wave` `cube` `rect` `disappear` | _string_ | `circle` |
| `loading-size` | loading 的尺寸,可选值为 `large` `normal` `small` `mini` 不作用于 `loading-type="circle"`| _string_ | `normal` |
| `auto-loading` | 自动 loading 模式,方便处理异步任务 | _boolean_ | `false` |
| `round` | 是否是圆形按钮 | _boolean_ | `false` |
| `block` | 是否是块级元素 | _boolean_ | `false` |
| `text` | 是否是文字按钮 | _boolean_ | `false` |
| `outline` | 是否使用外边框 | _boolean_ | `false` |
| `disabled` | 禁用状态 | _boolean_ | `false` |
| `ripple` | 是否使用水波纹 | _boolean_ | `true` |
| `text-color` | 文字颜色 | _string_ | `-` |
| `color` | 背景颜色 | _string_ | `-` |

### 事件

| 事件名 | 说明 | 参数 |
| --- | --- | --- |
| `click` | 点击按钮时触发,在 `loading``disabled` 状态为 `true` 时不触发 | `event: Event` |
| 事件名 | 说明 | 参数 |
| ------------ | ------------------------------------------------------------------------- | -------------- |
| `click` | 点击按钮时触发,在 `loading``disabled` 状态为 `true` 时不触发 | `event: Event` |
| `touchstart` | 触摸手指压下按钮时触发,在 `loading``disabled` 状态为 `true` 时不触发 | `event: Event` |

### 插槽

| 插槽名 | 说明 | 参数 |
| --- | --- | --- |
| `default` | 按钮内容 | `-` |
| 插槽名 | 说明 | 参数 |
| --------- | -------- | ---- |
| `default` | 按钮内容 | `-` |

### 样式变量

以下为组件使用的 css 变量,可以使用 [StyleProvider 组件](#/zh-CN/style-provider)进行样式定制

| 变量名 | 默认值 |
| --- | --- |
| `--button-default-color` | `#f5f5f5` |
| `--button-primary-color` | `var(--color-primary)`|
| `--button-danger-color` | `var(--color-danger)`|
| `--button-success-color` | `var(--color-success)`|
| `--button-warning-color` | `var(--color-warning)`|
| `--button-info-color` | `var(--color-info)`|
| `--button-disabled-color` | `var(--color-disabled)`|
| 变量名 | 默认值 |
| ------------------------------ | ---------------------------- |
| `--button-default-color` | `#f5f5f5` |
| `--button-primary-color` | `var(--color-primary)` |
| `--button-danger-color` | `var(--color-danger)` |
| `--button-success-color` | `var(--color-success)` |
| `--button-warning-color` | `var(--color-warning)` |
| `--button-info-color` | `var(--color-info)` |
| `--button-disabled-color` | `var(--color-disabled)` |
| `--button-disabled-text-color` | `var(--color-text-disabled)` |
| `--button-border-radius` | `4px` |
| `--button-mini-padding` | `0 9px` |
| `--button-small-padding` | `0 11px` |
| `--button-normal-padding` | `0 15px` |
| `--button-large-padding` | `0 22px` |
| `--button-round-padding` | `6px` |
| `--button-mini-height` | `20px` |
| `--button-small-height` | `28px` |
| `--button-normal-height` | `36px` |
| `--button-large-height` | `44px` |
| `--button-border-radius` | `4px` |
| `--button-mini-padding` | `0 9px` |
| `--button-small-padding` | `0 11px` |
| `--button-normal-padding` | `0 15px` |
| `--button-large-padding` | `0 22px` |
| `--button-round-padding` | `6px` |
| `--button-mini-height` | `20px` |
| `--button-small-height` | `28px` |
| `--button-normal-height` | `36px` |
| `--button-large-height` | `44px` |
67 changes: 67 additions & 0 deletions packages/varlet-vue2-ui/src/skeleton/Skeleton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<template>
<div class="var--box var-skeleton">
<div class="var-skeleton__data" v-if="!loading">
<slot />
</div>

<div class="var-skeleton__content" v-if="loading && !fullscreen">
<div class="var-skeleton__card" :style="{ height: toSizeUnit(cardHeight) }" v-if="card">
<div class="var-skeleton--animation"></div>
</div>
<div class="var-skeleton__article">
<div
class="var-skeleton__avatar"
:style="{
width: toSizeUnit(avatarSize),
height: toSizeUnit(avatarSize),
}"
v-if="avatar"
>
<div class="var-skeleton--animation"></div>
</div>
<div class="var-skeleton__section">
<div class="var-skeleton__title" :style="{ width: toSizeUnit(titleWidth) }" v-if="title">
<div class="var-skeleton--animation"></div>
</div>
<div
class="var-skeleton__row"
v-for="(r, index) in toNumber(rows)"
:key="r"
:style="{ width: toSizeUnit(rowsWidth[index]) }"
>
<div class="var-skeleton--animation"></div>
</div>
</div>
</div>
</div>

<div class="var-skeleton__fullscreen" :style="{ zIndex: toNumber(fullscreenZIndex) }" v-if="loading && fullscreen">
<div class="var-skeleton--animation"></div>
</div>
</div>
</template>

<script>
import { defineComponent } from '../utils/create'
import { props } from './props'
import { toSizeUnit } from '../utils/elements'
import { toNumber } from '../utils/shared'
export default defineComponent({
name: 'VarSkeleton',
props,
data() {
return {
toSizeUnit,
toNumber,
}
},
})
</script>

<style lang="less">
@import '../styles/common';
@import './skeleton';
</style>
Loading

0 comments on commit 2b89d31

Please sign in to comment.