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

Add progress bar to ds #1787

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { Link, type LinkProps } from './link';
export { Lozenge, type LozengeProps } from './lozenge';
export { Menu, type MenuProps, MenuItem, type MenuItemComponentProps } from './menu';
export { Modal, type ModalProps, modal } from './modal';
export { ProgressBar, type ProgressBarProps } from './progressBar';
export { Separator, type SeparatorProps } from './separator';
export { Skeleton, type SkeletonProps } from './skeleton';
export { Tabs, type TabsProps, type TabItem } from './tabs';
Expand Down
41 changes: 41 additions & 0 deletions src/blocks/progressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { FC } from 'react';
import styled, { FlattenSimpleInterpolation } from 'styled-components';

import type { ProgressBarProps } from './ProgressBar.types';
import { getProgressWidthPercentage } from './ProgressBar.utils';

const StyledProgressBarContainer = styled.div<{ css?: FlattenSimpleInterpolation }>`
/* Default CSS */
background-color: var(--components-progress-bar-background-default);
width: 100%;
height: 4px;
border-radius: var(--radius-xxs, 8px);

/* Extra CSS prop */
${({ css }) => css || ''}
`;

const StyledProgressBar = styled.div<{ width: string }>`
/* Default CSS */
border-radius: var(--radius-xxs, 8px);
background-color: var(--components-progress-bar-background-progress);
height: 100%;
width: ${({ width }) => width};
transition: width 0.3s ease;
`;

const ProgressBar: FC<ProgressBarProps> = ({ progress, max = 100, ...rest }) => (
<StyledProgressBarContainer
role="progressbar"
aria-valuemin={0}
aria-valuemax={max}
aria-valuenow={progress}
{...rest}
>
<StyledProgressBar width={`${getProgressWidthPercentage(progress, max)}%`} />
</StyledProgressBarContainer>
);

ProgressBar.displayName = 'ProgressBar';

export { ProgressBar };
11 changes: 11 additions & 0 deletions src/blocks/progressBar/ProgressBar.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { TransformedHTMLAttributes } from 'blocks/Blocks.types';
import { FlattenSimpleInterpolation } from 'styled-components';

export type ProgressBarProps = {
/* Additional prop from styled components to apply custom css to ProgressBar */
css?: FlattenSimpleInterpolation;
/* Progress value */
progress: number;
/* Max value */
max?: number;
} & TransformedHTMLAttributes<HTMLDivElement>;
4 changes: 4 additions & 0 deletions src/blocks/progressBar/ProgressBar.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const getProgressWidthPercentage = (progress: number, total = 100) => {
const percentage = (progress / total) * 100;
return Math.min(Math.max(percentage, 0), 100);
};
3 changes: 3 additions & 0 deletions src/blocks/progressBar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './ProgressBar';
export * from './ProgressBar.utils';
export * from './ProgressBar.types';
4 changes: 4 additions & 0 deletions src/blocks/theme/colors/colors.semantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { dropdownSemantics } from '../semantics/semantics.dropdown';
import { iconSemantics } from '../semantics/semantics.icon';
import { inputSemantics } from '../semantics/semantics.input';
import { modalSemantics } from '../semantics/semantics.modal';
import { progressBarSemantics } from '../semantics/semantics.progress-bar';
import { radioSemantics } from '../semantics/semantics.radio';
import { skeletonSemantics } from '../semantics/semantics.skeleton';
import { strokeSemantics } from '../semantics/semantics.stroke';
Expand All @@ -37,6 +38,7 @@ type SemanticKeys = {
icon: 'icon';
input: 'components-inputs';
modal: 'components-modal';
progressBar: 'components-progress-bar';
radio: 'components-radio-button';
surface: 'surface';
stroke: 'stroke';
Expand All @@ -62,6 +64,7 @@ export const semanticKeys: SemanticKeys = {
icon: 'icon',
input: 'components-inputs',
modal: 'components-modal',
progressBar: 'components-progress-bar',
radio: 'components-radio-button',
surface: 'surface',
stroke: 'stroke',
Expand All @@ -87,6 +90,7 @@ export const colorSemantics = {
[semanticKeys.icon]: iconSemantics,
[semanticKeys.input]: inputSemantics,
[semanticKeys.modal]: modalSemantics,
[semanticKeys.progressBar]: progressBarSemantics,
[semanticKeys.radio]: radioSemantics,
[semanticKeys.surface]: surfaceSemantics,
[semanticKeys.stroke]: strokeSemantics,
Expand Down
6 changes: 6 additions & 0 deletions src/blocks/theme/semantics/semantics.progress-bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { surfaceSemantics } from './semantics.surface';

export const progressBarSemantics = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-08-01 at 2 43 34 PM

The semantics doesn't matches figma.

'background-default': { light: surfaceSemantics['secondary'].light, dark: surfaceSemantics['secondary'].dark },
'background-progress': { light: surfaceSemantics['brand-medium'].light, dark: surfaceSemantics['brand-medium'].dark },
};
Loading