$ cnpm install styled-rhythm
Box and Line components for maintaining vertical rhythm with ease!
react
>= 16.0.0prop-types
>= 15.6.0styled-components
>= 2.2.0The entire package is just two components. You must provide them with a theme with these two fields:
baseFont: number
- your base font sizebaseLineScale: number
- your line height relative to the baseFont
To provide the theme, do one of the following:
theme
prop directlystyled-components
' ThemeProvider
import { Box } from 'styled-rhythm';
import { ThemeProvider } from 'styled-components';
const theme = {
baseFont: 16,
baseLineScale: 1.5,
};
// Prop:
const BoxProp = () => (
<Box
as="button"
theme={theme}
height={2.5}
marginTop={0}
marginBottom={1}
/>
);
// Theme provider:
const BoxProvider = () => (
<ThemeProvider theme={theme}>
<Box
as="button"
height={2.5}
marginTop={0}
marginBottom={1}
/>
</ThemeProvider>
);
Used for box elements such as div
, button
.
as: React.ComponentType<*> | string
- the component to render (default div
)height: number
- element height relative to the base line heightmarginTop: number
- top margin relative to the base line heightmarginBottom: number
- bottom margin relative to the base line heightimport { Box } from 'styled-rhythm';
const Button = props => (
<Box
as="button"
height={2.5}
marginTop={0}
marginBottom={1}
{...props}
/>
);
Used for text elements such as span
, a
.
as: React.ComponentType<*> | string
- the component to render (default span
)fontSize: number
- font size relative to the base font sizemarginTop: number
- top margin relative to the base line heightmarginBottom: number
- bottom margin relative to the base line heightborder?: number
- any extra borders the component will have in pixelsimport { Line } from 'styled-rhythm';
const Link = props => (
<Line
as="a"
fontSize={1.2}
marginTop={0.5}
marginBottom={0.5}
{...props}
/>
);
MIT
Copyright 2014 - 2017 © taobao.org |