Row component forces the use of flex layout, and add prop wrap. Col add flex prop

This commit is contained in:
梁灏 2021-01-15 17:59:30 +08:00
parent 27adf364c0
commit 8d9ba2b089
5 changed files with 274 additions and 219 deletions

View file

@ -1,152 +1,191 @@
<style> <style>
.view { .demo-row{
height: 100px; margin-bottom: 5px;
width: 100px; background-image: -webkit-linear-gradient(0deg, #F5F5F5 4.16666667%, transparent 4.16666667%, transparent 8.33333333%, #F5F5F5 8.33333333%, #F5F5F5 12.5%, transparent 12.5%, transparent 16.66666667%, #F5F5F5 16.66666667%, #F5F5F5 20.83333333%, transparent 20.83333333%, transparent 25%, #F5F5F5 25%, #F5F5F5 29.16666667%, transparent 29.16666667%, transparent 33.33333333%, #F5F5F5 33.33333333%, #F5F5F5 37.5%, transparent 37.5%, transparent 41.66666667%, #F5F5F5 41.66666667%, #F5F5F5 45.83333333%, transparent 45.83333333%, transparent 50%, #F5F5F5 50%, #F5F5F5 54.16666667%, transparent 54.16666667%, transparent 58.33333333%, #F5F5F5 58.33333333%, #F5F5F5 62.5%, transparent 62.5%, transparent 66.66666667%, #F5F5F5 66.66666667%, #F5F5F5 70.83333333%, transparent 70.83333333%, transparent 75%, #F5F5F5 75%, #F5F5F5 79.16666667%, transparent 79.16666667%, transparent 83.33333333%, #F5F5F5 83.33333333%, #F5F5F5 87.5%, transparent 87.5%, transparent 91.66666667%, #F5F5F5 91.66666667%, #F5F5F5 95.83333333%, transparent 95.83333333%);
background: yellow; background-image: linear-gradient(90deg, #F5F5F5 4.16666667%, transparent 4.16666667%, transparent 8.33333333%, #F5F5F5 8.33333333%, #F5F5F5 12.5%, transparent 12.5%, transparent 16.66666667%, #F5F5F5 16.66666667%, #F5F5F5 20.83333333%, transparent 20.83333333%, transparent 25%, #F5F5F5 25%, #F5F5F5 29.16666667%, transparent 29.16666667%, transparent 33.33333333%, #F5F5F5 33.33333333%, #F5F5F5 37.5%, transparent 37.5%, transparent 41.66666667%, #F5F5F5 41.66666667%, #F5F5F5 45.83333333%, transparent 45.83333333%, transparent 50%, #F5F5F5 50%, #F5F5F5 54.16666667%, transparent 54.16666667%, transparent 58.33333333%, #F5F5F5 58.33333333%, #F5F5F5 62.5%, transparent 62.5%, transparent 66.66666667%, #F5F5F5 66.66666667%, #F5F5F5 70.83333333%, transparent 70.83333333%, transparent 75%, #F5F5F5 75%, #F5F5F5 79.16666667%, transparent 79.16666667%, transparent 83.33333333%, #F5F5F5 83.33333333%, #F5F5F5 87.5%, transparent 87.5%, transparent 91.66666667%, #F5F5F5 91.66666667%, #F5F5F5 95.83333333%, transparent 95.83333333%);
}
.demo-col{
color: #fff;
padding: 30px 0;
text-align: center;
font-size: 18px;
background: rgba(0, 153, 229, .7);
}
.demo-col.light{
background: rgba(0, 153, 229, .5);
}
.demo-row.light .demo-col{
background: rgba(0, 153, 229, .5);
}
.demo-row.light .demo-col.light{
background: rgba(0, 153, 229, .3);
}
.example-demo .ivu-col, .example-demo .ivu-col div{
color: #fff;
padding: 10px 0;
text-align: center;
background: rgba(0, 153, 229, .9);
}
.example-demo .gutter .ivu-col{
background: transparent !important;
}
.example-demo .ivu-col:nth-child(odd), .example-demo .ivu-col:nth-child(odd) div{
background: rgba(0, 153, 229, .7);
}
.code-row-bg{
background: rgba(0,0,0,.05);
} }
</style> </style>
<template> <template>
<div> <div class="example-demo">
<Row type='flex' justify='center'> <Row>
<i-col span='21' class="offset-header"> <Col span="12">col-12</Col>
<Row type='flex' :gutter='16' justify='space-between'> <Col span="12">col-12</Col>
<i-col :order='25'> </Row>
<div class="view"> <br>
<label>245</label> <Row>
</div> <Col span="8">col-8</Col>
</i-col> <Col span="8">col-8</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='1'> <Col span="8">col-8</Col>
<div class="view" > </Row>
<label>1</label> <br>
</div> <Row>
</i-col> <Col span="6">col-6</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='2'> <Col span="6">col-6</Col>
<div class="view" > <Col span="6">col-6</Col>
<label>2</label> <Col span="6">col-6</Col>
</div> </Row>
</i-col> <Divider></Divider>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='3'> <Row :gutter="16">
<div class="view" > <Col span="6">
<label>3</label> <div>col-6</div>
</div> </Col>
</i-col> <Col span="6">
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='4'> <div>col-6</div>
<div class="view" > </Col>
<label>4</label> <Col span="6">
</div> <div>col-6</div>
</i-col> </Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='5'> <Col span="6">
<div class="view" > <div>col-6</div>
<label>5</label> </Col>
</div> </Row>
</i-col> <Divider></Divider>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='6'> <Row type="flex">
<div class="view" > <Col span="6" order="4">1 | order-4</Col>
<label>6</label> <Col span="6" order="3">2 | order-3</Col>
</div> <Col span="6" order="2">3 | order-2</Col>
</i-col> <Col span="6" order="1">4 | order-1</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='7'> </Row>
<div class="view" > <Divider></Divider>
<label>2</label> <Row>
</div> <Col span="18" push="6">col-18 | push-6</Col>
</i-col> <Col span="6" pull="18">col-6 | pull-18</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='8'> </Row>
<div class="view" > <Divider></Divider>
<label>2</label> <Row>
</div> <Col span="8">col-8</Col>
</i-col> <Col span="8" offset="8">col-8 | offset-8</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='9'> </Row>
<div class="view" > <br>
<label>2</label> <Row>
</div> <Col span="6" offset="8">col-6 | offset-8</Col>
</i-col> <Col span="6" offset="4">col-6 | offset-4</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='10'> </Row>
<div class="view" > <br>
<label>2</label> <Row>
</div> <Col span="12" offset="8">col-12 | offset-8</Col>
</i-col> </Row>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='11'> <Divider></Divider>
<div class="view" > <p>子元素向左排列</p>
<label>2</label> <Row type="flex" justify="start" class="code-row-bg">
</div> <Col span="4">col-4</Col>
</i-col> <Col span="4">col-4</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='12'> <Col span="4">col-4</Col>
<div class="view" > <Col span="4">col-4</Col>
<label>2</label> </Row>
</div> <p>子元素向右排列</p>
</i-col> <Row type="flex" justify="end" class="code-row-bg">
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='13'> <Col span="4">col-4</Col>
<div class="view" > <Col span="4">col-4</Col>
<label>12</label> <Col span="4">col-4</Col>
</div> <Col span="4">col-4</Col>
</i-col> </Row>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='14'> <p>子元素居中排列</p>
<div class="view" > <Row type="flex" justify="center" class="code-row-bg">
<label>2</label> <Col span="4">col-4</Col>
</div> <Col span="4">col-4</Col>
</i-col> <Col span="4">col-4</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='15'> <Col span="4">col-4</Col>
<div class="view" > </Row>
<label>2</label> <p>子元素等宽排列</p>
</div> <Row type="flex" justify="space-between" class="code-row-bg">
</i-col> <Col span="4">col-4</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='16'> <Col span="4">col-4</Col>
<div class="view" > <Col span="4">col-4</Col>
<label>2</label> <Col span="4">col-4</Col>
</div> </Row>
</i-col> <p>子元素分散排列</p>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='17'> <Row type="flex" justify="space-around" class="code-row-bg">
<div class="view" > <Col span="4">col-4</Col>
<label>2</label> <Col span="4">col-4</Col>
</div> <Col span="4">col-4</Col>
</i-col> <Col span="4">col-4</Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='18'> </Row>
<div class="view" > <Divider></Divider>
<label>2</label> <p>顶部对齐</p>
</div> <Row type="flex" justify="center" align="top" class="code-row-bg">
</i-col> <Col span="4"><p style="height: 80px">col-4</p></Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='19'> <Col span="4"><p style="height: 30px">col-4</p></Col>
<div class="view" > <Col span="4"><p style="height: 100px">col-4</p></Col>
<label>2</label> <Col span="4"><p style="height: 60px">col-4</p></Col>
</div> </Row>
</i-col> <p>底部对齐</p>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='20'> <Row type="flex" justify="center" align="bottom" class="code-row-bg">
<div class="view" > <Col span="4"><p style="height: 80px">col-4</p></Col>
<label>2</label> <Col span="4"><p style="height: 30px">col-4</p></Col>
</div> <Col span="4"><p style="height: 100px">col-4</p></Col>
</i-col> <Col span="4"><p style="height: 60px">col-4</p></Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='21'> </Row>
<div class="view" > <p>居中对齐</p>
<label>2</label> <Row type="flex" justify="center" align="middle" class="code-row-bg">
</div> <Col span="4"><p style="height: 80px">col-4</p></Col>
</i-col> <Col span="4"><p style="height: 30px">col-4</p></Col>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='22'> <Col span="4"><p style="height: 100px">col-4</p></Col>
<div class="view" > <Col span="4"><p style="height: 60px">col-4</p></Col>
<label>2</label> </Row>
</div> <Divider></Divider>
</i-col> <Row>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='23'> <Col :xs="2" :sm="4" :md="6" :lg="8">Col</Col>
<div class="view" > <Col :xs="20" :sm="16" :md="12" :lg="8">Col</Col>
<label>2</label> <Col :xs="2" :sm="4" :md="6" :lg="8">Col</Col>
</div> </Row>
</i-col> <Divider></Divider>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='24'> <Row>
<div class="view" > <Col :xs="{ span: 5, offset: 1 }" :lg="{ span: 6, offset: 2 }">Col</Col>
<label>2</label> <Col :xs="{ span: 11, offset: 1 }" :lg="{ span: 6, offset: 2 }">Col</Col>
</div> <Col :xs="{ span: 5, offset: 1 }" :lg="{ span: 6, offset: 2 }">Col</Col>
</i-col> </Row>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='25'> <Divider>Flex 填充</Divider>
<div class="view" > <Row>
<label>25-------</label> <Col :flex="2">2 / 5</Col>
</div> <Col :flex="3">3 / 5</Col>
</i-col> </Row>
<i-col :xs='12' :sm='12' :md='8' :lg='8' :order='26'> <Row>
<div class="view" > <Col flex="100px">100px</Col>
<label>26------</label> <Col flex="auto">Fill Rest</Col>
</div> </Row>
</i-col> <Row>
</Row> <Col flex="1 1 200px">1 1 200px</Col>
</i-col> <Col flex="0 1 300px">0 1 300px</Col>
</Row>
<Row :wrap="false">
<Col flex="none">
<div style="padding: 0 16px">none</div>
</Col>
<Col flex="auto">auto with no-wrap</Col>
</Row> </Row>
</div> </div>
</template> </template>

View file

@ -7,6 +7,18 @@
import { findComponentUpward } from '../../utils/assist'; import { findComponentUpward } from '../../utils/assist';
const prefixCls = 'ivu-col'; const prefixCls = 'ivu-col';
function parseFlex(flex) {
if (typeof flex === 'number') {
return `${flex} ${flex} auto`;
}
if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex)) {
return `0 0 ${flex}`;
}
return flex;
}
export default { export default {
name: 'iCol', name: 'iCol',
props: { props: {
@ -21,7 +33,12 @@
md: [Number, Object], md: [Number, Object],
lg: [Number, Object], lg: [Number, Object],
xl: [Number, Object], xl: [Number, Object],
xxl: [Number, Object] xxl: [Number, Object],
// 4.5.0
flex: {
type: [Number, String],
default: ''
}
}, },
data () { data () {
return { return {
@ -68,6 +85,11 @@
}; };
} }
// 4.5.0
if (this.flex) {
style.flex = parseFlex(this.flex);
}
return style; return style;
} }
}, },

View file

@ -11,6 +11,7 @@
export default { export default {
name: 'Row', name: 'Row',
props: { props: {
// todo 4.5.0 flex
type: { type: {
validator (value) { validator (value) {
return oneOf(value, ['flex']); return oneOf(value, ['flex']);
@ -30,17 +31,26 @@
type: Number, type: Number,
default: 0 default: 0
}, },
className: String className: String,
// 4.5.0
wrap: {
type: Boolean,
default: true
}
}, },
computed: { computed: {
classes () { classes () {
return [ return [
// todo 4.5.0 flex
`${prefixCls}`,
{ {
[`${prefixCls}`]: !this.type,
[`${prefixCls}-${this.type}`]: !!this.type, [`${prefixCls}-${this.type}`]: !!this.type,
[`${prefixCls}-${this.type}-${this.align}`]: !!this.align, [`${prefixCls}-${this.type}-${this.align}`]: !!this.align,
[`${prefixCls}-${this.type}-${this.justify}`]: !!this.justify, [`${prefixCls}-${this.type}-${this.justify}`]: !!this.justify,
[`${this.className}`]: !!this.className [`${prefixCls}-${this.align}`]: !!this.align,
[`${prefixCls}-${this.justify}`]: !!this.justify,
[`${this.className}`]: !!this.className,
[`${prefixCls}-no-wrap`]: !this.wrap
} }
]; ];
}, },

View file

@ -1,54 +1,56 @@
.@{row-prefix-cls} { .@{row-prefix-cls} {
.make-row(); display: flex;
display: block; flex-flow: row wrap;
&-flex { &::before,
&::after {
display: flex; display: flex;
flex-direction: row; }
flex-wrap: wrap;
&:before, // No wrap of flex
&:after { &-no-wrap {
display: flex; flex-wrap: nowrap;
} }
// x轴原点
&-start { // x轴原点
justify-content: flex-start; &-start{
} justify-content: flex-start;
// x轴居中 }
&-center { // x轴居中
justify-content: center; &-center{
} justify-content: center;
// x轴反方向 }
&-end { //x轴反方向
justify-content: flex-end; &-end {
} justify-content: flex-end;
// x轴平分 }
&-space-between { // x轴平分
justify-content: space-between; &-space-between {
} justify-content: space-between;
// x轴有间隔地平分 }
&-space-around { // x轴有间隔地平分
justify-content: space-around; &-space-around {
} justify-content: space-around;
// 顶部对齐 }
&-top { // 顶部对齐
align-items: flex-start; &-top {
} align-items: flex-start;
// 居中对齐 }
&-middle { // 居中对齐
align-items: center; &-middle {
} align-items: center;
// 底部对齐 }
&-bottom { // 底部对齐
align-items: flex-end; &-bottom {
} align-items: flex-end;
}; }
} }
.@{col-prefix-cls} { .@{col-prefix-cls} {
position: relative; position: relative;
display: block; max-width: 100%;
// Prevent columns from collapsing when empty
min-height: 1px;
} }
.make-grid(); .make-grid();

View file

@ -1,36 +1,13 @@
@row-prefix-cls: ~"@{css-prefix}row"; @row-prefix-cls: ~"@{css-prefix}row";
@col-prefix-cls: ~"@{css-prefix}col"; @col-prefix-cls: ~"@{css-prefix}col";
.make-row(@gutter: @grid-gutter-width) { // mixins for grid system
position: relative;
margin-left: (@gutter / -2);
margin-right: (@gutter / -2);
height: auto;
.clearfix;
}
.float-grid-columns(@class) {
.col(@index) { // initial
@item: ~".@{col-prefix-cls}-span@{class}-@{index}";
.col((@index + 1), @item);
}
.col(@index, @list) when (@index =< @grid-columns) { // general
@item: ~".@{col-prefix-cls}-span@{class}-@{index}";
.col((@index + 1), ~"@{list}, @{item}");
}
.col(@index, @list) when (@index > @grid-columns) { // terminal
@{list} {
float: left;
flex: 0 0 auto;
}
}
.col(1); // kickstart it
}
.loop-grid-columns(@index, @class) when (@index > 0) { .loop-grid-columns(@index, @class) when (@index > 0) {
.@{col-prefix-cls}-span@{class}-@{index} { .@{col-prefix-cls}-span@{class}-@{index} {
display: block; display: block;
width: percentage((@index / @grid-columns)); flex: 0 0 percentage((@index / @grid-columns));
max-width: percentage((@index / @grid-columns));
} }
.@{col-prefix-cls}@{class}-push-@{index} { .@{col-prefix-cls}@{class}-push-@{index} {
left: percentage((@index / @grid-columns)); left: percentage((@index / @grid-columns));
@ -51,6 +28,12 @@
.@{col-prefix-cls}-span@{class}-@{index} { .@{col-prefix-cls}-span@{class}-@{index} {
display: none; display: none;
} }
.@{col-prefix-cls}-push-@{index} {
left: auto;
}
.@{col-prefix-cls}-pull-@{index} {
right: auto;
}
.@{col-prefix-cls}@{class}-push-@{index} { .@{col-prefix-cls}@{class}-push-@{index} {
left: auto; left: auto;
} }
@ -66,6 +49,5 @@
} }
.make-grid(@class: ~'') { .make-grid(@class: ~'') {
.float-grid-columns(@class);
.loop-grid-columns(@grid-columns, @class); .loop-grid-columns(@grid-columns, @class);
} }