mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Merge pull request #131 from Human-Connection/add-grid-layout
Add grid component
This commit is contained in:
commit
9e49afaac3
70
src/system/components/layout/Grid/Grid.vue
Normal file
70
src/system/components/layout/Grid/Grid.vue
Normal file
@ -0,0 +1,70 @@
|
||||
<template>
|
||||
<component
|
||||
:is="tag"
|
||||
class="ds-grid"
|
||||
:style="styles"
|
||||
>
|
||||
<slot />
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getSpace } from '@@/utils'
|
||||
|
||||
/**
|
||||
* Used in combination with the grid item component to create masonry layouts.
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
export default {
|
||||
name: 'DsGrid',
|
||||
props: {
|
||||
/**
|
||||
* The vertical and horizontal gap between grid items
|
||||
* @options xxx-small|xx-small|x-small|small|base|large|x-large|xx-large|xxx-large
|
||||
*/
|
||||
gap: {
|
||||
type: String,
|
||||
default: 'small',
|
||||
validator: value => (
|
||||
value.match(/(xxx-small|xx-small|x-small|small|base|large|x-large|xx-large|xxx-large)/)
|
||||
)
|
||||
},
|
||||
/**
|
||||
* The minimum width of each column
|
||||
*/
|
||||
minColumnWidth: {
|
||||
type: Number,
|
||||
default: 250,
|
||||
},
|
||||
/**
|
||||
* The height of each row (recommended to use the default)
|
||||
*/
|
||||
rowHeight: {
|
||||
type: Number,
|
||||
default: 20,
|
||||
},
|
||||
/**
|
||||
* The outermost html tag
|
||||
*/
|
||||
tag: {
|
||||
type: String,
|
||||
default: 'div',
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
styles() {
|
||||
return {
|
||||
gridTemplateColumns: `repeat(auto-fill, minmax(${this.minColumnWidth}px, 1fr`,
|
||||
gridGap: `${getSpace(this.gap)}px`,
|
||||
gridAutoRows: `${this.rowHeight}px`,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" src="./style.scss">
|
||||
</style>
|
||||
|
||||
<docs src="./demo.md"></docs>
|
||||
51
src/system/components/layout/Grid/GridItem.vue
Normal file
51
src/system/components/layout/Grid/GridItem.vue
Normal file
@ -0,0 +1,51 @@
|
||||
<template>
|
||||
<component
|
||||
:is="tag"
|
||||
:style="styles"
|
||||
>
|
||||
<slot />
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @see DsGrid
|
||||
*/
|
||||
export default {
|
||||
name: 'DsGridItem',
|
||||
props: {
|
||||
/**
|
||||
* The number of columns the item will span
|
||||
* @options 'fullWidth'|number
|
||||
*/
|
||||
columnSpan: {
|
||||
type: [String, Number],
|
||||
default: 1,
|
||||
},
|
||||
/**
|
||||
* The number of rows the item will span
|
||||
*/
|
||||
rowSpan: {
|
||||
type: Number,
|
||||
default: 4,
|
||||
},
|
||||
/**
|
||||
* The outermost html tag
|
||||
*/
|
||||
tag: {
|
||||
type: String,
|
||||
default: 'div',
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
styles() {
|
||||
return {
|
||||
gridRowEnd: `span ${this.rowSpan}`,
|
||||
gridColumnStart: this.columnSpan === 'fullWidth' ? 1 : 'auto',
|
||||
gridColumnEnd: this.columnSpan === 'fullWidth' ? -1 : `span ${this.columnSpan}`,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
78
src/system/components/layout/Grid/demo.md
Normal file
78
src/system/components/layout/Grid/demo.md
Normal file
@ -0,0 +1,78 @@
|
||||
## Column Width
|
||||
|
||||
All columns share the space in the grid evenly and grow and shrink dynamically.
|
||||
|
||||
You can set a minimum width beyond which columns will continue to grow until there is enough space to fit another column of minimum width. (Resize the window to see the effect.)
|
||||
```
|
||||
<ds-grid :min-column-width="200">
|
||||
<ds-grid-item><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
</ds-grid>
|
||||
```
|
||||
|
||||
## Gaps
|
||||
|
||||
You can set a gap which will be applied as a vertical and horizontal space between all grid items. Allowed values are [the common space sizes](/design-tokens/#spaceSize) and `0`. The default is `small`.
|
||||
```
|
||||
<ds-grid gap="x-small">
|
||||
<ds-grid-item><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
</ds-grid>
|
||||
```
|
||||
|
||||
## Grid Item Size
|
||||
|
||||
Once the grid is defined a grid item can span several columns and/or rows. You can adjust this by setting the column span and/or row span of each item individually. The column span can also be set to `'fullWidth'`.
|
||||
```
|
||||
<ds-grid>
|
||||
<ds-grid-item column-span="fullWidth"><ds-placeholder>full width</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="6" :column-span="2"><ds-placeholder>2 columns, 6 rows</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="8"><ds-placeholder>8 rows</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item><ds-placeholder>default (1 column, 4 rows)</ds-placeholder></ds-grid-item>
|
||||
</ds-grid>
|
||||
```
|
||||
|
||||
## Row Height
|
||||
|
||||
You can set the height of a row – but this is only recommended in combination with setting the grid item property `row-span`! With these values you can fine tune the height of grid items which will always be a multiple of the defined `row-height`.
|
||||
|
||||
Low row height leads to a more fine-grained item height:
|
||||
```
|
||||
<ds-grid :row-height="4">
|
||||
<ds-grid-item :row-span="10"><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="11"><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="12"><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
</ds-grid>
|
||||
```
|
||||
|
||||
High row height leads to a rougher item height:
|
||||
```
|
||||
<ds-grid :row-height="100">
|
||||
<ds-grid-item :row-span="1"><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="2"><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="3"><ds-placeholder>same</ds-placeholder></ds-grid-item>
|
||||
</ds-grid>
|
||||
```
|
||||
|
||||
## Masonry Layout
|
||||
|
||||
In a classic masonry layout items usually have the same width but different heights and are sorted from left to right then top to bottom. You can achieve this by calculating and setting the `row-span` programmatically for each grid item, depending on its contents.
|
||||
|
||||
Some items may move slightly out of order to make sure existing rows are filled before creating new ones.
|
||||
```
|
||||
<ds-grid>
|
||||
<ds-grid-item :row-span="4"><ds-placeholder>first</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="8"><ds-placeholder>second</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="6"><ds-placeholder>third</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="6"><ds-placeholder>fourth</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="4"><ds-placeholder>fifth</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="8"><ds-placeholder>sixth</ds-placeholder></ds-grid-item>
|
||||
<ds-grid-item :row-span="4"><ds-placeholder>seventh</ds-placeholder></ds-grid-item>
|
||||
</ds-grid>
|
||||
```
|
||||
|
||||
**Hint:** Make sure to pass `numbers` with a colon (shortcut for `v-bind:`) so they are not interpreted as strings. For a more thorough explanation visit [the Vue.js docs](https://vuejs.org/v2/guide/components-props.html#Passing-a-Number).
|
||||
3
src/system/components/layout/Grid/style.scss
Normal file
3
src/system/components/layout/Grid/style.scss
Normal file
@ -0,0 +1,3 @@
|
||||
.ds-grid {
|
||||
display: grid;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
.ds-placeholder {
|
||||
@include reset;
|
||||
height: 100%;
|
||||
padding: $space-base;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@ -10,4 +11,4 @@
|
||||
@media #{$media-query-medium} {
|
||||
padding: $space-x-large 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user