@@ -9,77 +9,109 @@ import {
9
9
import { forwardRefWithAs } from "@bedrock-layout/type-utils" ;
10
10
import React , { CSSProperties } from "react" ;
11
11
12
+ /**
13
+ * Props for the `Columns` component.
14
+ */
12
15
export interface ColumnsProps {
16
+ /**
17
+ * Sets space between each element.
18
+ */
13
19
gutter ?: Gutter ;
20
+ /**
21
+ * Sets the number of columns.
22
+ */
14
23
columns ?: number ;
24
+ /**
25
+ * Sets the width breakpoint at which the columns
26
+ * will switch to a single column.
27
+ */
15
28
switchAt ?: number | CSSLength | SizesOptions ;
16
- children ?: React . ReactNode ;
17
29
}
18
30
19
- export const Columns = forwardRefWithAs < "div" , ColumnsProps > (
20
- ( { as, gutter, columns = 1 , style, switchAt, ...props } , ref ) => {
21
- const theme = useTheme ( ) ;
22
- const maybeGutter = getSafeGutter ( theme , gutter ) ;
23
- const safeColumns = columns > 0 ? columns : 1 ;
24
- const safeStyle = style ?? { } ;
25
- const safeSwitchAt = getSizeValue ( theme , switchAt ) ?? switchAt ;
31
+ /**
32
+ * The `Columns` component is designed to create a n-column layout.
33
+ * The complimentary `Column` component will allow elements to span and
34
+ * offset n-columns.
35
+ */
36
+ export const Columns = forwardRefWithAs < "div" , ColumnsProps > ( function Columns (
37
+ { as, gutter, columns = 1 , style, switchAt, ...props } ,
38
+ ref ,
39
+ ) {
40
+ const theme = useTheme ( ) ;
41
+ const maybeGutter = getSafeGutter ( theme , gutter ) ;
42
+ const safeColumns = columns > 0 ? columns : 1 ;
43
+ const safeStyle = style ?? { } ;
44
+ const safeSwitchAt = getSizeValue ( theme , switchAt ) ?? switchAt ;
26
45
27
- const Component = as ?? "div" ;
46
+ const Component = as ?? "div" ;
28
47
29
- return (
30
- < Component
31
- ref = { ref }
32
- data-bedrock-columns = { "" }
33
- style = {
34
- {
35
- ...safeStyle ,
36
- "--gutter" : maybeGutter ,
37
- "--columns" : safeColumns ,
38
- "--switchAt" : safeSwitchAt ,
39
- } as CSSProperties
40
- }
41
- { ...props }
42
- />
43
- ) ;
44
- } ,
45
- ) ;
46
-
47
- Columns . displayName = "Columns" ;
48
+ return (
49
+ < Component
50
+ ref = { ref }
51
+ data-bedrock-columns = { "" }
52
+ style = {
53
+ {
54
+ ...safeStyle ,
55
+ "--gutter" : maybeGutter ,
56
+ "--columns" : safeColumns ,
57
+ "--switchAt" : safeSwitchAt ,
58
+ } as CSSProperties
59
+ }
60
+ { ...props }
61
+ />
62
+ ) ;
63
+ } ) ;
48
64
65
+ /**
66
+ * Props for the `Column` component.
67
+ */
49
68
export interface ColumnProps {
69
+ /**
70
+ * Sets the number of columns the element will span.
71
+ */
50
72
span ?: number ;
73
+ /**
74
+ * Sets the number of columns the element will offset from the start.
75
+ */
51
76
offsetStart ?: number ;
77
+ /**
78
+ * Sets the number of columns the element will offset from the end.
79
+ */
52
80
offsetEnd ?: number ;
53
81
}
54
82
55
83
const safeSpan = ( span : unknown ) => {
56
84
return typeof span === "number" ? span : 1 ;
57
85
} ;
58
86
59
- export const Column = forwardRefWithAs < "div" , ColumnProps > (
60
- ( { as, span, style, offsetStart = 0 , offsetEnd = 0 , ...props } , ref ) => {
61
- const safeOffsetStart = offsetStart > 0 ? offsetStart : undefined ;
62
- const safeOffsetEnd = offsetEnd > 0 ? offsetEnd : undefined ;
63
- const safeStyle = style ?? { } ;
64
-
65
- const Component = as ?? "div" ;
87
+ /**
88
+ * The `Column` component is designed to be used in conjunction
89
+ * with the `Columns` component.
90
+ * It allows elements to span and offset n-columns.
91
+ */
92
+ export const Column = forwardRefWithAs < "div" , ColumnProps > ( function Column (
93
+ { as, span, style, offsetStart = 0 , offsetEnd = 0 , ...props } ,
94
+ ref ,
95
+ ) {
96
+ const safeOffsetStart = offsetStart > 0 ? offsetStart : undefined ;
97
+ const safeOffsetEnd = offsetEnd > 0 ? offsetEnd : undefined ;
98
+ const safeStyle = style ?? { } ;
66
99
67
- return (
68
- < Component
69
- data-bedrock-column
70
- ref = { ref }
71
- style = {
72
- {
73
- ...safeStyle ,
74
- "--span" : Math . max ( safeSpan ( span ) , 1 ) ,
75
- "--offsetStart" : safeOffsetStart ,
76
- "--offsetEnd" : safeOffsetEnd ,
77
- } as CSSProperties
78
- }
79
- { ...props }
80
- />
81
- ) ;
82
- } ,
83
- ) ;
100
+ const Component = as ?? "div" ;
84
101
85
- Column . displayName = "Column" ;
102
+ return (
103
+ < Component
104
+ data-bedrock-column
105
+ ref = { ref }
106
+ style = {
107
+ {
108
+ ...safeStyle ,
109
+ "--span" : Math . max ( safeSpan ( span ) , 1 ) ,
110
+ "--offsetStart" : safeOffsetStart ,
111
+ "--offsetEnd" : safeOffsetEnd ,
112
+ } as CSSProperties
113
+ }
114
+ { ...props }
115
+ />
116
+ ) ;
117
+ } ) ;
0 commit comments