Skip to content
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

feat: add expand/collapse all behaviour in docs menu #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions assets/css/_docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ html.docs {
}
}

.expand-collapse-btn {
display: flex;
align-items: center;
justify-content: flex-start;
margin-top: 2.4rem;
padding: 4px 8px;
border-radius: 5px;
color: #5f5f5f;
cursor: pointer;
p {
margin: 0;
font-size: 16px;
}
.fa {
color: #979797;
font-size: 1.5rem;
margin-right: 6px;
}
}

.toc-container {
@include minimal-scrollbar();

Expand Down
54 changes: 52 additions & 2 deletions assets/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
return {
'content': [],
'searchFound': true,
'searchValue': ''
'searchValue': '',
'allExpanded': true
}
},

Expand Down Expand Up @@ -192,12 +193,42 @@
})
},

'getAllExpandedState': function(content) {
if(_.every(content, { 'expanded': true })) {
return true;
}
else if(_.every(content, { 'expanded': false })) {
return false;
}
else {
return this.state.allExpanded;
}
},

'onChangeExpanded': function(event, index) {
var content = this.state.content.slice(),
collection = content[index]

content[index] = _.assign({}, collection, { 'expanded': !collection.expanded })
this.setState({ 'content': content })

this.setState({
'content': content,
'allExpanded': this.getAllExpandedState(content)
})
},

'onChangeExpandCollapseAll': function(event) {
const currentAllExpandedState = this.state.allExpanded

function expandCollapseAll(value) {
return _.assign({}, value, { 'expanded': !currentAllExpandedState })
}
var content = _.map(this.state.content, expandCollapseAll)

this.setState({
'allExpanded': !currentAllExpandedState,
'content': content
});
},

'onChangeSearch': function(event) {
Expand Down Expand Up @@ -353,6 +384,25 @@
}
)
),
React.createElement(
'button',
{
'className': "expand-collapse-btn",
'onClick': this.onChangeExpandCollapseAll
},
React.createElement(
'i',
{
'aria-hidden': true,
'className': `fa fa-${this.state.allExpanded ? 'compress' : 'expand'}`
}
),
React.createElement(
'p',
null,
this.state.allExpanded ? 'Collapse all' : 'Expand all'
)
),
elements,
React.createElement(
'div',
Expand Down