1.0.0-b5 • Published 9 years ago
bocxs v1.0.0-b5
Bocxs
React component primitives built with cxs and inspired by Basscss and jsxstyle
npm i bocxs// Basic example
import React from 'react'
import { Box } from 'bocxs'
const App = () => (
<Box p2 mb2 white bgBlue>
<h1>Box with padding, margin bottom, white text, and blue background</h1>
</Box>
)// Primitives
import {
Base,
Box,
Block,
InlineBlock,
Inline,
Flex
} from 'bocxs'<Block>Display block div</Block><InlineBlock>Display inline block div</InlineBlock><Inline>Display inline div</Inline><Flex>Display flex div</Flex><Box>Generic Bocxs div</Box><Base is='button'>Base element</Base>Props
css- style object for cxs - will be converted into a unique className and inject styles into the head of the document
Booleans
m0-m4- margin from a scale from 0 to 4mt0-mt4- margin topmr0-mr4- margin rightmb0-mb4- margin bottomml0-ml4- margin leftmx0-mx4- margin left and rightmy0-my4- margin left and rightm-1-m-4- negative margin from a scale from 0 to 4mt-1-mt-4- negative margin topmr-1-mr-4- negative margin rightmb-1-mb-4- negative margin bottomml-1-ml-4- negative margin leftmx-1-mx-4- negative margin left and rightmy-1-my-4- negative margin left and rightp0-p4- padding from a scale from 0 to 4pt0-pt4- padding toppr0-pr4- padding rightpb0-pb4- padding bottompl0-pl4- padding leftpx0-px4- padding left and rightpy0-py4- padding left and right
Numbers
w- percentage width as a number from 0 - 1sw- percentage width as a number from 0 - 1 from the small breakpoint and upmw- percentage width as a number from 0 - 1 from the medium breakpoint and uplw- percentage width as a number from 0 - 1 from the large breakpoint and up
Strings
display- sets display
Colors
Includes all colors from open-color
whiteblackgray-gray0-gray9red-red0-red9pink-pink0-pink9grape-grape0-grape9violet-violet0-violet9indigo-indigo0-indigo9blue-blue0-blue9cyan-cyan0-cyan9teal-teal0-teal9green-green0-green9lime-lime0-lime9yellow-yellow0-yellow9orange-orange0-orange9
Borders
border- one oftrue,false, Number,'top','right','bottom', or'left'borderColor
Border Radii
rounded- one oftrue,false,'top','right','bottom', or'left'
Server Side Rendering
When rendering client-side, cxs will automatically insert a style tag into the head. For server-side rendering, get the CSS string from cxs after render.
const React = require('react')
const { renderToString } = require('react-dom/server')
const { cxs } = require('cxs')
const App = require('./App')
module.exports = (req, res) => {
const html = renderToString(React.createElement(App))
const css = cxs.css
return `<!DOCTYPE html>
<style>${css}</style>
${html}`
}Higher Order Component
Bocxs style props can be added to any component using the higher order component.
import React from 'react'
import { Link } from 'react-router'
import { withBocxs } from 'bocxs'
const CustomLink = (props) => (
<Link {...props} />
)
export default withBocxs(CustomLink)Related
MIT License