npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

switch-multi-button

v1.2.0

Published

this package has a toggle and multiple switch buttons

Downloads

211

Readme

Introduction

The switch-multi-button is a react package to create a component to switch to multiple buttons or toggle components with a movable animation.

  • This package has a sweep movement when active button changes!

  • You can cutomize components styles and it has a automatic computing items size when your device changes to horizontal or vertical positioning in responisze page.

  • Support rtl and ltr languages.

Package size:

    package size:     4.9KB     gzipped size:     2.1KB

Installation

npm:     npm install --save switch-multi-button

yarn:     yarn add switch-multi-button

Links:

To see complete exmaples and document, refer to homepage at bottom link

    Homepage site(document, examples,...)

Example

import { useState } from 'react';
import { SwitchMultiButton } from 'switch-multi-button';

function Example = () => {
  const [state, setState] = useState('first');

  <SwitchMultiButton
    value={state} // set as default button
    setValue={setState}
    buttons={[
      {
        text: 'my first button',
        value: 'first'
      },
      {
        text: 'second button',
        value: 'second'
      },
      {
        text: 'third button',
        value: 'third'
      },
    ]}
  />
}
import { useState } from 'react';
import { SwitchMultiButton } from 'switch-multi-button';

function Example = () => {
  const [state, setState] = useState('یک');

  <SwitchMultiButton
    value={state} // set as default button
    setValue={setState}
    direction="rtl"
    buttons={[
      {
        text: 'شماره اول',
        value: 'یک'
      },
      {
        text: 'شماره ی دوم',
        value: 'دو'
      },
      {
        text: 'شماره ی سوم',
        value: 'سه'
      },
    ]}
  />
}
import { useState, useRef } from "react";
import { SwitchMultiButton } from "switch-multi-button";

function Component() {
  const [state, setState] = useState("one");
  const changeTo = useRef();

  return (
    <div>
      <SwitchMultiButton
        value={state}
        setValue={setState}
        changeTo={changeTo}
        buttons={[
          {
            text: "first button",
            value: "one",
          },
          {
            text: "second button",
            value: "two",
          },
        ]}
      />

      <button
        onClick={() => {
          changeTo.current.byValue("one");
        }}
      >
        Change active button by value
      </button>

      <button
        onClick={() => {
          changeTo.current.byIndex(2);
        }}
      >
        Change active button by index
      </button>
    </div>
  );
}

Document: website (For more information)

SwitchMultiButton.propTypes = {
  /**
   * root style
   */
  style: PropTypes.object,

  /**
   * set state
   */
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,

  /**
   * set your setState callback
   */
  setValue: PropTypes.func.isRequired,

  /**
   * you can change active button by sending ref as props
   * and changing active button with value or index.
   * usage:
   * changeTo.current.byValue('some-value');
   * changeTo.current.byIndex(2);
   */
  changeTo: PropTypes.object,

  /**
   * each object in array creates a button for you,
   * {
   *  text: show button label or children
   *  value: every button have to be unique value
   *  key: set your unique custom (default: package handle)
   *  Button: item element type (default: 'div'), (custom: 'a', 'p', 'pre', ... etc.)
   *  props: {} can be set all of the element props as object property.  => { onclick: () =>{}, ...}
   * }
   */
  buttons: PropTypes.array.isRequired,

  /**
   * root className
   */
  className: PropTypes.string,

  /**
   * button transition time. 1 equal to 1 seconds
   */
  transition: PropTypes.number,

  /**
   * language direction
   */
  direction: PropTypes.oneOf(["ltr", "rtl"]),

  /**
   * {
   *  toggleContext: undefined,
   *  removeCss: false,
   *  userSelect: 'none'
   * }
   * see document for more info
   */
  options: PropTypes.object,
};