forked from Standard-Hashrate-Group/btcst.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpandable.tsx
More file actions
33 lines (28 loc) · 978 Bytes
/
Expandable.tsx
File metadata and controls
33 lines (28 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React, { FC, ReactNode, useState } from "react";
import { View, ViewStyle } from "react-native";
import useTranslation from "../hooks/useTranslation";
import Heading from "./Heading";
export interface ExpandableProps {
title: string;
expanded: boolean;
onExpand?: () => void;
style?: ViewStyle;
children?: ReactNode;
}
const Expandable: FC<ExpandableProps> = props => {
const t = useTranslation();
const [expanded, setExpanded] = useState(true);
const shouldExpand = props.expanded && expanded;
const buttonText = shouldExpand ? undefined : t("change");
const onPress = () => {
setExpanded(true);
props.onExpand?.();
};
return (
<View style={props.style}>
<Heading text={props.title} buttonText={buttonText} onPressButton={onPress} />
<View style={{ display: shouldExpand ? "flex" : "none" }}>{props.children}</View>
</View>
);
};
export default Expandable;