-
Notifications
You must be signed in to change notification settings - Fork 30
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
Components/progress bar #1756
Merged
Merged
Components/progress bar #1756
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
066f2f3
resolve progressBar issues
NAsriGhada 6fa4944
progress bar preview
NAsriGhada 9f1502b
progreesbar
NAsriGhada 5f8187f
progress bar with storybook
NAsriGhada 1c9627b
description not working
NAsriGhada 10e5522
description not working and not autogenerated
NAsriGhada ad34f70
encapsulated props
NAsriGhada bc9e9cc
encapsulated props but description is still not working
NAsriGhada 0831545
new changes
NAsriGhada 2b1d5af
use the same props coming from radix
Enjoy2Live b09a08e
linked the progressbar element to its related text to improve accessi…
Enjoy2Live 390902d
install @radix-ui/react-progress
Enjoy2Live fc4570d
Merge pull request #1788 from dev-launchers/progressbar-changes
NAsriGhada 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
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,24 @@ | ||
import * as React from 'react'; | ||
|
||
function Clock(props: React.SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg | ||
width="22" | ||
height="22" | ||
viewBox="0 0 22 22" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<path | ||
d="M11 5V11L15 13M21 11C21 16.5228 16.5228 21 11 21C5.47715 21 1 16.5228 1 11C1 5.47715 5.47715 1 11 1C16.5228 1 21 5.47715 21 11Z" | ||
stroke="black" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</svg> | ||
); | ||
} | ||
|
||
export default Clock; |
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 @@ | ||
import * as React from 'react'; | ||
function Done(props: React.SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg | ||
width="22" | ||
height="22" | ||
viewBox="0 0 22 22" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<path | ||
d="M8 11L10 13L14 9M21 11C21 16.5228 16.5228 21 11 21C5.47715 21 1 16.5228 1 11C1 5.47715 5.47715 1 11 1C16.5228 1 21 5.47715 21 11Z" | ||
stroke="black" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</svg> | ||
); | ||
} | ||
|
||
export default Done; |
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,27 @@ | ||
import { Progress } from './Progress.tsx'; | ||
import * as ProgressStories from './Progress.stories.tsx'; | ||
import { | ||
Meta, | ||
Stories, | ||
Description, | ||
Story, | ||
ArgTypes, | ||
Canvas, | ||
Controls, | ||
} from '@storybook/blocks'; | ||
|
||
<Meta of={ProgressStories} /> | ||
<div className="gap-14"> | ||
<h1>Progress Bar</h1> | ||
<p className="text-[#8A8D97]"> | ||
Component with all the variants, states, etc. | ||
</p> | ||
</div> | ||
<div className="flex flex-col items-start gap-3 rounded-lg p-4 outline-dashed outline-2 outline-brand-alt-nebula-500 w-96"> | ||
<Story of={ProgressStories.Primary} /> | ||
<Story of={ProgressStories.Secondary} /> | ||
<Story of={ProgressStories.Tertiary} /> | ||
<Story of={ProgressStories.Quartary} /> | ||
</div> | ||
<Canvas /> | ||
<Controls of={ProgressStories.Primary} exclude={['asChild']} /> |
65 changes: 65 additions & 0 deletions
65
packages/UI/src/components/progressBar/Progress.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,65 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { Progress } from './Progress'; | ||
import '@devlaunchers/tailwind/tailwind.css'; | ||
|
||
const meta: Meta<typeof Progress> = { | ||
component: Progress, | ||
parameters: { | ||
layout: 'centered', | ||
docs: { | ||
// Customize the args table by excluding certain arg types | ||
argTypes: { | ||
exclude: ['asChild'], | ||
}, | ||
}, | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/EwzuhhvTulvFRMvhTD5VAh/DL-Universal-Design-System?type=design&node-id=11653-23398&mode=design&t=pKeXByjq7arsjXYv-0', | ||
}, | ||
}, | ||
argTypes: { | ||
value: { | ||
control: { | ||
type: 'range', | ||
min: 0, | ||
max: 100, | ||
step: 25, | ||
}, | ||
defaultValue: 25, | ||
}, | ||
toggleClock: { | ||
control: 'boolean', | ||
defaultValue: true, | ||
}, | ||
}, | ||
} as Meta<typeof Progress>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Progress>; | ||
|
||
export const Primary: Story = { | ||
args: { | ||
value: 25, | ||
fileName: 'File name', | ||
toggleClock: true, | ||
}, | ||
}; | ||
|
||
export const Secondary: Story = { | ||
args: { | ||
...Primary.args, | ||
value: 50, | ||
}, | ||
}; | ||
export const Tertiary: Story = { | ||
args: { | ||
...Primary.args, | ||
value: 75, | ||
}, | ||
}; | ||
export const Quartary: Story = { | ||
args: { | ||
...Primary.args, | ||
value: 100, | ||
}, | ||
}; |
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,105 @@ | ||
import * as ProgressPrimitive from '@radix-ui/react-progress'; | ||
import * as React from 'react'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { cn } from '../../utils/classesMerger'; | ||
import Clock from './../../assets/icons/Clock'; | ||
import Done from './../../assets/icons/Done'; | ||
|
||
const styles = { | ||
startColor: 'bg-brand-alt-cosmic-500', | ||
endColor: 'bg-brand-alt-nebula-500', | ||
backgroundColor: 'bg-grayscale-100', | ||
width: 'w-80', | ||
height: 'h-6', | ||
textColor: 'text-grayscale-900', | ||
font: 'font-normal', | ||
fontStyle: 'not-italic', | ||
flex: 'flex', | ||
flexDirection: 'flex-col', | ||
alignItems: 'items-start', | ||
justifyContent: 'justify-between', | ||
indigo: 'bg-indigo-500', | ||
}; | ||
|
||
interface ProgressProps | ||
extends React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> { | ||
/** | ||
* Progress value passed as a prop | ||
*/ | ||
value: ProgressPrimitive.ProgressProps['value']; | ||
/** | ||
* It is used to uniquely identify the name of the file | ||
*/ | ||
fileName: string; | ||
/** | ||
* You can choose whether to show the clock or not | ||
*/ | ||
toggleClock: boolean; // This prop now controls both icons. | ||
} | ||
|
||
const Progress = React.forwardRef< | ||
React.ElementRef<typeof ProgressPrimitive.Root>, | ||
ProgressProps | ||
>( | ||
( | ||
{ | ||
className, | ||
fileName = 'name your file', | ||
value = 0, | ||
toggleClock, | ||
...props | ||
}, | ||
ref | ||
) => { | ||
const labelId = React.useRef(uuidv4()); | ||
const isComplete = value === 100; | ||
const currentColor = isComplete ? styles.endColor : styles.startColor; | ||
const progressPercentage = `${value}%`; | ||
const icon = toggleClock ? isComplete ? <Done /> : <Clock /> : null; | ||
|
||
return ( | ||
<div | ||
className={`${styles.flex} ${styles.flexDirection} ${styles.alignItems} gap-14 rounded-lg p-4`} | ||
> | ||
<div | ||
className={`${styles.flex} ${styles.width} ${styles.flexDirection} ${styles.alignItems} gap-3`} | ||
> | ||
<div className={`${styles.flex} w-full ${styles.justifyContent}`}> | ||
<p | ||
className={`text-base ${styles.font} ${styles.fontStyle} leading-6 ${styles.textColor}`} | ||
id={labelId.current} | ||
> | ||
{fileName} | ||
</p> | ||
<div className={`${styles.flex} ${styles.justifyContent} gap-2`}> | ||
<span | ||
className={`text-xs ${styles.font} ${styles.fontStyle} leading-5 ${styles.textColor}`} | ||
> | ||
{progressPercentage} | ||
</span> | ||
{icon} | ||
</div> | ||
</div> | ||
<ProgressPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
`relative ${styles.width} ${styles.height} overflow-hidden rounded-full ${styles.backgroundColor} border-solid border-2 border-brand-alt-cosmic-500`, | ||
className | ||
)} | ||
{...props} | ||
aria-labelledby={labelId.current} | ||
> | ||
<ProgressPrimitive.Indicator | ||
className={`h-full w-full flex-1 ${currentColor} transition-all`} | ||
style={{ transform: `translateX(-${100 - (value ?? 0)}%)` }} | ||
/> | ||
</ProgressPrimitive.Root> | ||
</div> | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
Progress.displayName = ProgressPrimitive.Root.displayName; | ||
|
||
export { Progress }; |
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.
I think styles.flex,styles.width, styles.flexDirection , styles.alignItems can be used directly instead
ls there a reason why you made it in an object?
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.
Yeah simply for code readability and the DRY principle which made the lines shorter.