-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: [M3-7449] - Dismissible Banner v7 story migration (#9932)
* update imports/exports * update comments, move styles to new file * storybook * some cleanup * changeset and dismissible banner tests * address feedback + add labels to styled components
- Loading branch information
1 parent
eb5f1ef
commit e6ce6c7
Showing
18 changed files
with
199 additions
and
164 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-9932-tech-stories-1700688400660.md
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,5 @@ | ||
--- | ||
"@linode/manager": Tech Stories | ||
--- | ||
|
||
Dismissible Banner V7 story migration ([#9932](https://github.com/linode/manager/pull/9932)) |
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
126 changes: 0 additions & 126 deletions
126
packages/manager/src/components/DismissibleBanner/DismissibleBanner.stories.mdx
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
packages/manager/src/components/DismissibleBanner/DismissibleBanner.stories.tsx
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,65 @@ | ||
import * as React from 'react'; | ||
|
||
import { Button } from 'src/components/Button/Button'; | ||
import { Link } from 'src/components/Link'; | ||
import { Typography } from 'src/components/Typography'; | ||
|
||
import { DismissibleBanner } from './DismissibleBanner'; | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
type Story = StoryObj<typeof DismissibleBanner>; | ||
|
||
export const Default: Story = { | ||
render: (args) => ( | ||
<DismissibleBanner {...args}> | ||
<Typography>This is an example of a dismissible banner.</Typography> | ||
</DismissibleBanner> | ||
), | ||
}; | ||
|
||
/** | ||
* Example of a dismissible banner with an associated action | ||
*/ | ||
export const CallToActionBanner: Story = { | ||
render: () => ( | ||
<DismissibleBanner | ||
actionButton={ | ||
<Button buttonType="primary" onClick={() => null}> | ||
Upgrade Version | ||
</Button> | ||
} | ||
preferenceKey="cluster-v1" | ||
variant="info" | ||
> | ||
<Typography>A new version of Kubernetes is available.</Typography> | ||
</DismissibleBanner> | ||
), | ||
}; | ||
|
||
/** | ||
* Beta banners, along with [beta chips](/docs/elements-chips-beta-chips--default-story), provide notice to users about beta features. | ||
*/ | ||
export const BetaBanner: Story = { | ||
render: () => ( | ||
<DismissibleBanner preferenceKey="beta-banner" variant="info"> | ||
<Typography> | ||
Managed Database for MySQL is available in a free, open beta period | ||
until May 2nd, 2022. This is a beta environment and should not be used | ||
to support production workloads. Review the{' '} | ||
<Link to="https://www.linode.com/legal-eatp"> | ||
Early Adopter Program SLA | ||
</Link> | ||
. | ||
</Typography> | ||
</DismissibleBanner> | ||
), | ||
}; | ||
|
||
const meta: Meta<typeof DismissibleBanner> = { | ||
args: { preferenceKey: 'dismissible-banner' }, | ||
component: DismissibleBanner, | ||
title: 'Components/Notifications/Dismissible Banners', | ||
}; | ||
|
||
export default meta; |
31 changes: 31 additions & 0 deletions
31
packages/manager/src/components/DismissibleBanner/DismissibleBanner.styles.ts
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,31 @@ | ||
import { styled } from '@mui/material/styles'; | ||
|
||
import { Notice } from 'src/components/Notice/Notice'; | ||
|
||
import { StyledLinkButton } from '../Button/StyledLinkButton'; | ||
|
||
export const StyledNotice = styled(Notice, { label: 'StyledNotice' })( | ||
({ theme }) => ({ | ||
'&&': { | ||
p: { | ||
lineHeight: '1.25rem', | ||
}, | ||
}, | ||
alignItems: 'center', | ||
background: theme.bg.bgPaper, | ||
borderRadius: 1, | ||
display: 'flex', | ||
flexFlow: 'row nowrap', | ||
justifyContent: 'space-between', | ||
marginBottom: theme.spacing(), | ||
padding: theme.spacing(2), | ||
}) | ||
); | ||
|
||
export const StyledButton = styled(StyledLinkButton, { label: 'StyledButton' })( | ||
({ theme }) => ({ | ||
color: theme.textColors.tableStatic, | ||
display: 'flex', | ||
marginLeft: 20, | ||
}) | ||
); |
50 changes: 50 additions & 0 deletions
50
packages/manager/src/components/DismissibleBanner/DismissibleBanner.test.tsx
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,50 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
|
||
import { Button } from 'src/components/Button/Button'; | ||
import { Typography } from 'src/components/Typography'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { DismissibleBanner } from './DismissibleBanner'; | ||
|
||
describe('Dismissible banner', () => { | ||
const props = { | ||
preferenceKey: 'dismissible-banner', | ||
}; | ||
|
||
it('renders a dismissible banner and can dismiss it', () => { | ||
const { getByLabelText, getByText } = renderWithTheme( | ||
<DismissibleBanner {...props}> | ||
<Typography>This is a dismissible banner</Typography> | ||
</DismissibleBanner> | ||
); | ||
const text = getByText('This is a dismissible banner'); | ||
expect(text).toBeVisible(); | ||
const dismissButton = getByLabelText('Dismiss dismissible-banner banner'); | ||
expect(dismissButton).toBeVisible(); | ||
fireEvent.click(dismissButton); | ||
expect(dismissButton).not.toBeInTheDocument(); | ||
}); | ||
it('renders a dismissible banner with an action button', () => { | ||
const onClickProp = { | ||
onClick: vi.fn(), | ||
}; | ||
|
||
const { getByText } = renderWithTheme( | ||
<DismissibleBanner | ||
{...props} | ||
actionButton={ | ||
<Button {...onClickProp} buttonType="primary"> | ||
Action button | ||
</Button> | ||
} | ||
> | ||
<Typography>Banner with action button</Typography> | ||
</DismissibleBanner> | ||
); | ||
const button = getByText('Action button'); | ||
expect(button).toBeVisible(); | ||
fireEvent.click(button); | ||
expect(onClickProp.onClick).toHaveBeenCalled(); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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.