-
-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): button原型制作中 已完成基本type size color基本交互
affects: @varlet/cli, @varlet/ui
- Loading branch information
Showing
14 changed files
with
503 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<button | ||
v-ripple="{ disabled }" | ||
class="varlet-button varlet-elevation--3" | ||
:class="[ | ||
`varlet-button--${type}`, | ||
`varlet-button--${size}`, | ||
block ? 'varlet--block' : 'varlet--inline', | ||
round ? 'varlet-button--round': null, | ||
disabled ? 'varlet-button--disabled': null | ||
]" | ||
:style="{ | ||
'color': color, | ||
'background': background | ||
}" | ||
:disabled="disabled" | ||
@click="$emit('click')" | ||
> | ||
<slot/> | ||
</button> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Ripple from '../ripple' | ||
import { defineComponent } from 'vue' | ||
import { props, emits } from './propsEmits' | ||
export default defineComponent({ | ||
name: 'VarletButton', | ||
directives: { Ripple }, | ||
props, | ||
emits | ||
}) | ||
</script> | ||
|
||
<style lang="less"> | ||
@import "./button"; | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Button = require('../../../cjs/button').default | ||
const { render } = require('@testing-library/vue') | ||
|
||
test('test button', async () => { | ||
const wrapper = render(Button) | ||
console.log(wrapper) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
@import "../styles/var"; | ||
@import "../styles/elevation"; | ||
@import "../styles/common"; | ||
|
||
@button-border-radius: 4px; | ||
|
||
@button-normal-width: 64px; | ||
@button-normal-height: 36px; | ||
@button-normal-padding: 3px 16px; | ||
|
||
@button-large-width: 78px; | ||
@button-large-height: 44px; | ||
@button-large-padding: 6px 20px; | ||
|
||
@button-small-width: 50px; | ||
@button-small-height: 28px; | ||
@button-small-padding: 2px 12px; | ||
|
||
@button-mini-width: 36px; | ||
@button-mini-height: 22px; | ||
@button-mini-padding: 1px 8px; | ||
|
||
@button-round-size: auto; | ||
@button-round-padding: 7px; | ||
|
||
@button-disabled-color: rgba(0,0,0,.26); | ||
@button-disabled-background-color: rgba(0,0,0,.12); | ||
|
||
.varlet-button { | ||
justify-content: center; | ||
align-items: center; | ||
outline: none; | ||
border: none; | ||
line-height: 1.2; | ||
border-radius: @button-border-radius; | ||
user-select: none; | ||
transition: box-shadow .2s; | ||
|
||
&:active { | ||
box-shadow: | ||
0 3px 3px -2px @shadow-key-umbra-opacity, | ||
0 3px 4px 0 @shadow-key-penumbra-opacity, | ||
0 6px 8px 0 rgba(0, 0, 0, 0.24); | ||
} | ||
|
||
&--plain { | ||
background-color: @color-background-base; | ||
} | ||
|
||
&--primary { | ||
color: #fff; | ||
background-color: @color-primary; | ||
} | ||
|
||
&--info { | ||
color: #fff; | ||
background-color: @color-info; | ||
} | ||
|
||
&--success { | ||
color: #fff; | ||
background-color: @color-success; | ||
} | ||
|
||
&--warning { | ||
color: #fff; | ||
background-color: @color-warning; | ||
} | ||
|
||
&--danger { | ||
color: #fff; | ||
background-color: @color-danger; | ||
} | ||
|
||
&--normal { | ||
min-width: @button-normal-width; | ||
min-height: @button-normal-height; | ||
padding: @button-normal-padding; | ||
font-size: @font-size-md; | ||
} | ||
|
||
&--large { | ||
min-width: @button-large-width; | ||
min-height: @button-large-height; | ||
padding: @button-large-padding; | ||
font-size: @font-size-lg; | ||
} | ||
|
||
&--small { | ||
min-width: @button-small-width; | ||
min-height: @button-small-height; | ||
padding: @button-small-padding; | ||
font-size: @font-size-sm; | ||
} | ||
|
||
&--mini { | ||
min-width: @button-mini-width; | ||
min-height: @button-mini-height; | ||
padding: @button-mini-padding; | ||
font-size: @font-size-xs; | ||
} | ||
|
||
&--round { | ||
min-width: @button-round-size; | ||
min-height: @button-round-size; | ||
padding: @button-round-padding; | ||
border-radius: 50%; | ||
} | ||
|
||
&--disabled { | ||
background-color: @button-disabled-background-color; | ||
color: @button-disabled-color; | ||
} | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<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 | ||
> | ||
<img style="width: 40px; height: 40px" src="https://img.yzcdn.cn/vant/logo.png"> | ||
</varlet-button> | ||
|
||
<varlet-button | ||
class="example__button" | ||
block | ||
type="warning" | ||
size="large" | ||
background="rgb(114, 50, 221)" | ||
color="rgb(255,192,0)" | ||
@click="trigger" | ||
> | ||
修改颜色 | ||
</varlet-button> | ||
|
||
<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> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, ref, Ref } from 'vue' | ||
import Button from '..' | ||
export default defineComponent({ | ||
name: 'ButtonExample', | ||
components: { | ||
[Button.name]: Button | ||
}, | ||
setup() { | ||
const disabled: Ref<boolean> = ref(true) | ||
return { | ||
disabled, | ||
trigger() { | ||
disabled.value = !disabled.value | ||
} | ||
} | ||
} | ||
}) | ||
</script> | ||
|
||
<style lang="less"> | ||
.example { | ||
padding: 20px; | ||
&__button { | ||
margin-bottom: 20px; | ||
margin-right: 20px; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Button from './Button.vue' | ||
|
||
Button.install = function(app: any) { | ||
app.component(Button.name, Button) | ||
} | ||
|
||
export default Button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
function typeValidator(type: string): boolean { | ||
const validTypes = ['plain', 'primary', 'info', 'success', 'warning', 'danger'] | ||
|
||
return validTypes.includes(type) | ||
} | ||
|
||
function sizeValidator(size: string): boolean { | ||
const validSizes = ['normal', 'mini', 'small', 'large'] | ||
|
||
return validSizes.includes(size) | ||
} | ||
|
||
export const props = { | ||
// 按钮类型 | ||
type: { | ||
type: String, | ||
default: 'plain', | ||
validator: typeValidator | ||
}, | ||
// 按钮尺寸 | ||
size: { | ||
type: String, | ||
default: 'normal', | ||
validator: sizeValidator | ||
}, | ||
// 原型按钮 | ||
round: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
// 块级元素 | ||
block: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
// 禁用按钮 | ||
disabled: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
// 按钮文字颜色 | ||
color: { | ||
type: String | ||
}, | ||
// 按钮背景颜色 | ||
background: { | ||
type: String | ||
} | ||
} | ||
|
||
export const emits = ['click'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,12 @@ | |
&--hidden { | ||
overflow: hidden; | ||
} | ||
|
||
&--block { | ||
display: flex; | ||
} | ||
|
||
&--inline { | ||
display: inline-flex; | ||
} | ||
} |
Oops, something went wrong.