feat: update grid
parent
c91f709ff2
commit
7abdcc6fab
|
@ -1,5 +1,5 @@
|
|||
module.exports = {
|
||||
dev: {
|
||||
componentName: 'spin', // dev components
|
||||
componentName: 'grid', // dev components
|
||||
},
|
||||
};
|
||||
|
|
|
@ -55,10 +55,11 @@ export default {
|
|||
let sizeClassObj = {};
|
||||
['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].forEach(size => {
|
||||
let sizeProps = {};
|
||||
if (typeof this[size] === 'number') {
|
||||
sizeProps.span = this[size];
|
||||
} else if (typeof this[size] === 'object') {
|
||||
sizeProps = this[size] || {};
|
||||
const propSize = this[size];
|
||||
if (typeof propSize === 'number') {
|
||||
sizeProps.span = propSize;
|
||||
} else if (typeof propSize === 'object') {
|
||||
sizeProps = propSize || {};
|
||||
}
|
||||
|
||||
sizeClassObj = {
|
||||
|
@ -72,6 +73,7 @@ export default {
|
|||
};
|
||||
});
|
||||
const classes = {
|
||||
[`${prefixCls}`]: true,
|
||||
[`${prefixCls}-${span}`]: span !== undefined,
|
||||
[`${prefixCls}-order-${order}`]: order,
|
||||
[`${prefixCls}-offset-${offset}`]: offset,
|
||||
|
@ -86,10 +88,20 @@ export default {
|
|||
};
|
||||
if (rowContext) {
|
||||
const gutter = rowContext.getGutter();
|
||||
if (gutter > 0) {
|
||||
if (gutter) {
|
||||
divProps.style = {
|
||||
paddingLeft: `${gutter / 2}px`,
|
||||
paddingRight: `${gutter / 2}px`,
|
||||
...(gutter[0] > 0
|
||||
? {
|
||||
paddingLeft: `${gutter[0] / 2}px`,
|
||||
paddingRight: `${gutter[0] / 2}px`,
|
||||
}
|
||||
: {}),
|
||||
...(gutter[1] > 0
|
||||
? {
|
||||
paddingTop: `${gutter[1] / 2}px`,
|
||||
paddingBottom: `${gutter[1] / 2}px`,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,7 @@
|
|||
import PropTypes from '../_util/vue-types';
|
||||
import BaseMixin from '../_util/BaseMixin';
|
||||
import { ConfigConsumerProps } from '../config-provider';
|
||||
|
||||
// matchMedia polyfill for
|
||||
// https://github.com/WickyNilliams/enquire.js/issues/82
|
||||
let enquire = null;
|
||||
if (typeof window !== 'undefined') {
|
||||
const matchMediaPolyfill = mediaQuery => {
|
||||
return {
|
||||
media: mediaQuery,
|
||||
matches: false,
|
||||
addListener() {},
|
||||
removeListener() {},
|
||||
};
|
||||
};
|
||||
window.matchMedia = window.matchMedia || matchMediaPolyfill;
|
||||
enquire = require('enquire.js');
|
||||
}
|
||||
import ResponsiveObserve from '../_util/responsiveObserve';
|
||||
|
||||
const BreakpointMap = PropTypes.shape({
|
||||
xs: PropTypes.number,
|
||||
|
@ -28,30 +13,21 @@ const BreakpointMap = PropTypes.shape({
|
|||
}).loose;
|
||||
|
||||
const RowProps = {
|
||||
gutter: PropTypes.oneOfType([PropTypes.number, BreakpointMap]),
|
||||
gutter: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
|
||||
type: PropTypes.oneOf(['flex']),
|
||||
align: PropTypes.oneOf(['top', 'middle', 'bottom']),
|
||||
align: PropTypes.oneOf(['top', 'middle', 'bottom', 'stretch']),
|
||||
justify: PropTypes.oneOf(['start', 'end', 'center', 'space-around', 'space-between']),
|
||||
prefixCls: PropTypes.string,
|
||||
};
|
||||
|
||||
const responsiveArray = ['xxl', 'xl', 'lg', 'md', 'sm', 'xs'];
|
||||
|
||||
const responsiveMap = {
|
||||
xs: '(max-width: 575px)',
|
||||
sm: '(min-width: 576px)',
|
||||
md: '(min-width: 768px)',
|
||||
lg: '(min-width: 992px)',
|
||||
xl: '(min-width: 1200px)',
|
||||
xxl: '(min-width: 1600px)',
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'ARow',
|
||||
mixins: [BaseMixin],
|
||||
props: {
|
||||
...RowProps,
|
||||
gutter: PropTypes.oneOfType([PropTypes.number, BreakpointMap]).def(0),
|
||||
gutter: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]).def(0),
|
||||
},
|
||||
provide() {
|
||||
return {
|
||||
|
@ -69,51 +45,40 @@ export default {
|
|||
|
||||
mounted() {
|
||||
this.$nextTick(() => {
|
||||
Object.keys(responsiveMap).map(screen =>
|
||||
enquire.register(responsiveMap[screen], {
|
||||
match: () => {
|
||||
if (typeof this.gutter !== 'object') {
|
||||
return;
|
||||
}
|
||||
this.setState(prevState => ({
|
||||
screens: {
|
||||
...prevState.screens,
|
||||
[screen]: true,
|
||||
},
|
||||
}));
|
||||
},
|
||||
unmatch: () => {
|
||||
if (typeof this.gutter !== 'object') {
|
||||
return;
|
||||
}
|
||||
this.setState(prevState => ({
|
||||
screens: {
|
||||
...prevState.screens,
|
||||
[screen]: false,
|
||||
},
|
||||
}));
|
||||
},
|
||||
// Keep a empty destory to avoid triggering unmatch when unregister
|
||||
destroy() {},
|
||||
}),
|
||||
);
|
||||
this.token = ResponsiveObserve.subscribe(screens => {
|
||||
const { gutter } = this;
|
||||
if (
|
||||
typeof gutter === 'object' ||
|
||||
(Array.isArray(gutter) &&
|
||||
(typeof gutter[0] === 'object' || typeof gutter[1] === 'object'))
|
||||
) {
|
||||
this.screens = screens;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
beforeDestroy() {
|
||||
Object.keys(responsiveMap).map(screen => enquire.unregister(responsiveMap[screen]));
|
||||
ResponsiveObserve.unsubscribe(this.token);
|
||||
},
|
||||
methods: {
|
||||
getGutter() {
|
||||
const { gutter } = this;
|
||||
if (typeof gutter === 'object') {
|
||||
for (let i = 0; i < responsiveArray.length; i++) {
|
||||
const breakpoint = responsiveArray[i];
|
||||
if (this.screens[breakpoint] && gutter[breakpoint] !== undefined) {
|
||||
return gutter[breakpoint];
|
||||
const results = [0, 0];
|
||||
const { gutter, screens } = this;
|
||||
const normalizedGutter = Array.isArray(gutter) ? gutter : [gutter, 0];
|
||||
normalizedGutter.forEach((g, index) => {
|
||||
if (typeof g === 'object') {
|
||||
for (let i = 0; i < responsiveArray.length; i++) {
|
||||
const breakpoint = responsiveArray[i];
|
||||
if (screens[breakpoint] && g[breakpoint] !== undefined) {
|
||||
results[index] = g[breakpoint];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
results[index] = g || 0;
|
||||
}
|
||||
}
|
||||
return gutter;
|
||||
});
|
||||
return results;
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -129,13 +94,20 @@ export default {
|
|||
[`${prefixCls}-${type}-${justify}`]: type && justify,
|
||||
[`${prefixCls}-${type}-${align}`]: type && align,
|
||||
};
|
||||
const rowStyle =
|
||||
gutter > 0
|
||||
const rowStyle = {
|
||||
...(gutter[0] > 0
|
||||
? {
|
||||
marginLeft: `${gutter / -2}px`,
|
||||
marginRight: `${gutter / -2}px`,
|
||||
marginLeft: `${gutter[0] / -2}px`,
|
||||
marginRight: `${gutter[0] / -2}px`,
|
||||
}
|
||||
: {};
|
||||
: {}),
|
||||
...(gutter[1] > 0
|
||||
? {
|
||||
marginTop: `${gutter[1] / -2}px`,
|
||||
marginBottom: `${gutter[1] / -2}px`,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
return (
|
||||
<div class={classes} style={rowStyle}>
|
||||
{$slots.default}
|
||||
|
|
|
@ -3,19 +3,19 @@
|
|||
exports[`renders ./components/grid/demo/basic.md correctly 1`] = `
|
||||
<div>
|
||||
<div class="ant-row">
|
||||
<div class="ant-col-12">col-12</div>
|
||||
<div class="ant-col-12">col-12</div>
|
||||
<div class="ant-col ant-col-12">col-12</div>
|
||||
<div class="ant-col ant-col-12">col-12</div>
|
||||
</div>
|
||||
<div class="ant-row">
|
||||
<div class="ant-col-8">col-8</div>
|
||||
<div class="ant-col-8">col-8</div>
|
||||
<div class="ant-col-8">col-8</div>
|
||||
<div class="ant-col ant-col-8">col-8</div>
|
||||
<div class="ant-col ant-col-8">col-8</div>
|
||||
<div class="ant-col ant-col-8">col-8</div>
|
||||
</div>
|
||||
<div class="ant-row">
|
||||
<div class="ant-col-6">col-6</div>
|
||||
<div class="ant-col-6">col-6</div>
|
||||
<div class="ant-col-6">col-6</div>
|
||||
<div class="ant-col-6">col-6</div>
|
||||
<div class="ant-col ant-col-6">col-6</div>
|
||||
<div class="ant-col ant-col-6">col-6</div>
|
||||
<div class="ant-col ant-col-6">col-6</div>
|
||||
<div class="ant-col ant-col-6">col-6</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
@ -24,38 +24,38 @@ exports[`renders ./components/grid/demo/flex.md correctly 1`] = `
|
|||
<div>
|
||||
<p>sub-element align left</p>
|
||||
<div class="ant-row-flex ant-row-flex-start">
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
</div>
|
||||
<p>sub-element align center</p>
|
||||
<div class="ant-row-flex ant-row-flex-center">
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
</div>
|
||||
<p>sub-element align right</p>
|
||||
<div class="ant-row-flex ant-row-flex-end">
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
</div>
|
||||
<p>sub-element monospaced arrangement</p>
|
||||
<div class="ant-row-flex ant-row-flex-space-between">
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
</div>
|
||||
<p>sub-element align full</p>
|
||||
<div class="ant-row-flex ant-row-flex-space-around">
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
<div class="ant-col ant-col-4">col-4</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
@ -64,46 +64,46 @@ exports[`renders ./components/grid/demo/flex-align.md correctly 1`] = `
|
|||
<div>
|
||||
<p>Align Top</p>
|
||||
<div class="ant-row-flex ant-row-flex-center ant-row-flex-top">
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-100">col-4</p>
|
||||
</div>
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-50">col-4</p>
|
||||
</div>
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-120">col-4</p>
|
||||
</div>
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-80">col-4</p>
|
||||
</div>
|
||||
</div>
|
||||
<p>Align Center</p>
|
||||
<div class="ant-row-flex ant-row-flex-space-around ant-row-flex-middle">
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-100">col-4</p>
|
||||
</div>
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-50">col-4</p>
|
||||
</div>
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-120">col-4</p>
|
||||
</div>
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-80">col-4</p>
|
||||
</div>
|
||||
</div>
|
||||
<p>Align Bottom</p>
|
||||
<div class="ant-row-flex ant-row-flex-space-between ant-row-flex-bottom">
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-100">col-4</p>
|
||||
</div>
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-50">col-4</p>
|
||||
</div>
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-120">col-4</p>
|
||||
</div>
|
||||
<div class="ant-col-4">
|
||||
<div class="ant-col ant-col-4">
|
||||
<p class="height-80">col-4</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -113,10 +113,10 @@ exports[`renders ./components/grid/demo/flex-align.md correctly 1`] = `
|
|||
exports[`renders ./components/grid/demo/flex-order.md correctly 1`] = `
|
||||
<div>
|
||||
<div class="ant-row-flex">
|
||||
<div class="ant-col-6 ant-col-order-4">1 col-order-4</div>
|
||||
<div class="ant-col-6 ant-col-order-3">2 col-order-3</div>
|
||||
<div class="ant-col-6 ant-col-order-2">3 col-order-2</div>
|
||||
<div class="ant-col-6 ant-col-order-1">4 col-order-1</div>
|
||||
<div class="ant-col ant-col-6 ant-col-order-4">1 col-order-4</div>
|
||||
<div class="ant-col ant-col-6 ant-col-order-3">2 col-order-3</div>
|
||||
<div class="ant-col ant-col-6 ant-col-order-2">3 col-order-2</div>
|
||||
<div class="ant-col ant-col-6 ant-col-order-1">4 col-order-1</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
@ -124,16 +124,16 @@ exports[`renders ./components/grid/demo/flex-order.md correctly 1`] = `
|
|||
exports[`renders ./components/grid/demo/gutter.md correctly 1`] = `
|
||||
<div class="gutter-example">
|
||||
<div class="ant-row" style="margin-left: -8px; margin-right: -8px;">
|
||||
<div class="gutter-row ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="gutter-row ant-col ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="gutter-box">col-6</div>
|
||||
</div>
|
||||
<div class="gutter-row ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="gutter-row ant-col ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="gutter-box">col-6</div>
|
||||
</div>
|
||||
<div class="gutter-row ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="gutter-row ant-col ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="gutter-box">col-6</div>
|
||||
</div>
|
||||
<div class="gutter-row ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="gutter-row ant-col ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="gutter-box">col-6</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -143,22 +143,31 @@ exports[`renders ./components/grid/demo/gutter.md correctly 1`] = `
|
|||
exports[`renders ./components/grid/demo/offset.md correctly 1`] = `
|
||||
<div>
|
||||
<div class="ant-row">
|
||||
<div class="ant-col-8">col-8</div>
|
||||
<div class="ant-col-8 ant-col-offset-8">col-8</div>
|
||||
<div class="ant-col ant-col-8">col-8</div>
|
||||
<div class="ant-col ant-col-8 ant-col-offset-8">col-8</div>
|
||||
</div>
|
||||
<div class="ant-row">
|
||||
<div class="ant-col-6 ant-col-offset-6">col-6 col-offset-6</div>
|
||||
<div class="ant-col-6 ant-col-offset-6">col-6 col-offset-6</div>
|
||||
<div class="ant-col ant-col-6 ant-col-offset-6">col-6 col-offset-6</div>
|
||||
<div class="ant-col ant-col-6 ant-col-offset-6">col-6 col-offset-6</div>
|
||||
</div>
|
||||
<div class="ant-row">
|
||||
<div class="ant-col-12 ant-col-offset-6">col-12 col-offset-6</div>
|
||||
<div class="ant-col ant-col-12 ant-col-offset-6">col-12 col-offset-6</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renders ./components/grid/demo/playfround.md correctly 1`] = `
|
||||
<div id="components-grid-demo-playground">
|
||||
<div style="margin-bottom: 16px;"><span style="margin-right: 6px;">Gutter (px): </span>
|
||||
<div style="margin-bottom: 16px;"><span style="margin-right: 6px;">Horizontal Gutter (px): </span>
|
||||
<div style="width: 50%;">
|
||||
<div tabindex="-1" class="ant-slider ant-slider-with-marks">
|
||||
<div class="ant-slider-rail"></div>
|
||||
<div class="ant-slider-track" style="left: 0%; width: 20%;"></div>
|
||||
<div class="ant-slider-step"><span class="ant-slider-dot ant-slider-dot-active" style="left: 0%;"></span><span class="ant-slider-dot ant-slider-dot-active" style="left: 20%;"></span><span class="ant-slider-dot" style="left: 40%;"></span><span class="ant-slider-dot" style="left: 60%;"></span><span class="ant-slider-dot" style="left: 80%;"></span><span class="ant-slider-dot" style="left: 100%;"></span></div>
|
||||
<div role="slider" tabindex="0" aria-valuemin="0" aria-valuemax="5" aria-valuenow="1" class="ant-slider-handle" style="left: 20%;"></div>
|
||||
<div class="ant-slider-mark"><span class="ant-slider-mark-text ant-slider-mark-text-active" style="left: 0%; transform: translateX(-50%);">8</span><span class="ant-slider-mark-text ant-slider-mark-text-active" style="left: 20%; transform: translateX(-50%);">16</span><span class="ant-slider-mark-text" style="left: 40%; transform: translateX(-50%);">24</span><span class="ant-slider-mark-text" style="left: 60%; transform: translateX(-50%);">32</span><span class="ant-slider-mark-text" style="left: 80%; transform: translateX(-50%);">40</span><span class="ant-slider-mark-text" style="left: 100%; transform: translateX(-50%);">48</span></div>
|
||||
</div>
|
||||
</div> <span style="margin-right: 6px;">Vertical Gutter (px): </span>
|
||||
<div style="width: 50%;">
|
||||
<div tabindex="-1" class="ant-slider ant-slider-with-marks">
|
||||
<div class="ant-slider-rail"></div>
|
||||
|
@ -178,49 +187,68 @@ exports[`renders ./components/grid/demo/playfround.md correctly 1`] = `
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ant-row" style="margin-left: -8px; margin-right: -8px;">
|
||||
<div class="ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="ant-row" style="margin: -8px -8px -8px -8px;">
|
||||
<div class="ant-col ant-col-6" style="padding: 8px 8px 8px 8px;">
|
||||
<div>Column</div>
|
||||
</div>
|
||||
<div class="ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="ant-col ant-col-6" style="padding: 8px 8px 8px 8px;">
|
||||
<div>Column</div>
|
||||
</div>
|
||||
<div class="ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="ant-col ant-col-6" style="padding: 8px 8px 8px 8px;">
|
||||
<div>Column</div>
|
||||
</div>
|
||||
<div class="ant-col-6" style="padding-left: 8px; padding-right: 8px;">
|
||||
<div class="ant-col ant-col-6" style="padding: 8px 8px 8px 8px;">
|
||||
<div>Column</div>
|
||||
</div>
|
||||
</div> <pre><Row :gutter="16">
|
||||
<Col :span="6"/>
|
||||
<Col :span="6"/>
|
||||
<Col :span="6"/>
|
||||
<Col :span="6"/>
|
||||
</Row></pre>
|
||||
</div>
|
||||
<div class="ant-row" style="margin: -8px -8px -8px -8px;">
|
||||
<div class="ant-col ant-col-6" style="padding: 8px 8px 8px 8px;">
|
||||
<div>Column</div>
|
||||
</div>
|
||||
<div class="ant-col ant-col-6" style="padding: 8px 8px 8px 8px;">
|
||||
<div>Column</div>
|
||||
</div>
|
||||
<div class="ant-col ant-col-6" style="padding: 8px 8px 8px 8px;">
|
||||
<div>Column</div>
|
||||
</div>
|
||||
<div class="ant-col ant-col-6" style="padding: 8px 8px 8px 8px;">
|
||||
<div>Column</div>
|
||||
</div>
|
||||
</div> <pre><a-row :gutter="[16,16]">
|
||||
<a-col :span="6"/>
|
||||
<a-col :span="6"/>
|
||||
<a-col :span="6"/>
|
||||
<a-col :span="6"/>
|
||||
</a-row></pre> <pre><a-row :gutter="[16,16]">
|
||||
<a-col :span="6"/>
|
||||
<a-col :span="6"/>
|
||||
<a-col :span="6"/>
|
||||
<a-col :span="6"/>
|
||||
</a-row></pre>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renders ./components/grid/demo/responsive.md correctly 1`] = `
|
||||
<div class="ant-row">
|
||||
<div class="ant-col-xs-2 ant-col-sm-4 ant-col-md-6 ant-col-lg-8 ant-col-xl-10">Col</div>
|
||||
<div class="ant-col-xs-20 ant-col-sm-16 ant-col-md-12 ant-col-lg-8 ant-col-xl-4">Col</div>
|
||||
<div class="ant-col-xs-2 ant-col-sm-4 ant-col-md-6 ant-col-lg-8 ant-col-xl-10">Col</div>
|
||||
<div class="ant-col ant-col-xs-2 ant-col-sm-4 ant-col-md-6 ant-col-lg-8 ant-col-xl-10">Col</div>
|
||||
<div class="ant-col ant-col-xs-20 ant-col-sm-16 ant-col-md-12 ant-col-lg-8 ant-col-xl-4">Col</div>
|
||||
<div class="ant-col ant-col-xs-2 ant-col-sm-4 ant-col-md-6 ant-col-lg-8 ant-col-xl-10">Col</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renders ./components/grid/demo/responsive-more.md correctly 1`] = `
|
||||
<div class="ant-row">
|
||||
<div class="ant-col-xs-5 ant-col-xs-offset-1 ant-col-lg-6 ant-col-lg-offset-2">Col</div>
|
||||
<div class="ant-col-xs-11 ant-col-xs-offset-1 ant-col-lg-6 ant-col-lg-offset-2">Col</div>
|
||||
<div class="ant-col-xs-5 ant-col-xs-offset-1 ant-col-lg-6 ant-col-lg-offset-2">Col</div>
|
||||
<div class="ant-col ant-col-xs-5 ant-col-xs-offset-1 ant-col-lg-6 ant-col-lg-offset-2">Col</div>
|
||||
<div class="ant-col ant-col-xs-11 ant-col-xs-offset-1 ant-col-lg-6 ant-col-lg-offset-2">Col</div>
|
||||
<div class="ant-col ant-col-xs-5 ant-col-xs-offset-1 ant-col-lg-6 ant-col-lg-offset-2">Col</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renders ./components/grid/demo/sort.md correctly 1`] = `
|
||||
<div>
|
||||
<div class="ant-row">
|
||||
<div class="ant-col-18 ant-col-push-6">col-18 col-push-6</div>
|
||||
<div class="ant-col-6 ant-col-pull-18">col-6 col-pull-18</div>
|
||||
<div class="ant-col ant-col-18 ant-col-push-6">col-18 col-push-6</div>
|
||||
<div class="ant-col ant-col-6 ant-col-pull-18">col-6 col-pull-18</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
exports[`Grid renders wrapped Col correctly 1`] = `
|
||||
<div class="ant-row" style="margin-left: -10px; margin-right: -10px;">
|
||||
<div>
|
||||
<div class="ant-col-12" style="padding-left: 10px; padding-right: 10px;"></div>
|
||||
<div class="ant-col ant-col-12" style="padding-left: 10px; padding-right: 10px;"></div>
|
||||
</div>
|
||||
<div class="ant-col-12" style="padding-left: 10px; padding-right: 10px;"></div>
|
||||
<div class="ant-col ant-col-12" style="padding-left: 10px; padding-right: 10px;"></div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Grid should render Col 1`] = `<div class="ant-col-2"></div>`;
|
||||
exports[`Grid should render Col 1`] = `<div class="ant-col ant-col-2"></div>`;
|
||||
|
||||
exports[`Grid should render Row 1`] = `<div class="ant-row"></div>`;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import { mount } from '@vue/test-utils';
|
||||
import { Col, Row } from '..';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
|
||||
describe('Grid', () => {
|
||||
mountTest(Row);
|
||||
mountTest(Col);
|
||||
it('should render Col', () => {
|
||||
const wrapper = mount(Col, {
|
||||
propsData: {
|
||||
|
|
|
@ -2,12 +2,16 @@
|
|||
#### 区块间隔
|
||||
栅格常常需要和间隔进行配合,你可以使用 `Row` 的 `gutter` 属性,我们推荐使用 `(16+8n)px` 作为栅格间隔。(n 是自然数)
|
||||
如果要支持响应式,可以写成 `{ xs: 8, sm: 16, md: 24, lg: 32 }`。
|
||||
如果需要垂直间距,可以写成数组形式 `[水平间距, 垂直间距]` `[16, { xs: 8, sm: 16, md: 24, lg: 32 }]`。
|
||||
> 数组形式垂直间距在 `1.5.0` 之后支持。
|
||||
</cn>
|
||||
|
||||
<us>
|
||||
#### Grid Gutter
|
||||
You can use the `gutter` property of `Row` as grid spacing, we recommend set it to `(16 + 8n) px`. (`n` stands for natural number.)
|
||||
You can set it to a object like `{ xs: 8, sm: 16, md: 24, lg: 32 }` for responsive design.
|
||||
You can use a array to set vertical spacing, `[horizontal, vertical]` `[16, { xs: 8, sm: 16, md: 24, lg: 32 }]`.
|
||||
> vertical gutter was supported after `1.5.0`.
|
||||
</us>
|
||||
|
||||
```tpl
|
||||
|
|
|
@ -22,13 +22,13 @@ const md = {
|
|||
};
|
||||
const md2 = {
|
||||
cn: `
|
||||
在多数业务情况下,Ant Design需要在设计区域内解决大量信息收纳的问题,因此在 12 栅格系统的基础上,我们将整个设计建议区域按照 24 等分的原则进行划分。
|
||||
在多数业务情况下,Ant Design Vue 需要在设计区域内解决大量信息收纳的问题,因此在 12 栅格系统的基础上,我们将整个设计建议区域按照 24 等分的原则进行划分。
|
||||
划分之后的信息区块我们称之为『盒子』。建议横向排列的盒子数量最多四个,最少一个。『盒子』在整个屏幕上占比见上图。设计部分基于盒子的单位定制盒子内部的排版规则,以保证视觉层面的舒适感。
|
||||
## 概述
|
||||
布局的栅格化系统,我们是基于行(row)和列(col)来定义信息区块的外部框架,以保证页面的每个区域能够稳健地排布起来。下面简单介绍一下它的工作原理:
|
||||
- 通过\`row\`在水平方向建立一组\`column\`(简写col)
|
||||
- 你的内容应当放置于\`col\`内,并且,只有\`col\`可以作为\`row\`的直接元素
|
||||
- 栅格系统中的列是指1到24的值来表示其跨越的范围。例如,三个等宽的列可以使用\`.col-8\`来创建
|
||||
- 栅格系统中的列是指 1 到 24 的值来表示其跨越的范围。例如,三个等宽的列可以使用 \`<a-col :span="8" />\` 来创建
|
||||
- 如果一个\`row\`中的\`col\`总和超过 24,那么多余的\`col\`会作为一个整体另起一行排列
|
||||
## Flex 布局
|
||||
我们的栅格化系统支持 Flex 布局,允许子元素在父节点内的水平对齐方式 - 居左、居中、居右、等宽排列、分散排列。子元素与子元素之间,支持顶部对齐、垂直居中对齐、底部对齐的方式。同时,支持使用 order 来定义元素的排列顺序。
|
||||
|
@ -36,7 +36,7 @@ Flex 布局是基于 24 栅格来定义每一个『盒子』的宽度,但不
|
|||
## 代码演示
|
||||
`,
|
||||
us: `
|
||||
In most business situations, Ant Design needs to solve a lot of information storage problems within the design area, so based on 12 Grids System, we divided the design area into 24 aliquots.
|
||||
In most business situations, Ant Design Vue needs to solve a lot of information storage problems within the design area, so based on 12 Grids System, we divided the design area into 24 sections.
|
||||
|
||||
We name the divided area 'box'. We suggest four boxes for horizontal arrangement at most, one at least. Boxes are proportional to the entire screen as shown in the picture above. To ensure a high level of visual comfort, we customize the typography inside of the box based on the box unit.
|
||||
|
||||
|
@ -48,7 +48,7 @@ Following is a brief look at how it works:
|
|||
|
||||
- Establish a set of \`column\` in the horizontal space defined by \`row\` (abbreviated col)
|
||||
- Your content elements should be placed directly in the \`col\`, and only \`col\` should be placed directly in \`row\`
|
||||
- The column grid system is a value of 1-24 to represent its range spans. For example, three columns of equal width can be created by \`.col-8\` (\`span=8\`).
|
||||
- The column grid system is a value of 1-24 to represent its range spans. For example, three columns of equal width can be created by \`<a-col :span="8" />\`.
|
||||
- If the sum of \`col\` spans in a \`row\` are more than 24, then the overflowing \`col\` as a whole will start a new line arrangement.
|
||||
|
||||
## Flex layout
|
||||
|
|
|
@ -11,29 +11,48 @@ A simple playground for column count and gutter.
|
|||
```tpl
|
||||
<template>
|
||||
<div id="components-grid-demo-playground">
|
||||
<div style="marginBottom:16px">
|
||||
<span style="marginRight:6px">Gutter (px): </span>
|
||||
<div style="margin-bottom:16px">
|
||||
<span style="margin-right:6px">Horizontal Gutter (px): </span>
|
||||
<div style="width:50%">
|
||||
<a-slider
|
||||
:min="0"
|
||||
:max="Object.keys(gutters).length - 1"
|
||||
v-model="gutterKey"
|
||||
:marks="this.gutters"
|
||||
:marks="gutters"
|
||||
:step="null"
|
||||
/>
|
||||
</div>
|
||||
<span style="marginRight:6px">Column Count:</span>
|
||||
<span style="margin-right: 6px">Vertical Gutter (px): </span>
|
||||
<div style="width: 50%">
|
||||
<a-slider
|
||||
:min="0"
|
||||
:max="Object.keys(vgutters).length - 1"
|
||||
v-model="vgutterKey"
|
||||
:marks="vgutters"
|
||||
:step="null"
|
||||
/>
|
||||
</div>
|
||||
<span style="margin-right:6px">Column Count:</span>
|
||||
<div style="width:50%">
|
||||
<a-slider
|
||||
:min="0"
|
||||
:max="Object.keys(colCounts).length - 1"
|
||||
v-model="colCountKey"
|
||||
:marks="this.colCounts"
|
||||
:marks="colCounts"
|
||||
:step="null"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<a-row :gutter="gutters[gutterKey]">
|
||||
<a-row :gutter="[gutters[gutterKey], vgutters[vgutterKey]]">
|
||||
<a-col
|
||||
v-for="(item, index) in colCounts[colCountKey]"
|
||||
:key="item.toString()"
|
||||
:span="24/colCounts[colCountKey]"
|
||||
>
|
||||
<div>Column</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-row :gutter="[gutters[gutterKey], vgutters[vgutterKey]]">
|
||||
<a-col
|
||||
v-for="(item, index) in colCounts[colCountKey]"
|
||||
:key="item.toString()"
|
||||
|
@ -43,49 +62,54 @@ A simple playground for column count and gutter.
|
|||
</a-col>
|
||||
</a-row>
|
||||
<pre v-text="rowColHtml"></pre>
|
||||
<pre v-text="rowColHtml"></pre>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
const gutters = {};
|
||||
const arr = [8, 16, 24, 32, 40, 48];
|
||||
arr.forEach((value, i) => {
|
||||
const colCounts = {};
|
||||
const vgutters = {};
|
||||
[8, 16, 24, 32, 40, 48].forEach((value, i) => {
|
||||
gutters[i] = value;
|
||||
});
|
||||
const colCounts = {};
|
||||
const arr1 = [2, 3, 4, 6, 8, 12];
|
||||
arr1.forEach((value, i) => {
|
||||
[8, 16, 24, 32, 40, 48].forEach((value, i) => {
|
||||
vgutters[i] = value;
|
||||
});
|
||||
[2, 3, 4, 6, 8, 12].forEach((value, i) => {
|
||||
colCounts[i] = value;
|
||||
});
|
||||
return {
|
||||
gutterKey: 1,
|
||||
vgutterKey: 1,
|
||||
colCountKey: 2,
|
||||
colCounts,
|
||||
gutters,
|
||||
vgutters,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
rowColHtml() {
|
||||
const colCount = this.colCounts[this.colCountKey];
|
||||
const getter = this.gutters[this.gutterKey];
|
||||
let colCode = '<Row :gutter="' + getter + '">\n';
|
||||
const getter = [this.gutters[this.gutterKey], this.vgutters[this.vgutterKey]];
|
||||
let colCode = '<a-row :gutter="[' + getter + ']">\n';
|
||||
for (let i = 0; i < colCount; i++) {
|
||||
const spanNum = 24 / colCount;
|
||||
colCode += ' <Col :span="' + spanNum + '"/>\n';
|
||||
colCode += ' <a-col :span="' + spanNum + '"/>\n';
|
||||
}
|
||||
colCode += '</Row>';
|
||||
colCode += '</a-row>';
|
||||
return colCode;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
#components-grid-demo-playground [class^='ant-col-'] {
|
||||
#components-grid-demo-playground [class~='ant-col'] {
|
||||
background: transparent;
|
||||
border: 0;
|
||||
}
|
||||
#components-grid-demo-playground [class^='ant-col-'] > div {
|
||||
#components-grid-demo-playground [class~='ant-col'] > div {
|
||||
background: #00a0e9;
|
||||
height: 120px;
|
||||
line-height: 120px;
|
||||
|
|
|
@ -26,3 +26,9 @@
|
|||
| xxl | `≥1600px`, could be a `span` value or an object containing above props | number\|object | - |
|
||||
|
||||
The breakpoints of responsive grid follow [BootStrap 4 media queries rules](https://getbootstrap.com/docs/4.0/layout/overview/#responsive-breakpoints)(not including `occasionally part`).
|
||||
|
||||
## FAQ
|
||||
|
||||
### How to support IE9 when using responsive?
|
||||
|
||||
You can use [matchMedia polyfill](https://github.com/paulirish/matchMedia.js/) to handle this.
|
||||
|
|
|
@ -26,3 +26,9 @@
|
|||
| xxl | `≥1600px` 响应式栅格,可为栅格数或一个包含其他属性的对象 | number\|object | - |
|
||||
|
||||
响应式栅格的断点扩展自 [BootStrap 4 的规则](https://getbootstrap.com/docs/4.0/layout/overview/#responsive-breakpoints)(不包含链接里 `occasionally` 的部分)。
|
||||
|
||||
## FAQ
|
||||
|
||||
### IE9 响应式不工作怎么办?
|
||||
|
||||
可以引入 [matchMedia polyfill](https://github.com/paulirish/matchMedia.js/) 添加支持。
|
||||
|
|
|
@ -4,22 +4,23 @@
|
|||
|
||||
import { AntdComponent } from '../component';
|
||||
|
||||
type Gutter =
|
||||
| number
|
||||
| {
|
||||
xs: number;
|
||||
sm: number;
|
||||
md: number;
|
||||
lg: number;
|
||||
xl: number;
|
||||
xxl: number;
|
||||
};
|
||||
export declare class Row extends AntdComponent {
|
||||
/**
|
||||
* spacing between grids, could be a number or a object like { xs: 8, sm: 16, md: 24}
|
||||
* @default 0
|
||||
* @type numner | object
|
||||
*/
|
||||
gutter:
|
||||
| number
|
||||
| {
|
||||
xs: number;
|
||||
sm: number;
|
||||
md: number;
|
||||
lg: number;
|
||||
xl: number;
|
||||
xxl: number;
|
||||
};
|
||||
gutter: Gutter | [Gutter, Gutter];
|
||||
|
||||
/**
|
||||
* layout mode, optional flex
|
||||
|
|
Loading…
Reference in New Issue