-
Notifications
You must be signed in to change notification settings - Fork 286
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 tailwind to wave, support shadcn + donut chart as a POC #1775
Merged
Merged
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a3e63ac
tailwind setup under .tw class wrapper
sawka 52cc8ab
add more files for tailwind
sawka 8fdd5fe
donutchart to use tailwind
sawka 5f31fa8
adding shadcn/chart
sawka d29f840
add to theme, rewrite donut
sawka e5c49de
optional props
sawka c2f0bfc
merge main
sawka fdd303d
remove non-nerdfont hack, and martian mono font
sawka bd6bb9b
re-add autoprefixer (lost in merge)
sawka b02a729
apply a lot more of the tailwind preflight.css to our css reset
sawka 7f2fb42
apply a bit more of the tailwind reset
sawka 8e7a79a
migrate to tailwind v4
sawka 8f5da07
remove unused scss
sawka 1176fc0
remove shape.tsx (was just a test file)
sawka ff3c47b
only scan tsx and jsx files
sawka 377b2e1
working on better tailwind setup
sawka 2c6e345
smaller indents
sawka b92f354
remove lato and fira code
sawka f186458
fixing tailwind setup
sawka 869152d
migrate workspace.tsx
sawka 6c19cba
remove import
sawka 1053c42
add flow back
sawka f15a0e2
remove 'tw' class, convert to full tailwind
sawka f8044d9
Merge remote-tracking branch 'origin/main' into sawka/tailwind
sawka 1f7373f
move import to top
sawka 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 |
---|---|---|
|
@@ -16,3 +16,5 @@ body { | |
background-color: orange; | ||
} | ||
} | ||
|
||
@import "../frontend/tailwindsetup.css"; |
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 |
---|---|---|
|
@@ -45,5 +45,8 @@ | |
}, | ||
"[md]": { | ||
"editor.wordWrap": "on" | ||
}, | ||
"files.associations": { | ||
"*.css": "tailwindcss" | ||
} | ||
} |
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
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,73 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import DonutChart from "./donutchart"; | ||
|
||
const meta = { | ||
title: "Components/DonutChart", | ||
component: DonutChart, | ||
parameters: { | ||
layout: "centered", | ||
docs: { | ||
description: { | ||
component: | ||
"The `DonutChart` component displays data in a donut-style chart with customizable colors, labels, and tooltip. Useful for visualizing proportions or percentages.", | ||
}, | ||
}, | ||
}, | ||
argTypes: { | ||
data: { | ||
description: | ||
"The data for the chart, where each item includes `label`, `value`, and optional `displayvalue`.", | ||
control: { type: "object" }, | ||
}, | ||
config: { | ||
description: "config for the chart", | ||
control: { type: "object" }, | ||
}, | ||
innerLabel: { | ||
description: "The label displayed inside the donut chart (e.g., percentages).", | ||
control: { type: "text" }, | ||
}, | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<div | ||
style={{ | ||
width: "200px", | ||
height: "200px", | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
border: "1px solid #ddd", | ||
}} | ||
> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
} satisfies Meta<typeof DonutChart>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof DonutChart>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
config: { | ||
chrome: { label: "Chrome", color: "#8884d8" }, | ||
safari: { label: "Safari", color: "#82ca9d" }, | ||
firefox: { label: "Firefox", color: "#ffc658" }, | ||
edge: { label: "Edge", color: "#ff8042" }, | ||
other: { label: "Other", color: "#8dd1e1" }, | ||
}, | ||
data: [ | ||
{ label: "chrome", value: 275, fill: "#8884d8" }, // Purple | ||
{ label: "safari", value: 200, fill: "#82ca9d" }, // Green | ||
{ label: "firefox", value: 287, fill: "#ffc658" }, // Yellow | ||
{ label: "edge", value: 173, fill: "#ff8042" }, // Orange | ||
{ label: "other", value: 190, fill: "#8dd1e1" }, // Light Blue | ||
], | ||
innerLabel: "50%", | ||
innerSubLabel: "50/100", | ||
dataKey: "value", | ||
nameKey: "label", | ||
}, | ||
}; |
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,101 @@ | ||
import { ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent } from "@/app/shadcn/chart"; | ||
import { isBlank } from "@/util/util"; | ||
import { Label, Pie, PieChart } from "recharts"; | ||
import { ViewBox } from "recharts/types/util/types"; | ||
|
||
const DEFAULT_COLORS = [ | ||
"#3498db", // blue | ||
"#2ecc71", // green | ||
"#e74c3c", // red | ||
"#f1c40f", // yellow | ||
"#9b59b6", // purple | ||
"#1abc9c", // turquoise | ||
"#e67e22", // orange | ||
"#34495e", // dark blue | ||
]; | ||
|
||
const NO_DATA_COLOR = "#E0E0E0"; | ||
|
||
const PieInnerLabel = ({ | ||
innerLabel, | ||
innerSubLabel, | ||
viewBox, | ||
}: { | ||
innerLabel: string; | ||
innerSubLabel: string; | ||
viewBox: ViewBox; | ||
}) => { | ||
if (isBlank(innerLabel)) { | ||
return null; | ||
} | ||
if (!viewBox || !("cx" in viewBox) || !("cy" in viewBox)) { | ||
return null; | ||
} | ||
return ( | ||
<text x={viewBox.cx} y={viewBox.cy} textAnchor="middle" dominantBaseline="middle"> | ||
<tspan x={viewBox.cx} y={viewBox.cy} fill="white" className="fill-foreground text-2xl font-bold"> | ||
{innerLabel} | ||
</tspan> | ||
{innerSubLabel && ( | ||
<tspan x={viewBox.cx} y={(viewBox.cy || 0) + 24} className="fill-muted-foreground"> | ||
{innerSubLabel} | ||
</tspan> | ||
)} | ||
</text> | ||
); | ||
}; | ||
|
||
const DonutChart = ({ | ||
data, | ||
config, | ||
innerLabel, | ||
innerSubLabel, | ||
dataKey, | ||
nameKey, | ||
}: { | ||
data: any[]; | ||
config: ChartConfig; | ||
innerLabel?: string; | ||
innerSubLabel?: string; | ||
dataKey: string; | ||
nameKey: string; | ||
}) => { | ||
return ( | ||
<div | ||
className="tw" | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
width: "100%", | ||
height: "100%", | ||
}} | ||
> | ||
<ChartContainer config={config} className="mx-auto w-full h-full aspect-square max-h-[250px]"> | ||
<PieChart> | ||
<ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel />} /> | ||
<Pie | ||
data={data} | ||
dataKey={dataKey} | ||
nameKey={nameKey} | ||
innerRadius={60} | ||
strokeWidth={5} | ||
isAnimationActive={false} | ||
> | ||
<Label | ||
content={({ viewBox }) => ( | ||
<PieInnerLabel | ||
innerLabel={innerLabel} | ||
innerSubLabel={innerSubLabel} | ||
viewBox={viewBox} | ||
/> | ||
)} | ||
/> | ||
</Pie> | ||
</PieChart> | ||
</ChartContainer> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DonutChart; |
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.
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.
🛠️ Refactor suggestion
Consider adding proper TypeScript types for data prop.
The
data
prop is typed asany[]
which loses type safety. Consider creating a proper interface for the data structure.📝 Committable suggestion