Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(Accordion): add UncontrolledAccordion
- Loading branch information
Phoebe Gao
committed
Feb 23, 2021
1 parent
b5fc217
commit 12b6906
Showing
8 changed files
with
185 additions
and
13 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
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,40 @@ | ||
import React from 'react'; | ||
import { UncontrolledAccordion, AccordionBody, AccordionHeader, AccordionItem } from 'reactstrap'; | ||
|
||
const Example = (props) => { | ||
return ( | ||
<div> | ||
<UncontrolledAccordion> | ||
<AccordionItem> | ||
<AccordionHeader targetId="1"> | ||
Accordion Item 1 | ||
</AccordionHeader> | ||
<AccordionBody accordionId="1"> | ||
<strong>This is the first item's accordion body.</strong> | ||
You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow. | ||
</AccordionBody> | ||
</AccordionItem> | ||
<AccordionItem> | ||
<AccordionHeader targetId="2"> | ||
Accordion Item 2 | ||
</AccordionHeader> | ||
<AccordionBody accordionId="2"> | ||
<strong>This is the second item's accordion body.</strong> | ||
You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow. | ||
</AccordionBody> | ||
</AccordionItem> | ||
<AccordionItem> | ||
<AccordionHeader targetId="3"> | ||
Accordion Item 3 | ||
</AccordionHeader> | ||
<AccordionBody accordionId="3"> | ||
<strong>This is the third item's accordion body.</strong> | ||
You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow. | ||
</AccordionBody> | ||
</AccordionItem> | ||
</UncontrolledAccordion> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Example; |
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,34 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { tagPropType } from './utils'; | ||
import Accordion from './Accordion'; | ||
|
||
const propTypes = { | ||
tag: tagPropType, | ||
className: PropTypes.string, | ||
cssModule: PropTypes.object, | ||
innerRef: PropTypes.oneOfType([ | ||
PropTypes.object, | ||
PropTypes.string, | ||
PropTypes.func, | ||
]), | ||
children: PropTypes.node, | ||
}; | ||
|
||
const defaultProps = { | ||
tag: 'div' | ||
}; | ||
|
||
const UncntrolledAccordion = (props) => { | ||
const [openId, setOpenId] = useState(); | ||
const toggle = (id) => { | ||
openId === id ? setOpenId(undefined) : setOpenId(id); | ||
}; | ||
|
||
return <Accordion {...props} openId={openId} toggle={toggle} />; | ||
}; | ||
|
||
Accordion.propTypes = propTypes; | ||
Accordion.defaultProps = defaultProps; | ||
|
||
export default UncntrolledAccordion; |
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,23 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { UncontrolledAccordion } from '../'; | ||
|
||
describe('Accordion', () => { | ||
it('should render with "accordion" class', () => { | ||
const wrapper = mount(<UncontrolledAccordion />); | ||
|
||
expect(wrapper.find('.accordion').length).toBe(1); | ||
}); | ||
|
||
it('should render additional classes', () => { | ||
const wrapper = mount(<UncontrolledAccordion className="other" />); | ||
|
||
expect(wrapper.find('.accordion').hasClass('other')).toBe(true); | ||
}); | ||
|
||
it('should render custom tag', () => { | ||
const wrapper = mount(<UncontrolledAccordion tag="main" />); | ||
|
||
expect(wrapper.find('main.accordion').length).toBe(1); | ||
}); | ||
}); |
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