1- import { Box , Button , Flex , H1 , Panel , Text } from '@bigcommerce/big-design' ;
1+ import { Box , Button , Flex , H1 , Panel , Table , Text } from '@bigcommerce/big-design' ;
22import React , { Fragment , useContext } from 'react' ;
33import styled , { ThemeContext } from 'styled-components' ;
44
55import { Code , CodePreview , ContentRoutingTabs , List , NextLink } from '../components' ;
66
7+ // If your theme exports a SPACING_KEYS array, prefer importing it:
8+ // import { SPACING_KEYS } from '@bigcommerce/big-design-theme';
9+
10+ // Keep this local list in docs to control order & avoid negatives/none in the visual demo.
11+ // (If you later export SPACING_KEYS from the theme, swap to that single source of truth.)
12+ const BASE_KEYS = [
13+ 'xxxLarge' ,
14+ 'xxLarge' ,
15+ 'xLarge' ,
16+ 'large' ,
17+ 'medium' ,
18+ 'small' ,
19+ 'xSmall' ,
20+ 'xxSmall' ,
21+ 'none' ,
22+ ] ;
23+
724const BlueBox = styled ( Box ) ( ( { theme } ) => ( {
825 backgroundColor : theme . colors . primary ,
926 display : 'inline-block' ,
@@ -24,13 +41,18 @@ const SpacingPage = () => {
2441 with any of the < Code primary > padding</ Code > and < Code primary > margin</ Code > props. There
2542 are a few ways we can consume these values.
2643 </ Text >
44+
2745 < Text bold > When to use:</ Text >
2846 < List >
2947 < List . Item >
3048 Using the < NextLink href = "/margin" > Margin</ NextLink > and{ ' ' }
3149 < NextLink href = "/padding" > Padding</ NextLink > props.
3250 </ List . Item >
33- < List . Item > Consuming it from the theme in a custom component.</ List . Item >
51+ < List . Item > Consuming spacing from the theme in custom components.</ List . Item >
52+ < List . Item >
53+ Using negative spacing tokens (e.g. < Code > xSmallN</ Code > ) for controlled overlap or
54+ gutter adjustments.
55+ </ List . Item >
3456 </ List >
3557 </ Panel >
3658
@@ -64,9 +86,7 @@ const SpacingPage = () => {
6486 title : 'Applying to a style' ,
6587 render : ( ) => (
6688 < Fragment key = "style" >
67- < Text >
68- You can also use spacing directly from the theme to style other components.
69- </ Text >
89+ < Text > You can also read spacing directly from the theme in styled code.</ Text >
7090 < CodePreview >
7191 { /* jsx-to-string:start */ }
7292 { function Example ( ) {
@@ -83,20 +103,78 @@ const SpacingPage = () => {
83103 </ Fragment >
84104 ) ,
85105 } ,
106+ {
107+ id : 'negative' ,
108+ title : 'Negative spacing' ,
109+ render : ( ) => (
110+ < Fragment key = "negative" >
111+ < Text >
112+ Every positive token has a negative counterpart formed by appending{ ' ' }
113+ < Code > N</ Code > . These are especially useful for collapsing gutters or creating
114+ controlled overlap, as demonstrated in the table within a panel component in the
115+ following example.
116+ </ Text >
117+ < CodePreview >
118+ { /* jsx-to-string:start */ }
119+ < Panel
120+ description = "The contents of the panel can have negative margins to collapse gutters."
121+ header = "Negative Margins"
122+ >
123+ < Box marginHorizontal = { { mobile : 'mediumN' , tablet : 'xLargeN' } } >
124+ < Table
125+ columns = { [
126+ {
127+ header : 'Sku' ,
128+ hash : 'sku' ,
129+ tooltip : 'Header tooltip' ,
130+ render : ( { sku } ) => sku ,
131+ } ,
132+ { header : 'Name' , hash : 'name' , render : ( { name } ) => name } ,
133+ { header : 'Stock' , hash : 'stock' , render : ( { stock } ) => stock } ,
134+ ] }
135+ items = { [
136+ { sku : 'SM13' , name : '[Sample] Smith Journal 13' , stock : 25 } ,
137+ { sku : 'DPB' , name : '[Sample] Dustpan & Brush' , stock : 34 } ,
138+ { sku : 'OFSUC' , name : '[Sample] Utility Caddy' , stock : 45 } ,
139+ { sku : 'CLC' , name : '[Sample] Canvas Laundry Cart' , stock : 2 } ,
140+ { sku : 'CGLD' , name : '[Sample] Laundry Detergent' , stock : 29 } ,
141+ ] }
142+ />
143+ </ Box >
144+ </ Panel >
145+ { /* jsx-to-string:end */ }
146+ </ CodePreview >
147+ </ Fragment >
148+ ) ,
149+ } ,
86150 ] }
87151 />
88152 </ Panel >
89153
90154 < Panel header = "Spacing values" headerId = "spacing-values" >
91- < Flex justifyContent = "space-around" >
92- { Object . keys ( spacing )
93- . reverse ( )
94- . map ( ( key ) => (
95- < Flex alignItems = "center" flexDirection = "column" key = { key } paddingBottom = "small" >
96- < Code > { key } </ Code >
97- < BlueBox marginTop = "medium" style = { { width : spacing [ key ] , height : spacing [ key ] } } />
98- </ Flex >
99- ) ) }
155+ < Text >
156+ The grid below shows the{ ' ' }
157+ < Text as = "span" bold >
158+ positive
159+ </ Text > { ' ' }
160+ spacing tokens. To use the same tokens for negative spacing, just append an < Code > N</ Code > { ' ' }
161+ (e.g. < Code > mediumN</ Code > ).
162+ </ Text >
163+
164+ < Flex flexWrap = "wrap" justifyContent = "space-around" >
165+ { BASE_KEYS . map ( ( key ) => (
166+ < Flex
167+ alignItems = "center"
168+ flexDirection = "column"
169+ key = { key }
170+ margin = "xSmall"
171+ paddingBottom = "small"
172+ >
173+ < Code > { key } </ Code >
174+ { /* Using the theme value directly keeps this demo accurate. */ }
175+ < BlueBox marginTop = "medium" style = { { width : spacing [ key ] , height : spacing [ key ] } } />
176+ </ Flex >
177+ ) ) }
100178 </ Flex >
101179 </ Panel >
102180 </ >
0 commit comments