Giter Site home page Giter Site logo

metabolize / react-flexbox-svg Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 2.07 MB

Flexbox for SVG in React, using css-layout

Home Page: https://react-flexbox-svg.netlify.app/

License: ISC License

JavaScript 100.00%
svg react flexbox layout react-component

react-flexbox-svg's Introduction

react-flexbox-svg

version license build code style

Flexbox for SVG in React, using css-layout.

css-layout is Facebook's JavaScript reimplementation of CSS which is now part of Yoga.

Based on react-flexbox-svg by David Manning.

Features

  • Define item layout statically or compute it from props.
  • Render layout rectangles for debugging (visible or not).
  • Pass layout into child props if needed.
  • No magic.
  • ES7 decorator ready.

Usage

import React from 'react'
import { FlexContext, FlexContainer } from 'react-flexbox-svg'

class StackedItemCollection extends React.Component {
  render() {
    return (
      <svg width="800" height="600">
        <FlexContext>
          <FlexContainer style={{ flexDirection: 'column' }}>
            <Item key="1" />
            <Item key="2" />
            <Item key="3" />
          </FlexContainer>
        </FlexContext>
      </svg>
    )
  }
}
class Item extends React.Component {
  render() {
    const { height } = Item.layout

    return <rect height={height} width="100%" stroke="black" strokeWidth="3" />
  }
}
Item.layout = { margin: 25, height: 50 }

export default layoutable(props => Item.layout)(Item)

As a functional component:

const Item = layoutable(props => ({ margin: 10, height: 50 }))(() => (
  <rect height="50" width="100%" stroke="black" strokeWidth="3" />
))

Using ES7 decorators:

@layoutable(props => Item.layout)
class Item extends React.Component {
  render() {
    const { height } = Item.layout

    return <rect height={height} width="100%" stroke="black" strokeWidth="3" />
  }
}
Item.layout = { margin: 10, height: 100 }

In the examples folder is a more interesting example featuring a dynamic collection.

Installation

npm install --save babel-runtime react-flexbox-svg

Contribute

Pull requests welcome!

Support

If you are having issues, please let me know.

License

This projects is licensed under the ISC license.

react-flexbox-svg's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar dlmanning avatar meandavejustice avatar paulmelnikow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.