You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CollapsibleList.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // @flow
  2. import React, { useCallback, useState } from 'react';
  3. import { Text, TouchableOpacity, View } from 'react-native';
  4. import { Icon, IconArrowDown, IconArrowUp } from '../../../base/icons';
  5. import { StyleType } from '../../../base/styles';
  6. import styles from '../breakout-rooms/components/native/styles';
  7. type Props = {
  8. /**
  9. * The children to be displayed within this list.
  10. */
  11. children: React$Node,
  12. /**
  13. * Additional style to be appended to the CollapsibleList container.
  14. */
  15. containerStyle?: StyleType,
  16. /**
  17. * Callback to invoke when the {@code CollapsibleList} is long pressed.
  18. */
  19. onLongPress?: Function,
  20. /**
  21. * Collapsible list title.
  22. */
  23. title: Object
  24. }
  25. const CollapsibleList = ({ children, containerStyle, onLongPress, title }: Props) => {
  26. const [ collapsed, setCollapsed ] = useState(false);
  27. const _toggleCollapsed = useCallback(() => {
  28. setCollapsed(!collapsed);
  29. }, [ collapsed ]);
  30. return (
  31. <View style = { !collapsed && containerStyle }>
  32. <TouchableOpacity
  33. onLongPress = { onLongPress }
  34. onPress = { _toggleCollapsed }
  35. style = { styles.collapsibleList }>
  36. <TouchableOpacity
  37. onPress = { _toggleCollapsed }
  38. style = { styles.arrowIcon }>
  39. <Icon
  40. size = { 18 }
  41. src = { collapsed ? IconArrowDown : IconArrowUp } />
  42. </TouchableOpacity>
  43. <Text style = { styles.listTile }>
  44. {
  45. title
  46. }
  47. </Text>
  48. </TouchableOpacity>
  49. {
  50. !collapsed && children
  51. }
  52. </View>
  53. );
  54. };
  55. export default CollapsibleList;