-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
17,661 additions
and
18,876 deletions.
There are no files selected for viewing
This file contains 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,8 +1,8 @@ | ||
{ | ||
"presets": [ | ||
"react", | ||
"es2015" | ||
"@babel/react", | ||
"@babel/env" | ||
], | ||
"plugins": ["transform-object-assign", "transform-object-rest-spread", | ||
"transform-class-properties", "array-includes","transform-async-to-generator"] | ||
"plugins": ["@babel/plugin-transform-object-assign", "@babel/plugin-proposal-object-rest-spread", | ||
"@babel/plugin-proposal-class-properties", "babel-plugin-array-includes","@babel/plugin-transform-async-to-generator"] | ||
} |
This file contains 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 |
---|---|---|
|
@@ -78,5 +78,11 @@ | |
"expect": true, | ||
"prettyPrint": true, | ||
"jest": true | ||
}, | ||
|
||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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,46 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
import {Accordion, AccordionItem} from '../components/accordion'; | ||
import {mount} from 'enzyme'; | ||
import React from 'react'; | ||
import sinon from 'sinon'; | ||
|
||
describe('Accordion', () => { | ||
it('Shows and hides content after clicking on header', () => { | ||
const el = mount( | ||
<Accordion> | ||
<AccordionItem title={'Click to open'}> | ||
<p id="test_content">Have a great day</p> | ||
</AccordionItem> | ||
</Accordion> | ||
); | ||
|
||
expect(el.find('.faux--accordion__item-content').hasClass('in')).toBe(false); | ||
el.find('.faux--accordion__item-header').simulate('click'); | ||
expect(el.find('.faux--accordion__item-content').hasClass('in')).toBe(true); | ||
}); | ||
|
||
it('Calls onClick event', () => { | ||
const spy = sinon.spy(); | ||
const el = mount( | ||
<Accordion> | ||
<AccordionItem title={'Click to open'} onClick={spy}> | ||
<p id="test_content">Have a great day</p> | ||
</AccordionItem> | ||
</Accordion> | ||
); | ||
|
||
el.find('.faux--accordion__item-header').simulate('click'); | ||
sinon.assert.called(spy); | ||
}); | ||
}); |
This file contains 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,27 @@ | ||
.faux--accordion { | ||
list-style: none; | ||
margin: 0px; | ||
width: 100%; | ||
} | ||
|
||
.faux--accordion__item { | ||
background-color: transparent; | ||
transition: all 0.5s linear; | ||
} | ||
|
||
.faux--accordion__item-header { | ||
border: 0; | ||
background-color: transparent; | ||
color: inherit; | ||
font-size: inherit; | ||
padding-left: 0px; | ||
span { | ||
padding-left: 0.5rem; | ||
} | ||
} | ||
|
||
.faux--accordion__item-content { | ||
padding-left: 1.35rem; | ||
padding-top: 0.75rem; | ||
font-size: inherit; | ||
} |
This file contains 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
This file contains 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
This file contains 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,64 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {Collapse} from 'react-bootstrap'; | ||
import classnames from 'classnames'; | ||
|
||
export const Accordion = props => { | ||
const {children, className, style} = props; | ||
const classNames = classnames('faux--accordion', className); | ||
return ( | ||
<ul className={classNames} style={style}> | ||
{children} | ||
</ul> | ||
); | ||
}; | ||
|
||
export class AccordionItem extends React.Component { | ||
static propTypes = { | ||
title: PropTypes.string.isRequired, | ||
}; | ||
|
||
static defaultProps = { | ||
onClick: () => {}, | ||
}; | ||
|
||
state = { | ||
open: false, | ||
}; | ||
|
||
handleClick = event => { | ||
const newOpen = !this.state.open; | ||
this.setState({open: newOpen}); | ||
this.props.onClick({isOpen: newOpen, event}); | ||
}; | ||
|
||
render() { | ||
const {children, title} = this.props; | ||
const icon = this.state.open ? 'fonticon-down-open' : 'fonticon-right-open'; | ||
const contentClassNames = classnames('faux--accordion__item-content', 'collapse', {in: this.state.open}); | ||
|
||
return ( | ||
<li className="faux--accordion__item" onClick={this.handleClick}> | ||
<button type="button" className={`faux--accordion__item-header`} onClick={this.handleClick}> | ||
<i className={icon}></i> | ||
<span>{title}</span> | ||
</button> | ||
<Collapse in={this.state.open}> | ||
<div className={contentClassNames}>{children}</div> | ||
</Collapse> | ||
</li> | ||
); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.