-
Notifications
You must be signed in to change notification settings - Fork 64
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: create BarChart component #2637
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
53ff8bc
feat: create Progressbar component
artursantiago a9b3f0c
feat: add import to uio components styles
artursantiago 6b6209a
fix(ProgressBar): html type import
artursantiago 0527ad1
fix(Progressbar): use token for bar height
artursantiago ff3d539
docs(ProgressBar): test it description comment
artursantiago f892aa7
refactor: rename ProgressBar to BarChart
artursantiago 186529a
feat(BarChart): use safeMin to calculate fillPercent
artursantiago File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { forwardRef, useMemo } from 'react' | ||
import type { HTMLAttributes } from 'react' | ||
|
||
export interface BarChartProps extends HTMLAttributes<HTMLDivElement> { | ||
/* Current value of the progress */ | ||
value?: number | ||
/* Minimum value (default 0) */ | ||
min?: number | ||
/* Maximum value (default 100) */ | ||
max?: number | ||
/** | ||
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest). | ||
*/ | ||
testId?: string | ||
} | ||
|
||
const BarChart = forwardRef<HTMLDivElement, BarChartProps>(function BarChart( | ||
{ value = 0, min = 0, max = 100, testId = 'fs-bar-chart', ...otherProps }, | ||
ref | ||
) { | ||
const fillPercent = useMemo(() => { | ||
const safeMax = Math.max(min, max) | ||
const safeMin = Math.min(min, max) | ||
|
||
if (safeMax === safeMin) { | ||
return 0 | ||
} | ||
|
||
const clampedValue = Math.min(Math.max(value, safeMin), safeMax) | ||
return ((clampedValue - safeMin) / (safeMax - safeMin)) * 100 | ||
}, [value, min, max]) | ||
|
||
return ( | ||
<div ref={ref} data-fs-bar-chart data-testid={testId} {...otherProps}> | ||
<div data-fs-bar-chart-track> | ||
<div data-fs-bar-chart-fill style={{ width: `${fillPercent}%` }} /> | ||
</div> | ||
</div> | ||
) | ||
}) | ||
export default BarChart |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default } from './BarChart' | ||
export { BarChartProps } from './BarChart' |
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[data-fs-bar-chart] { | ||
// -------------------------------------------------------- | ||
// Design Tokens for BarChart | ||
// -------------------------------------------------------- | ||
|
||
--fs-bar-chart-height : var(--fs-spacing-0); | ||
--fs-bar-chart-radius : 4px; | ||
--fs-bar-chart-track-color : var(--fs-color-neutral-2); | ||
--fs-bar-chart-fill-color : var(--fs-color-main-2); | ||
--fs-bar-chart-transition-function : var(--fs-transition-function); | ||
--fs-bar-chart-transition-property : var(--fs-transition-property); | ||
--fs-bar-chart-transition-timing : var(--fs-transition-timing); | ||
|
||
// Default properties | ||
width: 100%; | ||
height: var(--fs-bar-chart-height); | ||
|
||
[data-fs-bar-chart-track] { | ||
width: 100%; | ||
height: 100%; | ||
overflow: hidden; | ||
background-color: var(--fs-bar-chart-track-color); | ||
border-radius: var(--fs-bar-chart-radius); | ||
} | ||
|
||
[data-fs-bar-chart-fill] { | ||
height: 100%; | ||
background-color: var(--fs-bar-chart-fill-color); | ||
transition: | ||
var(--fs-bar-chart-transition-property) | ||
var(--fs-bar-chart-transition-timing) | ||
var(--fs-bar-chart-transition-function); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.