2016-12-25 21:09:49 +08:00
|
|
|
---
|
2019-11-20 11:13:24 +08:00
|
|
|
order: 10
|
2016-12-25 21:09:49 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 栅格配置器
|
|
|
|
en-US: Playground
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
可以简单配置几种等分栅格和间距。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
A simple playground for column count and gutter.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2016-12-25 21:09:49 +08:00
|
|
|
import { Row, Col, Slider } from 'antd';
|
|
|
|
|
2020-04-30 11:19:09 +08:00
|
|
|
const gutters = {};
|
|
|
|
const vgutters = {};
|
|
|
|
const colCounts = {};
|
|
|
|
|
|
|
|
[8, 16, 24, 32, 40, 48].forEach((value, i) => {
|
|
|
|
gutters[i] = value;
|
|
|
|
});
|
|
|
|
[8, 16, 24, 32, 40, 48].forEach((value, i) => {
|
|
|
|
vgutters[i] = value;
|
|
|
|
});
|
|
|
|
[2, 3, 4, 6, 8, 12].forEach((value, i) => {
|
|
|
|
colCounts[i] = value;
|
|
|
|
});
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-14 16:40:42 +08:00
|
|
|
export default () => {
|
|
|
|
const [state, setState] = React.useState({
|
2020-04-30 11:19:09 +08:00
|
|
|
gutterKey: 1,
|
|
|
|
vgutterKey: 1,
|
|
|
|
colCountKey: 2,
|
2022-05-14 16:40:42 +08:00
|
|
|
});
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-14 16:40:42 +08:00
|
|
|
const onGutterChange = gutterKey => {
|
|
|
|
setState({ ...state, gutterKey });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-14 16:40:42 +08:00
|
|
|
const onVGutterChange = vgutterKey => {
|
|
|
|
setState({ ...state, vgutterKey });
|
2019-09-24 21:44:20 +08:00
|
|
|
};
|
|
|
|
|
2022-05-14 16:40:42 +08:00
|
|
|
const onColCountChange = colCountKey => {
|
|
|
|
setState({ ...state, colCountKey });
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-14 16:40:42 +08:00
|
|
|
const { gutterKey, vgutterKey, colCountKey } = state;
|
|
|
|
const cols = [];
|
|
|
|
const colCount = colCounts[colCountKey];
|
|
|
|
let colCode = '';
|
|
|
|
for (let i = 0; i < colCount; i++) {
|
|
|
|
cols.push(
|
|
|
|
<Col key={i.toString()} span={24 / colCount}>
|
|
|
|
<div>Column</div>
|
|
|
|
</Col>,
|
2016-12-25 21:09:49 +08:00
|
|
|
);
|
2022-05-14 16:40:42 +08:00
|
|
|
colCode += ` <Col span={${24 / colCount}} />\n`;
|
2016-12-25 21:09:49 +08:00
|
|
|
}
|
|
|
|
|
2022-05-14 16:40:42 +08:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>Horizontal Gutter (px): </span>
|
|
|
|
<div style={{ width: '50%' }}>
|
|
|
|
<Slider
|
|
|
|
min={0}
|
|
|
|
max={Object.keys(gutters).length - 1}
|
|
|
|
value={gutterKey}
|
|
|
|
onChange={onGutterChange}
|
|
|
|
marks={gutters}
|
|
|
|
step={null}
|
|
|
|
tipFormatter={value => gutters[value]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<span>Vertical Gutter (px): </span>
|
|
|
|
<div style={{ width: '50%' }}>
|
|
|
|
<Slider
|
|
|
|
min={0}
|
|
|
|
max={Object.keys(vgutters).length - 1}
|
|
|
|
value={vgutterKey}
|
|
|
|
onChange={onVGutterChange}
|
|
|
|
marks={vgutters}
|
|
|
|
step={null}
|
|
|
|
tipFormatter={value => vgutters[value]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<span>Column Count:</span>
|
|
|
|
<div style={{ width: '50%', marginBottom: 48 }}>
|
|
|
|
<Slider
|
|
|
|
min={0}
|
|
|
|
max={Object.keys(colCounts).length - 1}
|
|
|
|
value={colCountKey}
|
|
|
|
onChange={onColCountChange}
|
|
|
|
marks={colCounts}
|
|
|
|
step={null}
|
|
|
|
tipFormatter={value => colCounts[value]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Row gutter={[gutters[gutterKey], vgutters[vgutterKey]]}>
|
|
|
|
{cols}
|
|
|
|
{cols}
|
|
|
|
</Row>
|
|
|
|
Another Row:
|
|
|
|
<Row gutter={[gutters[gutterKey], vgutters[vgutterKey]]}>{cols}</Row>
|
|
|
|
<pre className="demo-code">{`<Row gutter={[${gutters[gutterKey]}, ${vgutters[vgutterKey]}]}>\n${colCode}\n${colCode}</Row>`}</pre>
|
|
|
|
<pre className="demo-code">{`<Row gutter={[${gutters[gutterKey]}, ${vgutters[vgutterKey]}]}>\n${colCode}</Row>`}</pre>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|
2016-12-25 21:09:49 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```css
|
|
|
|
#components-grid-demo-playground [class~='ant-col'] {
|
2016-12-25 21:09:49 +08:00
|
|
|
background: transparent;
|
|
|
|
border: 0;
|
|
|
|
}
|
2019-05-07 14:57:32 +08:00
|
|
|
#components-grid-demo-playground [class~='ant-col'] > div {
|
2016-12-25 21:09:49 +08:00
|
|
|
height: 120px;
|
2020-02-26 21:00:43 +08:00
|
|
|
font-size: 14px;
|
2016-12-25 21:09:49 +08:00
|
|
|
line-height: 120px;
|
2020-02-26 21:00:43 +08:00
|
|
|
background: #0092ff;
|
|
|
|
border-radius: 4px;
|
2016-12-25 21:09:49 +08:00
|
|
|
}
|
2016-12-25 21:31:33 +08:00
|
|
|
#components-grid-demo-playground pre {
|
2020-02-26 21:00:43 +08:00
|
|
|
padding: 8px 16px;
|
|
|
|
font-size: 13px;
|
2016-12-25 21:31:33 +08:00
|
|
|
background: #f9f9f9;
|
|
|
|
border-radius: 6px;
|
|
|
|
}
|
2020-04-27 21:40:52 +08:00
|
|
|
#components-grid-demo-playground pre.demo-code {
|
|
|
|
direction: ltr;
|
|
|
|
}
|
2021-01-27 14:03:05 +08:00
|
|
|
#components-grid-demo-playground .ant-col {
|
|
|
|
padding: 0;
|
|
|
|
}
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|
2019-12-24 15:01:03 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
[data-theme="dark"] #components-grid-demo-playground [class~='ant-col'] > div {
|
|
|
|
background: #028ac8;
|
|
|
|
}
|
|
|
|
</style>
|