Coder Social home page Coder Social logo

squeezy's Introduction

Squeezy

An tiny 1KB React component for accessible accordions / collapse UI

npm i squeezy

Usage

import React from 'react';
import { Squeezy } from 'squeezy';

const App = () => (
  <div>
    <h1>My App</h1>

    <Squeezy
      id="thing"
      render={({ getButtonProps, getContentProps, isOpen }) => (
        <div>
          <div>
            Stuff
            <button {...getButtonProps({ className: 'whatever' })}>
              See {isOpen ? 'more' : 'less'}
            </button>
          </div>

          {isOpen ? (
            <div {...getContentProps({ className: '...' })}>Stuff to show</div>
          ) : null}
        </div>
      )}
    />
  </div>
);

export default App;

API

<Squeezy> Props

id: string

Required

An HTML id attribute. Used by Squeezy to make the accordion accessible.

debug?: boolean

Log changes to Squeezy state to the console.

isOpen?: boolean

If you want to make Squeezy a controlled component (i.e. manage its state externally), pass Squeezy an isOpen prop.

onToggle?: (state: SqueezyState, helpers: SqueezyActions) => void

Callback to run on state changes. If Squeezy is controlled, use this to set the next state externally. Otherwise, good place for side effects.

render: (props: SqueezyProps) => React.ReactNode

Render prop.

Squeezy State and Helpers

getButtonProps(moreProps: any) => void

Prop getter that returns accessible accordion button props and click handlers

getContentProps(moreProps: any) => void

Prop getter that returns accessible accordion content props. Spread this on the body / main area that you want show/hide

isOpen: boolean

Is the accordion open or close.

close: () => void

Close the accordion.

open: () => void

Open the accordion.

toggle: () => void

Toggle the accordion.

Inspiration

Author


MIT License

squeezy's People

Contributors

jaredpalmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bq1028

squeezy's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.