-
Notifications
You must be signed in to change notification settings - Fork 0
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
Set up Storybook; create an Icon component as a proof of concept #6
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d7375ed
Set up Storybook
jessepinho b0c632e
Export DripsyTheme
jessepinho 81ffe96
Create an Icon component; use it (as a proof of concept) in the main …
jessepinho 17b88a2
Add README blurb
jessepinho e57b6b0
Small tweaks to docs
jessepinho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,5 @@ yarn-error.* | |
/ios/ | ||
app-example | ||
modules/penumbra-sdk-module/ios/Mobile.xcframework/**/*.a | ||
|
||
*storybook.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import path from 'path'; | ||
import react from '@vitejs/plugin-react'; | ||
import type { StorybookConfig } from '@storybook/react-vite'; | ||
import svgr from 'vite-plugin-svgr'; | ||
|
||
const config: StorybookConfig = { | ||
stories: ['../**/*.stories.@(js|jsx|mjs|ts|tsx)'], | ||
async viteFinal(config) { | ||
const { mergeConfig } = await import('vite'); | ||
|
||
return mergeConfig(config, { | ||
optimizeDeps: { | ||
// Required for libraries that include JSX in their `.js` files. | ||
// @see https://github.com/vitejs/vite/discussions/3448#discussioncomment-5904031 | ||
esbuildOptions: { | ||
loader: { | ||
'.js': 'jsx', | ||
}, | ||
}, | ||
}, | ||
plugins: [ | ||
// Allows us to use JSX without `import React from 'react'` | ||
react({ jsxRuntime: 'automatic' }), | ||
// Allows us to `import foo from './foo.svg'` in Storybook Web just like | ||
// in React Native. | ||
svgr({ svgrOptions: { exportType: 'default' } }), | ||
], | ||
resolve: { | ||
alias: { | ||
// Match the tsconfig.json alias | ||
'@': path.resolve(__dirname, '../src'), | ||
|
||
// Tells Storybook to use react-native-web anytime there's an import | ||
// from react-native | ||
'react-native': 'react-native-web', | ||
|
||
// Use web-friendly versions of specific libraries | ||
'react-native-svg': 'react-native-svg-web', | ||
}, | ||
}, | ||
}); | ||
}, | ||
addons: [ | ||
'@storybook/addon-onboarding', | ||
'@storybook/addon-essentials', | ||
'@chromatic-com/storybook', | ||
'@storybook/addon-interactions', | ||
'@storybook/addon-react-native-web', | ||
], | ||
framework: { | ||
name: '@storybook/react-vite', | ||
options: {}, | ||
}, | ||
core: { | ||
builder: '@storybook/builder-vite', | ||
}, | ||
typescript: { | ||
reactDocgen: 'react-docgen-typescript', | ||
}, | ||
}; | ||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { DripsyProvider } from 'dripsy'; | ||
import dripsyTheme from '../utils/dripsyTheme'; | ||
import type { Preview } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
const preview: Preview = { | ||
decorators: [ | ||
Story => ( | ||
<DripsyProvider theme={dripsyTheme}> | ||
<Story /> | ||
</DripsyProvider> | ||
), | ||
], | ||
parameters: { | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/i, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default preview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { CheckCircle, Home, Coins } from 'lucide-react-native'; | ||
import { Meta, StoryObj } from '@storybook/react/*'; | ||
import Icon from '.'; | ||
import { DripsyTheme } from '@/utils/dripsyTheme'; | ||
|
||
const COLORS = { | ||
success: (colors: DripsyTheme['color']) => colors.success.main, | ||
destructive: (colors: DripsyTheme['color']) => colors.destructive.main, | ||
unshield: (colors: DripsyTheme['color']) => colors.unshield.main, | ||
}; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export | ||
const meta = { | ||
component: Icon, | ||
tags: ['autodocs'], | ||
argTypes: { | ||
IconComponent: { | ||
options: ['CheckCircle', 'Home', 'Coins'], | ||
mapping: { CheckCircle, Home, Coins }, | ||
}, | ||
color: { | ||
options: ['success', 'destructive', 'unshield'], | ||
mapping: COLORS, | ||
}, | ||
}, | ||
} satisfies Meta<typeof Icon>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Primary: Story = { | ||
args: { | ||
IconComponent: CheckCircle, | ||
size: 'md', | ||
color: COLORS.success, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { DripsyTheme } from '@/utils/dripsyTheme'; | ||
import { useDripsyTheme } from 'dripsy'; | ||
import { LucideIcon } from 'lucide-react-native'; | ||
import { ComponentProps, FC } from 'react'; | ||
|
||
export type IconSize = 'sm' | 'md' | 'lg'; | ||
|
||
export interface IconProps { | ||
/** | ||
* The icon import from `lucide-react` to render. | ||
* | ||
* ```tsx | ||
* import { ChevronRight } from 'lucide-react-native'; | ||
* <Icon IconComponent={ChevronRight} /> | ||
* ``` | ||
*/ | ||
IconComponent: LucideIcon | FC; | ||
/** | ||
* - `sm`: 16px square | ||
* - `md`: 24px square | ||
* - `lg`: 32px square | ||
*/ | ||
size: IconSize; | ||
/** | ||
* A function that takes the theme's `color` object and returns the hex color | ||
* to render: `color={color => color.success.main}` | ||
*/ | ||
color?: (themeColors: DripsyTheme['color']) => string; | ||
} | ||
|
||
const PROPS_BY_SIZE: Record<IconSize, ComponentProps<LucideIcon>> = { | ||
sm: { | ||
size: 16, | ||
strokeWidth: 1, | ||
}, | ||
md: { | ||
size: 24, | ||
strokeWidth: 1.5, | ||
}, | ||
lg: { | ||
size: 32, | ||
strokeWidth: 2, | ||
}, | ||
}; | ||
|
||
/** | ||
* Renders the Lucide icon passed in via the `IconComponent` prop. Use this | ||
* component rather than rendering Lucide icon components directly, since this | ||
* component standardizes the stroke width and sizes throughout the Penumbra | ||
* ecosystem. | ||
* | ||
* ```tsx | ||
* <Icon | ||
* IconComponent={ArrowRightLeft} | ||
* size='sm' | ||
* color={color => color.success.main} | ||
* /> | ||
* ``` | ||
*/ | ||
export default function Icon({ IconComponent, size = 'sm', color }: IconProps) { | ||
const { theme } = useDripsyTheme(); | ||
|
||
return ( | ||
<IconComponent | ||
absoluteStrokeWidth | ||
color={!color ? 'currentColor' : color(theme.color)} | ||
{...PROPS_BY_SIZE[size]} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.