logo

Inputs

Number

Number inputs come with a text input, buttons, and a slider.
// explicit
gooey.addNumber('bar', 10)

// implicit
gooey.add('foo', 0)

// binding
const data = { count: 0 }
gooey.bind(data, 'count')
gooey will try to guess useful min , max , and step values based on the initial value

Number Options

  • min     |  minimum value   lowest / inclusive
  • max     |  maximum value   highest / inclusive
  • step    |  increment / decrement amount
gooey.add('foo', 50, {
  min: 0,    
  max: 100,  
  step: 1,   
})
Hold cmd cmd to make the text input draggable. While dragging, holding shift shift will double the step, and alt alt will halve it (this works both on the slider, and when dragging the text input).
const number_input = gooey.add('drag', 50, {
    step: 1,
})

// Just so you can notice the tooltip ->
number_input.elements.controllers.input.tooltip.show()
Some more advanced stuff you can do with number inputs:
// Binding to an object property
const data = { count: 0 }
gooey.bind(data, 'count', { min: 0, max: 10 })

// Using onChange callback
gooey.add('value', 5, {
  onChange: (v) => console.log('New value:', v)
})

// Dynamic disabled state
gooey.add('dynamicNumber', 0, {
  disabled: () => someCondition
})
You can bind to object properties, use callbacks, or pass a function to `disabled` for dynamic, programmatic toggling, for example.

Switch

Switch inputs provide a toggle for boolean values with customizable labels.
// explicit
gooey.addSwitch('enabled', true)

// implicit
gooey.add('active', false)

// binding
const data = { visible: true }
gooey.bind(data, 'visible')

Switch Options

  • labels  |  customize text for true/false states and their actions
    • @default 
      { true: { state: "on", verb: "Enable" }, false: { state: "off", verb: "Disable" } }
gooey.add('darkMode', false, {
  labels: {  
    true: { state: 'dark', verb: 'Enable dark mode' },  
    false: { state: 'light', verb: 'Enable light mode' }  
  }  
})
Some more advanced stuff you can do with switch inputs:
// Binding to an object property
const data = { enabled: true }
gooey.bind(data, 'enabled')

// Using onChange callback
gooey.add('toggle', false, {
  onChange: (v) => console.log('Toggled:', v)
})

// Dynamic disabled state
gooey.add('dynamicSwitch', true, {
  disabled: () => someCondition
})
You can bind to object properties, use callbacks, or pass a function to `disabled` for dynamic, programmatic toggling, for example.

Text

Text inputs provide a simple text input field with configurable character limits.
// explicit
gooey.addText('name', 'Alice')

// implicit
gooey.add('username', 'user123')

// binding
const data = { message: 'Hello' }
gooey.bind(data, 'message')

Text Options

  • maxLength|  maximum number of characters that can be entered
gooey.add('bio', 'Short bio', {
  maxLength: 10,  
})
Some more advanced stuff you can do with text inputs:
// Binding to an object property
const data = { name: 'Alice' }
gooey.bind(data, 'name', { maxLength: 20 })

// Using onChange callback
gooey.add('username', 'user', {
  onChange: (v) => console.log('New value:', v)
})

// Dynamic disabled state
gooey.add('dynamicText', 'editable', {
  disabled: () => someCondition
})
You can bind to object properties, use callbacks, or pass a function to `disabled` for dynamic, programmatic toggling, for example.

TextArea

TextArea inputs provide a multi-line text input field with configurable character limits.
// explicit
gooey.addTextArea('description', 'Enter text here...')

// implicit
gooey.add('notes', 'Some notes')

// binding
const data = { content: 'Hello\nWorld' }
gooey.bind(data, 'content')

TextArea Options

  • maxLength|  maximum number of characters that can be entered
    • @default 
      50
gooey.add('bio', 'Tell us about yourself...', {
  maxLength: 200,  
})
Some more advanced stuff you can do with textarea inputs:
// Binding to an object property
const data = { message: 'Multi-line\ntext here' }
gooey.bind(data, 'message', { maxLength: 100 })

// Using onChange callback
gooey.add('comment', 'Type here...', {
  onChange: (v) => console.log('Text changed:', v)
})

// Dynamic disabled state
gooey.add('dynamicTextArea', 'editable', {
  disabled: () => someCondition
})
You can bind to object properties, use callbacks, or pass a function to `disabled` for dynamic, programmatic toggling, for example.

Color

Color inputs provide a full-featured color picker with multiple format support.
// explicit
gooey.addColor('primary', '#FF0000')

// implicit
gooey.add('accent', '#00FF00')

// binding
const data = { color: '#0000FF' }
gooey.bind(data, 'color')

Color Options

  • mode    |  color format mode
    • @default 
      "hex"
  • expanded|  whether the color picker is initially expanded
    • @default 
      false
gooey.add('color', '#FF00FF', {
  mode: 'rgba',     
  expanded: true,   
})
Some more advanced stuff you can do with color inputs:
// Binding to an object property
const data = { bgColor: '#FF5733' }
gooey.bind(data, 'bgColor', { mode: 'hex' })

// Using onChange callback
gooey.add('theme', '#0088FF', {
  onChange: (color) => console.log('New color:', color.hex)
})

// Dynamic disabled state
gooey.add('dynamicColor', '#AABBCC', {
  disabled: () => someCondition
})
You can bind to object properties, use callbacks, or pass a function to `disabled` for dynamic, programmatic toggling, for example.

Gradient

Gradient inputs edit a list of colour stops. Drag a stop to move it, press the strip to add one, and drag one off the strip (or press Delete) to remove it. The selected stop's colour is edited with the colour picker below the strip.
// stops
gooey.addGradient('heat', [
  { offset: 0, color: '#3b82f6' },
  { offset: 0.35, color: '#14b8a6' },
  { offset: 0.6, color: '#eab308' },
  { offset: 0.8, color: '#f97316' },
  { offset: 1, color: '#ef4444' },
])

// bare colours, spaced evenly
gooey.addGradient('sunset', ['#ff7e5f', '#feb47b', '#86a8e7'])

// binding
const theme = { ramp: [{ offset: 0, color: '#000000' }, { offset: 1, color: '#ffffff' }] }
gooey.bindGradient(theme, 'ramp')

Using the value

The value is plain { offset, color } stops, sorted by offset (0..1), so it saves and serializes as-is. gradientToString renders it as CSS, and sampleGradient reads the colour at any point along it.
import { gradientToString, sampleGradient } from 'gooey'

const usage = gooey.addGradient('usage', ['#3b82f6', '#22c55e', '#eab308', '#ef4444'])
const level = gooey.addNumber('level', 0.29, { min: 0, max: 1, step: 0.01 })

const paint = () => {
  swatch.style.background = sampleGradient(usage.value, level.value)
  bar.style.background = gradientToString(usage.value)
}
usage.on('change', paint)
level.on('change', paint)

Gradient Options

  • step    |  the increment a dragged stop snaps to, and the arrow keys move by
    • @default 
      0.01
  • mode    |  the selected stop's colour format
    • @default 
      "hex"
  • expanded|  whether the selected stop's colour picker starts open
    • @default 
      false

Bezier

Bezier inputs edit a cubic bézier easing curve: a graph with two draggable control points, a field for each of the four numbers, and a dropdown of named easings. The value is [x1, y1, x2, y2], the four arguments of CSS cubic-bezier().
// control points
gooey.addBezier('ease', [0.16, 1, 0.3, 1])

// binding: a CSS string stays a string
const params = {
  curve: 'cubic-bezier(0.4, 0, 0.2, 1)',
}
gooey.bindBezier(params, 'curve')
Drag a control point to reshape the curve; hold shift shift while dragging to snap to 0.05. Hovering a curve in the open dropdown previews it, and after each change a dot runs along the curve so you can feel the easing.
The value can also start as a CSS keyword like 'ease-out'. add won't guess a bezier: four numbers are an array like any other, so use addBezier or bindBezier.

Using the value

bezierToString renders the value as a CSS cubic-bezier() string, and cubicBezier turns it into an easing function for JavaScript animation.
import {
  bezierToString,
  cubicBezier,
} from 'gooey'

const ease = gooey.addBezier(
  'ease',
  [0.34, 1.56, 0.64, 1],
)

// ball and label: any two elements on your page
const play = () => {
  const css = bezierToString(ease.value)
  label.textContent = css
  ball.style.transition = 'none'
  ball.style.left = '0%'
  ball.offsetWidth // restart it
  ball.style.transition = `left 1s ${css}`
  ball.style.left = 'calc(100% - 1rem)'
}
ease.on('change', play)
gooey.addButton('play', play)

// or in JS: y at x = 0.5
cubicBezier(...ease.value)(0.5)

Bezier Options

  • easings |  the named curves in the dropdown, as { name: [x1, y1, x2, y2] }; false hides it
    • @default 
      BEZIER_EASINGS (the CSS keywords, plus out-expo, out-quint and out-back)
  • yMin    |  the lowest y a control point can be dragged to; below 0 allows anticipation
    • @default 
      -0.5
  • yMax    |  the highest y a control point can be dragged to; above 1 allows overshoot
    • @default 
      1.5
  • step    |  the increment a drag snaps to, and the step of the number fields
    • @default 
      0.01
  • preview |  whether a dot runs along the curve after each change
    • @default 
      true
  • previewDuration|  how long one preview run lasts, in milliseconds
    • @default 
      750
Only dragging is clamped to yMin / yMax: set takes any y, as CSS does, and the graph grows to fit it. x1 and x2 are always clamped to 0..1.

Select

Select inputs provide a dropdown menu for choosing from a list of options.
// explicit
gooey.addSelect('theme', 'dark', ['light', 'dark', 'auto'])

// implicit with inline options
gooey.add('size', { value: 'medium', options: ['small', 'medium', 'large'] })

// binding
const data = { mode: 'easy' }
gooey.bind(data, 'mode', { options: ['easy', 'normal', 'hard'] })

Select Options

  • options |  array of available options
  • labelKey|  key to use as label for object options
    • @default 
      auto-detects "label" or "title" properties
// String options
gooey.add('fruit', 'apple', {
  options: ['apple', 'banana', 'orange']  
})

// Labeled options
gooey.add('country', { label: 'USA', value: 'us' }, {
  options: [  
    { label: 'USA', value: 'us' },  
    { label: 'Canada', value: 'ca' }  
  ]  
})
Some more advanced stuff you can do with select inputs:
// Object options with labelKey
const users = [
  { name: 'Alice', id: 1 },
  { name: 'Bob', id: 2 }
]
gooey.add('user', users[0], {
  options: users,
  labelKey: 'name'
})

// Using onChange callback
gooey.add('choice', 'a', {
  options: ['a', 'b', 'c'],
  onChange: (v) => console.log('Selected:', v)
})

// Dynamic disabled state
gooey.add('dynamicSelect', 'opt1', {
  options: ['opt1', 'opt2', 'opt3'],
  disabled: () => someCondition
})
You can use labeled options, specify a labelKey for objects, use callbacks, or pass a function to `disabled` for dynamic, programmatic toggling, for example.

Button

Button inputs execute functions when clicked.
// explicit with text
gooey.addButton('Click me', () => console.log('clicked'))

// implicit with function
gooey.add('action', () => alert('Action!'))

// with custom text
gooey.add('Custom', {
  text: 'Do something',
  onClick: () => console.log('done')
})

Button Options

  • text    |  button label text (can be a string or function)
    • @default 
      "click me"
  • onClick |  function to execute when clicked
let count = 0
gooey.add('counter', {
  text: () => `Clicked ${count} times`,  
  onClick: () => count++  
})
Some more advanced stuff you can do with button inputs:
// Programmatically trigger click
const button = gooey.add('trigger', () => console.log('triggered'))
button.click()

// Access button context
gooey.add('context', function() {
  console.log('Button instance:', this)
})

// Dynamic disabled state
gooey.add('dynamicButton', () => alert('Enabled!'), {
  disabled: () => someCondition
})
You can programmatically trigger clicks, access the button context, or pass a function to `disabled` for dynamic, programmatic toggling, for example.

ButtonGrid

ButtonGrid inputs display a 2D grid of clickable buttons. Unlike other inputs, ButtonGrid must be created explicitly using addButtonGrid — it cannot be inferred via add() because TypeScript cannot distinguish 2D arrays from regular arrays at compile time.
gooey.addButtonGrid('grid', [
  [
    { text: 'A', onClick: () => console.log('A') },
    { text: 'B', onClick: () => console.log('B') }
  ],
  [
    { text: 'C', onClick: () => console.log('C') },
    { text: 'D', onClick: () => console.log('D') }
  ]
])

ButtonGrid Options

  • value   |  2D array of button configurations (rows × columns)
  • applyActiveClass|  apply "active" class to clicked buttons
    • @default 
      true
  • multiple|  allow multiple buttons to be active simultaneously
    • @default 
      false
let selected = 'A'
gooey.addButtonGrid('selector', [
  [
    { text: 'A', onClick: () => selected = 'A' },
    { text: 'B', onClick: () => selected = 'B' }
  ]
], {
  multiple: false,  
  applyActiveClass: true  
})
Some more advanced stuff you can do with button grid inputs:
// Multi-select grid
const selected = new Set()
gooey.addButtonGrid('multiGrid', [
  [
    { id: '1', text: '1', onClick: () => selected.add('1') },
    { id: '2', text: '2', onClick: () => selected.add('2') }
  ],
  [
    { id: '3', text: '3', onClick: () => selected.add('3') },
    { id: '4', text: '4', onClick: () => selected.add('4') }
  ]
], { multiple: true })

// Grid with tooltips
gooey.addButtonGrid('tooltipGrid', [
  [
    { text: 'ℹ️', onClick: () => {}, tooltip: { text: 'Info' } },
	{ text: '⚙️', onClick: () => {}, tooltip: { text: 'Settings' } },
  ]
])
You can create multi-select grids, add tooltips to buttons, or track selected button IDs programmatically.