-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from squidit/feature/sq-65090-frontend-criar-c…
…omponente-grafico-linhas-horizontal-com-percentual (SQ-65090) [frontend] Criar componente gráfico linhas horizontal com percentual
- Loading branch information
Showing
7 changed files
with
2,943 additions
and
5,298 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
19 changes: 19 additions & 0 deletions
19
src/components/sq-bar-chart-percent/__docs__/sq-bar-chart-percent.component.example.tsx
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,19 @@ | ||
import React from 'react' | ||
import SqBarChartPercent, { Props } from '../sq-bar-chart-percent.component' | ||
|
||
const SqBarChart = ({ ...props }: Props) => { | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
height: '100%', | ||
}} | ||
> | ||
<SqBarChartPercent {...props} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default SqBarChart |
35 changes: 35 additions & 0 deletions
35
src/components/sq-bar-chart-percent/__docs__/sq-bar-chart-percent.component.stories.tsx
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,35 @@ | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import SqBarChartExample from './sq-bar-chart-percent.component.example' | ||
|
||
const meta: Meta<typeof SqBarChartExample> = { | ||
title: 'Components/SqBarChartPercent', | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: 'A simple BarChartPercent component', | ||
}, | ||
}, | ||
}, | ||
component: SqBarChartExample, | ||
tags: ['autodocs'], | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof SqBarChartExample> | ||
|
||
export const Default: Story = { | ||
args: { | ||
percentage: true, | ||
colorBar: 'var(--primary_color)', | ||
label: 'Example', | ||
total: 100, | ||
value: 75, | ||
}, | ||
argTypes: { | ||
colorBar: { | ||
control: { | ||
type: 'color', | ||
}, | ||
}, | ||
}, | ||
} |
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 @@ | ||
export { default as SqBarChartPercent } from './sq-bar-chart-percent.component' |
23 changes: 23 additions & 0 deletions
23
src/components/sq-bar-chart-percent/sq-bar-chart-percent.component.scoped.scss
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,23 @@ | ||
.bar-chart { | ||
height: 0.8rem; | ||
background-color: var(--gray_light); | ||
border-radius: 1rem; | ||
display: flex; | ||
position: relative; | ||
|
||
.value-bar { | ||
position: absolute; | ||
background-color: var(--primary_color); | ||
border-radius: 1rem; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
animation: loadbar 2s ease-in-out; | ||
} | ||
|
||
@keyframes loadbar { | ||
from { | ||
width: 0; | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/components/sq-bar-chart-percent/sq-bar-chart-percent.component.tsx
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 @@ | ||
'use client' | ||
|
||
import SqNumbersHelper from '@helpers/sq-numbers/sq-numbers.helper' | ||
import { useMemo } from 'react' | ||
|
||
import './sq-bar-chart-percent.component.scoped.scss' | ||
|
||
export interface Props { | ||
value: number | ||
total: number | ||
percentage: boolean | ||
colorBar?: string | ||
label?: string | ||
} | ||
|
||
const BarChartPercent = ({ value, total, percentage = false, label = '', colorBar = 'var(--primary_color)' }: Props) => { | ||
const totalBar = useMemo(() => total || (percentage ? 1 : 100), [percentage, total]) | ||
const numbersHelper = useMemo(() => new SqNumbersHelper(), []) | ||
const { formatPercent } = numbersHelper | ||
|
||
const definePercentage = (value: number, maxValue: number): string => { | ||
return `${((value * 100) / maxValue).toFixed(0)}%` | ||
} | ||
|
||
const maxNumber = totalBar | ||
const widthUserBar = definePercentage(value, maxNumber) | ||
|
||
return ( | ||
<div> | ||
<div className="display-flex justify-content-space-between my-2"> | ||
<div className="text-bold">{label}</div> | ||
<div className="text-bold">{percentage ? formatPercent(value / 100) : value}</div> | ||
</div> | ||
<div className="bar-chart"> | ||
<div className="value-bar" style={{ width: widthUserBar, backgroundColor: colorBar }}></div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default BarChartPercent |