diff --git a/src/Accordion.js b/src/Accordion.js new file mode 100644 index 0000000..c496abd --- /dev/null +++ b/src/Accordion.js @@ -0,0 +1,209 @@ +import React, { useState, useEffect } from "react"; +import { + Animated, + TouchableWithoutFeedback, + FlatList, + StyleSheet, + Dimensions +} from "react-native"; +import PropTypes from "prop-types"; + +import Block from "./Block"; +import Icon from "./Icon"; +import Text from "./Text"; +import GalioTheme from "./theme"; + +const { width } = Dimensions.get("screen"); + +// +function AccordionContent({ content, contentStyle }) { + return {content}; +} + +function AccordionHeader({ + expanded, + expandedIcon, + headerStyle, + icon, + title, + chapterIcon +}) { + return ( + + {chapterIcon ? ( + + ) : null} + + {title} + {expanded + ? expandedIcon || ( + + ) + : icon || ( + + )} + + + ); +} + +function AccordionAnimation({ children, style }) { + const [fade, setFade] = useState(new Animated.Value(0.3)); + + useEffect(() => { + Animated.timing(fade, { + toValue: 1, + duration: 400, + useNativeDriver: true + }).start(); + }); + + return ( + + {children} + + ); +} + +function AccordionItem({ + expanded, + expandedIcon, + headerStyle, + contentStyle, + icon, + index, + item, + onAccordionClose, + onAccordionOpen, + setSelected +}) { + return ( + + { + onAccordionOpen && !expanded && onAccordionOpen(item, index); + onAccordionClose && expanded && onAccordionClose(item, index); + setSelected(index); + }} + > + + + + + {expanded ? ( + + + + ) : null} + + ); +} + +function Accordion({ + theme, + dataArray, + icon, + expandedIcon, + headerStyle, + contentStyle, + opened, + onAccordionOpen, + onAccordionClose, + listStyle, + style +}) { + const [selected, setSelected] = useState(opened); + + return ( + + String(index)} + renderItem={({ item, index }) => ( + setSelected(selected === s ? undefined : s)} + /> + )} + /> + + ); +} + +Accordion.propTypes = { + theme: PropTypes.any, + dataArray: PropTypes.array, + opened: PropTypes.number, + listStyle: PropTypes.any, + style: PropTypes.any, + icon: PropTypes.any, + expandedIcon: PropTypes.any, + headerStyle: PropTypes.any, + contentStyle: PropTypes.any, + onAccordionClose: PropTypes.func, + onAccordionOpen: PropTypes.func, +}; + +Accordion.defaultProps = { + theme: GalioTheme, + opened: 0 +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + width: width * 0.8, + borderRadius: 16, + padding: 8, + shadowColor: "black", + shadowOffset: { width: 0, height: 1 }, + shadowOpacity: 0.2, + shadowRadius: 4, + backgroundColor: 'white' + }, + header: { + padding: 6 + }, + content: { + padding: 10 + } +}); + +export default Accordion; diff --git a/src/index.js b/src/index.js index bdc8bf3..8758abc 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +import Accordion from './Accordion'; import Block from './Block'; import Button from './Button'; import Card from './Card'; @@ -15,6 +16,7 @@ import galioConfig from './config/galio.json'; const GalioFont = require('./fonts/galio.ttf'); export { + Accordion, Block, Button, Card,