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

fix: remove prop type warning and use only CSS for threshold dot #1380

Merged
merged 5 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions src/Popover/Popover.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import Popover from './index';
describe('<Popover />', () => {
describe('correct rendering', () => {
it('renders with correct class for variant success', () => {
const wrapper = mount(<Popover variant="success" />);
const wrapper = mount(<Popover id="popover-id" variant="success" />);
Copy link
Member Author

Choose a reason for hiding this comment

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

Missing required id props

const popover = wrapper.find('.popover');
expect(popover.hasClass('popover-success')).toEqual(true);
});
it('renders with correct class for variant warning', () => {
const wrapper = mount(<Popover variant="warning" />);
const wrapper = mount(<Popover id="popover-id" variant="warning" />);
const popover = wrapper.find('.popover');
expect(popover.hasClass('popover-warning')).toEqual(true);
});
it('renders with correct class for variant danger', () => {
const wrapper = mount(<Popover variant="danger" />);
const wrapper = mount(<Popover id="popover-id" variant="danger" />);
const popover = wrapper.find('.popover');
expect(popover.hasClass('popover-danger')).toEqual(true);
});
Expand Down
35 changes: 25 additions & 10 deletions src/ProgressBar/ProgressBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@
@each $name, $color in $progress-colors {
.pgn__progress-bar--#{$name} {
background-color: $color;
}

.pgn__progress-threshold-dot--#{$name} {
background: $color;
position: absolute;
margin-top: -(calc($progress-threshold-circle / 2) - calc($annotated-progress-height / 2));
margin-left: -(calc($progress-threshold-circle / 2));
width: $progress-threshold-circle;
height: $progress-threshold-circle;
border-radius: calc($progress-threshold-circle / 2);
z-index: 1;
&::after {
content: "";
display: block;
background: $color;
position: absolute;
top: -(calc($progress-threshold-circle / 2) - calc($annotated-progress-height / 2));
right: -(calc($progress-threshold-circle / 2));
width: $progress-threshold-circle;
height: $progress-threshold-circle;
border-radius: calc($progress-threshold-circle / 2);
z-index: 1;
}
}
}
}
Expand All @@ -74,6 +76,19 @@
right: 0;
}

@each $name, $color in $progress-colors {
.pgn__progress-threshold-dot--#{$name} {
background: $color;
position: absolute;
margin-top: -(calc(($progress-threshold-circle + $annotated-progress-height) / 2));
margin-left: -(calc($progress-threshold-circle / 2));
width: $progress-threshold-circle;
height: $progress-threshold-circle;
border-radius: calc($progress-threshold-circle / 2);
z-index: 1;
}
}

.pgn__progress-info {
display: inline-block;
position: relative;
Expand Down
23 changes: 12 additions & 11 deletions src/ProgressBar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useCallback, useEffect } from 'react';
import ProgressBarBase from 'react-bootstrap/ProgressBar';
import PropTypes from 'prop-types';
import classNames from 'classnames';
Expand Down Expand Up @@ -37,11 +37,21 @@ const ProgressBarAnnotated = ({
const progressColor = VARIANTS.includes(variant) ? variant : PROGRESS_DEFAULT_VARIANT;
const thresholdColor = VARIANTS.includes(thresholdVariant) ? thresholdVariant : THRESHOLD_DEFAULT_VARIANT;

useEffect(() => {
const positionAnnotations = useCallback(() => {
placeInfoAtZero(progressInfoRef, isProgressHintAfter, ANNOTATION_CLASS);
placeInfoAtZero(thresholdInfoRef, isThresholdHintAfter, ANNOTATION_CLASS);
}, [isProgressHintAfter, isThresholdHintAfter]);

useEffect(() => {
positionAnnotations();
const observer = new ResizeObserver(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This helps keep the annotation info positioned more accurately when the progress bar itself changes widths (e.g., when the Paragon documentation site theme changes).

positionAnnotations();
});
const progressInfoEl = progressInfoRef.current;
observer.observe(progressInfoEl);
return () => progressInfoEl && progressInfoEl.unobserve(progressInfoEl);
}, [positionAnnotations]);

const getHint = (text) => (
<span className="pgn__progress-hint">
{text}
Expand Down Expand Up @@ -80,12 +90,6 @@ const ProgressBarAnnotated = ({
srOnly
/>
)}
{!!threshold && (
Copy link
Member Author

Choose a reason for hiding this comment

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

Used CSS only for this threshold dot instead of a DOM element.

<div
className={`pgn__progress-threshold-dot--${thresholdColor}`}
style={{ left: `${threshold}%` }}
/>
)}
</ProgressBarBase>
{(!!threshold && !!thresholdLabel) && (
<div
Expand Down Expand Up @@ -116,8 +120,6 @@ ProgressBarAnnotated.propTypes = {
variant: PropTypes.oneOf(VARIANTS),
/** Specifies an additional `className` to add to the base element. */
className: PropTypes.string,
/** Hide's the label visually. */
visuallyHidden: PropTypes.bool,
Copy link
Member Author

Choose a reason for hiding this comment

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

This prop doesn't do anything for the annotated progress bar, and is currently causing a prop type warning.

/** Threshold current value. */
threshold: PropTypes.number,
/** Specifies label for `threshold`. */
Expand All @@ -135,7 +137,6 @@ ProgressBarAnnotated.defaultProps = {
label: undefined,
variant: PROGRESS_DEFAULT_VARIANT,
className: undefined,
visuallyHidden: false,
threshold: undefined,
thresholdLabel: undefined,
thresholdVariant: THRESHOLD_DEFAULT_VARIANT,
Expand Down