Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Design system improvements #575

Merged
merged 4 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion apps/storybook-react/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import '../styles/globals.css'

import React from 'react'
import * as NextImage from 'next/image'
import { DripsyProvider } from 'dripsy'

Expand Down
1 change: 0 additions & 1 deletion apps/storybook-react/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
Expand Down
1 change: 0 additions & 1 deletion apps/storybook-react/stories/pages/home.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import Home from '../../pages/index'

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// https://reactnavigation.org/docs/custom-navigators/#type-checking-navigators

import React from 'react'
import {
createNavigatorFactory,
DefaultNavigatorOptions,
Expand Down
2 changes: 0 additions & 2 deletions packages/app/screens/login.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react'

import { Modal } from 'design-system'
import { Login } from 'app/components/login'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { Meta } from '@storybook/react'

import { Pressable } from './index'
Expand Down
1 change: 0 additions & 1 deletion packages/design-system/skeleton/skeleton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { Meta } from '@storybook/react'

import { Skeleton } from './index'
Expand Down
35 changes: 26 additions & 9 deletions packages/design-system/text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import React, { ComponentProps } from 'react'
import { Text as DripsyText, Theme } from 'dripsy'
import { Theme, Text as DripsyText } from 'dripsy'
import { ComponentProps, createContext, forwardRef, useContext } from 'react'
import type { Text as TextType } from 'react-native'

import { tw as tailwind } from 'design-system/tailwind'

type Variant = keyof Theme['text']

type TextProps = { tw?: string; variant?: Variant } & Omit<ComponentProps<typeof DripsyText>, 'variant'>
type TextProps = ComponentProps<typeof DripsyText>

// Note: You can wrap <DripsyText> in a <View> with a background color
// to verify if the text is rendered correctly and if Capsize is working well.
type Props = { tw?: string; variant?: Variant } & Pick<TextProps, 'onLayout' | 'children' | 'selectable' | 'sx'>

function Text({ tw, sx, variant, ...props }: TextProps) {
return <DripsyText sx={{ ...sx, ...tailwind.style(tw) }} variant={variant} {...props} />
}
/**
* Text should inherit styles from parent text nodes.
*/
const ParentContext = createContext<{} | undefined>(undefined)

export { Text }
/**
* Note: You can wrap <DripsyText> in a <View> with a background color
* to verify if the text is rendered correctly and if Capsize is working well.
*/
export const Text = forwardRef<TextType, Props>(({ variant, onLayout, children, selectable, tw, sx }, ref) => {
const parentTw = useContext(ParentContext)

const compoundSx = { ...tailwind.style(parentTw), ...sx, ...tailwind.style(tw) }

return (
<DripsyText ref={ref} variant={variant} selectable={selectable} onLayout={onLayout} sx={compoundSx}>
<ParentContext.Provider value={compoundSx}>{children}</ParentContext.Provider>
</DripsyText>
)
})

Text.displayName = 'Text'
10 changes: 9 additions & 1 deletion packages/design-system/text/text.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { Meta } from '@storybook/react'

import { Text } from './index'
Expand All @@ -10,6 +9,15 @@ export default {

export const TextXS: React.VFC<{}> = () => <Text variant="text-xs">Hello World</Text>

export const TextXSBoldAndPurple: React.VFC<{}> = () => (
<Text variant="text-xs" tw="font-bold">
Hello{' '}
<Text variant="text-xs" tw="text-stpurple">
World
</Text>
</Text>
)

export const TextSM: React.VFC<{}> = () => <Text variant="text-sm">Hello World</Text>

export const TextBase: React.VFC<{}> = () => <Text variant="text-base">Hello World</Text>
Expand Down