2.2.5 • Published 1 year ago

onus-elements v2.2.5

Weekly downloads
1
License
MIT
Repository
-
Last release
1 year ago

onus-elements

npm Version License

Separate DOM position from rendering position. Like Portals, but better because you don't have to interact with the DOM, and you can easily replace or append to the previous content.

Installation

yarn add onus-elements

or

npm i --save onus-elements

Usage

import { GetElement, SetElement, OnusElementsProvider } from 'onus-elements'

<OnusElementsProvider>
  <header>
    <GetElement name='header' />
  </header>
  <footer>
    <SetElement name='header' priority={0}>
      <a href='/'>Home</a>
    </SetElement>
    // These can be rendered anywhere in your application, and it will appear where GetElement lives in the DOM
    <SetElement name='header' priority={1} append>
      <span>
        > <a href='/breadcrumb'>Breadcrumb</a>
      </span>
    </SetElement>
  </footer>
</OnusElementsProvider>

Props

GetElement

Used as placeholder for where you want content to be rendered

PropTypeDefaultDescription
nameStringRequiredUnique name that will be matched with SetElement
childrenNodeundefinedDefault content to render if nothing else has been provided

SetElement

Used to set the content to be rendered inside the GetContent component

PropTypeDefaultDescription
childrenNodeFragmentChildren to render in GetElement with a matching name
nameStringRequiredUnique name that will be matched with GetElement
priorityNumberRequiredPriority to render children, highest wins
appendBooleanundefinedAppend children to currently rendered content
prependBooleanundefinedPrepended children to currently rendered content

useSetElement

Hook to set the onus element at the top of your component

NameTypeDefaultDescription
ParamOptionsObjectRequiredDescribes the element to set
nameStringRequiredSame as SetElement name
priorityNumberRequiredSame as SetElement priority
appendBooleanundefinedSame as SetElement append
prependBooleanundefinedSame as SetElement prepend
ParamnodeNodenullChildren to render in the GetElement with a matching name

Testing

yarn test

Build Example

yarn build

Start Example

yarn start
2.2.5

1 year ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.2.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.2-4

4 years ago

2.0.2-3

4 years ago

2.0.2-2

4 years ago

2.0.2-1

4 years ago

2.0.2-0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

2.0.0-3

5 years ago

2.0.0-2

5 years ago

2.0.0-1

5 years ago

2.0.0-0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago