-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ProgressCircular): new component (#1011)
* feat(ProgressCircular): new component * fix: tokens * fix: comments * fix: snapshots
- Loading branch information
Showing
7 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/react/src/components/progress-circular/progress-circular.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,12 @@ | ||
import { renderWithTheme } from '../../test-utils/renderer'; | ||
import { ProgressCircular } from './progress-circular'; | ||
|
||
describe('ProgressCircular', () => { | ||
test('Matches the snapshot', () => { | ||
const tree = renderWithTheme( | ||
<ProgressCircular value={66} />, | ||
); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/react/src/components/progress-circular/progress-circular.test.tsx.snap
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,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ProgressCircular Matches the snapshot 1`] = ` | ||
.c0 { | ||
-webkit-transition: stroke-dashoffset 850ms ease; | ||
transition: stroke-dashoffset 850ms ease; | ||
} | ||
<svg | ||
aria-hidden="true" | ||
focusable="false" | ||
height="32" | ||
viewBox="0 0 64 64" | ||
width="32" | ||
> | ||
<circle | ||
class="c0" | ||
cx="32" | ||
cy="32" | ||
fill="none" | ||
r="28" | ||
stroke="#006296" | ||
stroke-dasharray="175.92918860102841" | ||
stroke-dashoffset="59.81592412434966" | ||
stroke-linecap="round" | ||
stroke-width="8" | ||
transform="rotate(-90 32 32)" | ||
/> | ||
</svg> | ||
`; |
65 changes: 65 additions & 0 deletions
65
packages/react/src/components/progress-circular/progress-circular.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 { VoidFunctionComponent } from 'react'; | ||
import styled, { useTheme } from 'styled-components'; | ||
|
||
const sizes = { | ||
xsmall: 16, | ||
small: 24, | ||
medium: 32, | ||
large: 64, | ||
}; | ||
|
||
type Size = keyof typeof sizes; | ||
|
||
const VIEWBOX = 64; | ||
const STROKE_WIDTH = 8; | ||
const RADIUS = (VIEWBOX - STROKE_WIDTH) / 2; | ||
const CENTER_XY = VIEWBOX / 2; | ||
const CIRCUMFERENCE = RADIUS * 2 * Math.PI; | ||
|
||
const Circle = styled.circle` | ||
transition: stroke-dashoffset 850ms ease; | ||
`; | ||
|
||
export interface ProgressCircularProps { | ||
className?: string; | ||
size?: Size; | ||
inverted?: boolean; | ||
value: number; | ||
} | ||
|
||
// Source: https://css-tricks.com/building-progress-ring-quickly/ | ||
export const ProgressCircular: VoidFunctionComponent<ProgressCircularProps> = ({ | ||
className, | ||
inverted = false, | ||
size = 'medium', | ||
value, | ||
}) => { | ||
const theme = useTheme(); | ||
const strokeDashoffset = (1 - (value / 100)) * CIRCUMFERENCE; | ||
|
||
return ( | ||
<svg | ||
width={sizes[size]} | ||
height={sizes[size]} | ||
viewBox={`0 0 ${VIEWBOX} ${VIEWBOX}`} | ||
className={className} | ||
aria-hidden="true" | ||
focusable="false" | ||
> | ||
<Circle | ||
cx={CENTER_XY} | ||
cy={CENTER_XY} | ||
r={RADIUS} | ||
stroke={inverted | ||
? theme.component['progress-circular-inverted-color'] | ||
: theme.component['progress-circular-color']} | ||
strokeWidth={STROKE_WIDTH} | ||
fill="none" | ||
strokeDasharray={CIRCUMFERENCE} | ||
strokeDashoffset={strokeDashoffset} | ||
strokeLinecap="round" | ||
transform={`rotate(-90 ${CENTER_XY} ${CENTER_XY})`} | ||
/> | ||
</svg> | ||
); | ||
}; |
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
17 changes: 17 additions & 0 deletions
17
packages/react/src/themes/tokens/component/progress-circular-tokens.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,17 @@ | ||
import { AliasTokens } from '../alias-tokens'; | ||
import { RefTokens } from '../ref-tokens'; | ||
|
||
export type ProgressCircularTokens = | ||
| 'progress-circular-color' | ||
| 'progress-circular-inverted-color' | ||
|
||
export type ProgressCircularTokenValue = AliasTokens | RefTokens; | ||
|
||
export type ProgressCircularTokenMap = { | ||
[Token in ProgressCircularTokens]: ProgressCircularTokenValue; | ||
}; | ||
|
||
export const defaultProgressCircularTokens: ProgressCircularTokenMap = { | ||
'progress-circular-color': 'color-background-brand', | ||
'progress-circular-inverted-color': 'color-white', | ||
}; |
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,47 @@ | ||
import { ProgressCircular } from '@equisoft/design-elements-react'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
const meta: Meta<typeof ProgressCircular> = { | ||
title: 'Components/Progress Circular', | ||
component: ProgressCircular, | ||
args: { | ||
size: 'medium', | ||
inverted: false, | ||
}, | ||
argTypes: { | ||
className: { | ||
control: { | ||
type: 'text', | ||
}, | ||
}, | ||
inverted: { | ||
control: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
value: { | ||
control: { | ||
type: 'range', | ||
min: 0, | ||
max: 100, | ||
}, | ||
}, | ||
size: { | ||
control: { | ||
type: 'select', | ||
options: ['xsmall', 'small', 'medium', 'large'], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof ProgressCircular>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
value: 60, | ||
inverted: false, | ||
}, | ||
}; |