You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to create a custom widget?
To use <ColorPick title="#ccc"/> in the jsx code
importGtkfrom"gi://Gtk?version=3.0";import{execAsync}from"astal";importAstalfrom"gi://Astal?version=3.0";exportclassColorPickextends/* What should be here? */{label: Gtk.Widget;
color: string;constructor({ text }: {text: string}){this.label=<labellabel={text}/>;this.color="#fff";}asyncpick(e: Astal.ClickEvent){try{if(e.button!=Astal.MouseButton.PRIMARY){this.color=(awaitexecAsync("hyprpicker")).trim();this.label.set_css(`color: ${this.color}`);}awaitexecAsync(`wl-copy "${this.color}"`);}catch(e){print(e);}}render(){return<buttononClick={(_,e)=>this.pick(e)}>{this.label}</button>;}}
The text was updated successfully, but these errors were encountered:
There is no need to create a new class. The easiest way is to just use function, which return the widget like this:
functionColorPick(){constcolor=Variable("#fff")constclicked=async(self: Astal.Button,event: Astal.ClickEvent)=>{constc=awaitexecAsync("hyprpicker")color.set(c);execAsync(`wl-copy "${c}"`)}return(<buttononClick={clicked}css={color().as(c=>`color: ${c}`)}>{color()}</button>);}//then just use like this:<ColorPick/>
How to create a custom widget?
To use
<ColorPick title="#ccc"/>
in the jsx codeThe text was updated successfully, but these errors were encountered: