Spacing
Consistent spacing creates visual rhythm and improves readability in Teardrop Design System.
Spacing System
Teardrop uses an 8px base unit spacing scale. All spacing values are multiples of 8px, ensuring consistency and alignment.
Spacing Scale
| Token | Value | Pixels | Usage |
|---|---|---|---|
spacing.xsmall | 0.5 | 4px | Tight spacing, icons |
spacing.small | 1 | 8px | Compact spacing |
spacing.medium | 2 | 16px | Default spacing |
spacing.large | 3 | 24px | Comfortable spacing |
spacing.xlarge | 4 | 32px | Generous spacing |
spacing.xxlarge | 6 | 48px | Section spacing |
spacing.xxxlarge | 8 | 64px | Large section spacing (Studios) |
Using Spacing
In Components
import { Box, Stack, Inline } from '@hardwater/teardrop';
// Padding
<Box padding="medium">Content</Box>
<Box paddingX="large" paddingY="small">Content</Box>
// Gap in Stack
<Stack gap="medium">
<div>Item 1</div>
<div>Item 2</div>
</Stack>
// Gap in Inline
<Inline gap="small">
<Button>Action 1</Button>
<Button>Action 2</Button>
</Inline>
In CSS
.card {
padding: var(--teardrop-spacing-medium);
margin-bottom: var(--teardrop-spacing-large);
}
.flex-container {
gap: var(--teardrop-spacing-small);
}
With Tokens
import { tokens } from '@hardwater/teardrop';
const style = {
padding: tokens.spacing.medium,
marginTop: tokens.spacing.large,
gap: tokens.spacing.small,
};
Spacing Patterns
Component Padding
Use consistent padding for similar components:
// Cards
<Box padding="medium">Card content</Box>
// Buttons
<Button paddingX="medium" paddingY="small">Click me</Button>
// Inputs
<Input paddingX="small" paddingY="small" />
Layout Spacing
Use spacing to create visual hierarchy:
<Stack gap="large">
<Section>
<Heading>Section 1</Heading>
<Content />
</Section>
<Section>
<Heading>Section 2</Heading>
<Content />
</Section>
</Stack>
Inline Spacing
Space related elements closely, unrelated elements further:
// Related elements - small gap
<Inline gap="small">
<Icon />
<Text>Label</Text>
</Inline>
// Unrelated elements - medium gap
<Inline gap="medium">
<Button>Save</Button>
<Button>Cancel</Button>
</Inline>
Spacing Guidelines
Padding vs Margin
- Padding - Space inside a component (between border and content)
- Margin - Space outside a component (between components)
// Padding - internal spacing
<Box padding="medium">Content</Box>
// Margin - external spacing
<Box marginBottom="large">Content</Box>
Consistent Spacing
Use the same spacing value for similar relationships:
// All form fields have the same spacing
<Stack gap="medium">
<Input label="Email" />
<Input label="Password" />
<Input label="Confirm" />
</Stack>
Visual Rhythm
Create visual rhythm with consistent spacing:
// Consistent spacing creates rhythm
<Stack gap="large">
<Card />
<Card />
<Card />
</Stack>
Responsive Spacing
Adjust spacing for different screen sizes:
<Box
padding={{ mobile: 'small', desktop: 'medium' }}
gap={{ mobile: 'small', desktop: 'large' }}
>
Content
</Box>
Best Practices
- Use the scale - Always use predefined spacing tokens
- Be consistent - Use the same spacing for similar relationships
- Create rhythm - Use consistent spacing to create visual rhythm
- Consider context - Adjust spacing based on content density
- Test on mobile - Ensure spacing works on small screens
Spacing Tokens
Access spacing through the token system:
import { tokens } from '@hardwater/teardrop';
tokens.spacing.xsmall // 4px
tokens.spacing.small // 8px
tokens.spacing.medium // 16px
tokens.spacing.large // 24px
tokens.spacing.xlarge // 32px
tokens.spacing.xxlarge // 48px