-
Notifications
You must be signed in to change notification settings - Fork 358
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
refactor: [M3-7575] CircleProgress and ColorPalette storybook v7 migrations #10015
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
35 changes: 0 additions & 35 deletions
35
packages/manager/src/components/CircleProgress/CircleProgress.stories.mdx
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
packages/manager/src/components/CircleProgress/CircleProgress.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,18 @@ | ||
import React from 'react'; | ||
|
||
import { CircleProgress } from './CircleProgress'; | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
type Story = StoryObj<typeof CircleProgress>; | ||
|
||
export const Default: Story = { | ||
render: (args) => <CircleProgress {...args} />, | ||
}; | ||
|
||
const meta: Meta<typeof CircleProgress> = { | ||
component: CircleProgress, | ||
title: 'Components/Loading States/Circle Progress', | ||
}; | ||
|
||
export default meta; |
54 changes: 54 additions & 0 deletions
54
packages/manager/src/components/CircleProgress/CircleProgress.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,54 @@ | ||
import React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { CircleProgress } from './CircleProgress'; | ||
|
||
const CONTENT_LOADING = 'Content is loading'; | ||
|
||
describe('CircleProgress', () => { | ||
it('renders a CircleProgress properly', () => { | ||
const screen = renderWithTheme(<CircleProgress />); | ||
|
||
const circleProgress = screen.getByLabelText(CONTENT_LOADING); | ||
expect(circleProgress).toBeVisible(); | ||
const circle = screen.getByTestId('circle-progress'); | ||
expect(circle).toBeInTheDocument(); | ||
expect(circle).toHaveStyle('width: 124px; height: 124px;'); | ||
const innerCircle = screen.getByTestId('inner-circle-progress'); | ||
expect(innerCircle).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders a mini CircleProgress', () => { | ||
const screen = renderWithTheme(<CircleProgress mini />); | ||
|
||
const circleProgress = screen.getByLabelText(CONTENT_LOADING); | ||
expect(circleProgress).toBeVisible(); | ||
expect(circleProgress).toHaveStyle('width: 40px; height: 40px;'); | ||
}); | ||
|
||
it('sets a mini CircleProgress with no padding', () => { | ||
const screen = renderWithTheme(<CircleProgress mini noPadding />); | ||
|
||
const circleProgress = screen.getByLabelText(CONTENT_LOADING); | ||
expect(circleProgress).toBeVisible(); | ||
expect(circleProgress).toHaveStyle('width: 22px; height: 22px;'); | ||
}); | ||
|
||
it('sets a mini CircleProgress with a custom size', () => { | ||
const screen = renderWithTheme(<CircleProgress mini size={25} />); | ||
|
||
const circleProgress = screen.getByLabelText(CONTENT_LOADING); | ||
expect(circleProgress).toBeVisible(); | ||
expect(circleProgress).toHaveStyle('width: 25px; height: 25px;'); | ||
}); | ||
|
||
it('renders a CircleProgress without the inner circle', () => { | ||
const screen = renderWithTheme(<CircleProgress noInner />); | ||
|
||
const circleProgress = screen.getByLabelText(CONTENT_LOADING); | ||
expect(circleProgress).toBeVisible(); | ||
const innerCircle = screen.queryByTestId('inner-circle-progress'); | ||
expect(innerCircle).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
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 |
---|---|---|
|
@@ -9,26 +9,37 @@ import { | |
import { omittedProps } from 'src/utilities/omittedProps'; | ||
|
||
interface CircleProgressProps extends CircularProgressProps { | ||
/** | ||
* Additional child elements to pass in | ||
*/ | ||
children?: JSX.Element; | ||
className?: string; | ||
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. Removing this method of adding additional styles since this prop is never used + we're moving away from classNames. Keeping the other option, sx, as a prop |
||
/** | ||
* Displays a smaller version of the circle progress. | ||
*/ | ||
mini?: boolean; | ||
/** | ||
* If true, will not show an inner circle beneath the spinning circle | ||
*/ | ||
noInner?: boolean; | ||
/** | ||
* Removes the padding for `mini` circle progresses only. | ||
*/ | ||
noPadding?: boolean; | ||
/** | ||
* To be primarily used with mini and noPadding. Set spinner to a custom size. | ||
*/ | ||
size?: number; | ||
/** | ||
* Additional styles to apply to the root element. | ||
*/ | ||
sx?: SxProps; | ||
} | ||
|
||
/** | ||
* Use for short, indeterminate activities requiring user attention. | ||
*/ | ||
const CircleProgress = (props: CircleProgressProps) => { | ||
const { | ||
children, | ||
className, | ||
mini, | ||
noInner, | ||
noPadding, | ||
size, | ||
sx, | ||
...rest | ||
} = props; | ||
const { children, mini, noInner, noPadding, size, sx, ...rest } = props; | ||
|
||
const variant = | ||
typeof props.value === 'number' ? 'determinate' : 'indeterminate'; | ||
|
@@ -48,16 +59,12 @@ const CircleProgress = (props: CircleProgressProps) => { | |
} | ||
|
||
return ( | ||
<StyledRootDiv | ||
aria-label="Content is loading" | ||
className={className} | ||
sx={sx} | ||
> | ||
<StyledRootDiv aria-label="Content is loading" sx={sx}> | ||
{children !== undefined && ( | ||
<Box sx={{ marginTop: 4, position: 'absolute' }}>{children}</Box> | ||
)} | ||
{noInner !== true && ( | ||
<StyledTopWrapperDiv> | ||
<StyledTopWrapperDiv data-testid="inner-circle-progress"> | ||
<StyledTopDiv /> | ||
</StyledTopWrapperDiv> | ||
)} | ||
|
21 changes: 0 additions & 21 deletions
21
packages/manager/src/components/ColorPalette/ColorPalette.stories.mdx
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/manager/src/components/ColorPalette/ColorPalette.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,16 @@ | ||
import React from 'react'; | ||
|
||
import { ColorPalette } from './ColorPalette'; | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
export const Default: StoryObj<typeof ColorPalette> = { | ||
render: () => <ColorPalette />, | ||
}; | ||
|
||
const meta: Meta<typeof ColorPalette> = { | ||
component: ColorPalette, | ||
title: 'Design System/Color Palette', | ||
}; | ||
|
||
export default meta; |
21 changes: 21 additions & 0 deletions
21
packages/manager/src/components/ColorPalette/ColorPalette.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,21 @@ | ||
import React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { ColorPalette } from './ColorPalette'; | ||
|
||
describe('Color Palette', () => { | ||
it('renders the Color Palette', () => { | ||
const { container, getByText } = renderWithTheme(<ColorPalette />); | ||
|
||
getByText('Primary Colors'); | ||
getByText('Etc.'); | ||
getByText('Background Colors'); | ||
getByText('Typography Colors'); | ||
getByText('Border Colors'); | ||
|
||
// there are 55 individual colors in our Color Palette currently | ||
const colors = container.querySelectorAll('[class="css-n6e2zj-swatch"]'); | ||
coliu-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(colors.length).toBe(55); | ||
}); | ||
}); |
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
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.
π