-
Notifications
You must be signed in to change notification settings - Fork 0
feat(CircularProgress): add new component #317
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
Open
daralehina
wants to merge
1
commit into
master
Choose a base branch
from
feature/circular-progress
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
37 changes: 37 additions & 0 deletions
37
packages/react/src/components/CircularProgress/CircularProgress.api.mdx
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 { Meta } from '@storybook/addon-docs'; | ||
| import LinkTo from '@storybook/addon-links/react'; | ||
| import { TableInterface } from '~storybook/components/TableInterface'; | ||
|
|
||
| <Meta title="Components API/CircularProgress" /> | ||
|
|
||
| # CircularProgress API | ||
|
|
||
| ```js | ||
| import { CircularProgress } from '@elonkit/react'; | ||
| ``` | ||
|
|
||
| ## Component name | ||
|
|
||
| The name `ESCircularProgress` can be used when providing default props or style overrides in the theme. | ||
|
|
||
| ## Props | ||
|
|
||
| <TableInterface name="CircularProgressProps" variant="props" /> | ||
|
|
||
| <br /> | ||
|
|
||
| ## CSS | ||
|
|
||
| <TableInterface name="CircularProgressClasses" variant="css" /> | ||
|
|
||
| <br /> | ||
|
|
||
| ## Demos | ||
|
|
||
| <ul> | ||
| <li> | ||
| <LinkTo kind="components-CircularProgress" story="demo"> | ||
| <code>CircularProgress</code> | ||
| </LinkTo> | ||
| </li> | ||
| </ul> |
53 changes: 53 additions & 0 deletions
53
packages/react/src/components/CircularProgress/CircularProgress.classes.ts
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,53 @@ | ||
| import { generateUtilityClass, generateUtilityClasses } from '@mui/material'; | ||
|
|
||
| export interface CircularProgressClasses { | ||
| /** Styles applied to the root element. */ | ||
| root: string; | ||
| /** Styles applied to the root element if `variant="determinate"`. */ | ||
| determinate: string; | ||
| /** Styles applied to the root element if `variant="indeterminate"`. */ | ||
| indeterminate: string; | ||
| /** Styles applied to the root element if `color="primary"`. */ | ||
| colorPrimary: string; | ||
| /** Styles applied to the root element if `color="secondary"`. */ | ||
| colorSecondary: string; | ||
| /** Styles applied to the svg element. */ | ||
| svg: string; | ||
| /** Styles applied to the `circle` svg path. */ | ||
| circle: string; | ||
| /** Styles applied to the `circle` svg path if `variant="determinate"`. | ||
| * @deprecated Combine the [.MuiCircularProgress-circle](/material-ui/api/circular-progress/#circular-progress-classes-circle) and [.MuiCircularProgress-determinate](/material-ui/api/circular-progress/#circular-progress-classes-determinate) classes instead. See [Migrating from deprecated APIs](/material-ui/migration/migrating-from-deprecated-apis/) for more details. | ||
| */ | ||
| circleDeterminate: string; | ||
| /** Styles applied to the `circle` svg path if `variant="indeterminate"`. | ||
| * @deprecated Combine the [.MuiCircularProgress-circle](/material-ui/api/circular-progress/#circular-progress-classes-circle) and [.MuiCircularProgress-indeterminate](/material-ui/api/circular-progress/#circular-progress-classes-indeterminate) classes instead. See [Migrating from deprecated APIs](/material-ui/migration/migrating-from-deprecated-apis/) for more details. | ||
| */ | ||
| circleIndeterminate: string; | ||
| /** Styles applied to the `circle` svg path if `disableShrink={true}`. */ | ||
| circleDisableShrink: string; | ||
| /** Styles applied to the background `circle` svg path. */ | ||
| background: string; | ||
| /** Styles applied to the content. */ | ||
| content: string; | ||
| } | ||
|
|
||
| export type CircularProgressClassKey = keyof CircularProgressClasses; | ||
|
|
||
| export function getCircularProgressUtilityClass(slot: string): string { | ||
| return generateUtilityClass('MuiCircularProgress', slot); | ||
| } | ||
|
|
||
| export const circularProgressClasses: CircularProgressClasses = generateUtilityClasses('MuiCircularProgress', [ | ||
| 'root', | ||
| 'determinate', | ||
| 'indeterminate', | ||
| 'colorPrimary', | ||
| 'colorSecondary', | ||
| 'svg', | ||
| 'circle', | ||
| 'circleDeterminate', | ||
| 'circleIndeterminate', | ||
| 'circleDisableShrink', | ||
| 'background', | ||
| 'content', | ||
| ]); |
49 changes: 49 additions & 0 deletions
49
packages/react/src/components/CircularProgress/CircularProgress.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,49 @@ | ||||||
| import { Meta, StoryObj } from '@storybook/react'; | ||||||
|
|
||||||
| import { Typography } from '@mui/material'; | ||||||
|
|
||||||
| import { CircularProgress } from '.'; | ||||||
|
|
||||||
| const meta: Meta<typeof CircularProgress> = { | ||||||
| tags: ['autodocs'], | ||||||
| component: CircularProgress, | ||||||
| parameters: { | ||||||
| references: ['CircularProgress'], | ||||||
| }, | ||||||
| argTypes: { | ||||||
| variant: { | ||||||
| options: ['determinate', 'indeterminate'], | ||||||
| control: { | ||||||
| type: 'select', | ||||||
| }, | ||||||
| }, | ||||||
| color: { | ||||||
| options: ['primary', 'secondary', 'error', 'info', 'success', 'warning', 'inherit'], | ||||||
|
Collaborator
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. Падает демка
Suggested change
|
||||||
| control: { | ||||||
| type: 'select', | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| args: { | ||||||
| variant: 'indeterminate', | ||||||
| color: 'primary', | ||||||
| value: 20, | ||||||
| }, | ||||||
| }; | ||||||
|
|
||||||
| export default meta; | ||||||
| type Story = StoryObj<typeof CircularProgress>; | ||||||
|
|
||||||
| export const Demo: Story = { | ||||||
| render: (args) => { | ||||||
| return ( | ||||||
| <CircularProgress {...args}> | ||||||
| <Typography | ||||||
| color="monoA.A700" | ||||||
| component="div" | ||||||
| variant="caption" | ||||||
| >{`${Math.round(args.value ?? 0)}%`}</Typography> | ||||||
| </CircularProgress> | ||||||
| ); | ||||||
| }, | ||||||
| }; | ||||||
231 changes: 231 additions & 0 deletions
231
packages/react/src/components/CircularProgress/CircularProgress.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,231 @@ | ||
| import { forwardRef } from 'react'; | ||
|
|
||
| import { CircularProgressProps } from './CircularProgress.types'; | ||
|
|
||
| import clsx from 'clsx'; | ||
| import { getCircularProgressUtilityClass } from './CircularProgress.classes'; | ||
|
|
||
| import { unstable_composeClasses as composeClasses } from '@mui/base'; | ||
|
|
||
| import { styled, useThemeProps } from '@mui/material/styles'; | ||
| import { css, keyframes } from '@mui/system'; | ||
| import { capitalize } from '@mui/material'; | ||
|
|
||
| const SIZE = 44; | ||
|
|
||
| const circularRotateKeyframe = keyframes` | ||
| 0% { | ||
| transform: rotate(0deg); | ||
| } | ||
|
|
||
| 100% { | ||
| transform: rotate(360deg); | ||
| } | ||
| `; | ||
|
|
||
| const circularDashKeyframe = keyframes` | ||
| 0% { | ||
| stroke-dasharray: 1px, 200px; | ||
| stroke-dashoffset: 0; | ||
| } | ||
|
|
||
| 50% { | ||
| stroke-dasharray: 100px, 200px; | ||
| stroke-dashoffset: -15px; | ||
| } | ||
|
|
||
| 100% { | ||
| stroke-dasharray: 100px, 200px; | ||
| stroke-dashoffset: -125px; | ||
| } | ||
| `; | ||
|
|
||
| type CircularProgressOwnerState = { | ||
| classes?: CircularProgressProps['classes']; | ||
| variant: NonNullable<CircularProgressProps['variant']>; | ||
| color: NonNullable<CircularProgressProps['color']>; | ||
| disableShrink: NonNullable<CircularProgressProps['disableShrink']>; | ||
| thickness: NonNullable<CircularProgressProps['thickness']>; | ||
| value: NonNullable<CircularProgressProps['value']>; | ||
| }; | ||
|
|
||
| const useUtilityClasses = (ownerState: CircularProgressOwnerState) => { | ||
| const { classes, variant, color, disableShrink } = ownerState; | ||
|
|
||
| const slots = { | ||
| root: ['root', variant, `color${capitalize(color)}`], | ||
| svg: ['svg'], | ||
| circle: ['circle', `circle${capitalize(variant)}`, disableShrink && 'circleDisableShrink'], | ||
| background: ['background'], | ||
| content: ['content'], | ||
| }; | ||
|
|
||
| return composeClasses(slots, getCircularProgressUtilityClass, classes); | ||
| }; | ||
|
|
||
| const CircularProgressRoot = styled('span', { | ||
| name: 'ESCircularProgress', | ||
| slot: 'Root', | ||
| overridesResolver: (props, styles) => { | ||
| const { ownerState } = props; | ||
|
|
||
| return [styles.root, styles[ownerState.variant], styles[`color${capitalize(ownerState.color)}`]]; | ||
| }, | ||
| })<{ ownerState: CircularProgressOwnerState }>(({ ownerState: { color, variant }, theme }) => ({ | ||
| display: 'inline-block', | ||
| color: theme.vars.palette[color][300], | ||
| position: 'relative', | ||
|
|
||
| ...(variant === 'determinate' && { | ||
| transition: theme.transitions.create('transform'), | ||
| }), | ||
| })); | ||
|
|
||
| const CircularProgressSVG = styled('svg', { | ||
| name: 'ESCircularProgress', | ||
| slot: 'Svg', | ||
| overridesResolver: (props, styles) => { | ||
| return styles.svg; | ||
| }, | ||
| })<{ ownerState: CircularProgressOwnerState }>(({ ownerState: { variant } }) => ({ | ||
| transform: 'rotate(-90deg)', | ||
| display: 'block', | ||
| ...(variant === 'indeterminate' && { | ||
| animation: `${circularRotateKeyframe} 1.4s linear infinite`, | ||
| }), | ||
| })); | ||
|
|
||
| const CircularProgressCircle = styled('circle', { | ||
| name: 'ESCircularProgress', | ||
| slot: 'Circle', | ||
| overridesResolver: (props, styles) => { | ||
| const { ownerState } = props; | ||
|
|
||
| return [ | ||
| styles.circle, | ||
| styles[`circle${capitalize(ownerState.variant)}`], | ||
| ownerState.disableShrink && styles.circleDisableShrink, | ||
| ]; | ||
| }, | ||
| })<{ ownerState: CircularProgressOwnerState }>( | ||
| ({ ownerState: { variant, thickness, value }, theme }) => ({ | ||
| stroke: 'currentColor', | ||
| ...(variant === 'determinate' && { | ||
| transition: theme.transitions.create('stroke-dashoffset'), | ||
| strokeDasharray: (2 * Math.PI * ((SIZE - thickness) / 2)).toFixed(3), | ||
| strokeDashoffset: `${(((100 - value) / 100) * (2 * Math.PI * ((SIZE - thickness) / 2))).toFixed(3)}px`, | ||
| }), | ||
| ...(variant === 'indeterminate' && { | ||
| strokeDasharray: '80px, 200px', | ||
| strokeDashoffset: 0, | ||
| animation: `${circularDashKeyframe} 1.4s ease-in-out infinite`, | ||
| }), | ||
| }), | ||
| ({ ownerState }) => | ||
| ownerState.variant === 'indeterminate' && | ||
| css` | ||
| animation: ${circularDashKeyframe} 1.4s ease-in-out infinite; | ||
| ` | ||
| ); | ||
|
|
||
| const CircularProgressBackground = styled('circle', { | ||
| name: 'ESCircularProgress', | ||
| slot: 'Background', | ||
| overridesResolver: (props, styles) => styles.background, | ||
| })<{ ownerState: CircularProgressOwnerState }>(({ ownerState: { color }, theme }) => ({ | ||
| stroke: theme.vars.palette[color].A400, | ||
| transition: theme.transitions.create('stroke-dashoffset'), | ||
| })); | ||
|
|
||
| const CircularProgressContent = styled('div', { | ||
| name: 'ESCircularProgress', | ||
| slot: 'Content', | ||
| overridesResolver: (props, styles) => styles.content, | ||
| })(() => ({ | ||
| top: 0, | ||
| left: 0, | ||
| bottom: 0, | ||
| right: 0, | ||
| position: 'absolute', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| })); | ||
|
|
||
| export const CircularProgress = forwardRef<HTMLButtonElement, CircularProgressProps>( | ||
| function CircularProgress(inProps, ref) { | ||
| const props = useThemeProps({ props: inProps, name: 'ESCircularProgress' }); | ||
| const { | ||
| children, | ||
| className, | ||
| color = 'primary', | ||
| disableShrink = false, | ||
| size = 40, | ||
| thickness = 3.6, | ||
| value = 0, | ||
| variant = 'indeterminate', | ||
| ...other | ||
| } = props; | ||
|
|
||
| const ownerState = { | ||
| color, | ||
| disableShrink, | ||
| size, | ||
| thickness, | ||
| value, | ||
| variant, | ||
| ...props, | ||
| }; | ||
|
|
||
| const classes = useUtilityClasses(ownerState); | ||
|
|
||
| // const circleStyle = {}; | ||
| // const rootStyle = {}; | ||
| // const rootProps = {}; | ||
|
|
||
| // if (variant === 'determinate') { | ||
| // const circumference = 2 * Math.PI * ((SIZE - thickness) / 2); | ||
| // circleStyle.strokeDasharray = circumference.toFixed(3); | ||
| // circleStyle.strokeDashoffset = `${(((100 - value) / 100) * circumference).toFixed(3)}px`; | ||
| // rootStyle.transform = 'rotate(-90deg)'; | ||
| // } | ||
|
|
||
| return ( | ||
| <CircularProgressRoot | ||
| ref={ref} | ||
| className={clsx(classes.root, className)} | ||
| ownerState={ownerState} | ||
| role="progressbar" | ||
| style={{ width: size, height: size }} | ||
| {...other} | ||
| > | ||
| <CircularProgressSVG | ||
| className={classes.svg} | ||
| ownerState={ownerState} | ||
| viewBox={`${SIZE / 2} ${SIZE / 2} ${SIZE} ${SIZE}`} | ||
| > | ||
| <CircularProgressCircle | ||
| className={classes.circle} | ||
| cx={SIZE} | ||
| cy={SIZE} | ||
| fill="none" | ||
| ownerState={ownerState} | ||
| r={(SIZE - thickness) / 2} | ||
| strokeWidth={thickness} | ||
| /> | ||
| <CircularProgressBackground | ||
| className={classes.background} | ||
| cx={SIZE} | ||
| cy={SIZE} | ||
| fill="none" | ||
| ownerState={ownerState} | ||
| r={(SIZE - thickness) / 2} | ||
| strokeWidth={thickness} | ||
| /> | ||
| </CircularProgressSVG> | ||
|
|
||
| {!!children && <CircularProgressContent className={classes.content}>{children}</CircularProgressContent>} | ||
| </CircularProgressRoot> | ||
| ); | ||
| } | ||
| ); |
Oops, something went wrong.
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.
В демке контрол size как объект отображается, надо бы number сделать