Ant Design Svelte

Space

Spaces, separators and compact groups: Space, SpaceCompact and SpaceAddon.

When to use

Space sets equal spacing between individual elements: buttons, tags or fields. SpaceCompact connects compatible controls with a common border without gaps. SpaceAddon adds a cell with a signature to such a compact group.

If you need to distribute free space and align immediate children without wrappers, use Flex.

Individual elements and intervals

In Svelte, pass individual elements through items: text, numbers, snippets, or objects with key and children. Stable key are needed so that the correct instances of interactive elements are preserved when rearranged.

Problem Setting Example
Explode individual elements items, size Spacing between elements
Place elements in a column orientation="vertical" Vertical spacing
Set up two axes Value pair size Interval size
Add separators separator Separators between elements
Save state when rearranging Objects with key Durable items keys

One children snippet is considered one item. Several buttons inside it do not become separate Space elements: there will be no gaps between them. Empty strings, null, undefined and boolean regular Space are skipped.

size is selected in the order local prop → ConfigProvider.space.size → small. small/medium/large and numeric gap in px are available; the pair specifies intervals along two axes. The generic componentSize does not define gap Space. orientation takes precedence over vertical, wrap allows horizontal group wrapping, align controls the alignment of wrappers.

Compact groups

SpaceCompact also receives independent items, but does not create additional DOM wrappers for them. Through context, controls learn their position, overall size, and adjacent boundaries. Field group connects Select, Input and Button.

Do not combine multiple controls into one snippet if they need to get their own edges. Nested Compacts inherit their position in the overall group. block stretches the group across its width; The transfer of the usual Space is not used here, since it would break the overall frame.

On a narrow screen, limit the width, allow the field to shrink via min-width:0, or change the composition. Vertical group is shown for Button. An arbitrary HTML container does not automatically receive the styling of a compatible control.

SpaceAddon is a native cell, not an input field. variant, status and disabled change its appearance; Disable the adjacent field itself separately.

Design and context

Space has root, item and separator slots available via classNames/styles as an object or function from props. styles contains CSS strings. ConfigProvider.space specifies the overall size and design; the passed nested record replaces the entire parent record. General settings show the priority of local values.

SpaceCompact and SpaceAddon do not have their own semantic classNames/styles; use class/style. The regular Space gap presets are based on the theme's general margins. bind:nativeElement returns the root div after the mount.

All three components have their own prefixCls. A non-empty value specifies the full prefix; empty string and undefined use ConfigProvider.prefixCls with the suffixes -space, -space-compact and -space-addon respectively. Compact's local prefix changes its container, and Addon and fields choose their own classes independently. Independent prefixes show two areas with the same local names: the Badge spacing and decoration remain isolated, the text in the fields is preserved.

theme.cssVar.prefix specifies the namespace of theme variables separate from CSS classes. The service variables of Addon variants and statuses follow the common provider prefix without dots, regardless of the local prefixCls. These internal variables are not public design tokens. Semantic callbacks of regular Space receive the original local props.prefixCls.

Wrappers and decorative separator do not replace the semantics of nested elements. For buttons, links, and fields, maintain accessible names and keyboard focus sequence.

Examples

Actions

Spacing between elements

Each items element gets its own wrapper and indentation. Snippets are used for Svelte components.

Preparation
Select components.
Check
Check status and availability.

Vertical spacing

orientation="vertical" arranges elements in a column. The width of root and item is set explicitly for cards to the full available width.

Interval size

Presets follow the theme. The number specifies px; a pair of values ​​sets the horizontal and vertical spacing separately.

Текст
Aa

Alignment of elements

start, center, end and baseline are visible on elements of different heights. stretch from the current React API is not supported in the installed package.

Line breaks

wrap transfers individual items. In this example, the horizontal gap is 8px, the vertical gap is 16px.

Описание
·
Доставка
·
Оплата

Separators between elements

separator can be a string or a snippet. Empty values ​​are ignored; There is no separator after the last element.

Address not collected yet

Compact field group

SpaceCompact connects the borders of Select, Input and Button. Each control is passed to a separate item; the action uses the current values.

Action not selected

Compact button group

The group shares a common size and connected boundaries. Each button saves its own action.

Overview

Vertical group of buttons

Vertical connection is for Button. orientation specifies the axis.

Weight
kg

Additional cell SpaceAddon

SpaceAddon creates a native compact group cell. The option is specified for both the cell and the field.

Подготовка
/
Проверка
/
Выпуск

Semantic slots

The classNames object and the styles function style root, item, and separator separately. These props are missing in Compact.

Name

Resistant keys items

Stable key preserve instances of components when rearranged. The field text remains the same after changing the order.

Первый
Второй
Первый
Второй
Первый
Второй

General settings Space

ConfigProvider.space: size and semantic defaults, local priority and theme aliases.

|
Count: 5
|
Метка
Weight
kg
Count: 3
Соседняя область
Weight
General: suite; Space: project-space; Compact: project-compact; Addon: suite-space-addon

The neighboring area uses the common prefix neighbor. Local Compact changes container; Addon and Input retain their own classes and styling.

Independent prefixes Space

Space, Compact and Addon choose their own classes. Two areas with the same local names save spacing, Badge, and field design.

https://

Actions and project address

Saved review example: vertical, separators, counter and address assembly via SpaceCompact.

API

Themes of the ant.design live page are mapped to the public API of the installed package. Full definitions of Props are in @woodger/antd.

Topics of official examples
ThemeExample or limitation
Basic UsageSeparate snippets in items.
Vertical SpaceCards in a column.
Space SizePresets and a couple of numbers.
AlignAvailable types of alignment; stretch is marked as space.
WrapSeparate spacing between lines.
separatorString or Divider snippet.
Compact Mode for form componentSelect, Input and Button.
Button Compact ModeSize and actions of buttons.
Vertical Compact ModeButtons in a column.
Custom semantic dom stylingClass object and style function.
CSS prefixSeparate prefixes Space, Compact and Addon in independent areas.
Basic parameters Space
PropertyDescriptionTypeDefault
prefixClsFull local CSS prefix. The empty string and undefined inherit the common provider prefix.stringConfigProvider.prefixCls + "-space"
itemsIndividual elements: scalars, snippets or key/children objects. If present, takes precedence over children.readonly (SpaceContent | SpaceItem)[]—
childrenOne common item. Multiple elements within a snippet are not automatically split.Snippet—
orientationSets horizontal or vertical position.horizontal | verticalhorizontal
verticalShort recording of vertical orientation.booleanfalse
sizesmall/medium/large, px number or gap pair. Local size takes precedence; componentSize is not involved.SpaceSize | [SpaceSize, SpaceSize]ConfigProvider.space.size / small
alignAlignment items; stretch of the current React API is missing.start | end | center | baselinecenter horizontal
wrapTransfer of individual items in a horizontal position.booleanfalse
separatorSeparator between non-empty items.SpaceContent—
classNamesThe root, item and separator classes.SpaceSlots | function—
stylesCSS lines for slots; the function receives info.props.SpaceSlots | function—
nativeElementbind:nativeElement; root is missing if the items array is empty.HTMLDivElement—

ConfigProvider.space

PropertyDescriptionTypeDefault
sizeTotal interval if there is no local size.SpaceSize | readonly [SpaceSize, SpaceSize]small
classThe general root class to which the local class is appended.string—
styleRoot CSS after context styles.root and before local styles.root/style.string—
classNamesAn object or function with classes root/item/separator.SpaceSemantic—
stylesObject or function with CSS root/item/separator. The nested space record is replaced entirely.SpaceSemantic—

SpaceCompact

items and children accept the same content format. size — small/medium/large, by default inherits the provider size. orientation/vertical set the axis, block stretches root to the full width. class, rootClassName, style and bind:nativeElement refer to the container.

prefixCls specifies the full container prefix. Without a non-empty value, ConfigProvider.prefixCls + "-space-compact" is used. Child controls choose their prefixes regardless of the local Compact.

SpaceAddon

children - content snippet. variant: outlined, filled, borderless or underlined, default is outlined. status: error/warning, disabled: boolean; class/style and bind:nativeElement refer to the cell. These parameters formalize the addon, the state of the field is transferred to the field itself separately.

prefixCls specifies the full prefix of the cell; empty string and undefined use ConfigProvider.prefixCls + "-space-addon". Local SpaceCompact.prefixCls does not change this choice.

Semantic DOM

Space creates a root div, a wrapper div item for each non-empty value, and a span separator between them. classNames/styles accept an object or function. Empty strings, null, undefined and boolean for Space are ignored; A stable key is needed to rearrange dynamic items.

SpaceCompact creates a root div and passes the context to individual items without additional DOM wrappers. Therefore, controls should be independent items, and not several neighbors within one snippet. Nested Compacts inherit their position in the overall group.

SpaceAddon creates a div with the contents of the cell. This is not an input field: disabled specifies the cell's appearance; the field is disabled separately. ConfigProvider.space sets the defaults of regular Space; Compact/Addon does not have semantic props.

Semantic callbacks Space get the original local props.prefixCls. Class prefix and theme.cssVar.prefix are independent; Addon service variables follow the common provider prefix without dots.

Registration tokens

Space, SpaceCompact and Addon do not have their own component tokens. Spacing sizes small/medium/large use common paddingXS/padding/paddingLG; theme.components.Space can refine these aliases. Typography and direction are inherited from the provider. The Compact size refers to the controls, and the Space size refers to the distance between them.

Common tokens of the current topic
TokenCurrent value
padding16
paddingLG24
paddingXS8

FAQ

Which size has priority?

Space's local size overlaps ConfigProvider.space.size; without them, small is used. ComponentSize specifies the size of the controls, not the gap Space.

Why did the elements inside children stick together?

One children snippet is considered one item. Pass individual snippets to items.

When to choose Flex?

When you need to manage immediate children without wrappers and distribute free space.

Why does Compact not transfer fields?

This is a connected group without a gap. For a narrow screen, adjust the dimensions or change the composition.

Is it possible to connect any components?

The control must support the Compact context. The examples tested Select, Input, Button and SpaceAddon; a regular container itself does not receive a common frame.