Skip to content

Commit

Permalink
feat: Add sectionContainerStyle prop to Accordion (#247)
Browse files Browse the repository at this point in the history
Gives users the ability to add styling to the entire accordion container.
  • Loading branch information
Michael Jasinski authored and iRoachie committed Oct 4, 2018
1 parent 3392a03 commit ff18c22
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Accordion.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { StyleProp, ViewStyle } from 'react-native';
import { EasingMode } from './index';

export interface AccordionProps {
Expand Down Expand Up @@ -100,6 +101,11 @@ export interface AccordionProps {
* Object of props to pass to the touchable component
*/
touchableProps?: {};

/**
* Optional styling for the section container
*/
sectionContainerStyle?: StyleProp<ViewStyle>;
}

export default class Accordion extends React.Component<AccordionProps> {}
5 changes: 4 additions & 1 deletion Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class Accordion extends Component {
expandFromBottom: PropTypes.bool,
expandMultiple: PropTypes.bool,
onAnimationEnd: PropTypes.func,
sectionContainerStyle: ViewPropTypes.style,
};

static defaultProps = {
Expand All @@ -35,6 +36,7 @@ export default class Accordion extends Component {
touchableComponent: TouchableHighlight,
renderSectionTitle: () => null,
onAnimationEnd: () => null,
sectionContainerStyle: {},
};

_toggleSection(section) {
Expand Down Expand Up @@ -77,6 +79,7 @@ export default class Accordion extends Component {

const {
activeSections,
sectionContainerStyle,
expandFromBottom,
sections,
underlayColor,
Expand All @@ -101,7 +104,7 @@ export default class Accordion extends Component {
return (
<View {...viewProps}>
{sections.map((section, key) => (
<View key={key}>
<View key={key} style={sectionContainerStyle}>
{renderSectionTitle(section, key, activeSections.includes(key))}

{expandFromBottom && renderCollapsible(section, key)}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import Accordion from 'react-native-collapsible/Accordion';
| **`onAnimationEnd(key, index)`** | See `Collapsible`. |
| **`expandFromBottom`** | Expand content from the bottom instead of the top |
| **`expandMultiple`** | Allow more than one section to be expanded. Defaults to false. |
| **`sectionContainerStyle`** | Optional styling for the section container. |

## Demo

Expand Down

0 comments on commit ff18c22

Please sign in to comment.