<div class="bcp-acordion" data-component="accordion">
<button data-role="accordion-trigger" type="button">Toggle</button>
<p>Content goes here.</p>
</div>
<script>
var Accordion = (function () {
this.toggle = function() {
$('[data-component="accordion"]').toggleClass('is-expanded');
};
$(document).on('click', '[data-component="accordion"]
[data-role="accordion-trigger"]', toggle);
}());
</script>
<div class="bcp-acordion" data-component="accordion"
data-bind="css: {'is-expanded': isExpanded}">
<button data-bind="click: toggle" type="button">Toggle</button>
<p>Content goes here.</p>
</div>
<script>
var Accordion = function() {
this.isExpanded = ko.observable(false);
};
ko.applyBindings(Accordion,
document.querySelector('[data-component="accordion"]');
</script>
<div data-component="accordion"></div>
<script>
class Accordion extends React.Component {
state = { expanded: false }
render() {
return (
<div className={classNames('bcp-accordion',
'is-expanded': this.state.expanded)}>
<button onClick={this.setState({ expanded: !expanded })}>
Toggle
</button>
<p>Content goes here.<p>
</div>
);
}
}
ReactDOM.render(Accordion,
document.querySelector('[data-component="accordion"]');
</script>
const toggleAccordion = () => ({
type: 'bcp/accordion/TOGGLE'
});
const initialState = {
expanded: false
};
const reducer = (state = initialState, action = {}) => {
switch (action.type) {
case 'bcp/accordion/TOGGLE':
return {
...state,
expanded: !expanded
};
default:
return state;
}
};