Skip to content

Repository files navigation

ctrl-panel

<ctrl-panel>

A simple control panel.

GitHubnpmnpmnpm bundle size


Why Build This

See my blog post on 9am.github.io

Every Animation Lover Needs A Control Panel

Features

  • 9 custom elements to choose.
  • 3 themes out of the box.
  • Control the value shape with the template.
  • Customize or make your own theme with CSS properties.

Elements

ElementScreenshotVarientDescriptionLive Demo
ctrl-panel--------------The root element.demo
ctrl-group--------------Group ctrl-* together to shape the value.demo
ctrl-sliderslider-1slider-2A numblic slider.demo
ctrl-clampclamp-1clamp-2Select a tuple low-high value.demo
ctrl-switchswitch-1switch-2A ON/OFF switch.demo
ctrl-radioradio-1radio-2Multiple/Single switch.demo
ctrl-vectorvectorSelect a tuple vector on a 2D surface.demo
ctrl-texttextText input.demo
ctrl-colorcolorColor picker.demo

Usage

Install

npm install @9am/ctrl-panel

HTML

<ctrl-paneltheme="neumorphism"><ctrl-slidername="slider">slider</ctrl-slider><ctrl-clampname="clamp">clamp</ctrl-clamp><ctrl-vectorname="vector">vector</ctrl-vector><ctrl-switchname="switch">switch</ctrl-switch><ctrl-radioname="radio"><ctrl-switchname="a">A</ctrl-switch><ctrl-switchname="b">B</ctrl-switch><ctrl-switchname="c" default="true">C</ctrl-switch></ctrl-radio><ctrl-groupname="group"><ctrl-textname="text">text</ctrl-text><ctrl-colorname="color">color</ctrl-color></ctrl-group></ctrl-panel>

Javascript

import'@9am/ctrl-panel';// import '@9am/ctrl-panel/theme.css'; // css to enable default themes.document.querySelector('ctrl-panel').addEventListener('CHANGE',(evt)=>{console.log('[panel value]:',evt.currentTarget.value);/* output: * { * slider: 5, * clamp: [0, 10], * vector: [0, 0], * switch: false, * radio: 'c', * group: { * text: '', * color: '#000000' * } * } */});

Documentation

<ctrl-group>

DocNameTypeDefaultDescription
attributename*stringrequiredvalue key
attributeorientationh | vhlayout direction
attributetypeobject | arrayobjectvalue shape
----
propertyget valueValue{}value
----
slotlabelhtml taglabel
slotdefaultctrl-*''value

<ctrl-panel>

DocNameTypeDefaultDescription
attributeextends <ctrl-group>------------
attributethemestringflattheme (flat | oldschool | neumorphism)
attributewidthcss lengthautopanel width
attributeheightcss lengthautopanel height
attributeplacementtop-left | top-right | bottom-left | bottom-right''if placement is set, panel will be positioned as fixed, and with a button to toggle the visibility.
----
propertyextends <ctrl-group>------------
----
slotextends <ctrl-group>------------

<ctrl-radio>

DocNameTypeDefaultDescription
attributeextends <ctrl-group>------------
attributemultiplebooleanfalseenable select multiple items
----
propertyextends <ctrl-group>------------
----
slotextends <ctrl-group>------------
slotdefaultctrl-switch''value

<ctrl-slider>

DocNameTypeDefaultDescription
attributename*stringrequiredvalue key
attributeorientationh | vhlayout direction
attributetyperange | knobrangeslider type
attributeminnumber0min value
attributemaxnumber10max value
attributestepnumber | 'any'1step interval
attributedefaultnumber5default value
----
propertyget valuenumber5value

<ctrl-clamp>

DocNameTypeDefaultDescription
attributeextends <ctrl-slider>------------
attributedefaultstring(JSON)'[0,10]'default value
----
propertyextends <ctrl-slider>------------
propertyget valuenumber[0,10]value
----
slotextends <ctrl-slider>------------

<ctrl-switch>

DocNameTypeDefaultDescription
attributename*stringrequiredvalue key
attributeorientationh | vhlayout direction
attributetyperange | toggletoggleslider type
attributedefaultbooleandefault value
----
propertyget valuenumberfalsevalue

<ctrl-text>

DocNameTypeDefaultDescription
attributename*stringrequiredvalue key
attributedefaultstring''default value
----
propertyget valuenumber''value

<ctrl-color>

DocNameTypeDefaultDescription
attributename*stringrequiredvalue key
attributeorientationh | vhlayout direction
attributedefaultstring#000000default value
----
propertyget valuenumber#000000value

Event

{type: 'CHANGE',detail: {name: string,// attribute 'name' of <ctrl-*>value: Value,// property 'value' of <ctrl-*>}}

License

MIT

Releases

Used by

Contributors

Languages