-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
feat: support branding #639
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e61338b
feat: support branding
tlow92 9fd32d8
fix: make title also clickable
tlow92 29b725e
fix: typo
tlow92 03c3df3
fix: typo
tlow92 dce569a
Merge branch 'next' into feat-support-branding
dannyhw cf3092d
Merge branch 'next' into feat-support-branding
dannyhw 8923659
Merge branch 'next' into feat-support-branding
dannyhw 673b34b
fix: logo not rendering on mobile and limit to just image source prop
dannyhw 8e73c0a
fix: types
dannyhw 7dec39c
Merge branch 'next' into feat-support-branding
dannyhw 58c9850
Merge remote-tracking branch 'origin/next' into pr/tlow92/639
dannyhw a2b6bb2
fix: allow react element
dannyhw ce5b0e2
fix: update story
dannyhw a2b74ac
fix
dannyhw 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
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,81 @@ | ||
import type { StoryObj, Meta } from '@storybook/react'; | ||
import { StorybookLogo } from './StorybookLogo'; | ||
import { useTheme } from '@storybook/react-native-theming'; | ||
|
||
const meta = { | ||
component: StorybookLogo, | ||
title: 'UI/StorybookLogo', | ||
args: { | ||
theme: null, | ||
}, | ||
} satisfies Meta<typeof StorybookLogo>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const TitleLogo: Story = { | ||
decorators: [ | ||
(Story) => { | ||
const theme = useTheme(); | ||
return <Story args={{ theme: { ...theme, brand: { title: 'React Native' } } }} />; | ||
}, | ||
], | ||
}; | ||
|
||
export const ImageLogo: Story = { | ||
decorators: [ | ||
(Story) => { | ||
const theme = useTheme(); | ||
return ( | ||
<Story | ||
args={{ | ||
theme: { ...theme, brand: { image: 'https://reactnative.dev/img/oss_logo.svg' } }, | ||
}} | ||
/> | ||
); | ||
}, | ||
], | ||
}; | ||
|
||
export const ImageUrlLogo: Story = { | ||
decorators: [ | ||
(Story) => { | ||
const theme = useTheme(); | ||
return ( | ||
<Story | ||
args={{ | ||
theme: { | ||
...theme, | ||
brand: { | ||
image: 'https://reactnative.dev/img/oss_logo.svg', | ||
url: 'https://reactnative.dev', | ||
}, | ||
}, | ||
}} | ||
/> | ||
); | ||
}, | ||
], | ||
}; | ||
|
||
export const ImageSourceLogo: Story = { | ||
decorators: [ | ||
(Story) => { | ||
const theme = useTheme(); | ||
return ( | ||
<Story | ||
args={{ | ||
theme: { | ||
...theme, | ||
brand: { | ||
imageSource: require('./assets/react-native-logo.png'), | ||
url: 'https://reactnative.dev', | ||
}, | ||
}, | ||
}} | ||
/> | ||
); | ||
}, | ||
], | ||
}; |
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,82 @@ | ||
import { Theme } from '@storybook/react-native-theming'; | ||
import { FC, useMemo } from 'react'; | ||
import { Image, Linking, StyleProp, Text, TextStyle, TouchableOpacity } from 'react-native'; | ||
import { DarkLogo } from './icon/DarkLogo'; | ||
import { Logo } from './icon/Logo'; | ||
|
||
const WIDTH = 125; | ||
const HEIGHT = 25; | ||
|
||
const NoBrandLogo: FC<{ theme: Theme }> = ({ theme }) => | ||
theme.base === 'light' ? ( | ||
<Logo height={HEIGHT} width={WIDTH} /> | ||
) : ( | ||
<DarkLogo height={HEIGHT} width={WIDTH} /> | ||
); | ||
|
||
const BrandLogo: FC<{ theme: Theme & { brand: NonNullable<Theme['brand']> } }> = ({ theme }) => { | ||
const image = ( | ||
<Image | ||
source={ | ||
typeof theme.brand.image === 'string' ? { uri: theme.brand.image } : theme.brand.image | ||
} | ||
resizeMode="contain" | ||
style={{ height: HEIGHT, width: WIDTH }} | ||
/> | ||
); | ||
|
||
if (theme.brand.url) { | ||
return ( | ||
<TouchableOpacity | ||
onPress={() => { | ||
if (theme.brand.url) Linking.openURL(theme.brand.url); | ||
}} | ||
> | ||
{image} | ||
</TouchableOpacity> | ||
); | ||
} else { | ||
return image; | ||
} | ||
}; | ||
|
||
const BrandTitle: FC<{ theme: Theme & { brand: NonNullable<Theme['brand']> } }> = ({ theme }) => { | ||
const brandTitleStyle = useMemo<StyleProp<TextStyle>>(() => { | ||
return { | ||
width: WIDTH, | ||
height: HEIGHT, | ||
color: theme.color.defaultText, | ||
fontSize: theme.typography.size.m1, | ||
}; | ||
}, [theme]); | ||
|
||
const title = ( | ||
<Text style={brandTitleStyle} numberOfLines={1} ellipsizeMode="tail"> | ||
{theme.brand.title} | ||
</Text> | ||
); | ||
|
||
if (theme.brand.url) { | ||
return ( | ||
<TouchableOpacity | ||
onPress={() => { | ||
if (theme.brand.url) Linking.openURL(theme.brand.url); | ||
}} | ||
> | ||
{title} | ||
</TouchableOpacity> | ||
); | ||
} else { | ||
return title; | ||
} | ||
}; | ||
|
||
export const StorybookLogo: FC<{ theme: Theme }> = ({ theme }) => { | ||
if (theme.brand.image) { | ||
return <BrandLogo theme={theme} />; | ||
} else if (theme.brand.title) { | ||
return <BrandTitle theme={theme} />; | ||
} else { | ||
return <NoBrandLogo theme={theme} />; | ||
} | ||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think just use the existing Storybook logo to prevent having another asset, |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
I don't like having this decorator in every story just to make typescript happy. Essentially the problem is only that theme requires a lot of properties that we don't want to define here.
Maybe I missed something to make it easier?
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.
https://github.com/trajano/expo-experiments/blob/4287571d3a9fe568700ce97ecc266d5a5bff621e/packages/my-app/.storybook/index.ts#L11-L16 shows what I did on mine to pass it in, but I cheated with the
any
because of theimageSource
thing which you resolved in web-theme.ts I think.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.
But I think what you have looks correct. At least for the context of the story.