-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat: Conversation requests screen UI components #1608
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bfc622d
Remove the segmented controller and replace with new toggle design
lourou 2123fe1
Implement right action UI for deleting all requests
lourou 1cd7abc
Use theme spacing values
lourou 814522d
Fix
lourou 4e29a16
Implement composable `Chip` component
lourou 3ad20ae
Fixes
lourou 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 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,67 @@ | ||
import React from "react"; | ||
import { View } from "react-native"; | ||
import { Chip } from "./chip"; | ||
import { Icon } from "@/design-system/Icon/Icon"; | ||
|
||
export default { | ||
title: "Design System/Chip", | ||
}; | ||
|
||
export function ChipExamples() { | ||
return ( | ||
<View style={{ gap: 10, padding: 10 }}> | ||
{/* Basic usage with just text */} | ||
<Chip> | ||
<Chip.Text>Basic Chip</Chip.Text> | ||
</Chip> | ||
|
||
{/* With avatar and text */} | ||
<Chip> | ||
<Chip.Avatar uri="https://example.com/avatar.jpg" name="John Doe" /> | ||
<Chip.Text>John Doe</Chip.Text> | ||
</Chip> | ||
|
||
{/* With custom icon */} | ||
<Chip> | ||
<Chip.Icon> | ||
<Icon icon="star" size={16} /> | ||
</Chip.Icon> | ||
<Chip.Text>With Icon</Chip.Text> | ||
</Chip> | ||
|
||
{/* Filled variant */} | ||
<Chip variant="filled"> | ||
<Chip.Text>Filled Chip</Chip.Text> | ||
</Chip> | ||
|
||
{/* Disabled state */} | ||
<Chip disabled> | ||
<Chip.Text>Disabled Chip</Chip.Text> | ||
</Chip> | ||
|
||
{/* Selected state with medium size */} | ||
<Chip size="md" isSelected> | ||
<Chip.Text>Selected (Medium)</Chip.Text> | ||
</Chip> | ||
|
||
{/* Interactive chip with onPress */} | ||
<Chip onPress={() => alert("Chip pressed!")}> | ||
<Chip.Text>Pressable Chip</Chip.Text> | ||
</Chip> | ||
|
||
{/* Combination of multiple props */} | ||
<Chip | ||
variant="filled" | ||
size="md" | ||
isSelected | ||
onPress={() => alert("Complex chip pressed!")} | ||
> | ||
<Chip.Avatar uri="https://example.com/avatar.jpg" name="Jane Smith" /> | ||
<Chip.Icon> | ||
<Icon icon="checkmark" size={16} /> | ||
</Chip.Icon> | ||
<Chip.Text>Complex Chip</Chip.Text> | ||
</Chip> | ||
</View> | ||
); | ||
} |
This file contains 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 |
---|---|---|
@@ -1,58 +1,117 @@ | ||
import { Avatar } from "@/components/Avatar"; | ||
import { Avatar as RNAvatar } from "@/components/Avatar"; | ||
import { Center } from "@/design-system/Center"; | ||
import { Text } from "@/design-system/Text"; | ||
import { Text as RNText } from "@/design-system/Text"; | ||
import { useAppTheme } from "@/theme/useAppTheme"; | ||
import React from "react"; | ||
import { Pressable, StyleProp, ViewStyle } from "react-native"; | ||
import { StyleProp, ViewStyle, TextStyle } from "react-native"; | ||
import { AnimatedPressable } from "@design-system/Pressable"; | ||
|
||
type ChipProps = { | ||
name: string; | ||
avatarUri?: string; | ||
const ChipContext = React.createContext<{ | ||
size: "sm" | "md"; | ||
disabled?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should have type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
isSelected?: boolean; | ||
} | null>(null); | ||
|
||
function useChipContext() { | ||
const context = React.useContext(ChipContext); | ||
if (!context) { | ||
throw new Error("Chip components must be used within a Chip"); | ||
} | ||
return context; | ||
} | ||
|
||
type IChipProps = { | ||
isSelected?: boolean; | ||
onPress?: () => void; | ||
size?: "sm" | "md"; | ||
showAvatar?: boolean; | ||
disabled?: boolean; | ||
variant?: "filled" | "outlined"; | ||
children: React.ReactNode; | ||
}; | ||
|
||
export function Chip({ | ||
name, | ||
avatarUri, | ||
children, | ||
isSelected, | ||
onPress, | ||
size = "sm", | ||
showAvatar = true, | ||
}: ChipProps) { | ||
const { theme } = useAppTheme(); | ||
disabled, | ||
variant = "outlined", | ||
}: IChipProps) { | ||
const styles = useChipStyles({ variant }); | ||
|
||
const styles = useChipStyles(); | ||
return ( | ||
<ChipContext.Provider value={{ size, disabled, isSelected }}> | ||
<AnimatedPressable | ||
onPress={onPress} | ||
disabled={disabled} | ||
style={({ pressed }) => [ | ||
styles.$container, | ||
isSelected && styles.$selectedContainer, | ||
disabled && styles.$disabledContainer, | ||
pressed && styles.$pressedContainer, | ||
]} | ||
> | ||
<Center style={styles.$content}>{children}</Center> | ||
</AnimatedPressable> | ||
</ChipContext.Provider> | ||
); | ||
} | ||
|
||
type IChipTextProps = { | ||
children: string; | ||
style?: StyleProp<TextStyle>; | ||
}; | ||
|
||
export function ChipText({ children, style }: IChipTextProps) { | ||
const { size, disabled, isSelected } = useChipContext(); | ||
const styles = useChipStyles({ variant: "outlined" }); | ||
|
||
return ( | ||
<Pressable | ||
onPress={onPress} | ||
style={[styles.$container, isSelected && styles.$selectedContainer]} | ||
<RNText | ||
preset={size === "sm" ? "small" : "body"} | ||
style={[ | ||
style, | ||
disabled && styles.$disabledText, | ||
isSelected && styles.$selectedText, | ||
]} | ||
> | ||
<Center | ||
// {...debugBorder()} | ||
style={styles.$content} | ||
> | ||
{showAvatar && ( | ||
<Avatar uri={avatarUri} name={name} size={theme.avatarSize.xs} /> | ||
)} | ||
<Text preset={size === "sm" ? "small" : "body"}>{name}</Text> | ||
</Center> | ||
</Pressable> | ||
{children} | ||
</RNText> | ||
); | ||
} | ||
|
||
export function useChipStyles() { | ||
type IChipIconProps = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
export function ChipIcon({ children }: IChipIconProps) { | ||
return children; | ||
} | ||
|
||
type IChipAvatarProps = { | ||
uri?: string; | ||
name: string; | ||
}; | ||
|
||
export function ChipAvatar({ uri, name }: IChipAvatarProps) { | ||
const { theme } = useAppTheme(); | ||
return <RNAvatar uri={uri} name={name} size={theme.avatarSize.xs} />; | ||
} | ||
|
||
export function useChipStyles({ variant }: { variant: "filled" | "outlined" }) { | ||
const { theme } = useAppTheme(); | ||
|
||
const $container = { | ||
borderRadius: theme.spacing.xs, | ||
borderWidth: theme.borderWidth.sm, | ||
borderWidth: variant === "outlined" ? theme.borderWidth.sm : 0, | ||
borderColor: theme.colors.border.subtle, | ||
backgroundColor: theme.colors.background.surface, | ||
paddingVertical: theme.spacing.xxs - theme.borderWidth.sm * 2, | ||
backgroundColor: | ||
variant === "outlined" | ||
? theme.colors.background.surface | ||
: theme.colors.fill.minimal, | ||
paddingVertical: | ||
theme.spacing.xxs - | ||
(variant === "outlined" ? theme.borderWidth.sm * 2 : 0), | ||
paddingHorizontal: theme.spacing.xs, | ||
} satisfies StyleProp<ViewStyle>; | ||
|
||
|
@@ -70,8 +129,26 @@ export function useChipStyles() { | |
$container, | ||
$selectedContainer: { | ||
backgroundColor: theme.colors.fill.minimal, | ||
borderColor: theme.colors.fill.minimal, | ||
borderColor: | ||
variant === "outlined" ? theme.colors.fill.minimal : "transparent", | ||
}, | ||
$content, | ||
$disabledContainer: { | ||
opacity: 0.5, | ||
}, | ||
$pressedContainer: { | ||
opacity: 0.8, | ||
}, | ||
$disabledText: { | ||
color: theme.colors.text.inactive, | ||
}, | ||
$selectedText: { | ||
color: theme.colors.text.primary, | ||
}, | ||
} as const; | ||
thierryskoda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Add Chip compound components to the main export | ||
Chip.Text = ChipText; | ||
Chip.Icon = ChipIcon; | ||
Chip.Avatar = ChipAvatar; |
This file contains 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 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 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
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.
why
Text as RNText
? Why not just Text? same withRNAvatar
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.
Fixed! That should not have been there :)