Package Exports
- react-native-style-tachyons
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-style-tachyons) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React Native Style Tachyons
React Native Style Tachyons brings atomic styling to react-native. It is inspired by Tachyons and uses it's scales and naming convention. More about the advantages of this approach.
Let's see how tachyons compares to traditional styling:
1. Traditional react-native style:
import {StyleSheet} from "react-native";
const s = StyleSheet.create({
view: {
borderWidth: 1,
justifyContent: "flex-start",
padding: MAGIC_PIXEL_VALUE
},
text: {
color: "white",
textAlign: "center"
}
})
<View style={[s.view]}
<Text style={[s.text]}>Something</Text>
</View>2. Improved with react-native-style-tachyons:
import {styles as s} from "react-native-style-tachyons";
<View style={[s.ba, s.jcfs, s.pa2]}> /* 'ba' means border-all */
<Text style={[s.white, s.tc]}>
Something
</Text>
</View>3. or even simpler:
<View cls="ba jcfs pa2"> /* string is checked for validity */
<Text cls="white tc">
Something
</Text>
</View>Of course you can use your old styles along tachyon's classes.
Advantages
Less code
No need to maintain a separate stylesheet
No need to find a proper name for every component you want to style
Looking at a component tells you exactly how it looks, it's all in one place.
Tachyons dimensions and typography build on a proven scale, which is relative to REM, the root font-size. Instead of specifying a pixel-padding, you specify a step at the scale.
pa2gets youpaddingof0.5rem. This way your spaces are always relative to your font-size, which is a great advantage when building a responsive app.
Usage
react-native-style-tachyons needs to know your rem upon start.
In the entry point of your app include:
import NativeTachyons from 'react-native-style-tachyons'; import { StyleSheet } from 'react-native'; NativeTachyons.build({ /* REM parameter it optional, default is 16 */ rem: width > 340 ? 18 : 16 }, StyleSheet); /* the need to pass "StyleSheet" from react-native will be removed */
To use the styles
import { styles as s } from "react-native-style-tachyons";
To support javascript property syntax, all style names with hyphens have an equivalent with an underscore, e.g.
s.bg_blackinstead ofs["bg-black"].To use the
cls=''wrappingimport NativeTachyons from "react-native-style-tachyons"; NativeTachyons.wrap( class MyComponent extends React.Component { ... })
Reference / Supported Properties
Colors
Specify a color palette in the options and Tachyons will generate styles for you, complete with a light and a dark version:
NativeTachyons.build({
colors: {
palette: {
green: "#00FF00",
red: "#FF0000"
},
lighten: 0.2 /* default: 0.2 */
darken: 0.2 /* default: 0.2 */
}
}, StyleSheet);bg-green green background
bg-light-green lighter green background
bg-dark-green darker green background
b--green green border // Note: double hyphens signify a class that needs another class
b--light-green light-green border // to work, in this case one of the border-settings
b--dark-green dark-green border
green green text
light-green light-green text
dark-green dark-green textFlexBox
absolute position: "absolute" /* position: "relative" is default */
flx-i flex: 1
flx-row flexDirection: "row" /* flexDirection: "column" is default */
flx-row-reverse flexDirection: "row-reverse"
flx-col-reverse flexDirection: "column-reverse"
flx-wrap flexWrap: "wrap" /* flexWrap: "nowrap" is default */
aifs alignItems: "flex-start" /* alignItems: "stretch" is default */
aic alignItems: "center"
aife alignItems: "flex-end"
jcc justifyContent: "center" /* justifyContent: "flex-start" is default */
jcfe justifyContent: "flex-end"
jcsb justifyContent: "space-between"
jcsa justifyContent: "space-around"
asfs alignSelf: "flex-start"
asfe alignSelf: "flex-end"
asc alignSelf: "center"
ass alignSelf: "stretch"Margins & Paddings (Scale)
ma0 ... ma7 margin: 0|0.25|0.5|1|2|4|8|16rem
ml|mr|mb|mt [0-7] marginLeft, marginRight, marginBottom, marginTop
mh [0-7] marginHorizontal
mv [0-7] marginVertical
Same with p for paddingHeights & Widths
h1 ... h5 height: 1|2|4|8|16rem
w1 ... w5 width: 1|2|4|8|16rem
absolute-fill position: absolute, top/left/right/bottom: 0Borders
ba borderWidth: 1
bl|br|bt|bb borderLeftWidth: 1 | borderRightWidth: 1...
br0 ... br4 borderRadius: 0|0.125|0.25|0.5|1rem
br--bottom bottom radius only
br--top top radius only
br--right right radius only
br--left left radius onlyText & Fonts (Scale)
f1 ... f6 fontSize: 3|2.25|1.5|1.25|1|0.875rem
f-headline fontSize: 6rem
f-subheadline fontSize: 5rem
normal fontWeight: normal
b fontWeight: bold
fw1 ... fw900 fontWeight: 100 ... fontWeight: 900
i fontStyle: italic
tl|tc|tr|tj textAlign: left|right|center|justifyImages
rm-contain resizeMode: "contain"
rm-cover resizeMode: "cover"
rm-stretch resizeMode: "stretch"Opacity
o-10|20|...|100 opacity: 0.1|0.2|...|1
o-05 opacity: 0.05
o-025 opacity: 0.025Changes
v2.0.0- renamed
absolute--filltoabsolute-filland explained the double hypens in the Readme. - removed
relative,flx-col,flx-nowrap,aisandjcfs` as those are default-values, and there's no inheritance in RN. - added
flx-row-reverseandflx-col-reverse v1.7.8moved package to tachyons-css and updated documentationv1.7.7updated documentationv1.7.6updated documentationremoved “relative” as it’s a default
v1.7.5added notice to readmev1.7.4bump because of npm-quirksv1.7.3renamed package to react-native-style-tachyonsv1.7.2updated readme & dependenciesv1.7.1updated readmev1.7all styles with hypened in their names now have version with underscoresv1.6.11updated dependenciesv1.6.10addedbr--leftandbr--rightv1.6.9usefilesdirective to ignore more filesv1.6.8added.babelrcto.npmignorev1.6.7bugfixv1.6.6bugfixv1.6.5yet another small improvementv1.6.4yet another bugfixv1.6.3bugfixv1.6.2translation performance improved by a factor of 2v1.6.1removedh-100andw-100. I consider this a bugfix under semver, since usingDimensionsis buggy on Android #3219. You can get the same behaviour withflx-iandabsolute--fill.v1.6.0addedabsolute--fillfor easy full-screen viewsv1.5.0addedh-100andw-100for 100% height/width of window, needsDimensionsto be passed intoNativeTachyons.build()v1.4.0support opacitiesv1.3.0set react-native peer-dependency to 0.xv1.2.0support border-radii propertiesv1.1.1added more tests and a bugfix when merging existing stylesv1.1.0added more properties and referencesv1.0.1fixed badgev1.0.0first version