-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added linear progress bar component
- Loading branch information
1 parent
92a6b68
commit 0d7e936
Showing
3 changed files
with
140 additions
and
49 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,24 +1,101 @@ | ||
.progress-bar { | ||
display: flex; | ||
justify-content: center; | ||
cursor: pointer; | ||
/** @define dc-progress-slider */ | ||
// Progress Slider | ||
.deriv-progress-slider { | ||
position: relative; | ||
width: 100%; | ||
padding: unset; | ||
box-sizing: border-box; | ||
margin: 8px 0; | ||
border-bottom: 1px solid var(--general-section-1); | ||
|
||
&-active { | ||
width: 2.5rem; | ||
height: 0.8rem; | ||
background-color: #ff444f; | ||
border-radius: 1rem; | ||
&__track { | ||
background: var(--text-disabled); | ||
position: relative; | ||
margin: 2px 0 8px; | ||
height: 6px; | ||
width: 100%; | ||
border-radius: #{$BORDER_RADIUS * 2}; | ||
} | ||
|
||
&-inactive { | ||
width: 0.8rem; | ||
height: 0.8rem; | ||
margin: 0 0.4rem; | ||
border-radius: 50%; | ||
background-color: #c2c2c2; | ||
&__line { | ||
background: var(--state-hover); | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: 100%; | ||
border-radius: #{$BORDER_RADIUS * 2}; | ||
pointer-events: none; | ||
transition: width 0.3s; | ||
|
||
&--green { | ||
background: var(--status-success) !important; | ||
} | ||
&--yellow { | ||
background: var(--status-warning) !important; | ||
} | ||
&--red { | ||
background: var(--status-danger) !important; | ||
} | ||
} | ||
&__infinite-loader { | ||
position: relative; | ||
height: 4px; | ||
display: block; | ||
width: 100%; | ||
background-color: var(--state-hover); | ||
border-radius: 2px; | ||
background-clip: padding-box; | ||
margin: 0.5rem 0 1rem; | ||
overflow: hidden; | ||
|
||
&--indeterminate { | ||
background-color: var(--state-active); | ||
|
||
&-transition { | ||
transition: all 0.24s linear; | ||
&:before, | ||
&:after { | ||
content: ''; | ||
position: absolute; | ||
background-color: inherit; | ||
top: 0; | ||
left: 0; | ||
bottom: 0; | ||
will-change: left, right; | ||
} | ||
&:before { | ||
animation: indeterminate 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite; | ||
} | ||
&:after { | ||
animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite; | ||
animation-delay: 1.15s; | ||
} | ||
} | ||
@keyframes indeterminate { | ||
0% { | ||
left: -35%; | ||
right: 100%; | ||
} | ||
60% { | ||
left: 100%; | ||
right: -90%; | ||
} | ||
100% { | ||
left: 100%; | ||
right: -90%; | ||
} | ||
} | ||
@keyframes indeterminate-short { | ||
0% { | ||
left: -200%; | ||
right: 100%; | ||
} | ||
60% { | ||
left: 107%; | ||
right: -8%; | ||
} | ||
100% { | ||
left: 107%; | ||
right: -8%; | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,27 +1,49 @@ | ||
import React from 'react'; | ||
import './ProgressBar.scss'; | ||
import clsx from 'clsx'; | ||
import { Text } from '../Text'; | ||
import { TGenericSizes } from "../../types"; | ||
import "./ProgressBar.scss" | ||
|
||
type TProps = { | ||
activeIndex: number; | ||
count: number; | ||
onClick?: (index: number) => void; | ||
type TProgressSliderProps = { | ||
className?: string; | ||
is_loading: boolean; | ||
label:React.ReactNode; | ||
percentage:number; | ||
size?: Extract<TGenericSizes, "lg" | "md" | "sm" | "xs">; | ||
}; | ||
|
||
export const ProgressBar: React.FC<TProps> = ({ activeIndex, count, onClick }) => { | ||
export const LinearProgressBar = ({ | ||
className, | ||
is_loading, | ||
label, | ||
percentage, | ||
size="xs" | ||
}: TProgressSliderProps) => { | ||
return ( | ||
<div className='progress-bar' role='progressbar'> | ||
{[...Array(count).keys()].map(idx => { | ||
const isActive = idx === activeIndex; | ||
const barClassname = isActive ? 'progress-bar-active' : 'progress-bar-inactive'; | ||
<div className={clsx('deriv-progress-slider', className)}> | ||
<React.Fragment> | ||
<Text size={size} className='deriv-progress-slider__remaining-time'> | ||
{label} | ||
</Text> | ||
{is_loading || percentage < 1 ? ( | ||
<div className='deriv-progress-slider__infinite-loader'> | ||
<div className='deriv-progress-slider__infinite-loader--indeterminate' /> | ||
</div> | ||
) : ( | ||
/* Calculate line width based on percentage of time left */ | ||
<div className='deriv-progress-slider__track'> | ||
<div | ||
className={clsx('deriv-progress-slider__line', { | ||
'deriv-progress-slider__line--green': percentage >= 50, | ||
'deriv-progress-slider__line--yellow': percentage < 50 && percentage >= 20, | ||
'deriv-progress-slider__line--red': percentage < 20, | ||
})} | ||
style={{ width: `${percentage}%` }} | ||
/> | ||
</div> | ||
)} | ||
</React.Fragment> | ||
|
||
return ( | ||
<div | ||
className={`${barClassname} progress-bar-transition`} | ||
key={`progress-bar-${idx}`} | ||
onClick={() => onClick?.(idx)} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; |
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