From 11b58c4de3cf12b3dcb19d115c2be68ec152c7ee Mon Sep 17 00:00:00 2001 From: Avinash Lingaloo Date: Tue, 24 May 2022 14:04:36 +0400 Subject: [PATCH] Gekidou - Section Component (#6308) * added section and sectionItem component * some code fix --- app/components/section/index.tsx | 90 +++++++++++++++++++++++++++ app/components/section_item/index.tsx | 17 ++--- 2 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 app/components/section/index.tsx diff --git a/app/components/section/index.tsx b/app/components/section/index.tsx new file mode 100644 index 0000000000..84d7366249 --- /dev/null +++ b/app/components/section/index.tsx @@ -0,0 +1,90 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {MessageDescriptor} from '@formatjs/intl/src/types'; +import React from 'react'; +import {StyleProp, View, ViewStyle} from 'react-native'; + +import FormattedText from '@components/formatted_text'; +import {useTheme} from '@context/theme'; +import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; + +const getStyleSheet = makeStyleSheetFromTheme((theme) => { + return { + container: { + marginBottom: 30, + }, + header: { + marginHorizontal: 15, + marginBottom: 10, + fontSize: 13, + color: changeOpacity(theme.centerChannelColor, 0.5), + }, + items: { + backgroundColor: theme.centerChannelBg, + borderTopWidth: 1, + borderBottomWidth: 1, + borderTopColor: changeOpacity(theme.centerChannelColor, 0.1), + borderBottomColor: changeOpacity(theme.centerChannelColor, 0.1), + }, + footer: { + marginTop: 10, + marginHorizontal: 15, + fontSize: 12, + color: changeOpacity(theme.centerChannelColor, 0.5), + }, + }; +}); + +type SectionText = { + id: string; + defaultMessage: string; + values?: MessageDescriptor; +} + +type SectionProps = { + children: React.ReactNode; + disableFooter?: boolean; + disableHeader?: boolean; + footerText?: SectionText; + headerText: SectionText; + containerStyles?: StyleProp; +} + +const Section = ({ + children, + containerStyles, + disableFooter, + disableHeader, + footerText, + headerText, +}: SectionProps) => { + const theme = useTheme(); + const style = getStyleSheet(theme); + + return ( + + {(headerText && !disableHeader) && + + } + + {children} + + {(footerText && !disableFooter) && + + } + + ); +}; + +export default Section; diff --git a/app/components/section_item/index.tsx b/app/components/section_item/index.tsx index 3c448e1b83..95eab0eeb4 100644 --- a/app/components/section_item/index.tsx +++ b/app/components/section_item/index.tsx @@ -1,13 +1,8 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React, {useCallback, useMemo} from 'react'; -import { - Switch, - Text, - TouchableOpacity, - View, -} from 'react-native'; +import React, {ReactElement, useCallback, useMemo} from 'react'; +import {Switch, Text, TouchableOpacity, View} from 'react-native'; import CompassIcon from '@components/compass_icon'; import {useTheme} from '@context/theme'; @@ -64,14 +59,14 @@ const getStyleSheet = makeStyleSheetFromTheme((theme) => { }); type Props = { - testID?: string; action: (value: string | boolean) => void; actionType: string; actionValue?: string; - label: string; - selected: boolean; - description: string; + description?: string | ReactElement; icon?: string; + label: string | ReactElement; + selected?: boolean; + testID?: string; } const SectionItem = ({testID = 'sectionItem', action, actionType, actionValue, label, selected, description, icon}: Props) => {