Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lay-it-out

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lay-it-out

A helper for building complex components with multiple child areas

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-94.44%
Maintainers
1
Weekly downloads
 
Created
Source

lay-it-out

NPM Build Status

A helper for building complex react components with multiple child areas.

Install

npm install --save lay-it-out

Usage

Imagin you want to build a component like this:

Modal example image

And of course all the child elements are variable. You could do it like this:

import React from 'react'
import { withLayout, Place } from 'lay-it-out';

const Modal = ({ headerComponent, contentComponent, footerComponent }) => (
    <section className="modal">
        <header className="modal-header">
            {headerComponent}
        </header>
        <div className="modal-content">
            {contentComponent}
        </div>
        <footer className="modal-footer">
            {footerComponent}
        </footer>
    </section>
)

const App = () => (
    <Modal
        headerComponent={<h2><small>the</small> Header</h2>}
        contentComponent={<h1><small>the</small> Content</h1>}
        footerComponent={<button>Ok, cool!</button>}
    />
);

Or you are using lay-it-out

import React from 'react'
import { withLayout, Place } from 'lay-it-out';

const _Modal = ({ children, child }) => (
    <section className="modal">
        <header className="modal-header">
            {child.header}
        </header>
        <div className="modal-content">
            {children}
        </div>
        <footer className="modal-footer">
            {child.footer}
        </footer>
    </section>
)

const Modal = withLayout(_Modal);

const App = () => (
    <Modal open>
        <Place toBe="header">
            <h2><small>the</small> Header</h2>
        </Place>

        <h1><small>the</small> Content</h1>

        <Place toBe="footer">
            <button>Ok, cool!</button>
        </Place>
    </Modal>
);

export default App;

collision with prop name "child"

You can set an option object to prevent prop name collision of "child".

// Layout.js
import React from 'react'
import { withLayout, Place } from 'lay-it-out';

const _Modal = ({ children, myCustomPropName }) => (
    <section className="modal">
        <header className="modal-header">
            {myCustomPropName.header}
        </header>
        <div className="modal-content">
            {children}
        </div>
        <footer className="modal-footer">
            {myCustomPropName.footer}
        </footer>
    </section>
)

const Modal = withLayout(_Modal, { customChildPropName: 'myCustomPropName' });

Also tested with SSR (next.js). More test coming soon.

If you tried this package with other SSR methods or with react-native , please let me know if it's work ;)

License

MIT © christianheyn

Keywords

FAQs

Package last updated on 19 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc