@@ -8,14 +8,14 @@ import { size } from './utils/size'
88const Position = type ( `'start' | 'end' | 'center'` )
99export const FlexboxType = type ( {
1010 direction : `'row' | 'column'` ,
11- justify : Position ,
12- align : Position ,
13- gap : `string | number` ,
11+ justify : Position . optional ( ) ,
12+ align : Position . optional ( ) ,
13+ gap : type ( `string | number` ) . optional ( ) ,
1414 wrap : `'nowrap' | 'wrap' | 'wrap-reverse'` ,
1515 grow : `number` ,
1616 shrink : `number` ,
17- basis : `string | number` ,
18- } ) . partial ( ) . and ( BlockType )
17+ basis : type ( `string | number` ) . optional ( ) ,
18+ } ) . and ( BlockType )
1919
2020export default defineComponent < 'flexbox' , typeof FlexboxType . infer , { direction : Ref < 'row' | 'column' > } > ( ( attrs , context ) => {
2121 const extend = block ( attrs , context )
@@ -25,6 +25,12 @@ export default defineComponent<'flexbox', typeof FlexboxType.infer, { direction:
2525 return {
2626 name : 'flexbox' ,
2727 attrs : FlexboxType ,
28+ defaults : {
29+ direction : 'row' ,
30+ wrap : 'nowrap' ,
31+ grow : 1 ,
32+ shrink : 0 ,
33+ } ,
2834 setup : ( children ) => {
2935 const element = extend . setup ! ( children ) as HTMLDivElement
3036
@@ -34,15 +40,15 @@ export default defineComponent<'flexbox', typeof FlexboxType.infer, { direction:
3440 element . style . width = '100%'
3541 if ( selfDirection === 'column' )
3642 element . style . height = '100%'
37- element . style . flexDirection = toValue ( attrs . direction ?? 'row' ) as string
38- direction . value = toValue ( attrs . direction ?? 'row' ) as string
39- element . style . justifyContent = toValue ( attrs . justify ?? 'auto' ) as string
40- element . style . alignItems = toValue ( attrs . align ?? 'auto' ) as string
41- element . style . gap = size ( toValue ( attrs . gap ?? 'auto' ) as string )
42- element . style . flexWrap = toValue ( attrs . wrap ?? 'nowrap' ) as string
43+ element . style . flexDirection = toValue ( attrs . direction )
44+ direction . value = toValue ( attrs . direction )
45+ element . style . justifyContent = toValue ( attrs . justify ?? 'auto' ) !
46+ element . style . alignItems = toValue ( attrs . align ?? 'auto' ) !
47+ element . style . gap = size ( toValue ( attrs . gap ) ?? 'auto' )
48+ element . style . flexWrap = toValue ( attrs . wrap )
4349 element . style . flexGrow = ( toValue ( attrs . grow ) ?? 1 ) . toString ( )
4450 element . style . flexShrink = ( toValue ( attrs . shrink ) ?? 0 ) . toString ( )
45- element . style . flexBasis = size ( toValue ( attrs . basis ?? 'auto' ) as string )
51+ element . style . flexBasis = size ( toValue ( attrs . basis ) ?? 'auto' )
4652 return element
4753 } ,
4854 provides : {
0 commit comments