File tree Expand file tree Collapse file tree 9 files changed +144
-20
lines changed Expand file tree Collapse file tree 9 files changed +144
-20
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { Stack } from "@chakra-ui/core";
11
11
```
12
12
13
13
By default, each item is stacked vertically. Stack clones it's children and
14
- passes the spacing to them via the ` margin-bottom ` or ` margin-right ` .
14
+ passes the spacing to them using ` margin-bottom ` or ` margin-right ` .
15
15
16
16
## Usage
17
17
@@ -43,10 +43,12 @@ function StackEx() {
43
43
render (< StackEx / > );
44
44
```
45
45
46
- ### Inline stack
46
+ ### Stack items horizontally
47
47
48
- The stack each item horizonally, pass the ` isInline ` prop. Optionally, you can
49
- use ` align ` and ` justify ` to adjust the alignment of the items.
48
+ Pass the ` isInline ` prop or ` direction ` and set it to ` horizontal ` .
49
+
50
+ Optionally, you can use ` align ` and ` justify ` to adjust the alignment and
51
+ distribution of the items.
50
52
51
53
``` jsx isManual=true
52
54
function Feature ({ title, desc, ... rest }) {
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as React from "react";
2
2
import * as StyledSystem from "styled-system" ;
3
3
import { BoxProps } from "../Box" ;
4
4
5
- interface IGrid {
5
+ export interface IGrid {
6
6
templateColumns ?: StyledSystem . GridTemplateColumnsProps [ "gridTemplateColumns" ] ;
7
7
gap ?: StyledSystem . GridGapProps [ "gridGap" ] ;
8
8
rowGap ?: StyledSystem . GridRowGapProps [ "gridRowGap" ] ;
Original file line number Diff line number Diff line change @@ -4,14 +4,14 @@ import Box from "../Box";
4
4
const Grid = forwardRef (
5
5
(
6
6
{
7
- templateColumns,
8
7
gap,
9
8
rowGap,
10
9
columnGap,
11
10
autoFlow,
12
11
autoRows,
13
12
autoColumns,
14
13
templateRows,
14
+ templateColumns,
15
15
templateAreas,
16
16
area,
17
17
column,
Original file line number Diff line number Diff line change
1
+ /** @jsx jsx */
2
+ import { jsx } from "@emotion/core" ;
3
+ import { storiesOf } from "@storybook/react" ;
4
+ import Box from "../Box" ;
5
+ import SimpleGrid from "." ;
6
+
7
+ const stories = storiesOf ( "SimpleGrid" , module ) ;
8
+ stories . add ( "Default" , ( ) => (
9
+ < SimpleGrid columns = { 2 } autoFit spacing = "40px" minChildWidth = "300px" >
10
+ < Box bg = "tomato" height = "200px" > </ Box >
11
+ < Box bg = "tomato" height = "200px" > </ Box >
12
+ < Box bg = "tomato" height = "200px" > </ Box >
13
+ < Box bg = "tomato" height = "200px" > </ Box >
14
+ < Box bg = "tomato" height = "200px" > </ Box >
15
+ </ SimpleGrid >
16
+ ) ) ;
Original file line number Diff line number Diff line change
1
+ import * as React from "react" ;
2
+ import { FlexboxProps } from "styled-system" ;
3
+ import { BoxProps } from "../Box" ;
4
+
5
+ interface ISimpleGrid {
6
+ /**
7
+ * The width at which child elements will break into columns. Pass a number for pixel values or a string for any other valid CSS length.
8
+ */
9
+ minChildWidth ?: React . CSSProperties [ "minWidth" ] ;
10
+ /**
11
+ * The align-items to control child element alignment.
12
+ */
13
+ align ?: FlexboxProps [ "alignItems" ] ;
14
+ /**
15
+ * The justify-items to control child element alignment.
16
+ */
17
+ justify ?: FlexboxProps [ "justifyItems" ] ;
18
+ /**
19
+ * The number of rows
20
+ */
21
+ rows ?: number ;
22
+ /**
23
+ * The number of columns
24
+ */
25
+ columns ?: number ;
26
+ /**
27
+ * The gap between the grid items
28
+ */
29
+ spacing ?: BoxProps [ "gridGap" ] ;
30
+ /**
31
+ * The row gap between the grid items
32
+ */
33
+ spacingX ?: BoxProps [ "gridGap" ] ;
34
+ /**
35
+ * The column gap between the grid items
36
+ */
37
+ spacingY ?: BoxProps [ "gridGap" ] ;
38
+ /**
39
+ * If `true` will apply `auto-fit` to the grid-template-columns
40
+ */
41
+ autoFit ?: boolean ;
42
+ /**
43
+ * If `true` will apply `auto-fill` to the grid-template-columns
44
+ */
45
+ autoFill ?: boolean ;
46
+ }
47
+
48
+ type SimpleGridProps = BoxProps & ISimpleGrid ;
49
+
50
+ declare const SimpleGrid : React . FC < SimpleGridProps > ;
Original file line number Diff line number Diff line change
1
+ import React , { forwardRef } from "react" ;
2
+ import Grid from "../Grid" ;
3
+
4
+ const SimpleGrid = forwardRef (
5
+ (
6
+ {
7
+ rows,
8
+ columns,
9
+ spacingX,
10
+ spacingY,
11
+ spacing,
12
+ autoFit,
13
+ autoFill,
14
+ minChildWidth,
15
+ align,
16
+ justify,
17
+ ...props
18
+ } ,
19
+ ref ,
20
+ ) => {
21
+ let templateColumns ;
22
+ if ( autoFit && minChildWidth ) {
23
+ templateColumns = `repeat(auto-fit, minmax(${ minChildWidth } , 1fr))` ;
24
+ }
25
+ if ( autoFill && minChildWidth ) {
26
+ templateColumns = `repeat(auto-fill, minmax(${ minChildWidth } , 1fr))` ;
27
+ }
28
+ return (
29
+ < Grid
30
+ ref = { ref }
31
+ gap = { spacing }
32
+ columnGap = { spacingX }
33
+ rowGap = { spacingY }
34
+ templateRows = { `repeat(${ rows } , 1fr)` }
35
+ templateColumns = { templateColumns || `repeat(${ columns } , 1fr)` }
36
+ justifyItems = { justify }
37
+ alignItems = { align }
38
+ { ...props }
39
+ />
40
+ ) ;
41
+ } ,
42
+ ) ;
43
+
44
+ export default SimpleGrid ;
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
2
import { storiesOf } from "@storybook/react" ;
3
3
import Stack from "." ;
4
+ import Box from "../Box" ;
4
5
5
6
const stories = storiesOf ( "Stack" , module ) ;
6
7
@@ -13,9 +14,9 @@ stories.add("vertical stack", () => (
13
14
) ) ;
14
15
15
16
stories . add ( "Inline Stack" , ( ) => (
16
- < Stack isInline spacing = { 5 } >
17
- < span > ooooooo </ span >
18
- < span > ahhhhh </ span >
19
- < span > Woah! </ span >
17
+ < Stack bg = "blue.500" w = "100%" h = "60px" direction = "horizontal" >
18
+ < Box size = "40px" background = { "#fff" } rounded = "full" / >
19
+ < Box size = "40px" background = { "#fff" } rounded = "full" / >
20
+ < Box size = "40px" background = { "#fff" } rounded = "full" / >
20
21
</ Stack >
21
22
) ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,10 @@ interface IStack {
8
8
* If `true` the items will be stacked horizontally inline.
9
9
*/
10
10
isInline ?: boolean ;
11
+ /**
12
+ * If `true` the items will be stacked horizontally inline.
13
+ */
14
+ direction ?: FlexProps [ "direction" ] ;
11
15
/**
12
16
* The content of the stack.
13
17
*/
Original file line number Diff line number Diff line change @@ -5,27 +5,34 @@ import Flex from "../Flex";
5
5
import Box from "../Box" ;
6
6
7
7
const Stack = ( {
8
+ direction,
8
9
isInline,
9
10
children,
10
- align,
11
+ align = "center" ,
11
12
justify,
12
13
spacing = 2 ,
13
14
shouldWrapChildren,
14
15
...rest
15
16
} ) => {
17
+ let flexDirection ;
18
+
19
+ if ( isInline ) {
20
+ flexDirection = isInline ? "row" : "column" ;
21
+ }
22
+
23
+ if ( direction ) {
24
+ flexDirection = direction ;
25
+ }
26
+
16
27
return (
17
- < Flex
18
- align = { align }
19
- justify = { justify }
20
- flexDir = { isInline ? "row" : "column" }
21
- { ...rest }
22
- >
28
+ < Flex align = { align } justify = { justify } direction = { flexDirection } { ...rest } >
23
29
{ Children . map ( children , ( child , index ) => {
24
30
if ( ! isValidElement ( child ) ) return ;
25
31
let isLastChild = children . length === index + 1 ;
26
- let spacingProps = isInline
27
- ? { mr : isLastChild ? null : spacing }
28
- : { mb : isLastChild ? null : spacing } ;
32
+ let spacingProps =
33
+ isInline || direction === "horizontal"
34
+ ? { mr : isLastChild ? null : spacing }
35
+ : { mb : isLastChild ? null : spacing } ;
29
36
30
37
if ( shouldWrapChildren ) {
31
38
return (
You can’t perform that action at this time.
0 commit comments