Styling
Components use CSS styles + flexbox layout.
Layout Styles
| property | type | supported? |
|---|---|---|
shadowColor | Color | β |
shadowOffset | { width: number, height: number } | β |
shadowOpacity | number | β |
shadowSpread | number | β |
shadowRadius | number | β |
width | number | percentage | β |
height | number | percentage | β |
top | number | percentage | β |
left | number | percentage | β |
right | number | percentage | β |
bottom | number | percentage | β |
minWidth | number | percentage | β |
maxWidth | number | percentage | β |
minHeight | number | percentage | β |
maxHeight | number | percentage | β |
margin | number | percentage | β |
marginVertical | number | percentage | β |
marginHorizontal | number | percentage | β |
marginTop | number | percentage | β |
marginBottom | number | percentage | β |
marginLeft | number | percentage | β |
marginRight | number | percentage | β |
padding | number | percentage | β |
paddingVertical | number | percentage | β |
paddingHorizontal | number | percentage | β |
paddingTop | number | percentage | β |
paddingBottom | number | percentage | β |
paddingLeft | number | percentage | β |
paddingRight | number | percentage | β |
position | absolute | relative | β |
flexDirection | row | row-reverse | column | column-reverse | β |
flexWrap | wrap | nowrap | β |
justifyContent | flex-start | flex-end | center | space-between | space-around | β |
alignItems | flex-start | flex-end | center | stretch | β |
alignSelf | auto | flex-start | flex-end | center | stretch | β |
overflow | visible | hidden | scroll | β |
flex | number | β |
flexGrow | number | β |
flexShrink | number | β |
flexBasis | number | percentage | β |
aspectRatio | number | β |
zIndex | number | β |
backfaceVisibility | visible | hidden | βοΈ |
backgroundImage | string | {uri: string} | β |
backgroundColor | Color | β |
borderColor | Color | β |
borderTopColor | Color | β |
borderRightColor | Color | β |
borderBottomColor | Color | β |
borderLeftColor | Color | β |
borderRadius | number | percentage | β |
borderTopLeftRadius | number | percentage | β |
borderTopRightRadius | number | percentage | β |
borderBottomLeftRadius | number | percentage | β |
borderBottomRightRadius | number | percentage | β |
borderStyle | solid | dotted | dashed | β |
borderWidth | number | percentage | β |
borderTopWidth | number | percentage | β |
borderRightWidth | number | percentage | β |
borderBottomWidth | number | percentage | β |
borderLeftWidth | number | percentage | β |
opacity | number | β |
Type Styles
| property | type | supported? |
|---|---|---|
Color | Color | β |
fontFamily | string | β |
fontSize | number | β |
fontStyle | normal | italic | solid | β |
fontWeight | 'normal' | 'bold' | '100' | '200' | ... | '900' | β |
textDecorationLine | none | underline | line-through | β |
textShadowOffset | { width: number, height: number } | β |
textShadowRadius | number | β |
textShadowColor | Color | β |
letterSpacing | number | percentage | β |
lineHeight | auto | number | percentage | β |
textAlign | auto | left | right | center | justify | β |
writingDirection | auto | ltr | rtl | βοΈ |
opacity | number | β |
percentage | points | percentages | β |
Styles can be passed to components as plain objects.
import { View, StyleSheet } from 'react-figma';
// inline props
<View
style={{
backgroundColor: 'hotPink',
width: 300,
}}
/>
// plain JS object
const style = {
backgroundColor: 'hotPink',
width: 300,
}
<View style={style} />
// StyleSheet
const styles = StyleSheet.create({
foo: {
backgroundColor: 'hotPink',
width: 300,
}
})
<View style={styles.foo} />
<View style={[styles.foo, styles.bar]} />
You can use variables in your styles just like a standard React application:
const colors = {
Haus: '#F3F4F4',
Night: '#333',
Sur: '#96DBE4',
Peach: '#EFADA0',
Pear: '#93DAAB',
};
<View>
{Object.keys(colors).map(name => (
<View
key={name}
style={{
flex: 1,
backgroundColor: colors[name],
}}
/>
))}
</View>;
Inheritance
It's possible to enable a CSS-like inheritance.
Available under the flag process.env.REACT_FIGMA_STYLE_INHERITANCE_ENABLED.
An example:
<View style={{ fontSize: 50, fontWeight: 'bold', fontFamily: 'Roboto' }}>
<View style={{ fontSize: 48 }}>
<View style={{ width: 200, height: 100, backgroundColor: '#dd55aa' }} />
<Text style={{ color: '#ffffff' }}>text</Text>
</View>
</View>
The text got a combined style:
({fontWeight: 'bold', fontFamily: 'Roboto', fontSize: 48, color: '#ffffff' })
Inherited styles props:
- color
- fontFamily
- fontSize
- fontStyle
- fontVariant
- fontWeight
- textAlign
- lineHeight
- letterSpacing
Supported components:
- Frame (and View)
- Page
- Text (as a recipient)
Warning! Inheritance is not compatible with React Native.
Web defaults
Available under the flag process.env.REACT_FIGMA_WEB_DEFAULTS_ENABLED.
On the Web defaults mode, react-figma will try to simulate Web default behavior:
- A text with display: block should get full width (
width: 100%) - A container with display: flex should get
flexDirection: row alignItems: stretchfor containers by default