1.0.0 • Published 7 months ago

react-compound-factory v1.0.0

Weekly downloads
-
License
-
Repository
github
Last release
7 months ago

react-compound-factory

place components where you want. for design that could not be expressed as a series of children.

Usage

import { getCompoundFactory } from "react-compound-factory"

function Image(/* ... */) {
  return <img />
}

function Name(/* ... */) {
  return <h1>{/* ... */}</h1>
}

function Description(/* ... */) {
  return <p>{/* ... */}</p>
}

function Statistics(/* ... */) {
  return <>{/* ... */}</>
}

function ButtonGroup(/* ... */) {
  return <div className="flex justify-between">{/* ... */}</div>
}

function Card({ children }: { children: React.ReactNode }) {
  const { image, name, description, statistics, buttonGroup } =
    getCompoundFactory(children, {
      image: Image,
      name: Name,
      description: Description,
      statistics: Statistics,
      buttonGroup: ButtonGroup,
    })

  return (
    <section className="card">
      <div className="flex">
        {image}
        <div className="wrapInformation">
          {name}
          {description}
          <div className="flex">{statistics}</div>
        </div>
      </div>
      {buttonGroup}
    </section>
  )
}

export default Object.assign(Card, {
  Image,
  Name,
  Description,
  Statistics,
  ButtonGroup,
})
1.0.0

7 months ago

0.0.0-beta5

7 months ago

0.0.0-beta4

7 months ago

0.0.0-beta3

7 months ago

0.0.0-beta2

7 months ago

0.0.0-beta1

7 months ago