-
Notifications
You must be signed in to change notification settings - Fork 25
issue/2824-jsx JSX version of accordion #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d6695f6
issue/2824-jsx React version of accordion
olivermartinfoster a88494f
issue/2824-jsx var to const
oliverfoster 2631865
issue/2824-jsx Converted model to import/export directives
olivermartinfoster 2efb976
issue/2824-jsx switch to template string
oliverfoster 8a4848a
issue/2824-jsx removed preventDefault
olivermartinfoster 91c04e4
Merge branch 'master' into issue/2824-jsx
oliverfoster 17e2da0
issue/2824-jsx classes > array syntax, fixed typo in _id reference
olivermartinfoster 36a871d
issue/2824-jsx Removed unused variable
olivermartinfoster 3690efc
issue/2824-jsx Switched to altered syntax
olivermartinfoster 22cc033
issue/2824-jsx Fixed indentation to eslint rules
olivermartinfoster 2ef524f
issue/2824-jsx Added whitespace and changed block styling
olivermartinfoster 56d7fcb
issue/2824-jsx Added more whitespace
olivermartinfoster 40d1a1e
issue/2824-jsx Added more whitespace
olivermartinfoster 7bbe077
issue/2824-jsx Nesting reductions, image alt improvements
olivermartinfoster 1877556
issue/2824-jsx Switched from get('_children') to getChildren()
oliverfoster ef60e8f
Update templates/accordion.jsx
oliverfoster f844bd8
Update templates/accordion.jsx
oliverfoster 2ec9719
Update templates/accordion.jsx
oliverfoster 8714b8d
Update templates/accordion.jsx
oliverfoster eae6a79
issue/3105 Updated
oliverfoster be95d9b
issue/3105 Added missing onClick bind
oliverfoster 5fa44f9
issue/3105 Switched to image template
oliverfoster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,24 @@ | ||
| define([ | ||
| 'core/js/models/itemsComponentModel' | ||
| ], function(ItemsComponentModel) { | ||
| import ItemsComponentModel from 'core/js/models/itemsComponentModel'; | ||
|
|
||
| var AccordionModel = ItemsComponentModel.extend({ | ||
| export default class AccordionModel extends ItemsComponentModel { | ||
|
|
||
| defaults: function() { | ||
| return _.extend({}, _.result(ItemsComponentModel.prototype, 'defaults'), { | ||
| _shouldCollapseItems: true, | ||
| _toggleSpeed: 200 | ||
| }); | ||
| }, | ||
| defaults() { | ||
| return ItemsComponentModel.resultExtend('defaults', { | ||
| _shouldCollapseItems: true, | ||
| _toggleSpeed: 200 | ||
| }); | ||
| } | ||
|
|
||
| toggleItemsState: function(index) { | ||
| var item = this.getItem(index); | ||
| var previousActiveItem = this.getActiveItem(); | ||
| toggleItemsState(index) { | ||
| const item = this.getItem(index); | ||
| const previousActiveItem = this.getActiveItem(); | ||
|
|
||
| item.toggleActive(); | ||
| item.toggleVisited(true); | ||
| item.toggleActive(); | ||
| item.toggleVisited(true); | ||
|
|
||
| if (previousActiveItem && this.get('_shouldCollapseItems')) { | ||
| previousActiveItem.toggleActive(false); | ||
| } | ||
| if (previousActiveItem && this.get('_shouldCollapseItems')) { | ||
| previousActiveItem.toggleActive(false); | ||
| } | ||
| } | ||
|
|
||
| }); | ||
|
|
||
| return AccordionModel; | ||
|
|
||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,84 +1,58 @@ | ||
| define([ | ||
| 'core/js/views/componentView' | ||
| ], function(ComponentView) { | ||
|
|
||
| var AccordionView = ComponentView.extend({ | ||
|
|
||
| events: { | ||
| 'click .js-toggle-item': 'onClick' | ||
| }, | ||
|
|
||
| preRender: function() { | ||
| this.checkIfResetOnRevisit(); | ||
|
|
||
| this.model.resetActiveItems(); | ||
|
|
||
| this.listenTo(this.model.get('_children'), { | ||
| 'change:_isActive': this.onItemsActiveChange, | ||
| 'change:_isVisited': this.onItemsVisitedChange | ||
| }); | ||
| }, | ||
|
|
||
| postRender: function() { | ||
| this.setReadyStatus(); | ||
|
|
||
| if (this.model.get('_setCompletionOn') === 'inview') { | ||
| this.setupInviewCompletion(); | ||
| } | ||
| }, | ||
|
|
||
| checkIfResetOnRevisit: function() { | ||
| var isResetOnRevisit = this.model.get('_isResetOnRevisit'); | ||
|
|
||
| // If reset is enabled set defaults | ||
| if (isResetOnRevisit) { | ||
| this.model.reset(isResetOnRevisit); | ||
| } | ||
| }, | ||
|
|
||
| onClick: function(event) { | ||
| event.preventDefault(); | ||
|
|
||
| this.model.toggleItemsState($(event.currentTarget).parent().data('index')); | ||
| }, | ||
|
|
||
| onItemsActiveChange: function(item, isActive) { | ||
| this.toggleItem(item, isActive); | ||
| }, | ||
|
|
||
| onItemsVisitedChange: function(item, isVisited) { | ||
| if (!isVisited) return; | ||
|
|
||
| var $item = this.getItemElement(item); | ||
|
|
||
| $item.children('.accordion__item-btn').addClass('is-visited'); | ||
| }, | ||
|
|
||
| toggleItem: function(item, shouldExpand) { | ||
| var $item = this.getItemElement(item); | ||
| var $body = $item.children('.accordion__item-content').stop(true, true); | ||
|
|
||
| $item.children('.accordion__item-btn') | ||
| .toggleClass('is-selected is-open', shouldExpand) | ||
| .toggleClass('is-closed', !shouldExpand) | ||
| .attr('aria-expanded', shouldExpand); | ||
|
|
||
| if (!shouldExpand) { | ||
| $body.slideUp(this.model.get('_toggleSpeed')); | ||
| return; | ||
| } | ||
|
|
||
| $body.slideDown(this.model.get('_toggleSpeed')); | ||
| }, | ||
|
|
||
| getItemElement: function(item) { | ||
| var index = item.get('_index'); | ||
| import ComponentView from 'core/js/views/componentView'; | ||
|
|
||
| class AccordionView extends ComponentView { | ||
|
|
||
| preRender() { | ||
| this.checkIfResetOnRevisit(); | ||
| this.model.resetActiveItems(); | ||
| this.listenTo(this.model.get('_children'), { | ||
| 'change:_isActive': this.onItemsActiveChange, | ||
| 'change:_isVisited': this.onItemsVisitedChange, | ||
| 'all': this.changed | ||
| }); | ||
| } | ||
|
|
||
| postRender() { | ||
| this.setReadyStatus(); | ||
| if (this.model.get('_setCompletionOn') === 'inview') { | ||
| this.setupInviewCompletion(); | ||
| } | ||
| } | ||
|
|
||
| return this.$('.accordion__item').filter('[data-index="' + index +'"]'); | ||
| checkIfResetOnRevisit() { | ||
| const isResetOnRevisit = this.model.get('_isResetOnRevisit'); | ||
| // If reset is enabled set defaults | ||
| if (isResetOnRevisit) { | ||
| this.model.reset(isResetOnRevisit); | ||
| } | ||
| } | ||
|
|
||
| onClick(event) { | ||
| event.preventDefault(); | ||
| this.model.toggleItemsState($(event.currentTarget).parent().data('index')); | ||
| } | ||
|
|
||
| onItemsActiveChange(item, isActive) { | ||
| this.toggleItem(item, isActive); | ||
| } | ||
|
|
||
| toggleItem(item, shouldExpand) { | ||
| const $item = this.getItemElement(item); | ||
| const $body = $item.children('.accordion__item-content').stop(true, true); | ||
| if (!shouldExpand) { | ||
| $body.slideUp(this.model.get('_toggleSpeed')); | ||
| return; | ||
| } | ||
| $body.slideDown(this.model.get('_toggleSpeed')); | ||
| } | ||
|
|
||
| getItemElement(item) { | ||
| const index = item.get('_index'); | ||
| return this.$('.accordion__item').filter('[data-index="' + index +'"]'); | ||
oliverfoster marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| }); | ||
| } | ||
|
|
||
| return AccordionView; | ||
| AccordionView.template = 'accordion.jsx'; | ||
|
|
||
| }); | ||
| export default AccordionView; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,8 @@ | ||
| define([ | ||
| 'core/js/adapt', | ||
| './accordionModel', | ||
| './accordionView' | ||
| ], function(Adapt, AccordionModel, AccordionView) { | ||
|
|
||
| return Adapt.register('accordion', { | ||
| model: AccordionModel, | ||
| view: AccordionView | ||
| }); | ||
| import Adapt from 'core/js/adapt'; | ||
| import AccordionModel from './accordionModel'; | ||
| import AccordionView from './accordionView'; | ||
|
|
||
| export default Adapt.register('accordion', { | ||
| model: AccordionModel, | ||
| view: AccordionView | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { compile, classes, templates, html } from 'core/js/reactHelpers'; | ||
|
|
||
| export default function (view, data) { | ||
| return <div className="component__inner accordion__inner"> | ||
| {templates.component(view, data)} | ||
| <div className="component__widget accordion__widget"> | ||
| {data._items.map(({ _id, _graphic, _classes, title, body, _index, _isVisited, _isActive }, index) => { | ||
| return <div key={_index} className={classes( | ||
| "accordion__item", | ||
| _graphic.src && 'has-image', | ||
| _classes && _classes | ||
oliverfoster marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| )} data-index={_index}> | ||
| <button onClick={view.onClick.bind(view)} id={`${_id}-${index}-accordion-button`} className={classes( | ||
| 'accordion__item-btn', | ||
| 'js-toggle-item', | ||
| _isVisited && 'is-visited', | ||
| _isActive ? 'is-open is-selected' : 'is-closed' | ||
| )} aria-expanded={_isActive ? 'true' : 'false'}> | ||
| <div className="accordion__item-btn-inner"> | ||
| <div className="accordion__item-icon"> | ||
| <div className="icon"></div> | ||
| </div> | ||
| <div className="accordion__item-title"> | ||
| <div className="accordion__item-title-inner"> | ||
| {html(title)} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </button> | ||
| <div className="accordion__item-content" role="region" aria-labelledby={`${_id}-${index}-accordion-button`}> | ||
| <div className="accordion__item-content-inner"> | ||
| {body && | ||
| <div className="accordion__item-body"> | ||
| <div className="accordion__item-body-inner"> | ||
| {html(compile(body))} | ||
| </div> | ||
| </div> | ||
| } | ||
| {_graphic.src && | ||
| <div className={classes( | ||
| 'accordion__item-image-container', | ||
| _graphic.attribution && 'has-attribution' | ||
| )}> | ||
| <img className="accordion__item-image" src={_graphic.src} aria-label={_graphic.alt} aria-hidden={_graphic.alt ? 'true' : 'false'} /> | ||
| {_graphic.attribution && | ||
| <div className="component__attribution accordion__attribution"> | ||
| <div className="component__attribution-inner accordion__attribution-inner"> | ||
| {html(_graphic.attribution)} | ||
| </div> | ||
| </div> | ||
| } | ||
| </div> | ||
| } | ||
| </div> | ||
| </div> | ||
| </div> | ||
| })} | ||
| </div> | ||
| </div> | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.