-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat(trial): Reusable banner components #7106
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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
105 changes: 105 additions & 0 deletions
105
packages/components/src/components/Banner/Banner.stories.tsx
This file contains hidden or 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,105 @@ | ||
import React from 'react'; | ||
|
||
import { Banner } from './Banner'; | ||
import { Stack } from '../Stack'; | ||
import { Text } from '../Text'; | ||
import { Button } from '../Button'; | ||
import { Icon } from '../Icon'; | ||
import { Grid, Column } from '../Grid'; | ||
|
||
export default { | ||
title: 'components/facelift/Banner', | ||
component: Banner, | ||
}; | ||
|
||
export const WithDismiss = () => ( | ||
<Banner onDismiss={() => {}}> | ||
You are no longer in a Pro team. This private repo is in view mode only. | ||
Make it public or upgrade. | ||
</Banner> | ||
); | ||
|
||
export const WithoutDismiss = () => ( | ||
<Banner> | ||
You are no longer in a Pro team. This private repo is in view mode only. | ||
Make it public or upgrade. | ||
</Banner> | ||
); | ||
|
||
export const ExampleUsage = () => ( | ||
<Banner onDismiss={() => {}}> | ||
<Stack gap={2} justify="space-between"> | ||
<Stack direction="vertical" gap={8} justify="space-between"> | ||
<Text fontFamily="everett" size={24}> | ||
<Text color="#EDFFA5" weight="600" block> | ||
Upgrade to <Text css={{ textTransform: 'uppercase' }}>pro</Text> | ||
</Text> | ||
<Text block>Enjoy the full CodeSandbox experience.</Text> | ||
</Text> | ||
<Button autoWidth>Learn more</Button> | ||
</Stack> | ||
<Stack align="flex-end"> | ||
<Grid | ||
as="ul" | ||
columnGap={3} | ||
rowGap={3} | ||
css={{ | ||
color: '#EBEBEB', | ||
margin: 0, | ||
padding: 0, | ||
listStyleType: 'none', | ||
}} | ||
> | ||
<Column as="li" span={6}> | ||
<Stack gap={4}> | ||
<Icon name="profile" /> | ||
<Text size={13} lineHeight="16px"> | ||
Up to 20 editors | ||
</Text> | ||
</Stack> | ||
</Column> | ||
<Column as="li" span={6}> | ||
<Stack gap={4}> | ||
<Icon name="profile" /> | ||
<Text size={13} lineHeight="16px"> | ||
Private NPM packages | ||
</Text> | ||
</Stack> | ||
</Column> | ||
<Column as="li" span={6}> | ||
<Stack gap={4}> | ||
<Icon name="profile" /> | ||
<Text size={13} lineHeight="16px"> | ||
Unlimited sandboxes | ||
</Text> | ||
</Stack> | ||
</Column> | ||
<Column as="li" span={6}> | ||
<Stack gap={4}> | ||
<Icon name="profile" /> | ||
<Text size={13} lineHeight="16px"> | ||
Advanced privacy settings | ||
</Text> | ||
</Stack> | ||
</Column> | ||
<Column as="li" span={6}> | ||
<Stack gap={4}> | ||
<Icon name="profile" /> | ||
<Text size={13} lineHeight="16px"> | ||
Unlimited repositories | ||
</Text> | ||
</Stack> | ||
</Column> | ||
<Column as="li" span={6}> | ||
<Stack gap={4}> | ||
<Icon name="profile" /> | ||
<Text size={13} lineHeight="16px"> | ||
6GB RAM, 12GB Disk, 4 vCPUs | ||
</Text> | ||
</Stack> | ||
</Column> | ||
</Grid> | ||
</Stack> | ||
</Stack> | ||
</Banner> | ||
); |
This file contains hidden or 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 React from 'react'; | ||
|
||
import { Element } from '../Element'; | ||
import { IconButton } from '../IconButton'; | ||
|
||
interface BannerProps { | ||
children: React.ReactNode; | ||
onDismiss?: () => void; | ||
} | ||
|
||
export const Banner = ({ children, onDismiss }: BannerProps) => { | ||
return ( | ||
<Element | ||
css={{ | ||
position: 'relative', | ||
padding: [4, 6, 8], | ||
backgroundColor: '#252525', | ||
borderRadius: '4px', | ||
}} | ||
> | ||
{children} | ||
|
||
{onDismiss ? ( | ||
<Element | ||
css={{ position: 'absolute', right: [1, 2, 4], top: [1, 2, 4] }} | ||
> | ||
<IconButton | ||
name="cross" | ||
variant="round" | ||
title="Dismiss" | ||
onClick={onDismiss} | ||
/> | ||
</Element> | ||
) : null} | ||
</Element> | ||
); | ||
}; |
This file contains hidden or 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
36 changes: 36 additions & 0 deletions
36
packages/components/src/components/MessageStripe/MessageStripe.stories.tsx
This file contains hidden or 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,36 @@ | ||
import React from 'react'; | ||
import { MessageStripe } from './MessageStripe'; | ||
|
||
export default { | ||
title: 'components/facelift/MessageStripe', | ||
component: MessageStripe, | ||
}; | ||
|
||
export const TrialVariant = () => ( | ||
<MessageStripe variant="trial"> | ||
You are no longer in a Pro team. This private repo is in view mode only. | ||
Make it public or upgrade. | ||
<MessageStripe.Action>Upgrade now</MessageStripe.Action> | ||
</MessageStripe> | ||
); | ||
|
||
export const WarningVariant = () => ( | ||
<MessageStripe variant="warning"> | ||
There are some issues with your payment. Please update your payment details. | ||
<MessageStripe.Action>Update payment</MessageStripe.Action> | ||
</MessageStripe> | ||
); | ||
|
||
export const WithoutAction = () => ( | ||
<MessageStripe variant="warning"> | ||
You are no longer in a Pro team. This private repo is in view mode only, | ||
contact your team admin to upgrade. | ||
</MessageStripe> | ||
); | ||
|
||
export const SpaceBetween = () => ( | ||
<MessageStripe variant="trial" justify="space-between"> | ||
There are some issues with your payment. Please update your payment details. | ||
<MessageStripe.Action>Update payment</MessageStripe.Action> | ||
</MessageStripe> | ||
); |
90 changes: 90 additions & 0 deletions
90
packages/components/src/components/MessageStripe/MessageStripe.tsx
This file contains hidden or 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,90 @@ | ||
import React from 'react'; | ||
|
||
import { Element } from '../Element'; | ||
import { Stack } from '../Stack'; | ||
import { Button } from '../Button'; | ||
import { Text } from '../Text'; | ||
|
||
type Variant = 'trial' | 'warning'; | ||
|
||
interface MessageActionProps | ||
extends Omit<React.ComponentProps<typeof Button>, 'variant'> { | ||
children: string; | ||
variant?: Variant; | ||
} | ||
|
||
export const MessageAction = ({ | ||
children, | ||
variant, | ||
...buttonProps | ||
}: MessageActionProps) => { | ||
return ( | ||
<div> | ||
<Button | ||
variant={({ trial: 'light', warning: 'dark' } as const)[variant]} | ||
{...buttonProps} | ||
> | ||
{children} | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
const backgroundVariants = { | ||
trial: '#644ED7', | ||
warning: '#F7CC66', | ||
}; | ||
|
||
const colorVariants = { | ||
trial: 'inherit', | ||
warning: '#0E0E0E', | ||
}; | ||
|
||
interface MessageStripeProps { | ||
children: React.ReactNode; | ||
variant?: Variant; | ||
justify?: 'center' | 'space-between'; | ||
} | ||
|
||
const MessageStripe = ({ | ||
children, | ||
variant = 'trial', | ||
justify = 'center', | ||
}: MessageStripeProps) => { | ||
let hasAction: boolean; | ||
|
||
const augmentedChildren = React.Children.map(children, child => { | ||
if (React.isValidElement(child) && child.type === MessageAction) { | ||
hasAction = true; | ||
|
||
return React.cloneElement<Partial<MessageActionProps>>(child, { | ||
variant, | ||
}); | ||
} | ||
|
||
return ( | ||
<Text size={13} lineHeight="16px"> | ||
{child} | ||
</Text> | ||
); | ||
}); | ||
|
||
return ( | ||
<Element | ||
paddingY={hasAction ? 2 : 3} | ||
paddingX={4} | ||
css={{ | ||
backgroundColor: backgroundVariants[variant], | ||
color: colorVariants[variant], | ||
}} | ||
> | ||
<Stack direction="horizontal" justify={justify} align="center" gap={2}> | ||
{augmentedChildren} | ||
</Stack> | ||
</Element> | ||
); | ||
}; | ||
|
||
MessageStripe.Action = MessageAction; | ||
|
||
export { MessageStripe }; |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
is this a styled-component or a styled-system feature? I thought it only works with the css() function
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.
Styled System! It does only work with the
css()
function, yes. TheElement
component uses it to generate the component, so we can pass it with thecss
prop: