Git Product home page Git Product logo

retoggle's Introduction




Retoggle is a collection of React hooks which provides UI toggles to manipulate your component state from outside. Like Storybook Knobs. This library is inspired by ideas from Dan Abramov.

  • ๐ŸŽ‰ A wide range of toggles
  • ๐Ÿ’ก Frictionless integration
  • ๐ŸŽจ Themeable components
  • ๐ŸŽ Extensible. Write your custom toggles.

Available knobs

  • ๐Ÿ“ useLog() - Keeps track of a variable value
  • ๐Ÿ…ฐ useTextKnob() - Shows a text box
  • 1๏ธโƒฃ useNumberKnob() - Shows a number box
  • โœ…๏ธ useBooleanKnob() - Shows a check box
  • ๐ŸŽš useRangeKnob() - Shows a slider
  • ๐ŸŽ› useRangesKnob() - Shows multiple sliders
  • ๐ŸŽ useSelectKnob() - Shows a select box
  • โš’ useObjectKnob() - Shows an object editor
  • ๐ŸŽจ useColorKnob() - Shows a color picker
  • โฐ useTimemachine() - Shows a slider and tracks the state of a given variable and allows to travel back in time

๐Ÿ“š API Docs with live preview available here

๐Ÿ”ฎ Codesandbox Demo

An example

The value of state will be displayed in the inspector component.

import React, { useState } from "react";
import { Inspector, useLog } from "retoggle";

export default function Demo() {
  const [state, setState] = useState({ value: 5 });

  // logs your state to inspector
  useLog("My state", state);

  return (
    <div>
      <Inspector />
    </div>
  );
}

Contribute

Preparing dev environment

  • yarn install to install dev dependencies

Running and building the library

  • yarn start will start the dev server and expose the sample app
  • yarn build will output the build artifact to ./lib folder

Docs

  • docz:dev will start the docz development server
  • docz:build will build the docs

License

MIT

retoggle's People

Contributors

0xflotus avatar alampros avatar ammmze avatar dextermb avatar hasparus avatar hetpatel33 avatar ibrahimsassi avatar panzerstadt avatar raathigesh avatar rip21 avatar ymhr 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

retoggle's Issues

Add ability to move inspector around by drag and drop

It's quite hard to work with when you need to collapse and uncollapse this thing all the time if you have some UI on the right side that you want to interact with.

Also, make its z-index 999999999999 or something like that so it overlaps all possible UI in any scenario :)

Will this generate component code?

Are there any plans to be able to generate code? Would be cool to visually tweak a component and then grab and use that code in some way.

How to use this for multiple components?

Thank you for this project, I absolutely love the simplicity of hook-based knobs! I would like to be able to use this to debug different components simultaneously. I tried first by naively attaching a non-portal Inspector to each component I want to inspect but then found that hooks begin to mix between them.

Is this usage supported, in the roadmap or intended at all?

Generate type definitions for TypeScript

Generate type definitions for TypeScript and not only JS bundle. You can use tsc for that with option emitDeclarationOnly and don't forget to add typings url to the package.json.

doesn't deploy with CRA2 ?

create-react-app test-project
cd test-project
yarn add retoggle

then import retoggle somewhere in the app

yarn build
serve -s build

it return an error:

Uncaught TypeError: Super expression must either be null or a function, not undefined
    at index.js:6135
    at index.js:6134
    at Object.<anonymous> (index.js:6124)
    at t (index.js:5602)
    at Object.<anonymous> (index.js:8467)
    at t (index.js:5602)
    at Object.<anonymous> (index.js:7206)
    at t (index.js:5602)
    at Object.<anonymous> (index.js:6821)
    at t (index.js:5602)

these are the two lines i added to a new CRA2 template:

import React from "react";
import { Inspector } from "retoggle";
//...
return (...
<Inspector usePortal={true} />
)
//...

Could use a link to the repository from the docs

Just found this project from React Status and clicked through to the debuggable.io site. But, from there, I didn't see any way to get to this github repo. Oblivious me, I missed the link to the repo from the React Status newsletter. So I googled for "github retoggle" to get here. But, a link from the published docs would be nice too!

removeKnob does not work

Changed app.tsx like this:

export default function App() {
    const [ useIcon ] = useBooleanKnob('Use Icon', true)

    return useIcon ? <Icon /> : <div>123abc</div>
}

then switch 'Use Icon' to false.

Component Icon was unmounted, but knobs were still there .

Get missing keys warning from React

I get

Warning: Each child in an array or iterator should have a unique "key" prop.

for each knob added to the inspector. Is this a known issue?

Does not work with SSR

Love the project so I'm sad to find out this does not work for me because it fails for me when building with gatsby build

WebpackError: ReferenceError: window is not defined

but you can easily test it yourself with:

// fail-retoggle.js
require('retoggle')
node fail-retoggle.js

And get

ReferenceError: window is not defined

I tried searching for references to window in this project but could not find any which confuses me. Anyone else bumping into this problem?

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.