Atomic, functional and modular styling for React Native. Inspired by Basscss and Tachyons.
Usage
npm i Draper -S
Build draper styles in a styles.js
module:
;;
Then to use them:
; <View style= sbgWhite sp2 smt2 srounded > ... </View>
Customizing
The base config contains defaults for rem
, borderWidth
, typeScale
, (whitespace)scale
, lineHeightScale
and clrs
. You can modify these by passing in options
to the build function. For example:
; clrs: mauve: '#E0B0FF' scale: 1 2 3 4 typeScale: f2: 15 f3: 125 ;
Extending
;; ... ...StyleSheet;
Modules
Absolute
Absolute positioning and zIndex
utilities. It also aliases StyleSheet.absoluteFill
.
Border
Border radius and sizing utilities. Border radius scale: 1rem, 2rem, 3rem, 4rem, 8rem, 16rem
. Border sizing supports three options:
0
StyleSheet.hairlineWidth
config.borderWidth
Colors
Text, border and background colour utilities. The colour values used in this module are from mrmrs/colors. For example:
black: color: '#515163' bgBlack: backgroundColor: '#515163' borderBlack: borderColor: '#515163'
Dimensions
Width and height utilities using this scale: 1rem, 2rem, 3rem, 4rem, 8rem, 16rem
.
Flexbox
These entire flexbox module as utilities.
Typography
Font style, weight and size utilities. Font weight: normal, bold, 100 - 900
. Font sizes are generated using a type scale.
const typeScale = f1: 2 // * rem f2: 15 // * rem f3: 125 // * rem f4: 1 // * rem f5: 0875 // * rem f6: 075 // * rem;
In React Native lineHeight
is not a multiplier. This makes it hard to create line height utilities. Instead you can create text components which have all the fontSize
and lineHeight
stylings. See text.js for an example.
Whitespace
Margin and padding utilities.
Padding
base: p
modifiers: h, v, t, r, b, l
scale: 0, 1, 2, 3, 4, 5, 6
Margin
base: m
modifiers: h, v, t, r, b, l
scale: 0, 1, 2, 3, 4, 5, 6
Example:
mb1 = marginBottom: 0.5 * rem
ph1 = paddingHorizontal: 4 * rem
Example
To run the example:
npm install
npm run dev:ios
for iOS andnpm run dev:android
for Android.