Hudini Checkbox Component
Uncontrolled toggleable form control with custom icon, disabled/readOnly states, and a pop animation on state change.
Checkbox Component
A toggleable form control. The Checkbox owns its own state (uncontrolled): read it back via getValue() / isChecked(), mutate it via toggle() / setChecked(v), observe changes via the onChange callback.
For persistent named state, wire it up with phaser-hooks' withLocalState on the outside â the Checkbox stays decoupled from any store.
Features
- đ Custom icon: default
check, use any Font Awesome key (heart,star,thumbs-up, ...) - đ¨ Custom colors: box color + icon color independently
- đˇī¸ Optional label: clicking the label toggles too (HTML-label behavior)
- đĢ Disabled + readOnly: separate states â disabled mutes the visual, readOnly only blocks clicks
- ⨠Pop animation: icon scales + fades in on check, out on uncheck (Back.easeOut)
- đ Form-ready:
name+getValue()for building a Form later â no runtime dep on any state store
Props
checked- Initial state (defaultfalse)label- Optional text label to the right of the boxicon- Font Awesome icon shown when checked (defaultcheck)iconColor- Color of the icon (defaultwhite)color- Box fill / border color (defaultblue-500)labelColor,size,borderRadius,labelGapdisabled,readOnlyname- Form field name, passed as the second arg ofonChangeonChange-(checked, name?) => voidonClick- Fires on any click, even if the state does not change
Methods
toggle()/setChecked(v)isChecked()/getValue()disable()/enable()/setDisabled(v)/isDisabled()setReadOnly(v)/isReadOnly()onChange(cb)/onClick(cb)- Replace the handlers post-construction
Live Example
Loading game...
Usage Example
import Phaser from 'phaser';
import {
createTheme,
HUDINI_KEY,
HudiniPlugin,
withHudini,
Checkbox,
} from 'hudini';
class SettingsScene extends Phaser.Scene {
create(): void {
// 1. Basic checkbox with a label
const sound = new Checkbox({
scene: this, x: 100, y: 100,
label: 'Enable sound',
checked: true,
name: 'sound',
onChange: (v, name) => console.log(name, v),
});
// 2. Custom icon (a heart for "favorite")
const favorite = new Checkbox({
scene: this, x: 100, y: 160,
label: 'Favorite',
icon: 'heart',
color: 'red-500',
});
// 3. Collect values later (mini form)
const submit = () => {
const payload = {
sound: sound.getValue(),
favorite: favorite.getValue(),
};
console.log('form:', payload);
};
}
}