-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button type? #501
Comments
I tried creating a plugin for it: import React from 'react';
import { Leva, useControls } from 'leva';
import { createPlugin } from 'leva/plugin';
import { useInputContext, Components } from 'leva/plugin';
const { Row, Label } = Components;
const LevaButton = (...args) => {
const { label, displayValue, onUpdate, settings } = useInputContext<any>();
const onClick = () => {
if(typeof displayValue.onClick == 'function') {
displayValue.onClick();
}
};
return <>
<Row input>
<Label>{label}</Label>
<button type="button" onClick={onClick}>{displayValue.name || label}</button>
</Row>
</>
};
export const button = createPlugin({
component: LevaButton,
});
export { Leva, useControls }; And then I can use it as: import { Leva, useControls, button } from '../leva/leva.tsx';
const MyComponent : React.FC = () => {
useControls({
btn1: button({
name: 'Button 1',
onClick: () => { console.log('button 1') },
}),
btn2: button({
name: 'Button 2',
onClick: () => { console.log('button 2') },
}),
});
return <div>
<Leva />
</div>;
}; But the styling is a bit weird, and I'm unsure if I'm creating a plugin in the correct way given that its not documented. This also forces me to wrap each property in a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't see an input type for button under inputs.
I think the syntax should be something like the following:
Where
useControls
would detect if a parameter wastypeof Function
and then render it as a button that you can click on.Seems like there is even an empty docs section mentioning buttons?
The text was updated successfully, but these errors were encountered: