Comments (4)
mmm my bad, indeed I finalized my code and it's working with Object.entries:
import type { BindingParams } from 'tweakpane'
export interface ThemeOption {
default: string | number
options?: BindingParams
}
export type ThemeOptions = Record<string, ThemeOption>
const initDesigner = (
container: HTMLElement,
theme: ThemeOptions,
onChange: (key: string, value: string | number) => void,
) => {
const pane = new Pane({
title: 'Resume Designer',
expanded: true,
container,
})
const initialData: Record<string, string | number> = {}
Object.entries(theme).forEach(([key, option]) => {
initialData[key] = option.default
pane
.addBinding(initialData, key, option.options)
.on('change', (event) => {
onChange(key, event.value)
})
})
pane.addButton({ title: 'Reset' }).on('click', () => {
// pane.importState({})
})
return {...initialData}
}
Thanks for your help!
from tweakpane.
That error makes sense to me. You are trying to bind theme
keys to the data
object. But even if you fix that, there is stil the limitation of Object.entries
, which does not produce a fully typed object.
Assuming theme
is of type ThemeOptions
, you could do the following.
const TypedObject = {
entries: <T extends {}>(obj: T) => {
return Object.entries(obj) as [keyof T, T[keyof T]][];
}
}
TypedObject.entries(theme).forEach(([key, option]) => {
pane.addBinding(theme, key, option.options); // changed `data` for `theme`
})
Edit: Actually, Object.entries
will work just fine in this case too, if you use theme
instead of data
. Maybe I'm missing something about what you are trying to achieve?
from tweakpane.
Closing as this is not a bug
from tweakpane.
Happy to hear you got it working.
from tweakpane.
Related Issues (20)
- Pointer lock when dragging.
- `view` string autocomplete. HOT 2
- How to remove event listeners? HOT 3
- color panel is displaying incorrectly HOT 4
- Bug with Tab when we have controls after the Tab HOT 2
- Cannot read properties of undefined (reading 'valueController') HOT 3
- Theme builder HOT 8
- SVGs Not Scaling Correctly HOT 4
- color as array of values 0-255 HOT 1
- [feature request] tabs: html elements in title HOT 2
- [feature request] tabs: vertical layout HOT 4
- Considering sponsorship for sustainable OSS development
- Please add a UMD library version again. HOT 5
- export folder -> import folder not working as expected HOT 3
- Numerical values passed as list of strings incorrectly treated as colors HOT 2
- Ability to manually select the binding view type HOT 4
- support for React, Vue, Svelte, Solid, Angular, etc, by making Custom Elements
- Readonly `point2d`, `point3d`, `point4d` throws an error HOT 3
- Feat: support custom passing a custom BindingTarget
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tweakpane.