0.3.1 • Published 3 years ago

@zeejs/react v0.3.1

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

zeejs

zeejs React - simple API to create multi layered UI

test status npm version npm bundle size

what's in the box

  • layers - automatic ordering of nested layers
  • backdrop - hide / block background or keep a layer as part of the flow
  • focus
    • Tab between layers
    • trap focus above backdrop
    • re-focus when blocking layer close
    • focusChange notification when focus outside / inside logical layer
  • click outside - notification for click outside of logical layer
  • mouse interaction - notification for mouse enter / leave of logical layer
  • escape catching - notification for escape press
  • server rendering - single pass nested rendering of layers in the server
  • component primitives - Tooltip, Popover, Modal
  • typed - built with TypeScript
  • tested - tested in a browser

how to use

This document describes the zeejs React usage, For a more in depth overview of zeejs, please see the general documentation.

<Root> component

At the base of the application or website place the <Root> component. The Root component is responsible for collecting, rendering and managing the layers.

Notice that Root is required for zeejs to work properly.

props:

nametypedefaultrequireddescription
classNamestring""falseCSS class name to be placed on the wrapper element around all layers
styleReact.CSSProperties{}falseCSS styles to be placed on the wrapper element around all layers

code example:

import { Root } from '@zeejs/react';

ReactDOM.render(
    <Root className="app-root" style={{ height: `100%` }}>
        {/* application code */}
    </Root>
);

will output:

<div class="app-root" style="height: 100%">
    <zeejs-layer>
        <!-- application code -->
    </zeejs-layer>
</div>

<Layer> component

At every point that requires a part of the DOM to be moved up the normal layout flow and out of any overflows, a <Layer> component can be placed. The Layer is the low level primitive of zeejs that takes any given content and renders it in its own layer.

The component will generate a new zeejs layer above layer it is rendered in.

props:

nametypedefaultrequireddescription
backdrop"none" | "block" | "hide""none"falsebackground behavior; see docs
overlap"window" | HTMLElement"window"falselayer bounds reference
onClickOutside(target: EventTarget) => voidfalseinvoked on click outside; see docs
onMouseIntersection(isInside: boolean) => voidfalseinvoked when mouse leaves or enters layer; see docs
onFocusChange(isFocused: boolean) => voidfalseinvoked when focus is moved into/out of layer; see docs
onEscape(event: KeyboardEvent) => voidfalseinvoked when escape is pressed; see docs

code example:

import { Layer } from '@zeejs/react';

const Component = () => {
    return (
        <div>
            <Layer>{/* layer content */}</Layer>
        </div>
    );
};

will output (assuming render in the application layer):

<div>
    <zeejs-layer>
        <!-- application code containing layer component -->
    </zeejs-layer>
    <zeejs-layer style="/* bound to window or reference element */">
        <!-- layer content -->
    </zeejs-layer>
</div>

nesting code example:

import { Layer } from '@zeejs/react';

const Component = () => {
    return (
        <div>
            <Layer>
                <div>
                    {/* layer A content*/}
                    <Layer>{/* layer B content */}</Layer>
                </div>
            </Layer>
        </div>
    );
};

will output (assuming render in the application layer):

<div>
    <zeejs-layer>
        <!-- application code containing layer component -->
    </zeejs-layer>
    <zeejs-layer>
        <!-- layer A content -->
    </zeejs-layer>
    <zeejs-layer>
        <!-- layer B content -->
    </zeejs-layer>
</div>

<Modal> component

The modal primitive display content that is not affected by the scroll of lower layers.

props:

nametypedefaultrequireddescription
backdrop"none" | "block" | "hide""block"falsebackground behavior; see docs
position"topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight""center"falsefixed align position
showbooleantruefalseflag if the layer should be displayed
onClickOutside(target: EventTarget) => voidfalseinvoked on click outside; see docs
onMouseIntersection(isInside: boolean) => voidfalseinvoked when mouse leaves or enters layer; see docs
onFocusChange(isFocused: boolean) => voidfalseinvoked when focus is moved into/out of layer; see docs
onEscape(event: KeyboardEvent) => voidfalseinvoked when escape is pressed; see docs
classNamestring""falseCSS class name to add to the modal box
styleReact.CSSProperties{}falseCSS inline style to add to the modal box

<Tooltip> component

The tooltip primitive displays hovered content that is bound to the UI that opened it, usually used to label or describe it.

props:

nametypedefaultrequireddescription
mouseDelaynumber500delay for mouse out / in
positionX"before" | "start" | "center" | "end" | "after""center"falsealign X position
positionY"before" | "start" | "center" | "end" | "after""before"falsealign X position

<Popover> component

The modal primitive display content that is not affected by the scroll of lower layers while being bound to the UI the opened it.

props:

nametypedefaultrequireddescription
backdrop"none" | "block" | "hide""block"falsebackground behavior; see docs
positionX"before" | "start" | "center" | "end" | "after""center"falsealign X position
positionY"before" | "start" | "center" | "end" | "after""after"falsealign Y position
avoidAnchorbooleanfalsefalseattempt to not overlap the anchor that opened it while pushed in by overflow
matchWidthbooleanfalsefalseforce the popover box to be in the width of the anchor
matchHeightbooleanfalsefalseforce the popover box to be in the height of the anchor
showbooleantruefalseflag if the layer should be displayed
onClickOutside((target: EventTarget) => voidfalseinvoked on click outside; see docs
ignoreAnchorClickbooleanfalsefalsewhen true click on anchor does not invoke onClickOutside handler
onMouseIntersection(isInside: boolean) => voidfalseinvoked when mouse leaves or enters layer; see docs
onFocusChange(isFocused: boolean) => voidfalseinvoked when focus is moved into/out of layer; see docs
onEscape(event: KeyboardEvent) => voidfalseinvoked when escape is pressed; see docs
onDisplayChange(isPositioned: boolean) => voidfalseinvoked when the popover is displayed (after positioning) or removed from DOM
classNamestring""falseCSS class name to add to the popover box
styleReact.CSSProperties{}falseCSS inline style to add to the popover box