-
Notifications
You must be signed in to change notification settings - Fork 0
Bottom sheet lists #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9377f96
Add components for bottom sheet lists
barry-observation f293db1
Bump version
barry-observation 977f4c6
Update exports
barry-observation 3381f91
Review comments
barry-observation 125b0ae
Fix more review comments
barry-observation 8548645
Fix todo
barry-observation File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React from 'react' | ||
| import { Text, TextProps } from 'react-native' | ||
|
|
||
| import { capitalize } from '../lib/Utils' | ||
|
|
||
| /** | ||
| * Renders the children, capitalizing the first child when this is a string | ||
| */ | ||
| const CapitalizeText = ({ children, ...props }: TextProps) => ( | ||
| <Text {...props}> | ||
| {React.Children.map(children, (child, index) => | ||
| index === 0 && typeof child === 'string' ? capitalize(child) : child, | ||
| )} | ||
| </Text> | ||
| ) | ||
|
|
||
| export default CapitalizeText |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import React from 'react' | ||
| import { StyleProp, StyleSheet, Text, TextStyle, TouchableOpacity, View, ViewStyle } from 'react-native' | ||
|
|
||
| import CapitalizeText from './CapitalizeText' | ||
| import { Theme, useStyles, useTheme } from '../theme' | ||
| import { Icon } from './Icon' | ||
|
|
||
| type Props = { | ||
| label?: string | ||
| value?: string | ||
| onPress: () => void | ||
| containerStyle?: StyleProp<ViewStyle> | ||
| valueStyle?: StyleProp<TextStyle> | ||
| disabled?: boolean | ||
| capitalize?: boolean | ||
| showChevron?: boolean | ||
| } | ||
|
|
||
| const InputPanel = ({ | ||
| label, | ||
| value, | ||
| containerStyle, | ||
| valueStyle, | ||
| onPress, | ||
| disabled = false, | ||
| capitalize = false, | ||
| showChevron = true, | ||
| }: Props) => { | ||
| const theme = useTheme() | ||
| const styles = useStyles(createStyles) | ||
|
|
||
| // TODO: 48 and 36 should be input heights and we should make them dynamically themed | ||
| const paddingVertical = label | ||
| ? (48 - (styles.headerTextStyle.lineHeight! + styles.value.lineHeight!)) / 2 | ||
| : (36 - styles.value.lineHeight!) / 2 | ||
|
|
||
| return ( | ||
| <TouchableOpacity disabled={disabled} style={[styles.container, containerStyle]} onPress={onPress}> | ||
| <View style={[styles.contentContainer, { paddingVertical }]}> | ||
| {label && ( | ||
| <Text numberOfLines={1} ellipsizeMode="tail" style={styles.headerTextStyle}> | ||
| {label} | ||
| </Text> | ||
| )} | ||
| {capitalize && value ? ( | ||
| <CapitalizeText numberOfLines={1} ellipsizeMode="tail" style={[styles.value, valueStyle]}> | ||
| {value} | ||
| </CapitalizeText> | ||
| ) : ( | ||
| <Text numberOfLines={1} ellipsizeMode="tail" style={[styles.value, valueStyle]}> | ||
| {value || ' '} | ||
| </Text> | ||
| )} | ||
| </View> | ||
| {showChevron && ( | ||
| <View style={styles.icon}> | ||
| <Icon name="angle-down" color={theme.color.grey500} size={theme.icon.size.m} /> | ||
| </View> | ||
| )} | ||
| </TouchableOpacity> | ||
| ) | ||
| } | ||
|
|
||
| export default InputPanel | ||
|
|
||
| const createStyles = (theme: Theme) => | ||
| StyleSheet.create({ | ||
| container: { | ||
| flexDirection: 'row', | ||
| justifyContent: 'space-between', | ||
| alignItems: 'center', | ||
| paddingHorizontal: theme.margin.common, | ||
| }, | ||
| headerTextStyle: { | ||
| ...theme.font.extraSmall, | ||
| lineHeight: theme.font.extraSmall.fontSize, | ||
| letterSpacing: 0.03 * theme.font.extraSmall.fontSize, | ||
| color: theme.color.text.system.subtler, | ||
| }, | ||
| contentContainer: { | ||
| flex: 1, | ||
| flexDirection: 'column', | ||
| }, | ||
| value: { | ||
| ...theme.font.medium, | ||
| color: theme.color.text.system.strong, | ||
| }, | ||
| icon: { | ||
| marginLeft: theme.margin.half, | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import React from 'react' | ||
| import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native' | ||
|
|
||
| import { Theme, useStyles } from '../theme' | ||
|
|
||
| type Orientation = 'horizontal' | 'vertical' | ||
|
|
||
| type Props = { | ||
| style?: StyleProp<ViewStyle> | ||
| orientation?: Orientation | ||
| } | ||
|
|
||
| const ItemSeparator = ({ style, orientation = 'horizontal' }: Props) => { | ||
| const styles = useStyles(createStyles) | ||
| const separatorStyle = orientation === 'horizontal' ? styles.horizontalSeparator : styles.verticalSeparator | ||
| return <View style={[separatorStyle, style]} /> | ||
| } | ||
|
|
||
| export default ItemSeparator | ||
|
|
||
| const createStyles = (theme: Theme) => | ||
| StyleSheet.create({ | ||
| horizontalSeparator: { | ||
| borderBottomWidth: 1, | ||
| borderBottomColor: theme.color.background.system.surfaceRaised, | ||
| }, | ||
| verticalSeparator: { | ||
| borderRightWidth: 1, | ||
| borderRightColor: theme.color.background.system.surfaceRaised, | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import React from 'react' | ||
| import { StyleSheet, TouchableOpacity, View } from 'react-native' | ||
|
|
||
| import SingleLine from './SingleLine' | ||
| import { Theme, useStyles, useTheme } from '../theme' | ||
| import { Icon, IconProps } from './Icon' | ||
|
|
||
| type Props = { | ||
| icon?: IconProps | ||
| label: string | ||
| subLabel?: string | ||
| extraSubLabel?: string | ||
| onPress?: () => void | ||
| selected?: boolean | ||
| } | ||
|
|
||
| const ListItem = ({ icon, onPress, label, subLabel, extraSubLabel, selected = false }: Props) => { | ||
| const theme = useTheme() | ||
| const styles = useStyles(createStyles) | ||
|
|
||
| const iconMarginRight = subLabel ? theme.margin.common : theme.margin.half | ||
| const containerPaddingVertical = subLabel ? 7 : 13 | ||
| const containerBackgroundColor = selected ? theme.color.primary50 : undefined | ||
|
|
||
| const renderIcon = (() => { | ||
| switch (true) { | ||
| case !!icon: | ||
| return ( | ||
| <Icon | ||
| name={icon!.name} | ||
| style={icon!.style ?? 'solid'} | ||
| color={icon!.color ?? theme.color.grey500} | ||
| size={icon!.size ?? theme.icon.size.s} | ||
| /> | ||
| ) | ||
| case selected: | ||
| return ( | ||
| <Icon name={'circle-check'} style={'solid'} color={theme.color.icon.system.brand} size={theme.icon.size.xl} /> | ||
| ) | ||
| default: | ||
| return ( | ||
| <Icon name={'circle'} style={'light'} color={theme.color.icon.system.disabled} size={theme.icon.size.xl} /> | ||
| ) | ||
| } | ||
| })() | ||
|
|
||
| return ( | ||
| <TouchableOpacity activeOpacity={0.5} onPress={onPress} disabled={!onPress}> | ||
| <View | ||
| style={[ | ||
| styles.containerStyle, | ||
| { paddingVertical: containerPaddingVertical, backgroundColor: containerBackgroundColor }, | ||
| ]} | ||
| > | ||
| <View style={{ marginRight: iconMarginRight }}>{renderIcon}</View> | ||
| <View style={{ flex: 1 }}> | ||
| <SingleLine style={styles.labelTextStyle}>{label}</SingleLine> | ||
| {subLabel && ( | ||
| <View style={{ flexDirection: 'row', gap: theme.margin.half }}> | ||
| <SingleLine style={styles.subLabelTextStyle}>{subLabel}</SingleLine> | ||
| {extraSubLabel && <SingleLine style={styles.subLabelTextStyle}>{extraSubLabel}</SingleLine>} | ||
| </View> | ||
| )} | ||
| </View> | ||
| </View> | ||
| </TouchableOpacity> | ||
| ) | ||
| } | ||
|
|
||
| export default ListItem | ||
|
|
||
| const createStyles = (theme: Theme) => | ||
| StyleSheet.create({ | ||
| containerStyle: { | ||
| flexDirection: 'row', | ||
| alignItems: 'center', | ||
| paddingHorizontal: theme.margin.common, | ||
| }, | ||
| labelTextStyle: { | ||
| ...theme.font.medium, | ||
| lineHeight: theme.lineHeight.small, | ||
| color: theme.color.text.system.strong, | ||
| }, | ||
| subLabelTextStyle: { | ||
| ...theme.font.extraSmall, | ||
| color: theme.color.text.system.subtler, | ||
| }, | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import React from 'react' | ||
| import { StyleProp, StyleSheet, Text, View, ViewStyle } from 'react-native' | ||
|
|
||
| import { Theme, useStyles } from '../theme' | ||
|
|
||
| type Props = { | ||
| title?: string | ||
| containerStyle?: StyleProp<ViewStyle> | ||
| } | ||
|
|
||
| const SectionHeader = ({ title, containerStyle }: Props) => { | ||
| const styles = useStyles(createStyles) | ||
| return ( | ||
| <View style={[styles.header, title ? styles.headerPadding : null, containerStyle]}> | ||
| {title && <Text style={styles.contentHeaderStyle}>{title}</Text>} | ||
| </View> | ||
| ) | ||
| } | ||
|
|
||
| export default SectionHeader | ||
|
|
||
| const createStyles = (theme: Theme) => | ||
| StyleSheet.create({ | ||
| header: { | ||
| paddingHorizontal: theme.margin.common, | ||
| marginTop: theme.margin.common, | ||
| }, | ||
| headerPadding: { | ||
| paddingVertical: theme.margin.quarter, | ||
| }, | ||
| contentHeaderStyle: { | ||
| ...theme.font.smallBold, | ||
| color: theme.color.text.system.subtler, | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import React from 'react' | ||
| import { StyleProp, Text, TextStyle } from 'react-native' | ||
|
|
||
| type Props = { | ||
| children?: React.ReactNode | ||
| style?: StyleProp<TextStyle> | ||
| } | ||
|
|
||
| const SingleLine = ({ children, style }: Props) => ( | ||
| <Text numberOfLines={1} ellipsizeMode="tail" style={style}> | ||
| {children} | ||
| </Text> | ||
| ) | ||
|
|
||
| export default SingleLine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import React from 'react' | ||
| import { Text } from 'react-native' | ||
|
|
||
| import { describe, expect, test } from '@jest/globals' | ||
| import { render } from '@testing-library/react-native' | ||
|
|
||
| import CapitalizeText from '../CapitalizeText' | ||
|
|
||
| describe('CapitalizeText', () => { | ||
| test('Capitalizes the text', () => { | ||
| const { queryByText } = render(<CapitalizeText>hello world</CapitalizeText>) | ||
| expect(queryByText('Hello world')).toBeTruthy() | ||
| }) | ||
|
|
||
| test('With multiple children, the first one being a string, the text is capitalized', () => { | ||
| const { queryByText } = render( | ||
| <CapitalizeText> | ||
| hello <Text>world</Text> | ||
| </CapitalizeText>, | ||
| ) | ||
| expect(queryByText('Hello world')).toBeTruthy() | ||
| }) | ||
|
|
||
| test('When the first child is not a string, no text is capitalized', () => { | ||
| const { queryByText } = render( | ||
| <CapitalizeText> | ||
| <Text>hello</Text> world | ||
| </CapitalizeText>, | ||
| ) | ||
| expect(queryByText('hello world')).toBeTruthy() | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deze hard-coded padding is niet zo mooi maar ik kon geen betere manier verzinnen.