Code Monkey home page Code Monkey logo

veel's Introduction

logo

veel NPM version Js Standard Style

📦 Base React styling components using Fela with a design system

  • Low-Level - Exposes only a few components which can be used as a base layer to build your UI components upon
  • Consistency - Uses styled-system which encourages consistency of spacing, typography and color
  • Universal - By using fela it's really easy to prerender your styles on the server or anywhere
npm install veel
const Badge = (props) => (
  <Box
    m={2}
    fontSize={2}
    bg='tomato'
    css={{ textDecoration: 'underline' }}
    {...props}
  />
)

Contents

Example

The following renders a responsive row with two equally divided divs collapsing on mobile.

Example

const CenteredBox = props => (
  <Box
    p={2}
    w={[1, 0.5]}
    css={{ height: '50%' }}
    {...props}
  />
)

const App = () => (
  <Flex
    wrap
    align='center'
    css={{ height: '100vh' }}
  >
    <CenteredBox bg='lightblue'>1</CenteredBox>
    <CenteredBox color='white' bg='blue'>2</CenteredBox>
  </Flex>
)

Usage

  1. Create a fela renderer.
import { createRenderer } from 'veel'
const renderer = createRenderer()
  1. Wrap your application in a StyleProvider so that each veel component has access to the renderer and the optional theme.
import { StyleProvider, Box } from 'veel'

class App extends React.Component {
  render() {
    return (
      <StyleProvider={renderer}>
        <Box is='h1' fontSize={2}>Application</Box>
      </StyleProvider>
    )
  }
}
  1. Now you need some way of injecting the generated css into the html. There are many ways to do it, each with their positive and negative aspects.

Injecting the css dynamically

require('inject-css')(renderer.renderToString())

Render to a sheet list (Next.js example)

This makes the most sense when you create the document skeleton with JSX.

import Document, { Head } from 'next/document'

class CustomDocument extends Document {
  static getInitialProps ({ renderPage }) {
    const page = renderPage()
    const sheets = renderer.renderToSheetList()
    renderer.clear()
    return { ...page, sheets }
  }

  render () {
    const sheets = this.props.sheets
    return (
      <Head>
        {sheets.map(({ type, media, css }) => (
          <style data-fela-type={type} media={media}>{css}</style>
        ))}
      </Head>

      ...
    )
  }
}
  1. You're done!

Components

Box

<Box w={1}>Hello Veel!</Box>

The core layout component. Take a look at styled-system for documentation on <Box /> props.

Box.is

By default a <Box /> component will render out to a div. You can change the tag by providing an is property.

Flex

<Flex wrap center />

View the example on how to use it.

Flex.center

Sets both alignItems and justifyContent to center.

Flex.wrap

Sets flexWrap to wrap.

Flex.column

Sets flexDirection to column.

Flex.justify

CSS justifyContent property.

Flex.align

CSS alignItem property.

Flex.order

CSS order property.

Plugins

By using fela you have a wide variety of plugins available. Check out the plugin list

Recommend plugins

<Box css={{
  animationName: {
  '0%': { color: 'red ' },
  '100%': { color: 'blue' }
  },
}} />

// -> { animationName: 'k1' }

Author

veel © Fabian Eichenberger, Released under the MIT License.
Authored and maintained by Fabian Eichenberger with help from contributors (list).

GitHub @queckezz · Twitter @queckezz

veel's People

Contributors

queckezz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

veel's Issues

allow functions as attributes

this allows for

const Image = (props) => ({ backgroundColor: props.bg })

<Image bg={(props) => props.theme.colors.gray[1] }  />

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.