From 9cbf21599b56bf54b095bb74edfba542e79bb051 Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Wed, 12 Apr 2023 16:36:00 +0200 Subject: [PATCH] Add Tag (#372) * add tag * add next-env.d.ts * fix gap * use $full token for borderRadius * remove comments * fix system message render * fix action type * rm next-env.d.ts --- .../system-message/system-message.stories.tsx | 2 +- .../src/system-message/system-message.tsx | 6 +- packages/components/src/tag/index.tsx | 1 + packages/components/src/tag/tag.stories.tsx | 46 ++++++++++ packages/components/src/tag/tag.tsx | 87 +++++++++++++++++++ 5 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 packages/components/src/tag/index.tsx create mode 100644 packages/components/src/tag/tag.stories.tsx create mode 100644 packages/components/src/tag/tag.tsx diff --git a/packages/components/src/system-message/system-message.stories.tsx b/packages/components/src/system-message/system-message.stories.tsx index d64228ed..ecb098a9 100644 --- a/packages/components/src/system-message/system-message.stories.tsx +++ b/packages/components/src/system-message/system-message.stories.tsx @@ -32,7 +32,7 @@ export const AllVariants: Story = { timestamp="11:12" type="deleted" text="Message deleted for you" - action={{ label: 'Undo', onClick: action('undo') }} + action={{ label: 'Undo', onPress: action('undo') }} state={state} /> void + onPress: () => void } } | { @@ -47,7 +47,7 @@ type Props = { const SystemMessage = (props: Props) => { const { state = 'default', timestamp, type } = props - const renderMessage = (type: 'pinned' | 'deleted' | 'added') => { + const renderMessage = () => { switch (type) { case 'pinned': return ( @@ -89,7 +89,7 @@ const SystemMessage = (props: Props) => { type === 'deleted' && state === 'landed' ? 'landed_deleted' : state } > - {renderMessage(type)} + {renderMessage()} ) } diff --git a/packages/components/src/tag/index.tsx b/packages/components/src/tag/index.tsx new file mode 100644 index 00000000..9d018728 --- /dev/null +++ b/packages/components/src/tag/index.tsx @@ -0,0 +1 @@ +export { Tag } from './tag' diff --git a/packages/components/src/tag/tag.stories.tsx b/packages/components/src/tag/tag.stories.tsx new file mode 100644 index 00000000..17dc8761 --- /dev/null +++ b/packages/components/src/tag/tag.stories.tsx @@ -0,0 +1,46 @@ +import { Stack } from '@tamagui/core' + +import { Tag } from './tag' + +import type { Meta, StoryObj } from '@storybook/react' + +const meta: Meta = { + component: Tag, + argTypes: {}, + parameters: { + design: { + type: 'figma', + url: 'https://www.figma.com/file/IBmFKgGL1B4GzqD8LQTw6n/Design-System-for-Desktop%2FWeb?node-id=180-9685&t=tDEqIV09qddTZgXF-4', + }, + }, +} + +type Story = StoryObj + +export const Default: Story = { + render: () => { + return ( + + + + + + + + + + + + + + + + + + + + ) + }, +} + +export default meta diff --git a/packages/components/src/tag/tag.tsx b/packages/components/src/tag/tag.tsx new file mode 100644 index 00000000..c01d04ad --- /dev/null +++ b/packages/components/src/tag/tag.tsx @@ -0,0 +1,87 @@ +import { Stack, styled } from '@tamagui/core' + +import { Text } from '../text' + +import type { TextProps } from '../text' + +type Props = { + size: 32 | 24 + emoji?: string + label?: string + selected?: boolean + disabled?: boolean +} + +const textSizes: Record, TextProps['size']> = { + '32': 15, + '24': 13, +} + +const Tag = (props: Props) => { + const { size, emoji, label, selected, disabled } = props + + return ( + + {emoji && {emoji}} + {label && ( + + {label} + + )} + + ) +} + +const Base = styled(Stack, { + display: 'flex', + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'center', + borderWidth: 1, + borderColor: '$neutral-20', + borderRadius: '$full', + + variants: { + size: { + 32: { + height: 32, + minWidth: 32, + paddingHorizontal: 12, + gap: 6, + }, + 24: { + height: 24, + minWidth: 24, + paddingHorizontal: 8, + gap: 5, + }, + }, + + selected: { + true: { + backgroundColor: '$primary-50-opa-10', + borderColor: '$primary-50', + }, + }, + + disabled: { + true: { + opacity: 0.3, + cursor: 'default', + }, + }, + + emojiOnly: { + true: { + paddingHorizontal: 0, + }, + }, + }, +}) + +export { Tag }