Usage | Normalize CSS | Variables | Parsers | Units | Polyfill | Media Query
import { create } from 'cometta';
const styles = create({
container: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '100vh',
width: '100vw',
},
});
sheet(...)
generate style and insert tag into the DOM, returning className
.
jss(...)
generate jss style returning object
.
css(...)
generate inline style returning string
.
document.body.innerHTML = `<main class="${sheet(styles.container)}"></main>`
<main className={sheet(styles.container)}></main>
<View style={jss(styles.container)}></View>
<main :class="sheet(styles.container)"></main>
import { normalize } from 'cometta';
normalize();
Used to create css-like variables.
import { create, variables } from 'cometta';
variables({
primary: '#9EA1D4'
});
const styles = create({
container: {
backgroundColor: 'var(primary)'
},
});
Used to create customized parsers.
import { create, parser } from 'cometta';
parser('bg', (value) => {
if (value) {
return { backgroundColor: value }
}
});
const styles = create({
container: {
bg: 'green'
},
});
Used to resolve a custom value unit.
import { create, unit } from 'cometta';
unit('gap', (value) => {
return value * 16;
});
const styles = create({
container: {
padding: '1gap'
},
});
Used to define some values when the environment is not standardized. Example for React Native:
import { create, jss, polyfill } from 'cometta';
import { Dimensions, View } from 'react-native';
polyfill({
fontSize: 16,
screenWidth: () => Dimensions.get('window').width,
screenHeight: () => Dimensions.get('window').height,
});
const styles = create({
container: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '100vh',
width: '100vw',
},
});
function App() {
return (
<View style={jss(styles.container)}>
{/* ... */}
</View>
);
}
Works on sheet()
with no configuration and on jss()
using polyfill.
import { create } from 'cometta';
const styles = create({
container: {
backgroundColor: 'red',
'@media (min-width: 769px)': {
backgroundColor: 'green',
}
},
});