Giter Site home page Giter Site logo

ironsidevsquincy / o-expander Goto Github PK

View Code? Open in Web Editor NEW

This project forked from financial-times/o-expander

0.0 2.0 0.0 81 KB

Simple, fairly unopinionated widget for expanding and collapsing content

Home Page: http://registry.origami.ft.com/components/o-expander

HTML 50.43% JavaScript 37.35% CSS 12.22%

o-expander's Introduction

o-expander

Accessible, content-aware widget for expanding and collapsing content

Markup

<div data-o-component="o-expander" class="o-expander">
    <div class="o-expander__content"></div>
    <button class="o-expander__toggle o--if-js"></button>
</div>

o-expander__toggle and o-expander__content can be put anywhere within o-expander as long as o-expander__toggle is not contained within o-expander__content. There are no restrictions on sibling markup.

API

Static methods

init(el, opts)

This generally sticks to the usual origami convention. If el is an HTMLElement with the attribute data-o-component="o-expander" a single instance will be created for that element and returned, otherwise an expander will be created for each o-expander element found within el, and an array of instances returned.

Instance methods

destroy()

Destroys an o-expander instance and removes all event listeners

Options

All the following can be passed in an options object in the second parameter of oExpander#init() or as data-attributes (hyphenated and prefixed by o-expander e.g. data-o-expander-shrink-to="height")

  • shrinkTo ['height']: A non-negative integer, indicating the number of items to show when collapsed, or the string 'height', which will collapse to a max-height defined in the CSS
  • countSelector ['.o-expander__content > li']: Selector for identifying items to count, relative to .o-expander
  • expandedToggleText ['less|fewer']: Text to show on toggle button when expanded (defaults to fewer when in count mode, or less when in height mode). Accepts empty strings
  • collapsedToggleText ['more']: Text to show on toggle button when collapsed. Accepts empty strings
  • toggleSelector['button.o-expander__toggle']: Selector for expand/collapse toggle button. When using the default selector some styling, with an arrow icon, will come for free. If the selector matches more than one element they will all have the ability to expand/collapse the expander
  • toggleState['all|aria|none']: Do you want the epxander to update the button's text and aria-pressed attribute, just the aria attribute or neither (defaults to all)

Events

o-expander fires the following events, which always fire before any repainting/layout occurs

  • oExpander.init - fires when the expander has initialised
  • oExpander.expand - fires when the expander expands
  • oExpander.collapse - fires when the expander collapses

Configuration using markup/CSS

  • By default o-expander will collapse content on initialisation. To prevent this add the attribute aria-expanded="true" to .o-expander__content

  • Maximum height (when collapsed) should be set using css. Be mindful that when js doesn't run you may want to default to showing all the content e.g.

    .o-js .o-expander__content { // ensures all content is shown when js doesn't run
        max-height: 50px;
    }
    
    .o-expander__content { // collapses content when js doesn't run
        max-height: 50px;
    }
  • Animation and other fancy behaviour can be added using css and by listening to events. See the demos for examples

o-expander's People

Contributors

wheresrhys avatar kaelig avatar

Watchers

Darren Hurley avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.