Skip to content
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

Add tabs variants and remove blur #501

Merged
merged 5 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cold-jars-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@status-im/components": patch
---

- Add tabs variants
- Remove `backdrop-filter`
11 changes: 0 additions & 11 deletions packages/components/src/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,12 @@ const Base = styled(View, {
backgroundColor: '$neutral-80/5',
hoverStyle: { backgroundColor: '$neutral-80/10' },
pressStyle: { backgroundColor: '$neutral-80/20' },
'$platform-web': {
backdropFilter: 'blur(20px)',
// Tamagui does not accept this property even though it is valid (and works)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as unknown as any,
},
blur_outline: {
borderWidth: 1,
borderColor: '$neutral-80/10',
hoverStyle: { borderColor: '$neutral-80/20' },
pressStyle: { borderColor: '$neutral-80/30' },

'$platform-web': {
backdropFilter: 'blur(20px)',
// Tamagui does not accept this property even though it is valid (and works)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as unknown as any,
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const ReactionsDialog = (props: Props) => {
<Dialog.Content width={352} borderRadius="$12">
<Tabs defaultValue={initialReactionType}>
<Stack padding={16}>
<Tabs.List size={24}>
<Tabs.List variant="grey" size={24}>
{Object.entries(reactions).map(([reaction, value]) => {
const Icon = REACTIONS_ICONS[reaction as keyof ReactionsType]
return (
Expand Down
110 changes: 105 additions & 5 deletions packages/components/src/tabs/tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,114 @@ const meta: Meta<typeof Tabs> = {
},
}

export const Default: StoryObj<TabsProps> = {
export const Grey: StoryObj<TabsProps> = {
args: {
defaultValue: '1',
},
render(args) {
return (
<Tabs {...args}>
<Tabs.List size={32}>
<Tabs.List variant="grey" size={32}>
<Tabs.Trigger type="default" value="1">
Tab 1
</Tabs.Trigger>
<Tabs.Trigger type="default" value="2">
Tab 2
</Tabs.Trigger>
<Tabs.Trigger type="default" value="3">
Tab 3
</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="1">
<Text size={15}>Content 1</Text>
</Tabs.Content>
<Tabs.Content value="2">
<Text size={15}>Content 2</Text>
</Tabs.Content>
<Tabs.Content value="3">
<Text size={15}>Content 3</Text>
</Tabs.Content>
</Tabs>
)
},
}

export const GreyBlur: StoryObj<TabsProps> = {
args: {
defaultValue: '1',
},
render(args) {
return (
<Tabs {...args}>
<Tabs.List variant="blur_grey" size={32}>
<Tabs.Trigger type="default" value="1">
Tab 1
</Tabs.Trigger>
<Tabs.Trigger type="default" value="2">
Tab 2
</Tabs.Trigger>
<Tabs.Trigger type="default" value="3">
Tab 3
</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="1">
<Text size={15}>Content 1</Text>
</Tabs.Content>
<Tabs.Content value="2">
<Text size={15}>Content 2</Text>
</Tabs.Content>
<Tabs.Content value="3">
<Text size={15}>Content 3</Text>
</Tabs.Content>
</Tabs>
)
},
}

export const DarkGrey: StoryObj<TabsProps> = {
args: {
defaultValue: '1',
},
render(args) {
return (
<Tabs {...args}>
<Tabs.List variant="darkGrey" size={32}>
<Tabs.Trigger type="default" value="1">
Tab 1
</Tabs.Trigger>
<Tabs.Trigger type="default" value="2">
Tab 2
</Tabs.Trigger>
<Tabs.Trigger type="default" value="3">
Tab 3
</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="1">
<Text size={15}>Content 1</Text>
</Tabs.Content>
<Tabs.Content value="2">
<Text size={15}>Content 2</Text>
</Tabs.Content>
<Tabs.Content value="3">
<Text size={15}>Content 3</Text>
</Tabs.Content>
</Tabs>
)
},
}
export const DarkGreyBlur: StoryObj<TabsProps> = {
args: {
defaultValue: '1',
},
parameters: {
backgrounds: {
default: 'dark',
},
},
render(args) {
return (
<Tabs {...args}>
<Tabs.List variant="blur_darkGrey" size={32}>
<Tabs.Trigger type="default" value="1">
Tab 1
</Tabs.Trigger>
Expand Down Expand Up @@ -57,7 +157,7 @@ export const Icon: StoryObj<TabsProps> = {
render(args) {
return (
<Tabs {...args}>
<Tabs.List size={32}>
<Tabs.List variant="grey" size={32}>
<Tabs.Trigger
type="icon"
value="1"
Expand Down Expand Up @@ -101,7 +201,7 @@ export const Counter: StoryObj<TabsProps> = {
render(args) {
return (
<Tabs {...args}>
<Tabs.List size={32}>
<Tabs.List variant="grey" size={32}>
<Tabs.Trigger type="counter" value="1" count={5}>
Tab 1
</Tabs.Trigger>
Expand Down Expand Up @@ -133,7 +233,7 @@ export const Step: StoryObj<TabsProps> = {
render(args) {
return (
<Tabs {...args}>
<Tabs.List size={32}>
<Tabs.List variant="grey" size={32}>
<Tabs.Trigger type="step" value="1" step={1}>
Tab 1
</Tabs.Trigger>
Expand Down
82 changes: 67 additions & 15 deletions packages/components/src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const Tabs = (props: Props) => {

type ListProps = {
children: React.ReactElement[]
variant: Variants['variant']
size: Variants['size']
}

Expand All @@ -51,7 +52,7 @@ const TabsList = (props: ListProps) => {
<Stack flexDirection="row" gap={8}>
{Children.map(children, child => (
<Trigger asChild value={child.props.value}>
{cloneElement(child, { size: props.size })}
{cloneElement(child, { size: props.size, variant: props.variant })}
</Trigger>
))}
</Stack>
Expand Down Expand Up @@ -86,20 +87,21 @@ const TabsTrigger = (props: TriggerProps, ref: Ref<View>) => {
const providedProps = props as TriggerProps & {
size: 24 | 32
'aria-selected': boolean
variant: Variants['variant']
}

const { size, 'aria-selected': selected, variant } = providedProps

const { color, pressableProps } = usePressableColors(
{
default: '$neutral-100',
hover: '$neutral-100',
press: '$neutral-100',
default: variant === 'blur_darkGrey' ? '$white-100' : '$neutral-100',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use a const for now to avoid repetition?

hover: variant === 'blur_darkGrey' ? '$white-100' : '$neutral-100',
press: variant === 'blur_darkGrey' ? '$white-100' : '$neutral-100',
active: '$white-100',
},
providedProps
)

const { size, 'aria-selected': selected } = providedProps

const textSize = triggerTextSizes[size]

return (
Expand All @@ -108,6 +110,7 @@ const TabsTrigger = (props: TriggerProps, ref: Ref<View>) => {
{...pressableProps}
ref={ref}
size={size}
variant={variant}
active={selected}
>
{props.type === 'icon' &&
Expand Down Expand Up @@ -148,6 +151,35 @@ const TriggerBase = styled(View, {
justifyContent: 'center',

variants: {
variant: {
grey: {
backgroundColor: '$neutral-10',
hoverStyle: {
backgroundColor: '$neutral-20',
},
},
darkGrey: {
backgroundColor: '$neutral-20',
hoverStyle: {
backgroundColor: '$neutral-30',
},
},

blur_grey: {
backgroundColor: '$neutral-80/5',
hoverStyle: {
backgroundColor: '$neutral-80/10',
// backgroundColor: '$neutral-80/60',
prichodko marked this conversation as resolved.
Show resolved Hide resolved
},
},
blur_darkGrey: {
backgroundColor: '$white-5',
hoverStyle: {
backgroundColor: '$white-10',
// backgroundColor: '$white-20',
},
},
},
size: {
32: {
height: 32,
Expand All @@ -163,15 +195,35 @@ const TriggerBase = styled(View, {
},
},
active: {
true: {
cursor: 'default',
prichodko marked this conversation as resolved.
Show resolved Hide resolved
backgroundColor: '$neutral-50',
},
false: {
backgroundColor: '$neutral-10',
hoverStyle: {
backgroundColor: '$neutral-20',
},
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out how to fix this error in Tamagui, even though it's a valid syntax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving the function a type explicitly breaks type inference.

true: (_v, { props }) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const variant = (props as any).variant as Variants['variant']

if (variant === 'grey' || variant === 'darkGrey') {
return {
backgroundColor: '$neutral-50',
hoverStyle: { backgroundColor: '$neutral-50' },
pressStyle: { backgroundColor: '$neutral-50' },
}
}

if (variant === 'blur_grey') {
return {
backgroundColor: '$neutral-80/60',
hoverStyle: { backgroundColor: '$neutral-80/60' },
pressStyle: { backgroundColor: '$neutral-80/60' },
}
}

if (variant === 'blur_darkGrey') {
return {
backgroundColor: '$white-20',
hoverStyle: { backgroundColor: '$white-20' },
pressStyle: { backgroundColor: '$white-20' },
}
}
},
},
} as const,
Expand Down