@@ -12,6 +12,9 @@ import { cloneElement, forwardRef } from 'react';
1212 * @property {boolean } [props.isChild] - If `true`, applies child-specific styling for nested containers.
1313 * @property {boolean } [props.compact] - If `true`, the vertical padding is reduced for a more compact appearance.
1414 * @property {boolean } [props.standalone] - If `true`, the border radius is not adjusted automatically, based on neightboring containers.
15+ * @property {boolean } [props.centered] - If `true`, the content is centered vertically.
16+ * @property {boolean } [props.lessSpaceStart] - If `true`, space on the start (left) is reduced. Useful for symmetric components.
17+ * @property {boolean } [props.lessSpaceEnd] - If `true`, space on the end (right) is reduced. For example, use with text fields, or taller items.
1518 * @property {string|JSX.Element } [props.as] - The HTML element or React component to render as the container.
1619 *
1720 * @preserve
@@ -36,15 +39,15 @@ import { cloneElement, forwardRef } from 'react';
3639 * @preserve
3740 */
3841export const Container = forwardRef ( ( props , ref ) => {
39- const { className, children, as, hidden, accent, elevated, primary, isChild, compact, standalone, horizontal, ...rest } = props ;
42+ const { className, children, as, hidden, accent, elevated, primary, isChild, compact, standalone, horizontal, centered , lessSpaceStart , lessSpaceEnd , ...rest } = props ;
4043
4144 const ComponentToRender = as || 'div' ;
4245
4346 if ( hidden ) {
4447 return null ;
4548 }
4649
47- const containerClasses = cva ( [ ' es:inset-ring es:px-2.5 ' , className ] , {
50+ const containerClasses = cva ( [ 'es:inset-ring' , className ] , {
4851 variants : {
4952 elevated : {
5053 true : 'es:inset-shadow-sm es:shadow-sm es:shadow-black/5' ,
@@ -56,6 +59,17 @@ export const Container = forwardRef((props, ref) => {
5659 false : 'es:py-2 es:min-h-13' ,
5760 true : 'es:py-1 es:min-h-9' ,
5861 } ,
62+ centered : {
63+ true : 'es:flex es:items-center' ,
64+ } ,
65+ lessSpaceStart : {
66+ true : 'es:pl-2' ,
67+ false : 'es:pl-3' ,
68+ } ,
69+ lessSpaceEnd : {
70+ true : 'es:pr-2' ,
71+ false : 'es:pr-3' ,
72+ } ,
5973 } ,
6074 compoundVariants : [
6175 {
@@ -111,7 +125,7 @@ export const Container = forwardRef((props, ref) => {
111125 {
112126 accent : true ,
113127 elevated : false ,
114- class : 'es:bg-surface-50 es:inset-ring-surface-100 ' ,
128+ class : 'es:bg-surface-100/80 es:inset-ring-surface-200 es:text-accent-900 ' ,
115129 } ,
116130 {
117131 accent : false ,
@@ -132,14 +146,17 @@ export const Container = forwardRef((props, ref) => {
132146 compact : false ,
133147 standalone : false ,
134148 horizontal : false ,
149+ centered : false ,
150+ lessSpaceStart : false ,
151+ lessSpaceEnd : false ,
135152 } ,
136153 } ) ;
137154
138155 return (
139156 < ComponentToRender
140157 { ...rest }
141158 ref = { ref }
142- className = { containerClasses ( { accent, elevated, primary, isChild, compact, horizontal, standalone } ) }
159+ className = { containerClasses ( { accent, elevated, primary, isChild, compact, horizontal, standalone, centered , lessSpaceStart , lessSpaceEnd } ) }
143160 >
144161 { children }
145162 </ ComponentToRender >
@@ -151,6 +168,8 @@ Container.displayName = 'Container';
151168/**
152169 * @typedef {Object } ContainerGroupProps
153170 * @property {string } [className] - Classes to pass to the container group.
171+ * @property {string } [wrapClassName] - Classes to pass to the control wrapper - only if label is set.
172+ * @property {string|JSX.Element } [label] - Label to show above the container group.
154173 * @property {boolean } [hidden] - If `true`, the component is not rendered.
155174 * @property {boolean } [horizontal] - If `true`, the component uses a horizontal orientation.
156175 * @property {string|JSX.Element } [as] - The HTML element or React component to render as the container group.
@@ -178,7 +197,7 @@ Container.displayName = 'Container';
178197 * @preserve
179198 */
180199export const ContainerGroup = forwardRef ( ( props , ref ) => {
181- const { className, children, as, hidden, horizontal, ...rest } = props ;
200+ const { className, children, as, hidden, horizontal, label , wrapClassName , ...rest } = props ;
182201
183202 const ComponentToRender = as || 'div' ;
184203
@@ -188,7 +207,7 @@ export const ContainerGroup = forwardRef((props, ref) => {
188207
189208 const processedChildren = Array . isArray ( children )
190209 ? children . reduce ( ( acc , child , index ) => {
191- if ( child . type . displayName === 'Container' ) {
210+ if ( child ? .type ? .displayName === 'Container' ) {
192211 return [
193212 ...acc ,
194213 cloneElement ( child , {
@@ -202,7 +221,11 @@ export const ContainerGroup = forwardRef((props, ref) => {
202221 } , [ ] )
203222 : children ;
204223
205- return (
224+ if ( ! processedChildren || processedChildren ?. length < 1 ) {
225+ return null ;
226+ }
227+
228+ const inner = (
206229 < ComponentToRender
207230 { ...rest }
208231 ref = { ref }
@@ -211,6 +234,21 @@ export const ContainerGroup = forwardRef((props, ref) => {
211234 { processedChildren }
212235 </ ComponentToRender >
213236 ) ;
237+
238+ if ( ! label ) {
239+ return inner ;
240+ }
241+
242+ if ( Array . isArray ( inner ?. props ?. children ) && ! inner ?. props ?. children ?. filter ( Boolean ) ?. length ) {
243+ return null ;
244+ }
245+
246+ return (
247+ < div className = { wrapClassName } >
248+ < span className = 'es:ml-1 es:mb-1 es:inline-block es:text-12 es:font-variation-["wdth"_125,"wght"_400] es:text-surface-500' > { label } </ span >
249+ { inner }
250+ </ div >
251+ ) ;
214252} ) ;
215253
216254ContainerGroup . displayName = 'ContainerGroup' ;
0 commit comments