From db7befaec2b855a0e3310220d8a5420ce4fcad1f Mon Sep 17 00:00:00 2001 From: Pavel <14926950+prichodko@users.noreply.github.com> Date: Wed, 22 Mar 2023 10:57:25 +0100 Subject: [PATCH] Unify typography and enforce only valid variants (#354) * unify typography under Text component * migrate from paragraph/heading to text * update font configuration --- apps/web/index.html | 2 +- apps/web/src/app.tsx | 2 +- .../components/src/accordion/accordion.tsx | 17 +- .../src/accordion/accordionItem.tsx | 22 +-- packages/components/src/author/author.tsx | 10 +- packages/components/src/button/button.tsx | 44 ++--- .../src/divider-label/divider-label.tsx | 6 +- .../src/dropdown-menu/dropdown-menu.tsx | 6 +- .../components/src/icons/icons.stories.tsx | 10 +- packages/components/src/index.tsx | 2 +- packages/components/src/messages/message.tsx | 17 +- .../src/react-button/react-button.tsx | 6 +- packages/components/src/reply/reply.tsx | 14 +- packages/components/src/sidebar/sidebar.tsx | 14 +- packages/components/src/tamagui.config.ts | 104 ++++------- packages/components/src/text/index.tsx | 1 + packages/components/src/text/text.stories.tsx | 61 +++++++ packages/components/src/text/text.tsx | 119 ++++++++++++ packages/components/src/tooltip/tooltip.tsx | 6 +- .../components/src/topbar/topbar.stories.tsx | 2 +- packages/components/src/topbar/topbar.tsx | 39 ++-- packages/components/src/typography/index.tsx | 1 - .../src/typography/typography.stories.tsx | 60 ------ .../components/src/typography/typography.tsx | 171 ------------------ .../components/src/user-list/user-list.tsx | 6 +- 25 files changed, 315 insertions(+), 427 deletions(-) create mode 100644 packages/components/src/text/index.tsx create mode 100644 packages/components/src/text/text.stories.tsx create mode 100644 packages/components/src/text/text.tsx delete mode 100644 packages/components/src/typography/index.tsx delete mode 100644 packages/components/src/typography/typography.stories.tsx delete mode 100644 packages/components/src/typography/typography.tsx diff --git a/apps/web/index.html b/apps/web/index.html index 922831ea..29366175 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -5,7 +5,7 @@
component?
+const Text = (props: Props, ref: Ref) => {
+ const { color = '$neutral-100', ...rest } = props
+ return
+}
+
+const Base = styled(BaseText, {
+ name: 'Text',
+
+ variants: {
+ type: {
+ default: {
+ fontFamily: '$sans',
+ },
+ monospace: {
+ fontFamily: '$mono',
+ },
+ },
+
+ size: {
+ 27: {
+ fontSize: 27,
+ lineHeight: 32,
+ letterSpacing: -0.021,
+ },
+ 19: {
+ fontSize: 19,
+ lineHeight: 26,
+ letterSpacing: -0.016,
+ },
+ 15: {
+ fontSize: 15,
+ lineHeight: 22,
+ letterSpacing: -0.009,
+ },
+ 13: {
+ fontSize: 13,
+ lineHeight: 18,
+ letterSpacing: -0.003,
+ },
+ 11: {
+ fontSize: 11,
+ lineHeight: 18,
+ letterSpacing: -0.003,
+ },
+ },
+
+ weight: {
+ regular: {
+ fontWeight: '400',
+ },
+ medium: {
+ fontWeight: '500',
+ },
+ semibold: {
+ fontWeight: '600',
+ },
+ },
+
+ uppercase: {
+ true: {
+ textTransform: 'uppercase',
+ },
+ },
+
+ wrap: {
+ false: {
+ whiteSpace: 'nowrap',
+ },
+ },
+
+ truncate: {
+ true: {
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ wordWrap: 'normal',
+ maxWidth: '100%',
+ minWidth: 0,
+ },
+ },
+ } as const,
+
+ defaultVariants: {
+ type: 'default',
+ weight: 'regular',
+ },
+})
+
+const _Text = forwardRef(Text)
+
+export { _Text as Text }
+export type { Props as TextProps }
diff --git a/packages/components/src/tooltip/tooltip.tsx b/packages/components/src/tooltip/tooltip.tsx
index 7dbe1acb..f0a0b4c7 100644
--- a/packages/components/src/tooltip/tooltip.tsx
+++ b/packages/components/src/tooltip/tooltip.tsx
@@ -10,7 +10,7 @@ import {
} from '@radix-ui/react-tooltip'
import { Stack } from 'tamagui'
-import { Paragraph } from '../typography'
+import { Text } from '../text'
import type { TooltipContentProps } from '@radix-ui/react-tooltip'
import type { Ref } from 'react'
@@ -62,9 +62,9 @@ const Tooltip = (props: Props, ref: Ref) => {
shadowColor="rgba(9, 16, 28, 0.12)"
>
{typeof content === 'string' ? (
-
+
{content}
-
+
) : (
content
)}
diff --git a/packages/components/src/topbar/topbar.stories.tsx b/packages/components/src/topbar/topbar.stories.tsx
index 8d86d578..00caec79 100644
--- a/packages/components/src/topbar/topbar.stories.tsx
+++ b/packages/components/src/topbar/topbar.stories.tsx
@@ -38,7 +38,7 @@ export const Default: Story = {
export const WithMembersSelected: Story = {
args: {
...Default.args,
- membersVisisble: true,
+ showMembers: true,
},
}
diff --git a/packages/components/src/topbar/topbar.tsx b/packages/components/src/topbar/topbar.tsx
index b07e8b9c..51adc21f 100644
--- a/packages/components/src/topbar/topbar.tsx
+++ b/packages/components/src/topbar/topbar.tsx
@@ -10,18 +10,18 @@ import {
ShareIcon,
UpToDateIcon,
} from '@status-im/icons/20'
-import { Stack, Text } from '@tamagui/core'
+import { Stack, Text as RNText } from '@tamagui/core'
import { BlurView } from 'expo-blur'
import { Divider } from '../divider'
import { DropdownMenu } from '../dropdown-menu'
import { IconButton } from '../icon-button'
-import { Paragraph } from '../typography'
+import { Text } from '../text'
import type { Channel } from '../sidebar/mock-data'
type Props = {
- membersVisisble: boolean
+ showMembers: boolean
onMembersPress: () => void
goBack?: () => void
channel: Channel
@@ -29,7 +29,7 @@ type Props = {
}
const Topbar = (props: Props) => {
- const { membersVisisble, onMembersPress, goBack, blur, channel } = props
+ const { showMembers, onMembersPress, goBack, blur, channel } = props
const { title, description, emoji } = channel
@@ -57,14 +57,14 @@ const Topbar = (props: Props) => {
{emoji && (
- {emoji}
+ {emoji}
)}
{title && (
-
+
{title}
-
+
)}
@@ -81,24 +81,21 @@ const Topbar = (props: Props) => {
$sm={{ justifyContent: 'flex-end' }}
>
{description && (
-
- {description}
-
+
+
+ {description}
+
+
)}
}
- selected={membersVisisble}
+ selected={showMembers}
onPress={onMembersPress}
blur={blur}
/>
diff --git a/packages/components/src/typography/index.tsx b/packages/components/src/typography/index.tsx
deleted file mode 100644
index 324025ef..00000000
--- a/packages/components/src/typography/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export * from './typography'
diff --git a/packages/components/src/typography/typography.stories.tsx b/packages/components/src/typography/typography.stories.tsx
deleted file mode 100644
index f645fced..00000000
--- a/packages/components/src/typography/typography.stories.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import { Stack } from '@tamagui/core'
-
-import { Code, Heading, Paragraph } from '.'
-
-import type { Meta, StoryObj } from '@storybook/react'
-
-const meta: Meta = {
- title: 'typography',
- argTypes: {},
-}
-
-export const HeadingStory: StoryObj = {
- name: 'Heading',
- args: {
- children: 'The quick brown fox jumped over the lazy dog.',
- },
- render: args => (
-
-
-
-
-
-
-
-
- ),
-}
-
-export const TextStory: StoryObj = {
- name: 'Text',
- args: {
- children: 'The quick brown fox jumped over the lazy dog.',
- },
- render: args => (
-
-
-
-
-
-
-
-
- ),
-}
-
-export const CodeStory: StoryObj = {
- name: 'Code',
- args: {
- children: '// How to create variables:',
- },
- render: () => (
-
-
- The quick brown fox jumped over the lazy dog.
-
-
- ),
-}
-
-export default meta
diff --git a/packages/components/src/typography/typography.tsx b/packages/components/src/typography/typography.tsx
deleted file mode 100644
index 66981cdc..00000000
--- a/packages/components/src/typography/typography.tsx
+++ /dev/null
@@ -1,171 +0,0 @@
-import { styled } from '@tamagui/core'
-import { SizableText } from 'tamagui'
-
-export const Heading = styled(SizableText, {
- name: 'Heading',
- fontFamily: '$inter',
- color: '$textPrimary',
-
- variants: {
- heading: {
- h1: {
- fontSize: 27,
- lineHeight: 32,
- letterSpacing: -0.021,
- },
- h2: {
- fontSize: 19,
- lineHeight: 26,
- letterSpacing: -0.016,
- },
- },
- uppercase: {
- true: {
- textTransform: 'uppercase',
- },
- },
- weight: {
- regular: {
- fontWeight: '400',
- },
- medium: {
- fontWeight: '500',
- },
- semibold: {
- fontWeight: '600',
- },
- },
- } as const,
- defaultVariants: {
- // note tamagui uses a generic "true" token that your sizes should set to be the same as the default on your scale
- size: '$true',
- heading: 'h1',
- },
-})
-
-export const Paragraph = styled(SizableText, {
- name: 'Paragraph',
- fontFamily: '$inter',
- color: '$textPrimary',
-
- variants: {
- variant: {
- normal: {
- fontSize: 15,
- lineHeight: 22,
- letterSpacing: -0.009,
- },
- smaller: {
- fontSize: 13,
- lineHeight: 18,
- letterSpacing: -0.003,
- },
- 11: {
- fontSize: 11,
- lineHeight: 18,
- letterSpacing: -0.003,
- },
- },
- uppercase: {
- true: {
- textTransform: 'uppercase',
- },
- },
- weight: {
- regular: {
- fontWeight: '400',
- },
- medium: {
- fontWeight: '500',
- },
- semibold: {
- fontWeight: '600',
- },
- },
- } as const,
- defaultVariants: {
- // note tamagui uses a generic "true" token that your sizes should set to be the same as the default on your scale
- size: '$true',
- variant: 'normal',
- weight: 'regular',
- },
-})
-
-export const Label = styled(SizableText, {
- name: 'Label',
- fontFamily: '$inter',
- color: '$textPrimary',
-
- fontSize: 11,
- lineHeight: 16,
- letterSpacing: -0.005,
-
- variants: {
- uppercase: {
- true: {
- textTransform: 'uppercase',
- },
- },
- weight: {
- regular: {
- fontWeight: '400',
- },
- medium: {
- fontWeight: '500',
- },
- semibold: {
- fontWeight: '600',
- },
- },
- } as const,
- defaultVariants: {
- // note tamagui uses a generic "true" token that your sizes should set to be the same as the default on your scale
- size: '$true',
- weight: 'regular',
- },
-})
-
-export const Code = styled(SizableText, {
- name: 'Code',
- fontFamily: '$mono',
- color: '$textPrimary',
-
- fontSize: 11,
- lineHeight: 16,
- letterSpacing: -0.005,
-
- variants: {
- normal: {
- fontSize: 15,
- lineHeight: 22,
- letterSpacing: -0.009,
- },
- smaller: {
- fontSize: 13,
- lineHeight: 18,
- letterSpacing: -0.003,
- },
- uppercase: {
- true: {
- textTransform: 'uppercase',
- },
- },
- weight: {
- regular: {
- fontWeight: '400',
- },
- medium: {
- fontWeight: '500',
- },
- semibold: {
- fontWeight: '600',
- },
- },
- } as const,
- defaultVariants: {
- // note tamagui uses a generic "true" token that your sizes should set to be the same as the default on your scale
- size: '$true',
- variant: 'normal',
- weight: 'regular',
- },
-})
diff --git a/packages/components/src/user-list/user-list.tsx b/packages/components/src/user-list/user-list.tsx
index 8196ad88..6ad97924 100644
--- a/packages/components/src/user-list/user-list.tsx
+++ b/packages/components/src/user-list/user-list.tsx
@@ -2,7 +2,7 @@ import { XStack, YStack } from 'tamagui'
import { Author } from '../author/author'
import { Avatar } from '../avatar'
-import { Paragraph } from '../typography'
+import { Text } from '../text'
import type { AuthorProps } from '../author/author'
import type { AvatarProps } from '../avatar'
@@ -37,9 +37,9 @@ const UserList = (props: Props) => {
status={user.status}
orientation="vertical"
/>
-
+
{user.address}
-
+
)