add Button UI

add Button UI
This commit is contained in:
梁灏 2016-09-20 17:10:17 +08:00
parent 40f8606f58
commit e1596b7e2c
9 changed files with 456 additions and 119 deletions

View file

@ -1,7 +1,7 @@
<template>
<button :type="htmlType" :class="classes" :disabled="disabled">
<Icon type="loading" v-if="loading"></Icon>
<Icon :type="icon" v-if="icon && !loading"></Icon>
<i :class="loadingIconClasses" v-if="loading"></i>
<i :class="typeIconClasses" v-if="icon && !loading"></i>
<slot></slot>
</button>
</template>
@ -10,6 +10,7 @@
import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-btn';
const iconPrefixCls = 'ivu-icon';
export default {
components: { Icon },
@ -50,6 +51,17 @@
[`${prefixCls}-loading`]: this.loading != null && this.loading
}
]
},
loadingIconClasses () {
return `${iconPrefixCls} ivu-load-loop ${iconPrefixCls}-load-c`;
},
typeIconClasses () {
return [
`${iconPrefixCls}`,
{
[`${iconPrefixCls}-${this.icon}`]: !!this.icon
}
]
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,88 +1,74 @@
<style>
</style>
<template>
<Button size="small" shape="circle" type="primary" icon="add" @click="abc">
<Icon type="link"></Icon>
链接
<Button>Default</Button>
<Button type="primary">Primary</Button>
<Button type="ghost">Ghost</Button>
<br><br>
<Button type="primary" size="large">Large</Button>
<Button type="primary">Default</Button>
<Button type="primary" size="small">Small</Button>
<br><br>
<Button>Default</Button>
<Button disabled>Default(Disabled)</Button>
<br><br>
<Button type="primary">Primary</Button>
<Button type="primary" disabled>Primary(Disabled)</Button>
<br><br>
<Button type="ghost">Ghost</Button>
<Button type="ghost" disabled>Ghost(Disabled)</Button>
<br><br>
<Button type="primary" shape="circle" icon="ios-search"></Button>
<Button type="primary" icon="ios-search">搜索</Button>
<br><br>
<Button type="ghost" shape="circle">
<Icon type="search"></Icon>
</Button>
<Button-group>
<Button>上一页</Button>
<Button>1</Button>
<Button>2</Button>
<Button>3</Button>
<Button>下一页</Button>
<Button type="ghost">
<Icon type="search"></Icon>
搜索
</Button>
<Button type="ghost" shape="circle" size="large">
<Icon type="search"></Icon>
</Button>
<Button type="ghost" shape="circle" size="small">
<Icon type="search"></Icon>
</Button>
<br><br><br>
<Button type="primary" loading>Loading...</Button>
<Button type="primary" loading size="large">Loading...</Button>
<Button type="primary" loading size="small">Loading...</Button>
<Button type="primary" :loading="loading" @click="toLoading">
<span v-if="!loading">Click me!</span>
<span v-else>Loading...</span>
</Button>
<Button type="primary" :loading="loading2" icon="checkmark-round" @click="toLoading2">
<span v-if="!loading2">Click me!</span>
<span v-else>Loading...</span>
</Button>
<h4>基本</h4>
<Button-group size="large">
<Button>取消</Button>
<Button type="primary">确定</Button>
</Button-group>
<Button-group>
<Button type="primary">L</Button>
<Button>M</Button>
<Button type="ghost">R</Button>
</Button-group>
<h4>配合图标</h4>
<Button-group>
<Button type="primary">
<Icon type="chevron-left"></Icon>
前进
</Button>
<Button type="primary">
后退
<Icon type="chevron-right"></Icon>
</Button>
</Button-group>
<Button-group>
<Button type="primary" icon="cloud"></Button>
<Button type="primary" icon="upload"></Button>
</Button-group>
{{ msg }}
<i-input placeholder="请输入邮箱" size="large" :value.sync="msg" @keyup.enter="abc"></i-input>
<Switch size="large" @on-change="changeSwitch">
<span slot="checkedItem"></span>
<span slot="unCheckedItem"></span>
</Switch>
<br>
<Radio @on-change="changeRadio">梁灏</Radio>
<Radio checked>谦翔</Radio>
<br><br><br>
<Radio value="谦翔">
谦翔
</Radio>
<Radio value="梁灏">
梁灏
</Radio>
<Radio value="倪斌">
倪斌
</Radio>
<Radio value="段模">
段模
</Radio>
<br><br><br>
<Radio-group>
<Radio value="谦翔">
谦翔
</Radio>
<Radio value="梁灏">
梁灏
</Radio>
<Radio value="倪斌">
倪斌
</Radio>
<Radio value="段模">
段模
</Radio>
</Radio-group>
<br><br><br>
<Checkbox-group :model="checkbox" @on-change="groupChange">
<Checkbox value="梁灏">梁灏</Checkbox>
<Checkbox value="段模">段模</Checkbox>
<Checkbox value="倪斌">倪斌</Checkbox>
</Checkbox-group>
<br><br><br>
<div @click="changeCB">切换名称数据</div>
{{ checkbox | json }}
<br><br><br>
<Checkbox :checked.sync="singleRadio" @on-change="singleChange">梁灏</Checkbox>
<br>
{{ singleRadio }}
<div @click="singleRadio = !singleRadio">切换单个名称数据</div>
<br><br><br>
------------------------------
<Input-number :step="1.2" :value="1"></Input-number>
{{ inumber }}
<br><br><br>
<Row type="flex" align="top" justify="end" class="hello world">
<i-col span="8" offset="2" class="nihao shijie">1</i-col>
<i-col span="8" push="3">2</i-col>
<i-col span="8" order="2">3</i-col>
</Row>
<br><br><br>
<Page :current="1" :total="100" simple></Page>
</template>
<script>
import { Button, Icon, Input, Switch, Radio, Checkbox, InputNumber, Row, Col, Page } from 'iview';
@ -111,36 +97,16 @@
},
data () {
return {
msg: 123,
radio: '梁灏',
checkbox: ['倪斌'],
inumber: 5,
singleRadio: true
loading: false,
loading2: false
}
},
ready () {
setTimeout(() => {
// this.checkbox = ['', ''];
}, 2000);
},
methods: {
abc() {
console.log(123);
toLoading () {
this.loading = true;
},
changeSwitch (data) {
console.log(data);
},
changeRadio (data) {
console.log(data);
},
changeCB () {
this.checkbox = ['梁灏', '段模'];
},
groupChange (data) {
// console.log(data);
},
singleChange (data) {
// console.log(data);
toLoading2 () {
this.loading2 = true;
}
}
}

View file

@ -1,6 +1,6 @@
{
"name": "iview",
"version": "0.0.10",
"version": "0.0.11",
"title": "iView",
"description": "A high quality UI components Library with Vue.js",
"homepage": "http://www.iviewui.com",

View file

@ -1,7 +1,74 @@
@btn-prefix-cls: ~"@{css-prefix}btn";
.@{btn-prefix-cls} {
.btn;
.btn-default;
&-primary {
color: @primary-color;
.btn-primary;
.@{btn-prefix-cls}-group &:not(:first-child):not(:last-child) {
border-right-color: @btn-group-border;
border-left-color: @btn-group-border;
}
.@{btn-prefix-cls}-group &:first-child {
&:not(:last-child) {
border-right-color: @btn-group-border;
&[disabled] {
border-right-color: @btn-default-border;
}
}
}
.@{btn-prefix-cls}-group &:last-child:not(:first-child),
.@{btn-prefix-cls}-group & + .@{btn-prefix-cls} {
border-left-color: @btn-group-border;
&[disabled] {
border-left-color: @btn-default-border;
}
}
}
&-ghost {
.btn-ghost;
}
//&-dashed {
// .btn-dashed;
//}
&-circle,
&-circle-outline {
.btn-circle(@btn-prefix-cls);
}
&:before {
position: absolute;
top: -1px;
left: -1px;
bottom: -1px;
right: -1px;
background: #fff;
opacity: 0.35;
content: '';
border-radius: inherit;
z-index: 1;
.transition(opacity @animation-time);
pointer-events: none;
display: none;
}
&&-loading {
pointer-events: none;
position: relative;
&:before {
display: block;
}
}
&-group {
.btn-group(@btn-prefix-cls);
}
}

View file

@ -36,13 +36,13 @@
}
&-title {
font-size: 14px;
font-size: @font-size-base;
color: @text-color;
margin-bottom: 4px;
}
&-desc {
font-size: @font-size-base;
font-size: 12px;
color: @legend-color;
text-align: justify;
}

View file

@ -0,0 +1,261 @@
.button-size(@padding; @font-size; @border-radius) {
padding: @padding;
font-size: @font-size;
border-radius: @border-radius;
}
.button-color(@color; @background; @border) {
color: @color;
background-color: @background;
border-color: @border;
// a inside Button which only work in Chrome
// http://stackoverflow.com/a/17253457
> a:only-child {
color: currentColor;
&:after {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: transparent;
}
}
}
.button-variant(@color; @background; @border) {
.button-color(@color; @background; @border);
&:hover
//&:focus
{
.button-color(tint(@color, 20%); tint(@background, 20%); tint(@border, 20%));
}
&:active,
&.active {
.button-color(shade(@color, 5%); shade(@background, 5%); shade(@background, 5%));
}
&.disabled,
&[disabled],
fieldset[disabled] & {
&,
&:hover,
&:focus,
&:active,
&.active {
.button-color(@btn-disable-color; @btn-disable-bg; @btn-disable-border);
}
}
}
.button-group-base(@btnClassName) {
position: relative;
display: inline-block;
vertical-align: middle;
> .@{btnClassName} {
position: relative;
float: left;
&:hover,
//&:focus,
&:active,
&.active {
z-index: 2;
}
}
// size
&-large > .@{btnClassName} {
.button-size(@btn-padding-large; @btn-font-size-large; @btn-border-radius);
}
&-small > .@{btnClassName} {
.button-size(@btn-padding-small; @btn-font-size; @btn-border-radius-small);
> .@{css-prefix-iconfont} {
font-size: @btn-font-size;
}
}
}
.btn() {
display: inline-block;
margin-bottom: 0;
font-weight: @btn-font-weight;
text-align: center;
vertical-align: middle;
touch-action: manipulation;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
white-space: nowrap;
line-height: @line-height-base;
user-select: none;
.button-size(@btn-padding-base; @btn-font-size; @btn-border-radius);
.transform(translate3d(0, 0, 0));
.transition(all @animation-time linear);
> .@{css-prefix-iconfont} {
line-height: 1;
}
&,
&:active,
&:focus {
outline: 0;
}
&:not([disabled]):hover {
text-decoration: none;
}
&:not([disabled]):active {
outline: 0;
.transition(none)
}
&.disabled,
&[disabled] {
cursor: @cursor-disabled;
> * {
pointer-events: none;
}
}
&-large {
.button-size(@btn-padding-large; @btn-font-size-large; @btn-border-radius);
}
&-small {
.button-size(@btn-padding-small; @btn-font-size; @btn-border-radius-small);
}
}
// Default
.btn-default() {
.button-variant(@btn-default-color; @btn-default-bg; @btn-default-border);
&:hover
//&:focus
{
.button-color(tint(@primary-color, 20%); white; tint(@primary-color, 20%));
}
&:active,
&.active {
.button-color(shade(@primary-color, 5%); white; shade(@primary-color, 5%));
}
}
// Primary
.btn-primary() {
.button-variant(@btn-primary-color; @btn-primary-bg; @primary-color);
&:hover,
//&:focus,
&:active,
&.active {
color: @btn-primary-color;
}
}
// Ghost
.btn-ghost() {
.button-variant(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
&:hover
//&:focus
{
.button-color(tint(@primary-color, 20%); @btn-ghost-bg; tint(@primary-color, 20%));
}
&:active,
&.active {
.button-color(shade(@primary-color, 5%); @btn-ghost-bg; shade(@primary-color, 5%));
}
}
// Dashed
.btn-dashed() {
.button-variant(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
border-style: dashed;
&:hover
//&:focus
{
.button-color(tint(@primary-color, 20%); @btn-ghost-bg; tint(@primary-color, 20%));
}
&:active,
&.active {
.button-color(shade(@primary-color, 5%); @btn-ghost-bg; shade(@primary-color, 5%));
}
}
// Circle for Icon
.btn-circle(@btnClassName: ivu-btn) {
.square(@btn-circle-size);
.button-size(0; @font-size-base + 2; 50%);
&.@{btnClassName}-large {
.square(@btn-circle-size-large);
.button-size(0; @btn-font-size-large + 2; 50%);
}
&.@{btnClassName}-small {
.square(@btn-circle-size-small);
.button-size(0; @font-size-base; 50%);
}
}
// Group
.btn-group(@btnClassName: ivu-btn) {
.button-group-base(@btnClassName);
.@{btnClassName} + .@{btnClassName},
.@{btnClassName} + &,
& + .@{btnClassName},
& + & {
margin-left: -1px;
}
.@{btnClassName}:not(:first-child):not(:last-child) {
border-radius: 0;
padding-left: 8px;
padding-right: 8px;
}
> .@{btnClassName}:first-child {
margin-left: 0;
&:not(:last-child) {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
padding-right: 8px;
}
}
> .@{btnClassName}:last-child:not(:first-child) {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
padding-left: 8px;
}
& > & {
float: left;
}
& > &:not(:first-child):not(:last-child) > .@{btnClassName} {
border-radius: 0;
}
& > &:first-child:not(:last-child) {
> .@{btnClassName}:last-child {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
padding-right: 8px;
}
}
& > &:last-child:not(:first-child) > .@{btnClassName}:first-child {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
padding-left: 8px;
}
}

View file

@ -1,6 +1,6 @@
// Prefix
@css-prefix : ivu-;
@css-prefix-iconfont : ivu-icon;
// Color
@primary-color : #0099e5;
@info-color : #2db7f5;
@ -21,6 +21,7 @@
@line-height-computed : floor((@font-size-base * @line-height-base));
@border-radius-base : 6px;
@border-radius-small : 4px;
@cursor-disabled : not-allowed;
// Border color
@border-color-base : #d9d9d9; // outside
@ -38,6 +39,36 @@
@shadow-left : -1px 0 6px @shadow-color;
@shadow-right : 1px 0 6px @shadow-color;
// Button
@btn-font-weight : 400;
@btn-padding-base : 4px 15px;
@btn-padding-large : 4px 15px 5px 15px;
@btn-padding-small : 1px 7px;
@btn-font-size : 12px;
@btn-font-size-large : 14px;
@btn-border-radius : 4px;
@btn-border-radius-small: 3px;
@btn-group-border : shade(@primary-color, 5%);
@btn-disable-color : #ccc;
@btn-disable-bg : @background-color-base;
@btn-disable-border : @border-color-base;
@btn-default-color : @text-color;
@btn-default-bg : @background-color-base;
@btn-default-border : @border-color-base;
@btn-primary-color : #fff;
@btn-primary-bg : @primary-color;
@btn-ghost-color : @text-color;
@btn-ghost-bg : transparent;
@btn-ghost-border : @border-color-base;
@btn-circle-size : 28px;
@btn-circle-size-large : 32px;
@btn-circle-size-small : 22px;
// Layout and Grid
@grid-columns : 24;
@grid-gutter-width : 0;