Back

addAccordion

JS Py
Hello World
Content:
- Examples
- Properties
- Methods

Adds an accordion or expansion panel into your app.

acc = ui.addAccordion( parent, titles, options?, width?, height? ) → ui object: Accordion

Here are the methods available for Accordion Component.

Examples

Example - Complete accordion implementation

class Main extends App
{
    onStart()
    {
        // Creates a fullscreen main layout.
        this.main = ui.addLayout( "main", "Linear", "VCenter", 1, 1 )

        this.accords = [ "Accordion 1", "Accordion 2", "Accordion 3" ]

        // Adds an accordion to the main layout
        this.acc = ui.addAccordion( this.main, this.accords, "", 0.9 )

        // Secondary text to display
        var secTxt = [
            "This is the secondary text 1",
            "This is the secondary text 2",
            "This is the secondary text 3"
        ]

        // sets the secondary text
        this.acc.setSecondaryText( secTxt )

        // Add ontouch event handler to the accordion
        this.acc.setOnTouch( this.onTouch )

        // Add controls to the first accordion layout
        this.lay1 = this.acc.getLayout( 0 )
        this.txt = ui.addText(this.lay1, "This is a text in the first layout.")

        // Add controls to the second layout
        this.lay2 = this.acc.getLayout( 1 )
        this.btn = ui.addButton(this.lay2, "Button", "Primary")

        // Add controls to the third layout
        this.lay3 = this.acc.getLayout( 2 )
        this.tfd = ui.addTextField(this.lay3, "", "Outlined", 0.3)
        this.tfd.label = "Enter some text"
    }

    onTouch(index, expand)
    {
        var msg = `${this.accords[index]} is ${expand ? "open" : "close"}`
        ui.showPopup( msg )
    }
}
from hybrid import ui

def OnStart():
    global accords
    # Creates a fullscreen main layout.
    main = ui.addLayout("main", "Linear", "VCenter", 1, 1)

    accords = ["Accordion 1", "Accordion 2", "Accordion 3"]

    # Adds an accordion to the main layout
    acc = ui.addAccordion(main, accords, "", 0.9)

    # Secondary text to display
    secTxt = [
        "This is the secondary text 1",
        "This is the secondary text 2",
        "This is the secondary text 3"
    ]

    # sets the secondary text
    acc.setSecondaryText(secTxt)

    # Add ontouch event handler to the accordion
    acc.setOnTouch(onTouch)

    # Add controls to the first accordion layout
    lay1 = acc.getLayout(0)
    txt = ui.addText(lay1, "This is a text in the first layout.")

    # Add controls to the second layout
    lay2 = acc.getLayout(1)
    btn = ui.addButton(lay2, "Button", "Primary")

    # Add controls to the third layout
    lay3 = acc.getLayout(2)
    tfd = ui.addTextField(lay3, "", "Outlined", 0.3)
    tfd.label = "Enter some text"

def onTouch(index, expand):
    msg = f"{accords[index]} is {'open' if expand else 'close'}"
    ui.showPopup(msg)
Copy All       Run      

Example - Items manipulation

class Main extends App
{
    onStart()
    {
        this.count = 1;

        // Creates a fullscreen main layout.
        this.main = ui.addLayout( "main", "Linear", "VCenter", 1, 1 )
        this.main.setChildMargins(0, 0.01, 0, 0.01)

        var accords = [ "Accordion 1", "Accordion 2", "Accordion 3" ]

        // Adds an accordion to the main layout
        this.acc = ui.addAccordion( this.main, accords, "", 0.9 )

        this.lay = ui.addLayout(this.main, "Linear", "Horizontal", 0.9)
        this.lay.childSpacing = "evenly"

        // add a button controls to add or remove accordion item
        this.btn1 = ui.addButton( this.lay, "Append Item" )
        this.btn1.setOnTouch( this.btn1_onTouch )

        this.btn2 = ui.addButton( this.lay, "Add Item in index 1" )
        this.btn2.setOnTouch( this.btn2_onTouch )

        this.btn3 = ui.addButton( this.lay, "Remove Item" )
        this.btn3.setOnTouch( this.btn3_onTouch )
    }

    btn1_onTouch()
    {
        // add an item at the bottom of the accordion
        this.acc.addItem( "New Bottom Title", "New secondary text" )
    }

    btn2_onTouch()
    {
        var title = "New Title " + this.count++
        // insert item in the second index
        this.acc.addItem( title, "New secondary text", 1 )
    }

    btn3_onTouch()
    {
        this.acc.removeItemByIndex( 2 )
        ui.showPopup( "Second item is removed" )
    }
}
from hybrid import ui

def OnStart():
    global acc, count
    count = 1

    # Creates a fullscreen main layout.
    main = ui.addLayout("main", "Linear", "VCenter", 1, 1)
    main.setChildMargins(0, 0.01, 0, 0.01)

    accords = ["Accordion 1", "Accordion 2", "Accordion 3"]

    # Adds an accordion to the main layout
    acc = ui.addAccordion(main, accords, "", 0.9)

    lay = ui.addLayout(main, "Linear", "Horizontal", 0.9)
    lay.childSpacing = "evenly"

    # add a button controls to add or remove accordion item
    btn1 = ui.addButton(lay, "Append Item")
    btn1.setOnTouch(btn1_onTouch)

    btn2 = ui.addButton(lay, "Add Item in index 1")
    btn2.setOnTouch(btn2_onTouch)

    btn3 = ui.addButton(lay, "Remove Item")
    btn3.setOnTouch(btn3_onTouch)

def btn1_onTouch(event):
    # add an item at the bottom of the accordion
    acc.addItem("New Bottom Title", "New secondary text")

def btn2_onTouch(event):
    title = "New Title " + str(count)
    # insert item in the second index
    acc.addItem(title, "New secondary text", 1)
    count += 1

def btn3_onTouch(event):
    acc.removeItemByIndex(2)
    ui.showPopup("Second item is removed")
Copy All       Run      

Example - Custom styles

class Main extends App
{
    onStart()
    {
        // Creates a fullscreen main layout.
        this.main = ui.addLayout("main", "Linear", "VCenter")

        var items = ["Accordion 1", "Accordion 2", "Accordion 3"]
        var texts = ["Description for item 1", "Description for item 2", "Description for item 3"];

        // Adds an accordion to the main layout
        this.acc = ui.addAccordion(this.main, items, "", 0.9)
        this.acc.setSecondaryText( texts )

        // Sets the background color
        this.acc.backColor = "#b2dfdb"

        // Sets the text-sizes
        this.acc.textSize1 = 18
        this.acc.textSize2 = 14

        // Sets the text colors
        this.acc.textColor1 = "#00695c"
        this.acc.textColor2 = "#009688"

        // Sets the corner radius
        this.acc.cornerRadius = 14

        // Sets the expand icon
        this.acc.expandIcon = "favorite"
    }
}
from hybrid import ui

def OnStart():
    # Creates a fullscreen main layout.
    main = ui.addLayout("main", "Linear", "VCenter")

    items = ["Accordion 1", "Accordion 2", "Accordion 3"]
    texts = ["Description for item 1", "Description for item 2", "Description for item 3"]

    # Adds an accordion to the main layout
    acc = ui.addAccordion(main, items, "", 0.9)
    acc.setSecondaryText(texts)

    # Sets the background color
    acc.backColor = "#b2dfdb"

    # Sets the text-sizes
    acc.textSize1 = 18
    acc.textSize2 = 14

    # Sets the text colors
    acc.textColor1 = "#00695c"
    acc.textColor2 = "#009688"

    # Sets the corner radius
    acc.cornerRadius = 14

    # Sets the expand icon
    acc.expandIcon = "favorite"
Copy All       Run      

Properties

The following properties are available on the Accordion object:

absHeightNumber
absLeftNumber
absTopNumber
absWidthNumber
backColorString
backImageString
borderNumber
borderColorString
borderStyleString
cornerRadiusNumber
disabledBoolean
elObject
elStyleString
expandIconString
fontFileString
heightNumber
isVisibleBoolean
itemPaddingList
leftNumber
marginsList
opacityNumber
optionsString
paddingList
parentObject
positionObject
rotationNumber
roundedBoolean
secondaryTextList
textColorString
textColor1String
textColor2String
textSizeNumber
textSize1Number
textSize2Number
titlesList
titleWidthNumber
toggleNumber
topNumber
typeString
visibilityString
widthNumber

Methods

The following methods are available on the Accordion object:

getEnabled( index ) → Boolean
getEnabledByName( name ) → Boolean
getLayout( index ) → Object
getLayoutIndex( layout ) → Number
getPosition( options ) → Object
gone()
hide()
setScale( x, y )
show()
Boolean: Values can be `true` or `false`.
Number: Fraction of the parent width `[0-1]`.
Number: Fraction of the parent height `[0-1]`.
Number: The index at which the accordion item will be added. If `null`,  the item will be added at the bottom of the accordion.
Number: The time in milliseconds.
Number: The z-index. A negative value behaves like `sendBackward` method.
Number: The index of the accordion item.
Number: The index of the accordion. You can also pass accordion title.
Number: The index of the corresponding accordion to remove.
Number: The z-index. A positve value behaves like `bringForward` method.
Number: Border-left thickness in pixels.
Number: Border-top thickness in pixels.
Number: Border-right thickness in pixels.
Number: Border-bottom thickness in pixels.
Number: Top-left corner radius.
Number: Top-right corner radius.
Number: Bottom-left corner radius.
Number: Bottom-right corner radius.
Number: The index of the corresponding accordion.
Number: Left padding of the accordion item.
Number: Top padding of the accordion item.
Number: Right padding of the accordion item.
Number: Bottom padding of the accordion item.
Number: Left margin. You can also pass string e.g. `12rem`
Number: Top margin. You can also pass string e.g. `12rem`
Number: Right margin. You can also pass string e.g. `12rem`
Number: Bottom margin. You can also pass string e.g. `12rem`
Number: Fraction of the component width.
Number: Fraction of the component height. [0-1]
Number: Fraction of the component width. [0-1]
Number: Fraction of the parent width. [0-1]
Number: Fraction of the parent height. [0-1]
Number: The x-scale of the component.Values less than `0` is smaller than the normal. While values greater than `1` is greater than the normal.
Number: The y-scale of the component. Values less than `1` is smaller than the normal. While vaues greater than `1` is greater than the normal.
Number: If `index` is provided,  the corresponding index will be updated with the new text.
Number: The index of the corresponding title to updates.
String: “A comma separated options.
Style: `Square`
Layout type: `Linear`”
, “ `Absolute`”
String: “Accordion title”
String: “Accordion secondary text”
String: “The type of animation. Here are the available values
`bounce`”
, “ `flash`”, “ `pulse`”, “ `rubberBand`”, “ `shakeX`”, “ `shakeY`”, “ `headShake`”, “ `swing`”, “ `tada`”, “ `wobble`”, “ `jello`”, “ `heartBeat`”,
Back Entrances: `backInDown`”
, “ `backInLeft`”, “ `backInRight`”, “ `backInUp`
Back Exits: `backOutDown`”
, “ `backOutLeft`”, “ `backOutRight`”, “ `backOutUp`
Bouncing Entrances: `bounceIn`”
, “ `bounceInDown`”, “ `bounceInLeft`”, “ `bounceInRight`”, “ `bounceInUp`
Bouncing exits: `bounceOut`”
, “ `bounceOutDown`”, “ `bounceOutLeft`”, “ `bounceOutRight`”, “ `bounceOutUp`
Fading entrances: `fadeIn`”
, “ `fadeInDown`”, “ `fadeInDownBig`”, “ `fadeInLeft`”, “ `fadeInLeftBig`”, “ `fadeInRight`”, “ `fadeInRightBig`”, “ `fadeInUp`”, “ `fadeInUpBig`”, “ `fadeInTopLeft`”, “ `fadeInTopRight`”, “ `fadeInBottomLeft`”, “ `fadeInBottomRight`
Fading exits: `fadeOut`”
, “ `fadeOutDown`”, “ `fadeOutDownBig`”, “ `fadeOutLeft`”, “ `fadeOutLeftBig`”, “ `fadeOutRight`”, “ `fadeOutRightBig`”, “ `fadeOutUp`”, “ `fadeOutUpBig`”, “ `fadeOutTopLeft`”, “ `fadeOutTopRight`”, “ `fadeOutBottomRight`”, “ `fadeOutBottomLeft`
Flippers: `flip`”
, “ `flipInX`”, “ `flipInY`”, “ `flipOutX`”, “ `flipOutY`
Lightspeed: `lightSpeedInRight`”
, “ `lightSpeedInLeft`”, “ `lightSpeedOutRight`”, “ `lightSpeedOutLeft`
Rotating Entrances: `rotateIn`”
, “ `rotateInDownLeft`”, “ `rotateInDownRight`”, “ `rotateInUpLeft`”, “ `rotateInUpRight`
Rotating Exits: `rotateOut`”
, “ `rotateOutDownLeft`”, “ `rotateOutDownRight`”, “ `rotateOutUpLeft`”, “ `rotateOutUpRight`
Specials: `hinge`”
, “ `jackInTheBox`”, “ `rollIn`”, “ `rollOut`
Zooming Entrances: `zoomIn`”
, “ `zoomInDown`”, “ `zoomInLeft`”, “ `zoomInRight`”, “ `zoomInUp`
Zooming Exits: `zoomOut`”
, “ `zoomOutDown`”, “ `zoomOutLeft`”, “ `zoomOutRight`”, “ `zoomOutUp`
Sliding Entrances: `slideInDown`”
, “ `slideInLeft`”, “ `slideInRight`”, “ `slideInUp`
Sliding Exits: `slideOutDown`”
, “ `slideOutLeft`”, “ `slideOutRight`”, “ `slideOutUp`”
String: “The title of the accordion.”
String: “The mode of the measurements. Values can be `px` or `%`”
String: “The title of the corresponding accordion to remove.”
String: “Border color in hexadecimal format `#rrggbb`.”
String: “Border-styles. Values can be `dotted`”, “ `dashed`”, “ `solid`”, “ `double`”, “ `groove`”, “ `ridge`”, “ `inset` and `outset`. Default is `solid`”
String: “Unit of measurement. Values are `px` `rem` or `%`.”
String: “The title of the accordion”
String: “A material icon”
String: “Unit of measurement. Can be `rem`”, “ `px`”, “ `%`”, “ or `v` for viewport.”
String: “Unit of measurement.
`rem` for root em.
`px` for pixels
`%` relative to its parent dimension.
`v` relative to viewport dimension.”
String: “Unit of measurement.
`rem` for root em.
`px` for pixels
`%` relative to its parent dimensions
`v` relative to viewport dimensions.”
String: “Unit of measurment. Can be "px"”, “ "rem"”, “ "%"”, “ "v" for viewport width/height or any css supported unit.”
String: “Color of the title text in hexadecimal format `#rrggbb`”
String: “Color of the secondary text in hexadecimal format `#rrggbb`”
String: “The new title text.”
Object: The parent layout where to add the text.
Object: The layout to check.
Object: The position of the touch event.
List: An array of accordion titles.
List: The secondary text to display. You can also pass arguments as a comma separated string.
function( title , index , pos )
function( index , expand )
acc.absHeight
Returns the absolute height of the control in pixels.
acc.absLeft
Returns the absolute distance of the control from the left in pixels.
acc.absTop
Returns the absolute distance of the control from the top in pixels.
acc.absWidth
Returns the absolute width of the control in pixels.
acc.addItem
Adds an item to the accordion.
acc.animate
Animate the component.
acc.backColor
A hexadecimal color of the form #rrggbb
acc.backImage
The path to your image file.
acc.border
Sets or returns the border thickness in pixels.
acc.borderColor
Sets or returns the border color. Color is in hexadecimal form #rrggbb
acc.borderStyle
Sets or returns the border style. Values can be dotted, dashed, solid, double, groove, ridge, inset and outset. Default is solid.
acc.bringForward
Bring this component forward by a given z-index.
acc.cornerRadius
Sets or returns the corner radius in pixels.
acc.destroy
Destroy the component.
acc.disabled
Sets or returns the disabled state of the control.
acc.el
Returns the html container element for the control.
acc.elStyle
Sets the style of the html container element.
acc.expandIcon
Sets or returns the material icon font for the expand icon.
acc.fontFile
Sets or returns the relative path to the font-family use.
acc.getEnabled
Get the enabled state of an accordion item by its index.
acc.getEnabledByName
Get the enabled state of an accordion item by its name.
acc.getLayout
Get the layout of the corresponding accordion item. This is very useful when you add a control or component that will be displayed when the accordion collapse.
acc.getLayoutIndex
Get the index of the corresponding layout.
acc.getPosition
Returns the position of the component. The return object is of the form {left, top, right, bottom}
acc.gone
Destroy the component.
acc.height
Sets or returns the height of the control as a fraction of the parent control.
acc.hide
Hide the component.
acc.isVisible
Returns whether the control is visible or not.
acc.itemPadding
Sets or returns the padding of each accordion item. See also setItemPadding method.
acc.left
Returns the distance of the control from the left.
acc.margins
Sets or returns the margin of the control. Works on controls with Linear parent only. You can also pass a number to set equal margins for all sides.
acc.opacity
Sets or returns the opacity of the control.
acc.options
Sets or returns the options of the control.
acc.padding
Sets or returns the padding of the control. You can also pass a number to set equal padding for all sides.
acc.parent
Returns the parent layout control.
acc.popItem
Removes the last accordion item. This will return the item being removed.
acc.position
Returns the position of the control. The returned object has left top right and bottom props.
acc.removeItemByIndex
Removes accordion item by its index.
acc.removeItemByName
Removes accordion item by its title name.
acc.rotation
Sets or returns the angle of rotation in degrees.
acc.rounded
Sets or returns whether the accordion is rounded or not.
acc.secondaryText
Sets or returns the secondary text of the accordion items. See also setSecondaryText method.
acc.sendBackward
Bring this component backward by a given z-index.
acc.setBorder
Sets the border line for the component container.
acc.setCornerRadius
Sets the corner radius of the top and bottom accordion panels.
acc.setEnabled
Enable or disable the accordion component or an item in the accordion component.
acc.setEnabledByName
Enable or disable an accordion item by its name.
acc.setExpandIcon
Sets the expand icon at the right of the accordion.
acc.setItemPadding
Sets the padding of the accordion item. See itemPadding property for equivalent setter/getter property.
acc.setMargins
Sets the margin of the component.
acc.setOnContextMenu
Adds a callback function on right click.
acc.setOnTouch
Sets a callback function when the accordion is touch.
acc.setPadding
Sets the padding of the component's container.
acc.setPosition
Sets the position of the component relative to its parent dimensions.
acc.setScale
Sets the x and y scaling of the component. This will ignore the positioning and flow of controls in the layout.
acc.setSecondaryText
Adds a secondary text on the accordion.
acc.setSize
Sets the size of the component.
acc.setTextColor
Sets the color of the title and the secondary text respectively.
acc.setTitleText
Update the accordion title by passing its corresponding index.
acc.shiftItem
Removes the first accordion item. This will return the item being removed.
acc.show
Show the component.
acc.textColor
Sets or returns the color of the text.
acc.textColor1
Sets or returns the title text color in hexadecimal format #rrggbb
acc.textColor2
Sets or returns the secondary text color in hexadecimal format #rrggbb
acc.textSize
Sets or returns the size of the text within the control.
acc.textSize1
Sets or returns the accordion title text size.
acc.textSize2
Sets or returns the accordion secondary text size.
acc.titles
Sets or returns the list of titles for the accordion panel. Each element of the titles array is a string.
acc.titleWidth
Sets and returns the width of the title as fraction. Useful when you have a long title.
acc.toggle
Collapse or shrink a corresponding accordion by its index.
acc.top
Returns the distance of the control from the top.
acc.type
Returns the type of the control.
acc.visibility
Sets or returns the visibility of the control.
acc.width
Sets or returns the width of the control as a fraction of the parent control.