Not Particularly Meaningful


    2.4.1 • Public • Published

    Flourish controls

    Add interchangeable controls (dropdown, buttons or slider) to a page.

    How to install

    npm install -s @flourish/controls

    Add one or more control objects to your template state:

    export var state = {
    	controls: {},

    Import @flourish/controls into your template.yml settings.


    Initialise the control outside any function:

    import initControls from "@flourish/controls";
    var control = initControls(state.controls);

    You can also pass in optional functions for getting parsing and formatting functions. The former is required if you want to use user input and the user is using "," as the decimal separator. The latter is required if you want to format numbers to use "," as a decimal separator. For example:

    import initLocalization from "@flourish/number-localization";
    import initFormatter from "@flourish/number-formatter";
    import state from "../core/state";
    localization = initLocalization(state.localization);
    formatter = initFormatter(state.formatting);
    function getParser() {
    	return localization.getParser();
    function getFormatter() {
    	return formatter(localization.getFormatterFunction());
    var control = init(state.controls, getParser, getFormatter);

    Append the control to a container and add an on change handler: controls.appendTo(container).on("change", update);. This is usually done in the draw function.

    In update you typically want to update the set of options and then call the controls own update method: controls.options(options).update();.


    appendTo(parent_container, [bounding_container])

    Appends the control to the parent_container DOM node and injects CSS into the head if necessary. The optional bounding_container makes sure the dropdown list will never overflow outside that container.

    Returns the control object.


    Returns the index of the currently chosen value in a sorted version of the options array.


    With no argument returns the (unsorted) index of the currently selected option. If i is specified and corresponds to an index into the options array, sets the currently selected option to i. Returns the control object.


    Returns the current number of options.

    on(event, callback)

    Add callback to the list of event handlers. Currently the only supported event is "change". Returns the control object.


    With no argument returns a copy of the current list of options displayed by the current control. With an array, replaces the current options with a copy of arr and returns the control object.


    Removes the control (and its resize event handler) from the DOM. Returns the control object.


    Calls all the handlers assigned to event and returns the control object. Currently the only supported event type is "change".


    Rebuilds the control with latest settings. Returns the control object.


    With no argument returns the string value of the currently selected option. With val present changes the current index to match that of val in the options array and returns the control object. If val is not in the options array then nothing is changed but the control object is still returned.


    Returns the container of the control that has been created. It will have a class of "fl-controls-container"

    Styling the controls

    The controls have very basic styling. You can overwrite these styles with your own css and styling. We recommend using @flourish/ui-styles to style the controls.




    npm i @flourish/controls

    DownloadsWeekly Downloads






    Unpacked Size

    325 kB

    Total Files


    Last publish


    • axwalker
    • shar.k
    • flourish-canva
    • declanvong
    • pinkopunko
    • vee_canva
    • florin.oprina
    • robinhouston
    • duncanclark
    • daanlouter
    • timbrock
    • hughsk
    • mark-kiln
    • animateddata
    • larsvers
    • luptilu
    • bobbysebolao
    • liakouras
    • oliviajanelawlor
    • hrobertson
    • eademoon
    • qubyte
    • chrisnewell
    • oampo
    • sebr
    • alextreppass
    • wearymonkey
    • mattcarter-canva
    • marcfallows
    • mafecafe
    • connormj
    • simonaats