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

feat: progress: add progress component to octuple #420

13 changes: 0 additions & 13 deletions src/components/DateTimePicker/DatePicker/Styles/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ $picker-input-padding-vertical: max(
padding: $padding-top 0 $padding-bottom $padding-horizontal;
}

// Picker css reset
@mixin reset-component() {
box-sizing: border-box;
margin: 0;
padding: 0;
color: var(--text-primary-color);
font-size: 14px;
font-variant: tabular-nums;
line-height: 1.5715;
list-style: none;
font-feature-settings: 'tnum';
}

// Picker scroll bars
@mixin scroll-bars() {
-ms-overflow-style: none;
Expand Down
12 changes: 0 additions & 12 deletions src/components/Form/Styles/mixins.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
@mixin reset-component() {
box-sizing: border-box;
margin: 0;
padding: 0;
color: var(--text-primary-color);
font-size: $text-font-size-2;
font-variant: tabular-nums;
line-height: 1.5715;
list-style: none;
font-feature-settings: 'tnum';
}

@mixin reset-form() {
legend {
display: block;
Expand Down
88 changes: 88 additions & 0 deletions src/components/Progress/Circle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React, { FC } from 'react';
import OcCircle, { VIEW_BOX_SIZE } from './Internal/OcCircle';
import { CircleProps } from './Progress.types';
import { getSuccessPercent, validProgress } from './Utils';
import { mergeClasses } from '../../shared/utilities';

import styles from './progress.module.scss';

function getPercentage({ percent, success }: CircleProps) {
const realSuccessPercent = validProgress(getSuccessPercent({ success }));
return [
realSuccessPercent,
validProgress(validProgress(percent) - realSuccessPercent),
];
}

function getStrokeColor({
success = {},
strokeColor,
}: Partial<CircleProps>): (string | Record<string, string>)[] {
const { strokeColor: successColor } = success;
return [successColor || 'var(--success-color)', strokeColor || null!];
}

const Circle: FC<CircleProps> = (props) => {
const {
children,
gapDegree,
gapPosition,
strokeLinecap = 'butt',
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
strokeWidth = VIEW_BOX_SIZE / 1.6,
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
success,
trailColor = null as any,
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
type,
width,
} = props;

const circleSize = width || 120;
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
const circleStyle = {
width: circleSize,
height: circleSize,
fontSize: circleSize * 0.15 + 4,
} as React.CSSProperties;
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
const circleWidth = strokeWidth || 4;
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
const gapPos =
gapPosition || (type === 'dashboard' && 'bottom') || undefined;
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved

const getGapDegree = () => {
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
// Support gapDeg = 0 when type = 'dashboard'
if (gapDegree || gapDegree === 0) {
return gapDegree;
}
if (type === 'dashboard') {
return 75;
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
}
return undefined;
};

const isGradient: boolean =
Object.prototype.toString.call(props.strokeColor) === '[object Object]';
const strokeColor: (string | Record<string, string>)[] = getStrokeColor({
success,
strokeColor: props.strokeColor,
});

const wrapperClassNames: string = mergeClasses([
styles.progressInner,
{ [styles.progressCircleGradient]: isGradient },
]);

return (
<div className={wrapperClassNames} style={circleStyle}>
<OcCircle
gapDegree={getGapDegree()}
gapPosition={gapPos}
percent={getPercentage(props)}
strokeColor={strokeColor}
strokeLinecap={strokeLinecap}
strokeWidth={circleWidth}
trailColor={trailColor}
trailWidth={circleWidth}
/>
{children}
</div>
);
};

export default Circle;
44 changes: 44 additions & 0 deletions src/components/Progress/Internal/Common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useRef, useEffect } from 'react';
import { OcProgressProps } from './OcProgress.types';

export const defaultProps: Partial<OcProgressProps> = {
classNames: '',
percent: 0,
strokeColor: 'var(--primary-color-60)',
strokeLinecap: 'round',
strokeWidth: 1,
style: {},
trailColor: 'var(--accent-color-10)',
trailWidth: 1,
gapPosition: 'bottom',
};

export const useTransitionDuration = (): SVGPathElement[] => {
const pathsRef = useRef<SVGPathElement[]>([]);
const prevTimeStamp = useRef(null);

useEffect(() => {
const now = Date.now();
let updated = false;

pathsRef.current.forEach((path) => {
if (!path) {
return;
}

updated = true;
const pathStyle = path.style;
pathStyle.transitionDuration = '.3s, .3s, .3s, .06s';

if (prevTimeStamp.current && now - prevTimeStamp.current < 100) {
pathStyle.transitionDuration = '0s, 0s';
}
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
});

if (updated) {
prevTimeStamp.current = Date.now();
}
});

return pathsRef.current;
};
Loading