Space

Even though we have Divider, but sometimes we need more than one Divider to split the elements apart, so we stack each elements upon Divider, but doing so not only makes our code ugly but also makes it difficult to maintain. Space is this kind of component provides us both productivity and elegance.

Basic usage

The basic use case is using this component to provide unified space between each components

Using Space to provide space

Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4

Vertical layout

Using direction attribute to control the layout, we use flex-direction to implement this.

We also provide vertical layout.

Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4

Control the size of the space

Control the space size via size API.

You can set the size with built-in sizes small, default, large, these size coresponds to 8px, 12px, 16px. The default size is small, A.K.A. 8px

You can also using customized size to override it. Refer to the next part.

Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4

Customized Size

Sometimes built-in sizes could not meet the business needs, we can use custom size (number type) to control the space between items.

Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4

TIP

Do not use ElSpace with components that depend on ancestor width (height), e.g. ElSlider, in this case when you drag the trigger button the bar will grow which causes misplacement between cursor and trigger button.

Auto wrapping

When in horizontal mode, using wrap (bool type) to control auto wrapping behavior.

Using wrap to control line wrap

Spacer

Sometimes we want something more than blank space, so we have (spacer) to help us.

Literal type spacer

|

Spacer can also be VNode

Alignment

Setting this attribute can adjust the alignment of child nodes, the desirable value can be found at align-items.

Using alignment

string
header
body
string
header
body
string
header
body

Fill the container

Through the fill (Boolean type) parameter, you can control whether the child node automatically fills the container.

In the following example, when set to fill, the width of the child node will automatically adapt to the width of the container.

Use fill to automatically fill the container with child nodes

fill:
Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4

You can also use the fillRatio parameter to customize the filling ratio. The default value is 100, which represents filling based on the width of the parent container at 100%.

It should be noted that the expression of horizontal layout and vertical layout is slightly different, the specific effect can be viewed in the following example.

Use fillRatio to customize the fill ratio

direction:
fillRatio:
Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4
Card name
List item 1
List item 2
List item 3
List item 4

API

Attributes

NameDescriptionTypeDefault
alignmentControls the alignment of itemsenum align-itemscenter
classclassNamestring / object / array
directionPlacement directionenumhorizontal
prefixClsPrefix for space-itemsstring
styleExtra style rulesstring / object
spacerSpacerstring / number / VNode
sizeSpacing sizeenum / number / arraysmall
wrapAuto wrappingbooleanfalse
fillWhether to fill the containerbooleanfalse
fill-ratioRatio of fillnumber100

Slots

namedescription
defaultItems to be spaced

Source

ComponentStyleDocs

Contributors