Skip to content

Type and renderer

Here you can choose which type and renderer to use as well as override their default configuration if necessary.

keytypedescriptiondefault value
type.namestring*Name of the type to use, for example text, select, checkbox or radio'text'
type.configobject*The type's config (See each type for what kind of config they accept){}
renderer.namestring*Name of the renderer to use, for example popup or inlinepopup
renderer.configobject*The renderer's config (See each renderer for what kind of config they accept){}

Renderers

Flyter ships with 2 renderers which you can use out of the box.

INFO

Note that some configuration type are marked with *, this means that they can also take an (async) callback which returns an value of the expected type, which takes the renderer as single parameter.

Inline renderer

You can use it by setting renderer.name = inline. This renderer will hide the field and display the edition input when editing.

keytypedescriptiondefault value
closeOnClickOutsideboolean*Close the edition session when clicked outsidetrue
inlineTemplatestring*Template used by the rendererSee below
containerClassstring*A class that will be added to the inline renderer container''
onInitasync (renderer) => anyCalled when the renderer is initialized() => null
onShowasync (renderer) => anyCalled when the renderer becomes visible() => null
onHideasync (renderer) => anyCalled when the renderer is removed from the DOM() => null

Default renderer markup is the following:

html
<div class="flyter-inline">
  <div class="flyter-inline-content" data-flyter-inline-container>
    <!-- Will contain type and actions -->
  </div>
  <div class="flyter-inline-loading" data-flyter-inline-loading>Loading</div>
  <div class="flyter-inline-error" data-flyter-inline-error>
    <!-- if error, will display it here -->
  </div>
</div>

You can use it by setting renderer.name = popup. This renderer depends on Popperjs to work. If you include it in your webpage, flyter will automatically find it from window.popper. Otherwise you have to manually provide it like so:

js
import flyter from 'flyter';
import { createPopper } from '@popperjs/core';

flyter.attach('div', {
  renderer: {
    name: 'popup',
    config: {
      popper: createPopper,
    }
  }
});
keytypedescriptiondefault value
closeOnClickOutsideboolean*Close the edition session when clicked outsidetrue
poppercreatePopperThe popper builder`window.Popper.createPopper
popperConfigobject*Some additional config to pass to popper, such as placement{ placement: 'top' }
transitionDurationnumber*Duration in milliseconds of the renderer fade transition300
titlestring*Add a title to the popupnull
popupTemplatestring*Template used by the rendererSee below
popupClassstring*Add a class to the renderer container''
popupContainerstring | HTMLElement*Specify the HTML node that will contain the popup'body'
onInitasync (renderer) => anyCalled when the renderer is initialized() => null
onShowasync (renderer) => anyCalled when the renderer becomes visible() => null
onHideasync (renderer) => anyCalled when the renderer is removed from the DOM() => null

Types

Flyter ships with 4 types by default which have their own configuration you can override by setting type.config.

TextType

You can use it by setting type.name = text

keytypedescriptiondefault value
classstringA class that will be set on the input''
typestringthe input type, for example text, textarea, number, date...'text'
attributesstringSome additional attributes to set on the input''
treatEmptyAsNullbooleanWether to treat an empty string as a null valuetrue

SelectType

You can use it by setting type.name = select

keytypedescriptiondefault value
classstringA class that will be set on the input''
dataSourceArray<{ value: string, label: string }>The possible values. Can also be a callback or an async callback that returns an array.[]
multiplebooleanWhether the input is in multiple mode or notfalse
showEmptyValuebooleanShow an empty value which maps to the emptyValuefalse
displaySeparatorstringSeparator when displaying multiple values','

Here is a configuration example using the select type.

js
flyter.attach('div', {
  type: {
    name: 'select',
    config: {
      multiple: false,
      showEmptyValue: true,
      dataSource: async () => {
        return new Promise((resolve) => {
          setTimeout(() => resolve([
            { label: "isnt it cool", value: "cool" },
            { label: "Yeah no", value: "not cool" }
          ]), 1000);
        });
      }
    },
  }
});

CheckboxType

You can use it by setting type.name = checkbox

keytypedescriptiondefault value
classstringA class that will be set on the input''
dataSourceArray<{ value: string, label: string }>The possible values. Can also be a callback or an async callback that returns an array.[]
inputContainerClassstringEach [checkbox, label] is wrapped in a div, you can add a class to it''
checkboxClassstringAdd a class to each displayed checkbox''
labelClassstringAdd a class to each displayed label''
displaySeparatorstringSeparator when displaying multiple values','

RadioType

You can use it by setting type.name = radio

keytypedescriptiondefault value
classstringA class that will be set on the input''
dataSourceArray<{ value: string, label: string }>The possible values. Can also be a callback or an async callback that returns an array.[]
inputContainerClassstringEach [radio, label] is wrapped in a div, you can add a class to it''
radioClassstringAdd a class to each displayed radio input''
labelClassstringAdd a class to each displayed label''