@nonnontrivial/react-vfd

0.3.0ย โ€ขย Publicย โ€ขย Published

react-vfd

๐Ÿ‘ Keyboard-navigable React components for images

overview and ethos

Inspired by, and modaled after reach-ui, react-vfd offers a set of components for keyboard-navigable image showcasing.

It's early days, and this is primarily built for a personal project (the scope of which is uncertain), but the gist of using this can be grokked below.

isOpen, entities, and onDismiss are the only required props.

import { Lightbox } from '@nonnontrivial/react-vfd'

export class Viewer extends React.Component {
  state = {
    isOpen: false,
    entities: [
      { src: 'https://www.tarsnap.com/images/header.png', caption: 'tars' }
    ]
  };

  buttonRef = React.createRef();

  render() {
    const { isOpen, entities } = this.state
    return (
      <React.Fragment>
        <button
          ref={this.buttonRef}
          onClick={() => {
            this.setState(prevState => (
              isOpen: !prevState.isOpen
            ))
          }}
        >
          toggle
        </button>
        <Lightbox
          isOpen={isOpen}
          entities={entities}
          initialFocusRef={this.buttonRef}
          styles={{ modal: { background: 'rgba(5, 6, 17, 0.95)' } }}
          onCycle={({ src }) => {
            console.log(src)
          }}
          onDismiss={() => {
            this.setState({ isOpen: false })
          }}
        />
      </React.Fragment>
    )
  }
}

installation

yarn add @nonnontrivial/react-vfd

license

MIT ยฉ Kevin Donahue

Readme

Keywords

Package Sidebar

Install

npm i @nonnontrivial/react-vfd

Weekly Downloads

0

Version

0.3.0

License

MIT

Unpacked Size

14 kB

Total Files

7

Last publish

Collaborators

  • nonnontrivial