GithubHelp home page GithubHelp logo

tweakpane / use-tweaks Goto Github PK

View Code? Open in Web Editor NEW
759.0 7.0 22.0 2.09 MB

πŸŽ›οΈ Tweak React components with Tweakpane

Home Page: https://codesandbox.io/s/use-tweaks-example-58e02

License: MIT License

HTML 1.81% TypeScript 96.74% CSS 1.45%
gui creative-coding tweaks tweakpane

use-tweaks's Introduction

A screenshot of the library in use npm npm Discord Shield

Use Tweakpane in React apps

Try it here on Codesandbox

npm install tweakpane use-tweaks

Basic example

import { useTweaks } from "use-tweaks"

function MyComponent() {
  const { speed, factor } = useTweaks({
    speed: 1,
    factor: { value: 1, min: 10, max: 100 },
  });

  return (
    <div>
      {speed} * {factor}
    </div>
  );
}

Misc

Folders

You can add a top-level folder by passing the name as first argument of the hook:

import { useTweaks } from "use-tweaks"

const { speed, factor } = useTweaks("My title!", { speed: 1, factor: 1 })

You can also nest folders by using the makeFolder helper:

import { useTweaks, makeFolder } from "use-tweaks"

const { speed, factor } = useTweaks("My Title!", {
  speed: 1,
  ...makeFolder(
    "Advanced",
    {
      factor: 1,
    },
    false
  ), // pass false to make the folder collapsed by default
})

Buttons

Use the makeButton helper to create and add a button

import { useTweaks, makeButton } from "use-tweaks"

const { speed, factor } = useTweaks({
  speed: 1,
  factor: { value: 1, min: 10, max: 100 },
  ...makeButton("Log!", () => console.log("Hello World!"))
})

Separator

Use the makeSeparator helper to add a separator

import { useTweaks, makeSeparator } from "use-tweaks"

const { speed, factor } = useTweaks({
  speed: 1,
  ...makeSeparator(),
  factor: { value: 1, min: 10, max: 100 },
})

License

This project is open source and available under the MIT License

use-tweaks's People

Contributors

cocopon avatar dbismut avatar drcmda avatar giulioz avatar gsimone avatar ivanross avatar jadhielv avatar neefrehman avatar shahruz 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

use-tweaks's Issues

πŸ› 4/24/2023

Next.js 13.3.0

  • I cant use parameter name = "title" at useTweaks(name, schema, settings)
    image
    image

  • Can you consider replacing useLayoutEffect with useEffect
    image

use-tweaks 0.3.1

  • Missing icon checkbox :v
    image

Uncaught TypeError: import_tweakpane.default is not a constructor

This library throws an uncaught exception as in the title. The symbol Tweakpane is undefined when attempting to call this constructor. I looked a tweakpane module and it doesn't seem to export a default. I checked to make sure the peerDeps match. I reproduced this issue in a couple TS projects. I'm not providing a reproduction because I'm not sure if this is maintained given there are several stale pending PRs . Intent here is to warn other developers.

Special treatment for arrays

Right now tweakpane makes selects from an object like

{
   options: { a: 0, b: 0, c: 0 }
}

But I would like an api like this for useTweaks for simple cases

useTweaks({
   option: ["a", "b", "c"]
})

that would convert it to tweakpane's format.

Keep in mind that the value set by tweakpane is the key, not the value

Tweaks are lost when unmounting component

Since state is stored in the hook, tweaks are lost when unmounting the component.

To reproduce:

  • make a component that can be mounted/unmounted
  • add a tweak in the component
  • change some values
  • cause an unmount
  • remount the component
  • values will be back to default

Monitors

API for monitors, maybe a fn that hides constants or something

const  { mouseMonitor, x, y  } = useTweaks({ mouseMonitor: makeMonitor('2d'), x: 1, y: 1 })

// alt
const  { mouseMonitor, x, y  } = useTweaks({ mouseMonitor: { type: "MONITOR" }, x: 1, y: 1 })

useFrame(() => {
   mouseMonitor.set(mouse.x)

   // alt
  mouseMonitor(mouse.x)
})
 

Folders

Folders can be made with a context provider

<Pane>
   <Input name="outer" />
  <Folder title={title}>
      <Input name="test" />
   </Folder>
</Pane>

Here both Pane and Folder are folderContext.Providers that pass an instance of tweakpane or a pane.addFolder({ title })

function Input() {
  const { parent } = useContext(foldersContext);
  

   useEffect(() => { parent.addInput(...) }

}

Fix types

Internal types are placeholders
Types created by the hook are up in the air, look into how to do it

Broken Schema types

Using typescript 4.4.2, use-tweaks 0.3.1, and tweakpane 3.1.0:
image

image

image

Return type for useTweaks is {}, regardless of whether I pass in a type for the Schema generic or not. Am I missing something?

Create a license file

Is your feature request related to a problem? Please describe.
Create a license file

Describe the solution you'd like
Use MIT License

Describe alternatives you've considered
NONE

Additional context
NONE

Find a way to set initial values without ugly stuff

Initial values are hard to set with the current architecture

Init:

<Input name="test" value={0} />

Consumer:

const [test] = useGUI('test') // this will be undefined until the component executes its useLayoutEffect

Multiple panes on a page

Hi, I'm trying to add multiple tweak panes on a page, independent of each other, just separate demos stacked.

I figured I can pass a container via settings and this attaches the pane to a custom element, but what seems to happen is after the first instance, all tweak-panes are mounted to the same container regardless of their respective hook configuration.

I'm not sure if that's a bug, a feature or if I'm missing something, but I would certainly appreciate any help.

You can see a demo of the issue here:
https://scramble-git-demos.a7sc11u.vercel.app/

And here's my repo (main.jsx and typewriter.jsx) are the layouts that use useTweaks
https://github.com/a7sc11u/scramble-site/blob/demos/src/

Thanks in advance!

P.S. Thank you for putting this library together, I love it!

Keep state & order on HMR/FR

Plan:

We can use schema/name as keys, creating an out-of-react state:

state[generateKey(name,schema)] = value

This object is used at reload to

  1. regenerate panes in original order
  2. preserve state on unmounting/reloading

Tweaks with identical settings would be ambiguos, we need to catch this and warn + add documentation

Buttons

Buttons are a special case since they don't change values, they are just buttons.

Consider special treatment

const { button } = useTweaks({ button: makeButton(() => console.log("pushed")) })

Return type error with useTweaks

When using the useTweaks hook, I'm getting an error about the return types. The return type looks to be an object with a single key that is an empty string?

const {
    numCirclesPerGroup,
    circleGap,
    innerCircleRadius,
    numGroups,
  } = useTweaks({
    numCirclesPerGroup: { value: 12, min: 1, max: 40, step: 1 },
    circleGap: { value: 2, min: 0, max: 100, step: 1 },
    innerCircleRadius: { value: 20, min: 1, max: 100, step: 1 },
    numGroups: { value: 6, min: 2, max: 90, step: 1 },
  })
// Property 'innerCircleRadius' does not exist on type '{ "": { numCirclesPerGroup: ....

See this sandbox https://codesandbox.io/s/jovial-lamport-8c4u3?file=/src/App.tsx

step option?

I'm noticing the step option doesn't seem to be working. Are you planning to support this in the future?

Refresh Pane

Hello everybody!

I am using your cool library and trying to update values in the GUI. Tweakpane has the function pane.refresh() (Tweakpane API). Is there a way to trigger this in use-tweaks?

Thanks a lot!
Max

Handling multiple instances of a component with tweaks

Hey! Love the library :)

I have multiple instances of a component with a useTweaks call, say:

const Button = ({ text }: { text: string }) => {
  const { color } = useTweaks("Buttons", { color: "blue" });

  return <button style={{ backgroundColor: color }}> {text} </button>
}

However, every single instance Button will add its own color setting in the tweakpane, whereas my intent was to have them all share the same value.
My question: should I just hoist the useTweaks call up one level and pass the tweaked value down as a prop (feels kind of meh)? Or is there a nicer solution to this? I tried passing the same presetKey but they still have different tweakpane inputs.
Here's a sandbox demonstrating the "issue": https://codesandbox.io/s/gracious-bas-22vg2?file=/src/App.tsx.

i can't initiate tweakpane

Hi,

i'm encoutring an issue when i install Tweakpane and try to use it :

const tweakpane = require('tweakpane');

`const createPane = () => {
const pane = new tweakpane.Pane();
}

createPane();`

i have this error :

C:\wamp64\www\cours code crΓ©atif\skteches\node_modules\tweakpane\dist\tweakpane.js:7791
export { BladeApi, ButtonApi, FolderApi, ListBladeApi, ListInputBindingApi, Pane, Semver, SeparatorBladeApi, SliderBladeApi, SliderInputBindingApi, TabApi, TabPageApi, TextBladeApi, TpChangeEvent, VERSION };
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

anybody can help me please ?

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.