Skip to content
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

✨ Added size to Dots progress indicator #1098

Merged
merged 3 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ describe('DotProgress', () => {
const progressbar = screen.getByRole('progressbar')
expect(progressbar).toHaveStyleRule('position', 'absolute')
})
it('has correct default size ', () => {
const { container } = render(<StyledProgress />)
const progress = container.firstChild
expect(progress).toHaveAttribute('width', '32')
expect(progress).toHaveAttribute('height', `${32 / 4}`)
})
it('has correct size when size is 64', () => {
const { container } = render(<StyledProgress size={64} />)
const progress = container.firstChild
expect(progress).toHaveAttribute('width', '64')
expect(progress).toHaveAttribute('height', `${64 / 4}`)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that we shouldn't have knowledge of implementation details, would it be better to test for height as well? 🤔

Copy link
Contributor Author

@mimarz mimarz Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its 1/4 of height, which we could test.. but then again, its kinda implementation detail and kinda not. Its been decided by design 🤔 @wenche

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... Maybe it could be more of a "has height set" approach to make sure it's a circle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated tests @wenche

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

})
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,29 @@ const getColor = (color: 'primary' | 'tertiary' | 'neutral'): string => {
export type DotProgressProps = {
/** Color */
color?: 'primary' | 'tertiary' | 'neutral'
/** Size */
size?: 32 | 48 | 64
/** @ignore */
ref?: Ref<SVGSVGElement>
} & SVGProps<SVGSVGElement>

const DotProgress = forwardRef<SVGSVGElement, DotProgressProps>(
function DotProgress({ color = 'neutral', ...rest }, ref) {
function DotProgress({ color = 'neutral', size = 32, ...rest }, ref) {
const props = {
...rest,
color: getColor(color),
ref,
}

const height = size / 4
const width = size
return (
<Svg
{...props}
role="progressbar"
viewBox="0 0 16 4"
height="8px"
width="32px"
height={height}
width={width}
preserveAspectRatio="xMidYMid meet"
>
<circle cx={2} cy={2} r={2} />
<circle cx={8} cy={2} r={2} />
Expand Down
8 changes: 8 additions & 0 deletions libraries/core-react/stories/components/Dots.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export const Colors: Story<DotProgressProps> = () => (
</Wrapper>
)

export const Sizes: Story<DotProgressProps> = () => (
<Wrapper>
<Progress.Dots color="primary" size={32} />
<Progress.Dots color="primary" size={48} />
<Progress.Dots color="primary" size={64} />
</Wrapper>
)

export const InsideButton: Story<DotProgressProps> = () => (
<Wrapper>
<Button>
Expand Down