Skip to content

Commit

Permalink
fix: remove prop type warning and use only CSS for threshold dot in P…
Browse files Browse the repository at this point in the history
…rogressBar (#1380)
  • Loading branch information
adamstankiewicz committed Jun 14, 2022
1 parent 208e783 commit 81cae2e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/Popover/Popover.test.jsx
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" />);
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
22 changes: 12 additions & 10 deletions src/ProgressBar/ProgressBar.scss
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 Down
23 changes: 12 additions & 11 deletions src/ProgressBar/index.jsx
@@ -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(() => {
positionAnnotations();
});
const progressInfoEl = progressInfoRef.current;
observer.observe(progressInfoEl);
return () => progressInfoEl && observer.unobserve(progressInfoEl);
}, [positionAnnotations]);

const getHint = (text) => (
<span className="pgn__progress-hint">
{text}
Expand Down Expand Up @@ -80,12 +90,6 @@ const ProgressBarAnnotated = ({
srOnly
/>
)}
{!!threshold && (
<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,
/** 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
Expand Up @@ -17,7 +17,6 @@ exports[`<ProgressBar.Annotated /> correct rendering renders without props 1`] =
"width": "NaN%",
}
}
visuallyHidden={false}
>
<span
className="sr-only"
Expand Down
16 changes: 16 additions & 0 deletions src/setupTest.js
Expand Up @@ -3,4 +3,20 @@ import 'regenerator-runtime/runtime';
import Enzyme from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';

class ResizeObserver {
observe() {
// do nothing
}

unobserve() {
// do nothing
}

disconnect() {
// do nothing
}
}

window.ResizeObserver = ResizeObserver;

Enzyme.configure({ adapter: new Adapter() });

0 comments on commit 81cae2e

Please sign in to comment.