From 3290cdf114670d14b9ba8949665115cdd05a50a7 Mon Sep 17 00:00:00 2001 From: wanlei Date: Fri, 27 Oct 2017 13:24:22 +0800 Subject: [PATCH] update: [Grid] merged from vue-component/grid --- .babelrc | 7 +- components/grid/col.vue | 85 ++++++++++++++++++++++++ components/grid/index.js | 7 ++ components/grid/row.vue | 79 +++++++++++++++++++++++ components/grid/style/index.js | 2 + components/grid/style/index.less | 107 +++++++++++++++++++++++++++++++ components/grid/style/mixin.less | 100 +++++++++++++++++++++++++++++ components/index.js | 3 + examples/grid.vue | 98 ++++++++++++++++++++++++++++ examples/index.js | 7 +- package.json | 3 + 11 files changed, 495 insertions(+), 3 deletions(-) create mode 100644 components/grid/col.vue create mode 100644 components/grid/index.js create mode 100644 components/grid/row.vue create mode 100644 components/grid/style/index.js create mode 100644 components/grid/style/index.less create mode 100644 components/grid/style/mixin.less create mode 100644 examples/grid.vue diff --git a/.babelrc b/.babelrc index 3bde2e0da..b30bba26a 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,9 @@ { "presets": ["env"], - "plugins": ["transform-vue-jsx"] + "plugins": [ + "transform-vue-jsx", + "transform-es2015-destructuring", + "transform-es2015-parameters", + "transform-object-rest-spread" + ] } diff --git a/components/grid/col.vue b/components/grid/col.vue new file mode 100644 index 000000000..6a01bacfb --- /dev/null +++ b/components/grid/col.vue @@ -0,0 +1,85 @@ + + diff --git a/components/grid/index.js b/components/grid/index.js new file mode 100644 index 000000000..352a384d8 --- /dev/null +++ b/components/grid/index.js @@ -0,0 +1,7 @@ +import Row from './row.vue' +import Col from './col.vue' + +export default { + Col, Row, +} + diff --git a/components/grid/row.vue b/components/grid/row.vue new file mode 100644 index 000000000..65f76f579 --- /dev/null +++ b/components/grid/row.vue @@ -0,0 +1,79 @@ + + + diff --git a/components/grid/style/index.js b/components/grid/style/index.js new file mode 100644 index 000000000..cf31ed80f --- /dev/null +++ b/components/grid/style/index.js @@ -0,0 +1,2 @@ +import '../../style/index.less' +import './index.less' diff --git a/components/grid/style/index.less b/components/grid/style/index.less new file mode 100644 index 000000000..9671dc96d --- /dev/null +++ b/components/grid/style/index.less @@ -0,0 +1,107 @@ +@import "../../style/themes/default"; +@import "../../style/mixins/index"; +@import "./mixin"; + +// Grid system +.@{ant-prefix}-row { + .make-row(); + display: block; +} + +.@{ant-prefix}-row-flex { + display: flex; + flex-flow: row wrap; + + &:before, + &:after { + display: flex; + } +} + +// x轴原点 +.@{ant-prefix}-row-flex-start { + justify-content: flex-start; +} + +// x轴居中 +.@{ant-prefix}-row-flex-center { + justify-content: center; +} + +// x轴反方向 +.@{ant-prefix}-row-flex-end { + justify-content: flex-end; +} + +// x轴平分 +.@{ant-prefix}-row-flex-space-between { + justify-content: space-between; +} + +// x轴有间隔地平分 +.@{ant-prefix}-row-flex-space-around { + justify-content: space-around; +} + +// 顶部对齐 +.@{ant-prefix}-row-flex-top { + align-items: flex-start; +} + +// 居中对齐 +.@{ant-prefix}-row-flex-middle { + align-items: center; +} + +// 底部对齐 +.@{ant-prefix}-row-flex-bottom { + align-items: flex-end; +} + +.@{ant-prefix}-col { + position: relative; + display: block; +} + +.make-grid-columns(); +.make-grid(); + +// Extra small grid +// +// Columns, offsets, pushes, and pulls for extra small devices like +// smartphones. + +.make-grid(-xs); + +// Small grid +// +// Columns, offsets, pushes, and pulls for the small device range, from phones +// to tablets. + +@media (min-width: @screen-sm-min) { + .make-grid(-sm); +} + +// Medium grid +// +// Columns, offsets, pushes, and pulls for the desktop device range. + +@media (min-width: @screen-md-min) { + .make-grid(-md); +} + +// Large grid +// +// Columns, offsets, pushes, and pulls for the large desktop device range. + +@media (min-width: @screen-lg-min) { + .make-grid(-lg); +} + +// Extra Large grid +// +// Columns, offsets, pushes, and pulls for the full hd device range. + +@media (min-width: @screen-xl-min) { + .make-grid(-xl); +} diff --git a/components/grid/style/mixin.less b/components/grid/style/mixin.less new file mode 100644 index 000000000..ad6ed9623 --- /dev/null +++ b/components/grid/style/mixin.less @@ -0,0 +1,100 @@ +@import "../../style/mixins/index"; + +// mixins for grid system +// ------------------------ +.make-row(@gutter: @grid-gutter-width) { + position: relative; + margin-left: (@gutter / -2); + margin-right: (@gutter / -2); + height: auto; + .clearfix; +} + +.make-grid-columns() { + .col(@index) { + @item: ~".@{ant-prefix}-col-@{index}, .@{ant-prefix}-col-xs-@{index}, .@{ant-prefix}-col-sm-@{index}, .@{ant-prefix}-col-md-@{index}, .@{ant-prefix}-col-lg-@{index}"; + .col((@index + 1), @item); + } + .col(@index, @list) when (@index =< @grid-columns) { + @item: ~".@{ant-prefix}-col-@{index}, .@{ant-prefix}-col-xs-@{index}, .@{ant-prefix}-col-sm-@{index}, .@{ant-prefix}-col-md-@{index}, .@{ant-prefix}-col-lg-@{index}"; + .col((@index + 1), ~"@{list}, @{item}"); + } + .col(@index, @list) when (@index > @grid-columns) { + @{list} { + position: relative; + // Prevent columns from collapsing when empty + min-height: 1px; + padding-left: (@grid-gutter-width / 2); + padding-right: (@grid-gutter-width / 2); + } + } + .col(1); +} + +.float-grid-columns(@class) { + .col(@index) { // initial + @item: ~".@{ant-prefix}-col@{class}-@{index}"; + .col((@index + 1), @item); + } + .col(@index, @list) when (@index =< @grid-columns) { // general + @item: ~".@{ant-prefix}-col@{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 +} + +// lesshint false +.loop-grid-columns(@index, @class) when (@index > 0) { + .@{ant-prefix}-col@{class}-@{index} { + display: block; + width: percentage((@index / @grid-columns)); + } + .@{ant-prefix}-col@{class}-push-@{index} { + left: percentage((@index / @grid-columns)); + } + .@{ant-prefix}-col@{class}-pull-@{index} { + right: percentage((@index / @grid-columns)); + } + .@{ant-prefix}-col@{class}-offset-@{index} { + margin-left: percentage((@index / @grid-columns)); + } + .@{ant-prefix}-col@{class}-order-@{index} { + order: @index; + } + .loop-grid-columns((@index - 1), @class); +} + +.loop-grid-columns(@index, @class) when (@index = 0) { + .@{ant-prefix}-col@{class}-@{index} { + display: none; + } + .@{ant-prefix}-col-push-@{index} { + left: auto; + } + .@{ant-prefix}-col-pull-@{index} { + right: auto; + } + .@{ant-prefix}-col@{class}-push-@{index} { + left: auto; + } + .@{ant-prefix}-col@{class}-pull-@{index} { + right: auto; + } + .@{ant-prefix}-col@{class}-offset-@{index} { + margin-left: 0; + } + .@{ant-prefix}-col@{class}-order-@{index} { + order: 0; + } +} + +.make-grid(@class: ~'') { + .float-grid-columns(@class); + .loop-grid-columns(@grid-columns, @class); +} diff --git a/components/index.js b/components/index.js index 8a85844b2..07c0894d2 100644 --- a/components/index.js +++ b/components/index.js @@ -1,9 +1,12 @@ import './button/style' import './checkbox/style' import './icon/style' +import './grid/style' export { default as Button } from './button' export { default as Checkbox } from './checkbox' export { default as Icon } from './icon' + +export { default as Grid } from './grid' diff --git a/examples/grid.vue b/examples/grid.vue new file mode 100644 index 000000000..a721853b9 --- /dev/null +++ b/examples/grid.vue @@ -0,0 +1,98 @@ + + + diff --git a/examples/index.js b/examples/index.js index e9a228266..aea31b30f 100644 --- a/examples/index.js +++ b/examples/index.js @@ -1,19 +1,22 @@ import Vue from 'vue' import Checkbox from './checkbox.vue' import Button from './button.vue' +import Grid from './grid.vue' // import Dialog from './dialog.vue' import './index.less' new Vue({ el: '#app', template: `
- - + + +
`, components: { AntButton: Button, // AntDialog: Dialog, Checkbox, + Grid, }, }) diff --git a/package.json b/package.json index 52f8aef48..fb59e8dae 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,9 @@ "babel-loader": "^7.1.2", "babel-plugin-istanbul": "^4.1.1", "babel-plugin-syntax-jsx": "^6.18.0", + "babel-plugin-transform-es2015-destructuring": "^6.23.0", + "babel-plugin-transform-es2015-parameters": "^6.24.1", + "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-transform-vue-jsx": "^3.5.0", "babel-preset-env": "^1.6.0", "chai": "^4.1.2",