Merge pull request #217 from IBM/grid

feat(grid): support gutter, aspectRatio props
This commit is contained in:
Eric Liu 2020-07-23 14:35:22 -07:00 committed by GitHub
commit 18048d1fe1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 121 additions and 16 deletions

View file

@ -1,16 +1,35 @@
<script> <script>
export let as = false; export let as = false;
export let noGutter = false;
export let noGutterLeft = false;
export let noGutterRight = false;
/** /**
* Types for `sm`, `md`, `lg`, `xlg`, `max`: * Aspect ratio of the column
* true * @type {("2x1" | "16x9" | "9x16" | "1x2" | "4x3" | "3x4" | "1x1")} [aspectRatio]
* Number
* { span: Number | true; offset?: Number }
*/ */
export let aspectRatio = undefined;
/**
* @typedef {(boolean | number)} ColumnSize
* @typedef {Object} ColumnSizeDescriptor
* @property {ColumnSize} [ColumnSizeDescriptor.span] Column size
* @property {number} [ColumnSizeDescriptor.offset] Column offset
*/
/** @type {ColumnSize|ColumnSizeDescriptor} [sm] */
export let sm = undefined; export let sm = undefined;
/** @type {ColumnSize|ColumnSizeDescriptor} [md] */
export let md = undefined; export let md = undefined;
/** @type {ColumnSize|ColumnSizeDescriptor} [lg] */
export let lg = undefined; export let lg = undefined;
/** @type {ColumnSize|ColumnSizeDescriptor} [xlg] */
export let xlg = undefined; export let xlg = undefined;
/** @type {ColumnSize|ColumnSizeDescriptor} [max] */
export let max = undefined; export let max = undefined;
const breakpoints = ["sm", "md", "lg", "xlg", "max"]; const breakpoints = ["sm", "md", "lg", "xlg", "max"];
@ -43,9 +62,17 @@
.join(" "); .join(" ");
$: props = { $: props = {
...$$restProps, ...$$restProps,
class: [$$restProps.class, columnClass, !columnClass && "bx--col"] class: [
$$restProps.class,
columnClass,
!columnClass && "bx--col",
noGutter && "bx--no-gutter",
noGutterLeft && "bx--no-gutter--left",
noGutterRight && "bx--no-gutter--right",
aspectRatio && `bx--aspect-ratio bx--aspect-ratio--${aspectRatio}`,
]
.filter(Boolean) .filter(Boolean)
.join(" ") .join(" "),
}; };
</script> </script>

View file

@ -22,7 +22,6 @@
<div class="grid"> <div class="grid">
<h6>Columns with auto-width</h6> <h6>Columns with auto-width</h6>
<Grid> <Grid>
<Row> <Row>
<Column> <Column>
@ -49,7 +48,6 @@
</Grid> </Grid>
<h6>Responsive Grid</h6> <h6>Responsive Grid</h6>
<Grid> <Grid>
<Row> <Row>
<Column sm={1} md={4} lg={8}> <Column sm={1} md={4} lg={8}>
@ -76,7 +74,6 @@
</Grid> </Grid>
<h6>Columns with Offset</h6> <h6>Columns with Offset</h6>
<Grid> <Grid>
<Row> <Row>
<Column sm={{ span: 1, offset: 3 }}> <Column sm={{ span: 1, offset: 3 }}>
@ -103,7 +100,6 @@
</Grid> </Grid>
<h6>Condensed Grid</h6> <h6>Condensed Grid</h6>
<Grid condensed> <Grid condensed>
<Row> <Row>
<Column> <Column>
@ -130,7 +126,6 @@
</Grid> </Grid>
<h6>Condensed Columns</h6> <h6>Condensed Columns</h6>
<Grid> <Grid>
<Row> <Row>
<Column> <Column>
@ -201,7 +196,6 @@
</Grid> </Grid>
<h6>Full Width</h6> <h6>Full Width</h6>
<Grid fullWidth> <Grid fullWidth>
<Row> <Row>
<Column> <Column>
@ -226,4 +220,72 @@
</Column> </Column>
</Row> </Row>
</Grid> </Grid>
<h6>Aspect Ratio: 2x1</h6>
<Grid>
<Row>
<Column aspectRatio="2x1">1</Column>
<Column aspectRatio="2x1">1</Column>
</Row>
</Grid>
<h6>Aspect Ratio: 16x9</h6>
<Grid>
<Row>
<Column aspectRatio="16x9">1</Column>
<Column aspectRatio="16x9">1</Column>
<Column aspectRatio="16x9">1</Column>
<Column aspectRatio="16x9">1</Column>
</Row>
</Grid>
<h6>Aspect Ratio: 4x3</h6>
<Grid>
<Row>
<Column aspectRatio="4x3">1</Column>
<Column aspectRatio="4x3">1</Column>
<Column aspectRatio="4x3">1</Column>
<Column aspectRatio="4x3">1</Column>
</Row>
</Grid>
<h6>Aspect Ratio: 1x1</h6>
<Grid>
<Row>
<Column aspectRatio="1x1">1</Column>
<Column aspectRatio="1x1">1</Column>
<Column aspectRatio="1x1">1</Column>
<Column aspectRatio="1x1">1</Column>
</Row>
</Grid>
<h6>Aspect Ratio: 3x4</h6>
<Grid>
<Row>
<Column aspectRatio="3x4">1</Column>
<Column aspectRatio="3x4">1</Column>
<Column aspectRatio="3x4">1</Column>
<Column aspectRatio="3x4">1</Column>
</Row>
</Grid>
<h6>Aspect Ratio: 9x16</h6>
<Grid>
<Row>
<Column aspectRatio="9x16">1</Column>
<Column aspectRatio="9x16">1</Column>
<Column aspectRatio="9x16">1</Column>
<Column aspectRatio="9x16">1</Column>
</Row>
</Grid>
<h6>Aspect Ratio: 1x2</h6>
<Grid>
<Row>
<Column aspectRatio="1x2">1</Column>
<Column aspectRatio="1x2">1</Column>
<Column aspectRatio="1x2">1</Column>
<Column aspectRatio="1x2">1</Column>
</Row>
</Grid>
</div> </div>

View file

@ -2,6 +2,9 @@
export let as = false; export let as = false;
export let condensed = false; export let condensed = false;
export let fullWidth = false; export let fullWidth = false;
export let noGutter = false;
export let noGutterLeft = false;
export let noGutterRight = false;
$: props = { $: props = {
...$$restProps, ...$$restProps,
@ -9,10 +12,13 @@
$$restProps.class, $$restProps.class,
"bx--grid", "bx--grid",
condensed && "bx--grid--condensed", condensed && "bx--grid--condensed",
fullWidth && "bx--grid--full-width" fullWidth && "bx--grid--full-width",
noGutter && "bx--no-gutter",
noGutterLeft && "bx--no-gutter--left",
noGutterRight && "bx--no-gutter--right",
] ]
.filter(Boolean) .filter(Boolean)
.join(" ") .join(" "),
}; };
</script> </script>

View file

@ -1,12 +1,22 @@
<script> <script>
export let as = false; export let as = false;
export let condensed = false; export let condensed = false;
export let noGutter = false;
export let noGutterLeft = false;
export let noGutterRight = false;
$: props = { $: props = {
...$$restProps, ...$$restProps,
class: [$$restProps.class, "bx--row", condensed && "bx--row--condensed"] class: [
$$restProps.class,
"bx--row",
condensed && "bx--row--condensed",
noGutter && "bx--no-gutter",
noGutterLeft && "bx--no-gutter--left",
noGutterRight && "bx--no-gutter--right",
]
.filter(Boolean) .filter(Boolean)
.join(" ") .join(" "),
}; };
</script> </script>