-
-
Notifications
You must be signed in to change notification settings - Fork 458
feat: added Circular Progress #1488
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
Open
dhavalveera
wants to merge
8
commits into
themesberg:main
Choose a base branch
from
dhavalveera:feat/circular-progress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
61b6e73
feat: added Circular Progress
dhavalveera ff0487a
fix: typo mistake for giving name for example
dhavalveera fb1d1a3
added missing `labelText` to show label
dhavalveera 823ad60
feat: added Circular Progress
dhavalveera 785f9e9
fix: typo mistake for giving name for example
dhavalveera 3b66c5f
added missing `labelText` to show label
dhavalveera 51edf97
Merge branch 'feat/circular-progress' of https://github.com/dhavalvee…
dhavalveera 0865ccc
optimized the CircularProgress Bar Code
dhavalveera 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
import { Progress } from "flowbite-react"; | ||
import { type CodeData } from "~/components/code-demo"; | ||
|
||
const code = ` | ||
"use client"; | ||
|
||
import { Progress } from "flowbite-react"; | ||
|
||
export function Component() { | ||
return <Progress.Circular progress={45} />; | ||
} | ||
`; | ||
|
||
const codeRSC = ` | ||
import { ProgressCircular } from "flowbite-react"; | ||
|
||
export function Component() { | ||
return <ProgressCircular progress={45} />; | ||
} | ||
`; | ||
|
||
export function Component() { | ||
return <Progress.Circular progress={45} />; | ||
} | ||
|
||
export const circularProgress: CodeData = { | ||
type: "single", | ||
code: [ | ||
{ | ||
fileName: "client", | ||
language: "tsx", | ||
code, | ||
}, | ||
{ | ||
fileName: "server", | ||
language: "tsx", | ||
code: codeRSC, | ||
}, | ||
], | ||
githubSlug: "progress/progress.circular.tsx", | ||
component: <Component />, | ||
}; |
This file contains hidden or 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,42 @@ | ||
import { Progress } from "flowbite-react"; | ||
import { type CodeData } from "~/components/code-demo"; | ||
|
||
const code = ` | ||
"use client"; | ||
|
||
import { Progress } from "flowbite-react"; | ||
|
||
export function Component() { | ||
return <Progress.Circular progress={45} labelText textLabel="45%" />; | ||
} | ||
`; | ||
|
||
const codeRSC = ` | ||
import { ProgressCircular } from "flowbite-react"; | ||
|
||
export function Component() { | ||
return <ProgressCircular progress={45} labelText textLabel="45%" />; | ||
} | ||
`; | ||
|
||
export function Component() { | ||
return <Progress.Circular progress={45} labelText textLabel="45%" />; | ||
} | ||
dhavalveera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export const circularProgressWithText: CodeData = { | ||
type: "single", | ||
code: [ | ||
{ | ||
fileName: "client", | ||
language: "tsx", | ||
code, | ||
}, | ||
{ | ||
fileName: "server", | ||
language: "tsx", | ||
code: codeRSC, | ||
}, | ||
], | ||
githubSlug: "progress/progress.circularWithText.tsx", | ||
component: <Component />, | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/ui/src/components/Progress/CircularProgress.stories.tsx
This file contains hidden or 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,31 @@ | ||
import type { Meta, StoryFn } from "@storybook/react"; | ||
import type { CircularProgressProps } from "./ProgressCircular"; | ||
import { CircularProgress } from "./ProgressCircular"; | ||
|
||
export default { | ||
title: "Components/Circular Progress", | ||
component: CircularProgress, | ||
decorators: [ | ||
(Story): JSX.Element => ( | ||
<div className="flex w-1/2 flex-col"> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
} as Meta; | ||
|
||
const CircularTemplate: StoryFn<CircularProgressProps> = (args) => <CircularProgress {...args} />; | ||
|
||
export const CircularProgressBar = CircularTemplate.bind({}); | ||
CircularProgressBar.storyName = "Circular Progress"; | ||
CircularProgressBar.args = { | ||
progress: 25, | ||
}; | ||
|
||
export const CircularProgressBarWithText = CircularTemplate.bind({}); | ||
CircularProgressBarWithText.storyName = "Circular Progress With Text"; | ||
CircularProgressBarWithText.args = { | ||
progress: 25, | ||
labelText: true, | ||
textLabel: "25%", | ||
}; |
This file contains hidden or 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 hidden or 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,92 @@ | ||
import type { ComponentProps, FC } from "react"; | ||
import { useId, useMemo } from "react"; | ||
import { twMerge } from "tailwind-merge"; | ||
import { mergeDeep } from "../../helpers/merge-deep"; | ||
import { getTheme } from "../../theme-store"; | ||
import type { DeepPartial } from "../../types"; | ||
import type { FlowbiteColors } from "../Flowbite"; | ||
|
||
export interface FlowbiteCircularProgressTheme { | ||
base: string; | ||
bar: string; | ||
label: { | ||
base: string; | ||
text: string; | ||
textColor: CircularProgressColor; | ||
}; | ||
color: { | ||
bgColor: string; | ||
barColor: CircularProgressColor; | ||
}; | ||
} | ||
|
||
export interface CircularProgressColor | ||
extends Pick< | ||
FlowbiteColors, | ||
"dark" | "blue" | "red" | "green" | "yellow" | "indigo" | "purple" | "cyan" | "gray" | "lime" | "pink" | "teal" | ||
> { | ||
[key: string]: string; | ||
} | ||
|
||
export interface CircularProgressProps extends ComponentProps<"div"> { | ||
labelText?: boolean; | ||
progress: number; | ||
textLabel?: string; | ||
theme?: DeepPartial<FlowbiteCircularProgressTheme>; | ||
progressColor?: keyof CircularProgressColor; | ||
} | ||
|
||
export const CircularProgress: FC<CircularProgressProps> = ({ | ||
className, | ||
progressColor = "cyan", | ||
labelText = false, | ||
progress, | ||
dhavalveera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
textLabel = "65%", | ||
dhavalveera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
theme: customTheme = {}, | ||
...props | ||
}) => { | ||
const id = useId(); | ||
const theme = mergeDeep(getTheme().progress.circular, customTheme); | ||
|
||
// Memoize calculations for the circumference and stroke offset to avoid recalculating on each render | ||
const { offset } = useMemo(() => { | ||
const circumference = 2 * Math.PI * 16; // Fixed radius of 16 | ||
|
||
const offset = circumference * (1 - progress / 100); // Stroke dash offset based on progress | ||
|
||
return { offset }; | ||
}, [progress]); | ||
|
||
return ( | ||
<div id={id} aria-valuenow={progress} role="progressbar" {...props}> | ||
<div className={twMerge(theme.base, className)}> | ||
<svg className={theme.bar} viewBox="0 0 36 36" xmlns="http://www.w3.org/2000/svg"> | ||
<circle cx="18" cy="18" r="16" fill="none" className={theme.color.bgColor} strokeWidth="2" /> | ||
|
||
<circle | ||
cx="18" | ||
cy="18" | ||
r="16" | ||
fill="none" | ||
className={theme.color.barColor[progressColor]} | ||
strokeWidth="2" | ||
strokeDasharray="100" | ||
strokeDashoffset={offset} | ||
dhavalveera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
strokeLinecap="round" | ||
/> | ||
</svg> | ||
|
||
{labelText && textLabel ? ( | ||
<div className={theme.label.base}> | ||
<span | ||
data-testid="flowbite-circular-progress-label" | ||
className={twMerge(theme.label.text, theme.label.textColor[progressColor])} | ||
> | ||
{textLabel} | ||
</span> | ||
</div> | ||
) : null} | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.