GithubHelp home page GithubHelp logo

sghall / react-quickie-controls Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 1.83 MB

Quick development controls for React projects. Change values and colors quickly in your development environment or storybooks.

Home Page: https://react-quickie-controls.netlify.app

License: MIT License

TypeScript 97.75% JavaScript 2.25%
typescript react controls react-hooks storybooks development-tools

react-quickie-controls's Introduction

React Quickie Controls

React hooks to make quick controls to use for development or in storybooks. A test control can be added to your app or component by just importing this library and adding a single line to your code. You can append more controls to the same instance and experiment with different values for numbers, strings and colors. They can be in multiple places anywhere in the tree. When the hook unmounts that control will be removed from the list and any others will continue to work.

npm install react-quickie-controls
react-quickie-controls

NOTE: This is a beta project and is only being used in a couple of places. Since it's only for development it's relatively safe to put it out there for others to try out. Please don't put this in your app though.

How does it work?

For example, if you wanted to quickly be able to change a number to different values between 1 and 100 you could just do the following...

import { useValueSlider } from 'react-quickie-controls';

const MyComponent = () => {
  // this will render a value slider in the upper right of the screen
  // changing the slider value will cause this component to update
  const x = useValueSlider('X Value:', 10, 1, 100, 0.5); // (label, value, min?, max?, step?)

  return <div>The X Value: {x}</div>;
};

Need to add two color selectors as well? No problem.

import { useValueSlider, useColorPicker } from 'react-quickie-controls';

const MyComponent = () => {
  const x = useValueSlider('X Value:', 10, 0, 100, 0.5);
  const color = useColorPicker('Color:', '#333');
  const backgroundColor = useColorPicker('Background Color:', '#555');

  return <div style={{{color, backgroundColor }}>The X Value: {x}</div>;
};

You get the idea.

Currently, this package exports these three React hooks...

import {
  useValueSlider,
  useColorPicker,
  useSelectControl,
} from 'react-quickie-controls';

Fun Fact

Each control is actually a mini React app.

Road Map

If people start using this, there's a lot that could be done. More control types and better styling/customization come to mind.

One more example...

type MyOptionType = {
  value: () => string, // could be whatever, string, number, function, etc
  label: string,
};

export const kitchenSink = () => {
  const text =
    useSelectControl <
    MyOptionType >
    ('Select Control: ',
    [
      { value: () => 'Option 1', label: 'The First Option' },
      { value: () => 'Option 2', label: 'The Second Option' },
      { value: () => 'Option 3', label: 'The Third Option' },
    ]);

  const width = useValueSlider('Width: ', 100, 50, 300, 10);
  const height = useValueSlider('Height: ', 100, 50, 300, 10);

  const backgroundColor = useColorPicker('Background Color: ', '#0000ff');
  const border = useColorPicker('Border Color: ', '#ccc');

  return (
    <div
      style={{
        width,
        height,
        color: '#fff',
        backgroundColor,
        border: `2px solid ${border}`,
      }}
    >
      {text.value()}
    </div>
  );
};

react-quickie-controls's People

Contributors

sghall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jdiss

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.