1
1
import { ReactChild , ReactElement } from "react" ;
2
2
import flattenChildren from "react-keyed-flatten-children" ;
3
3
import { BoxType , BoxProps } from "../Box/createBentoBox" ;
4
- import { bentoSprinkles } from "../internal/sprinkles.css" ;
4
+ import {
5
+ bentoSprinkles ,
6
+ normalizeResponsiveValue ,
7
+ OptionalResponsiveValue ,
8
+ } from "../internal/sprinkles.css" ;
5
9
import { childKey } from "../util/childKey" ;
6
10
import { Children } from "../util/Children" ;
7
11
import {
8
12
CollapsibleAlignmentProps ,
9
13
responsiveCollapsibleAlignmentProps ,
10
14
} from "../util/collapsible" ;
11
- import * as columnStyles from "./Column.css" ;
15
+ import { desktopWidths , tabletWidths , mobileWidths , fullWidth } from "./Column.css" ;
12
16
13
17
export function createColumns < AtomsFn extends typeof bentoSprinkles > ( Box : BoxType < AtomsFn > ) {
14
18
type ResponsiveSpace = BoxProps < AtomsFn > [ "gap" ] ;
15
19
16
20
type ColumnProps = {
17
21
children : Children ;
18
- width ?: keyof typeof columnStyles . width | "content" ;
22
+ width ?: OptionalResponsiveValue < keyof typeof desktopWidths > ;
23
+ sticky ?: {
24
+ top : BoxProps < AtomsFn > [ "top" ] ;
25
+ } ;
19
26
} ;
20
27
21
- function Column ( props : ColumnProps ) {
28
+ function Column ( { children, width, sticky } : ColumnProps ) {
29
+ const { desktop, tablet, mobile } = width
30
+ ? normalizeResponsiveValue ( width )
31
+ : { desktop : undefined , tablet : undefined , mobile : undefined } ;
32
+
33
+ const className =
34
+ width == null
35
+ ? fullWidth
36
+ : [
37
+ desktop && desktopWidths [ desktop ] ,
38
+ tablet && tabletWidths [ tablet ] ,
39
+ mobile && mobileWidths [ mobile ] ,
40
+ ] ;
41
+
42
+ const stickyProps = sticky ? ( { position : "sticky" , top : sticky . top } as const ) : { } ;
43
+
22
44
return (
23
- < Box
24
- className = {
25
- props . width != null && props . width !== "content"
26
- ? columnStyles . width [ props . width ]
27
- : undefined
28
- }
29
- width = { props . width !== "content" ? "full" : undefined }
30
- flexShrink = { props . width === "content" ? 0 : undefined }
31
- >
32
- { props . children }
45
+ < Box className = { className } { ...stickyProps } >
46
+ { children }
33
47
</ Box >
34
48
) ;
35
49
}
@@ -39,12 +53,12 @@ export function createColumns<AtomsFn extends typeof bentoSprinkles>(Box: BoxTyp
39
53
children : Children ;
40
54
} & CollapsibleAlignmentProps ;
41
55
42
- function Columns ( { space, children, align, alignY, collapseBelow } : Props ) {
56
+ function Columns ( { space, children, align, alignY, collapseBelow, reverse } : Props ) {
43
57
return (
44
58
< Box
45
59
display = "flex"
46
60
gap = { space }
47
- { ...responsiveCollapsibleAlignmentProps ( { align, alignY, collapseBelow } ) }
61
+ { ...responsiveCollapsibleAlignmentProps ( { align, alignY, collapseBelow, reverse } ) }
48
62
>
49
63
{ flattenChildren ( children ) . map ( ( child , index ) => {
50
64
if ( isColumn ( child ) ) {
0 commit comments