Published
Edited
Nov 29, 2021
1 fork
Importers
4 stars
Insert cell
Insert cell
Insert cell
function slider({
min = 0,
max = 1,
value,
step,
title,
description,
disabled,
display,
// TODO precision
// TODO format
// TODO getValue
// TODO submit
} = {}) {
return Inputs.range([min, max], {
value,
step,
label: title === undefined ? description : title,
format: display,
disabled
});
}
Insert cell
function button(config = {}) {
const {
value = "Ok",
title,
description,
disabled
} = typeof config === "string" ? {value: config} : config;
return Inputs.button(value, {
label: title === undefined ? description : title,
value,
reduce: value => value,
disabled
});
}
Insert cell
function select(config = {}) {
const {
value,
title,
description,
disabled,
multiple,
size,
options
} = Array.isArray(config) ? {options: config} : config;
return Inputs.select(options, {
value,
label: title === undefined ? description : title,
format: o => typeof o === "object" ? o.label : o,
keyof: o => typeof o === "object" ? o.label : o,
valueof: o => typeof o === "object" ? o.value : o,
disabled: disabled || options.filter(o => typeof o === "object" && o.disabled).map(o => o.value),
multiple: multiple && size ? size : multiple
});
}
Insert cell
function autoSelect(config = {}) {
const {
value,
title,
description,
disabled,
placeholder,
options,
// TODO size
// TODO autocomplete = "off"
// TODO list = "options"
} = Array.isArray(config) ? {options: config} : config;
return Inputs.text({
value,
label: title === undefined ? description : title,
disabled,
placeholder,
datalist: options
});
}
Insert cell
function _text(type, config = {}) {
const {
value,
title,
description,
disabled,
maxlength,
minlength,
placeholder,
submit,
// TODO pattern
// TODO size
// TODO autocomplete = "off"
// TODO getValue
} = typeof config === "string" ? {value: config} : config;
return Inputs.text({
type,
value,
label: title === undefined ? description : title,
disabled,
maxlength,
minlength,
placeholder,
submit
});
}
Insert cell
text = config => _text("text", config)
Insert cell
date = config => _text("datetime-local", config)
Insert cell
time = config => _text("datetime-local", config)
Insert cell
password = config => _text("password", config)
Insert cell
color = config => _text("color", config)
Insert cell
function radio(config = {}) {
const {
value,
title,
description,
options,
disabled,
// TODO submit
} = Array.isArray(config) ? {options: config} : config;
return Inputs.radio(options, {
value,
label: title === undefined ? description : title,
format: o => typeof o === "object" ? o.label : o,
keyof: o => typeof o === "object" ? o.label : o,
valueof: o => typeof o === "object" ? o.value : o,
disabled: disabled || options.filter(o => typeof o === "object" && o.disabled).map(o => o.value)
});
}
Insert cell
function checkbox(config = {}) {
let {
value,
title,
description,
disabled,
options,
// TODO submit
// TODO false / value when only a single option?
} = Array.isArray(config) ? {options: config} : config;
return Inputs.checkbox(options, {
value,
label: title === undefined ? description : title,
format: o => typeof o === "object" ? o.label : o,
keyof: o => typeof o === "object" ? o.label : o,
valueof: o => typeof o === "object" ? o.value : o,
disabled: disabled || options.filter(o => typeof o === "object" && o.disabled).map(o => o.value)
});
}
Insert cell
function number(config = {}) {
const {
value,
title,
description,
disabled,
placeholder,
step = "any",
min,
max,
// TODO submit
// TODO hide the range input?
} = typeof config === "number" || typeof config === "string" ? {value: +config} : config;
return Inputs.range([min, max], {
value,
placeholder,
label: title === undefined ? description : title,
disabled,
step
});
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more