From 1e5e10eaddb50d6c0492ec600db5781205299252 Mon Sep 17 00:00:00 2001
From: Pavel <14926950+prichodko@users.noreply.github.com>
Date: Thu, 30 Mar 2023 14:41:56 +0200
Subject: [PATCH] Message reactions, add Tabs, update Dialog and Tooltip (#361)
* add Tabs component
* update Tooltip styling
* add reactions dialog
* use IconButton and simplify ReactButton
* add PressableTrigger to dialog
* update css reset
* update pressable type
* fix text story name
* update dynamic button props
* add counter to TabsTrigger
* fix casing in USerListProps
* make Dialog.Content customizable
* update dialogs
---
apps/web/styles/reset.css | 1 +
packages/components/.storybook/reset.css | 1 +
packages/components/package.json | 1 +
packages/components/src/counter/counter.tsx | 9 +-
.../components/src/dialog/dialog.stories.tsx | 5 +-
packages/components/src/dialog/dialog.tsx | 118 ++++++-------
packages/components/src/dialog/index.tsx | 2 +-
.../dynamic-button/dynamic-button.stories.tsx | 1 -
.../src/dynamic-button/dynamic-button.tsx | 9 +-
.../src/hooks/use-pressable-colors.tsx | 10 +-
.../src/icon-button/icon-button.tsx | 5 +-
.../messages/components/reaction-popover.tsx | 49 ++++--
.../messages/components/reactions-dialog.tsx | 89 ++++++++++
.../src/messages/components/reactions.tsx | 116 ++++++-------
.../src/pinned-message/pinned-message.tsx | 91 +++-------
.../src/react-button/react-button.stories.tsx | 54 +-----
.../src/react-button/react-button.tsx | 82 +++------
.../src/sidebar-members/sidebar-members.tsx | 4 +-
packages/components/src/tabs/index.tsx | 1 +
packages/components/src/tabs/tabs.stories.tsx | 72 ++++++++
packages/components/src/tabs/tabs.tsx | 164 ++++++++++++++++++
packages/components/src/text/text.stories.tsx | 6 +-
packages/components/src/tooltip/tooltip.tsx | 19 +-
packages/components/src/types.ts | 2 +-
.../components/src/user-list/user-list.tsx | 2 +-
yarn.lock | 15 ++
26 files changed, 580 insertions(+), 348 deletions(-)
create mode 100644 packages/components/src/messages/components/reactions-dialog.tsx
create mode 100644 packages/components/src/tabs/index.tsx
create mode 100644 packages/components/src/tabs/tabs.stories.tsx
create mode 100644 packages/components/src/tabs/tabs.tsx
diff --git a/apps/web/styles/reset.css b/apps/web/styles/reset.css
index 71df37c9..4dc13e3e 100644
--- a/apps/web/styles/reset.css
+++ b/apps/web/styles/reset.css
@@ -71,6 +71,7 @@ button,
textarea,
select {
font: inherit;
+ all: unset;
}
/*
8. Avoid text overflows
diff --git a/packages/components/.storybook/reset.css b/packages/components/.storybook/reset.css
index c793f03b..3d5db94d 100644
--- a/packages/components/.storybook/reset.css
+++ b/packages/components/.storybook/reset.css
@@ -71,6 +71,7 @@ button,
textarea,
select {
font: inherit;
+ all: unset;
}
/*
8. Avoid text overflows
diff --git a/packages/components/package.json b/packages/components/package.json
index b2f97890..310c3279 100644
--- a/packages/components/package.json
+++ b/packages/components/package.json
@@ -32,6 +32,7 @@
"@radix-ui/react-dialog": "^1.0.3",
"@radix-ui/react-dropdown-menu": "^2.0.4",
"@radix-ui/react-popover": "^1.0.5",
+ "@radix-ui/react-tabs": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.5",
"@status-im/icons": "*",
"@tamagui/animations-css": "1.7.7",
diff --git a/packages/components/src/counter/counter.tsx b/packages/components/src/counter/counter.tsx
index 89c4d514..a5965555 100644
--- a/packages/components/src/counter/counter.tsx
+++ b/packages/components/src/counter/counter.tsx
@@ -17,7 +17,7 @@ const Counter = (props: Props) => {
return (
-
+
{value > 99 ? '99+' : value}
@@ -31,7 +31,7 @@ const Base = styled(View, {
backgroundColor: '$primary-50',
paddingHorizontal: 3,
paddingVertical: 0,
- borderRadius: '6px', // TODO: use tokens when fixed its definition
+ borderRadius: 6, // TODO: use tokens when fixed its definition
height: 16,
minWidth: 16,
maxWidth: 28,
@@ -39,6 +39,8 @@ const Base = styled(View, {
justifyContent: 'center',
alignItems: 'center',
flexBasis: 'fit-content',
+ borderWidth: 1,
+ borderColor: 'transparent',
variants: {
type: {
@@ -54,13 +56,12 @@ const Base = styled(View, {
outline: {
backgroundColor: 'transparent',
borderColor: '$neutral-20',
- borderWidth: '1px',
},
},
},
})
-const textColor: Record, ColorTokens> = {
+const textColors: Record, ColorTokens> = {
default: '$white-100',
secondary: '$neutral-100',
outline: '$neutral-100',
diff --git a/packages/components/src/dialog/dialog.stories.tsx b/packages/components/src/dialog/dialog.stories.tsx
index 32117f79..b616533f 100644
--- a/packages/components/src/dialog/dialog.stories.tsx
+++ b/packages/components/src/dialog/dialog.stories.tsx
@@ -24,7 +24,10 @@ export const Default: Story = {
render: () => (
),
}
diff --git a/packages/components/src/dialog/dialog.tsx b/packages/components/src/dialog/dialog.tsx
index fa7b6ba9..306dda0f 100644
--- a/packages/components/src/dialog/dialog.tsx
+++ b/packages/components/src/dialog/dialog.tsx
@@ -1,10 +1,15 @@
-import { forwardRef } from 'react'
+import { cloneElement, forwardRef } from 'react'
-import { Content, Overlay, Portal, Root, Trigger } from '@radix-ui/react-dialog'
-import { Stack, styled, useMedia } from 'tamagui'
-
-import { Sheet } from '../sheet'
+import {
+ Close,
+ Content,
+ Overlay,
+ Portal,
+ Root,
+ Trigger,
+} from '@radix-ui/react-dialog'
+import type { DialogTriggerProps } from '@radix-ui/react-dialog'
import type { Ref } from 'react'
import type React from 'react'
@@ -15,74 +20,61 @@ interface Props {
press?: 'normal' | 'long'
}
-const Wrapper = styled(Stack, {
- position: 'absolute',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- width: '100vw',
- height: '100vh',
-})
-
-// const DialogTrigger = (
-// props: DialogTriggerProps & {
-// press: Props['press']
-// children: React.ReactElement
-// }
-// ) => {
-// const { children, press, onClick, type, ...triggerProps } = props
-// const handler = press === 'normal' ? 'onPress' : 'onLongPress'
-
-// // console.log('dialog', press, onClick, { ...triggerProps, [handler]: onClick })
-// return cloneElement(children, { ref, ...triggerProps, [handler]: onClick })
-// }
-
-// TODO: allow customization of press duration
const Dialog = (props: Props) => {
- const { children, open, onOpenChange /* press = 'normal' */ } = props
+ const { children, open, onOpenChange, press = 'normal' } = props
const [trigger, content] = children
- const media = useMedia()
+ // const media = useMedia()
- if (media.sm) {
- return (
-
- {trigger}
- {content}
-
- )
- }
+ // if (media.sm) {
+ // return (
+ //
+ // {trigger}
+ // {content}
+ //
+ // )
+ // }
return (
{/* TRIGGER */}
- {trigger}
+
+ {trigger}
+
{/* CONTENT */}
-
-
- {content}
-
+
+ {content}
)
}
+const PressableTrigger = forwardRef(function _PressableTrigger(
+ props: DialogTriggerProps & {
+ press: Props['press']
+ children: React.ReactElement
+ },
+ ref
+) {
+ const { children, press, onClick, ...triggerProps } = props
+ const handler = press === 'normal' ? 'onPress' : 'onLongPress'
+
+ return cloneElement(children, { ref, ...triggerProps, [handler]: onClick })
+})
+
interface DialogContentProps {
- // title: string
- // description?: string
children: React.ReactNode
- // action: string
- // onAction: (close: VoidFunction) => void
- // onCancel?: () => void
+ borderRadius: 8 | 12 | 16
+ width: number
initialFocusRef?: React.RefObject
}
@@ -96,25 +88,25 @@ const DialogContent = (props: DialogContentProps, ref: Ref) => {
}
}
- const media = useMedia()
+ // const media = useMedia()
- if (media.sm) {
- return {children}
- }
+ // if (media.sm) {
+ // return {children}
+ // }
return (
{children}
@@ -124,4 +116,4 @@ const DialogContent = (props: DialogContentProps, ref: Ref) => {
Dialog.Content = forwardRef(DialogContent)
-export { Dialog }
+export { Close, Dialog }
diff --git a/packages/components/src/dialog/index.tsx b/packages/components/src/dialog/index.tsx
index afbb355f..ac07eb6b 100644
--- a/packages/components/src/dialog/index.tsx
+++ b/packages/components/src/dialog/index.tsx
@@ -1 +1 @@
-export { Dialog } from './dialog'
+export { Close, Dialog } from './dialog'
diff --git a/packages/components/src/dynamic-button/dynamic-button.stories.tsx b/packages/components/src/dynamic-button/dynamic-button.stories.tsx
index 1080c01c..5580129d 100644
--- a/packages/components/src/dynamic-button/dynamic-button.stories.tsx
+++ b/packages/components/src/dynamic-button/dynamic-button.stories.tsx
@@ -6,7 +6,6 @@ import type { Meta, StoryObj } from '@storybook/react'
// More on how to set up stories at: https://storybook.js.org/docs/7.0/react/writing-stories/introduction
const meta: Meta = {
- title: 'DynamicButton',
component: DynamicButton,
args: {},
argTypes: {},
diff --git a/packages/components/src/dynamic-button/dynamic-button.tsx b/packages/components/src/dynamic-button/dynamic-button.tsx
index 16b535db..090feb40 100644
--- a/packages/components/src/dynamic-button/dynamic-button.tsx
+++ b/packages/components/src/dynamic-button/dynamic-button.tsx
@@ -6,10 +6,9 @@ import { Stack, styled } from '@tamagui/core'
import { Shadow } from '../shadow'
import { Text } from '../text'
-import type { GetVariants } from '../types'
-import type { ColorTokens, StackProps } from '@tamagui/core'
+import type { GetVariants, PressableProps } from '../types'
+import type { ColorTokens } from '@tamagui/core'
import type { Ref } from 'react'
-import type { PressableProps } from 'react-native'
type Variants = GetVariants
@@ -27,7 +26,7 @@ const DynamicButton = (props: Props, ref: Ref) => {
return (
diff --git a/packages/components/src/types.ts b/packages/components/src/types.ts
index 06346eaa..0e7e3539 100644
--- a/packages/components/src/types.ts
+++ b/packages/components/src/types.ts
@@ -17,7 +17,7 @@ type PressableProps = {
delayHoverIn?: NativePressableProps['delayHoverIn']
delayHoverOut?: NativePressableProps['delayHoverOut']
delayLongPress?: NativePressableProps['delayLongPress']
- disabled?: NativePressableProps['disabled']
+ disabled?: boolean
}
export type MapVariant<
diff --git a/packages/components/src/user-list/user-list.tsx b/packages/components/src/user-list/user-list.tsx
index 6ad97924..4977d972 100644
--- a/packages/components/src/user-list/user-list.tsx
+++ b/packages/components/src/user-list/user-list.tsx
@@ -49,4 +49,4 @@ const UserList = (props: Props) => {
}
export { UserList }
-export type { Props as USerListProps }
+export type { Props as UserListProps }
diff --git a/yarn.lock b/yarn.lock
index a78893cb..8401d19d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3541,6 +3541,21 @@
"@babel/runtime" "^7.13.10"
"@radix-ui/react-compose-refs" "1.0.0"
+"@radix-ui/react-tabs@^1.0.3":
+ version "1.0.3"
+ resolved "https://registry.yarnpkg.com/@radix-ui/react-tabs/-/react-tabs-1.0.3.tgz#8b4158160a7c6633c893c74641e929d2708e709a"
+ integrity sha512-4CkF/Rx1GcrusI/JZ1Rvyx4okGUs6wEenWA0RG/N+CwkRhTy7t54y7BLsWUXrAz/GRbBfHQg/Odfs/RoW0CiRA==
+ dependencies:
+ "@babel/runtime" "^7.13.10"
+ "@radix-ui/primitive" "1.0.0"
+ "@radix-ui/react-context" "1.0.0"
+ "@radix-ui/react-direction" "1.0.0"
+ "@radix-ui/react-id" "1.0.0"
+ "@radix-ui/react-presence" "1.0.0"
+ "@radix-ui/react-primitive" "1.0.2"
+ "@radix-ui/react-roving-focus" "1.0.3"
+ "@radix-ui/react-use-controllable-state" "1.0.0"
+
"@radix-ui/react-tooltip@^1.0.5":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@radix-ui/react-tooltip/-/react-tooltip-1.0.5.tgz#fe20274aeac874db643717fc7761d5a8abdd62d1"