-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into fix-undefined
- Loading branch information
Showing
8 changed files
with
210 additions
and
12 deletions.
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
71 changes: 71 additions & 0 deletions
71
code/core/src/components/components/ProgressSpinner/ProgressSpinner.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,71 @@ | ||
import React from 'react'; | ||
|
||
import { StopAltIcon } from '@storybook/icons'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { ProgressSpinner } from './ProgressSpinner'; | ||
|
||
const meta = { | ||
component: ProgressSpinner, | ||
} satisfies Meta<typeof ProgressSpinner>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Forty: Story = { | ||
args: { | ||
percentage: 40, | ||
}, | ||
}; | ||
|
||
export const Seventy: Story = { | ||
args: { | ||
percentage: 70, | ||
}, | ||
}; | ||
|
||
export const Zero: Story = { | ||
args: { | ||
percentage: 0, | ||
}, | ||
}; | ||
|
||
export const Small: Story = { | ||
args: { | ||
percentage: 40, | ||
size: 16, | ||
}, | ||
}; | ||
|
||
export const Thick: Story = { | ||
args: { | ||
percentage: 40, | ||
width: 3, | ||
}, | ||
}; | ||
|
||
export const Paused: Story = { | ||
args: { | ||
percentage: 40, | ||
running: false, | ||
}, | ||
}; | ||
|
||
export const Colored: Story = { | ||
args: Forty.args, | ||
decorators: [ | ||
(Story) => ( | ||
<div style={{ color: 'hotpink' }}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
}; | ||
|
||
export const WithContent: Story = { | ||
...Colored, | ||
args: { | ||
...Colored.args, | ||
children: <StopAltIcon size={10} />, | ||
}, | ||
}; |
93 changes: 93 additions & 0 deletions
93
code/core/src/components/components/ProgressSpinner/ProgressSpinner.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,93 @@ | ||
import React, { type ComponentProps } from 'react'; | ||
|
||
import { keyframes, styled } from '@storybook/core/theming'; | ||
|
||
const XMLNS = 'http://www.w3.org/2000/svg'; | ||
|
||
const rotate = keyframes({ | ||
'0%': { | ||
transform: 'rotate(0deg)', | ||
}, | ||
'100%': { | ||
transform: 'rotate(360deg)', | ||
}, | ||
}); | ||
|
||
const Wrapper = styled.div<{ size: number }>(({ size }) => ({ | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
position: 'relative', | ||
minWidth: size, | ||
minHeight: size, | ||
})); | ||
|
||
const Circle = styled.svg<{ size: number; width: number; progress?: boolean; spinner?: boolean }>( | ||
({ size, width }) => ({ | ||
position: 'absolute', | ||
width: `${size}px!important`, | ||
height: `${size}px!important`, | ||
transform: 'rotate(-90deg)', | ||
circle: { | ||
r: (size - Math.ceil(width)) / 2, | ||
cx: size / 2, | ||
cy: size / 2, | ||
opacity: 0.15, | ||
fill: 'transparent', | ||
stroke: 'currentColor', | ||
strokeWidth: width, | ||
strokeLinecap: 'round', | ||
strokeDasharray: Math.PI * (size - Math.ceil(width)), | ||
}, | ||
}), | ||
({ progress }) => | ||
progress && { | ||
circle: { | ||
opacity: 0.75, | ||
}, | ||
}, | ||
({ spinner }) => | ||
spinner && { | ||
animation: `${rotate} 1s linear infinite`, | ||
circle: { | ||
opacity: 0.25, | ||
}, | ||
} | ||
); | ||
|
||
interface ProgressSpinnerProps extends Omit<ComponentProps<typeof Wrapper>, 'size'> { | ||
percentage?: number; | ||
running?: boolean; | ||
size?: number; | ||
width?: number; | ||
children?: React.ReactNode; | ||
} | ||
|
||
export const ProgressSpinner = ({ | ||
percentage = undefined, | ||
running = true, | ||
size = 24, | ||
width = 1.5, | ||
children = null, | ||
...props | ||
}: ProgressSpinnerProps) => | ||
typeof percentage === 'number' ? ( | ||
<Wrapper size={size} {...props}> | ||
{children} | ||
<Circle size={size} width={width} xmlns={XMLNS}> | ||
<circle /> | ||
</Circle> | ||
{running && ( | ||
<Circle size={size} width={width} xmlns={XMLNS} spinner> | ||
<circle strokeDashoffset={Math.PI * (size - Math.ceil(width)) * (1 - percentage / 100)} /> | ||
</Circle> | ||
)} | ||
<Circle size={size} width={width} xmlns={XMLNS} progress> | ||
<circle strokeDashoffset={Math.PI * (size - Math.ceil(width)) * (1 - percentage / 100)} /> | ||
</Circle> | ||
</Wrapper> | ||
) : ( | ||
<Wrapper size={size} {...props}> | ||
{children} | ||
</Wrapper> | ||
); |
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