-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(#4078): List view and colour theming #4079
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
orochibraru
wants to merge
11
commits into
Dokploy:canary
Choose a base branch
from
orochibraru:feat/4078
base: canary
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.
+490
−20
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5a1bd6e
feat: layout switching
orochibraru 2aafa6b
feat: color switcher
orochibraru 20b3ccf
feat: color enhancements
orochibraru 267904c
chore: revert useless dependency update (handled by dependabot?)
orochibraru b9ab81e
chore: format
orochibraru a8babc1
chore: re-add libsql
orochibraru 52b9f94
chore: rollback vscode settings (not in scope)
orochibraru 35af1a7
fix: include `className` in `cn`
orochibraru 472c57d
fix: AI broken component (thanks greptile)
orochibraru dca7d51
fix: add additional breakpoints
orochibraru 0d1d3d6
fix: added pressed element
orochibraru 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
Some comments aren't visible on the classic Files Changed page.
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,121 @@ | ||
| import { LayoutGridIcon, LayoutListIcon } from "lucide-react"; | ||
| import React, { useEffect } from "react"; | ||
| import { Toggle } from "@/components/ui/toggle"; | ||
| import { | ||
| Tooltip, | ||
| TooltipContent, | ||
| TooltipTrigger, | ||
| } from "@/components/ui/tooltip"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| export enum Layout { | ||
| GRID = "grid", | ||
| LIST = "list", | ||
| } | ||
|
|
||
| export type CardsLayoutProps = React.HTMLAttributes<HTMLDivElement> & { | ||
| layout: Layout; | ||
| }; | ||
|
|
||
| /** | ||
| * Retrieves the default layout for the cards, either from localStorage or defaults to "grid". | ||
| * @returns The default layout, either "grid" or "list". | ||
| */ | ||
| export function getDefaultLayout(): Layout { | ||
| if (typeof window !== "undefined") { | ||
| const savedLayout = localStorage.getItem("servicesLayout") as Layout; | ||
| if (savedLayout === Layout.GRID || savedLayout === Layout.LIST) { | ||
| return savedLayout; | ||
| } | ||
| } | ||
| return Layout.GRID; // Default layout | ||
| } | ||
|
|
||
| /** | ||
| * LayoutSwitcher component that allows users to toggle between grid and list layouts for displaying cards. It uses a Toggle button to switch layouts and a Tooltip to provide context on the action. The selected layout is saved in localStorage to persist user preference across sessions. | ||
| * @param layout The layout to use for the cards, either "grid" or "list". | ||
| * @param setLayout Function to update the layout state in the parent component. | ||
| * @example | ||
| * const [layout, setLayout] = useState<Layout>(() => getDefaultLayout()); | ||
| * @returns JSX.Element | ||
| */ | ||
| const LayoutSwitcher = ({ | ||
| layout, | ||
| setLayout, | ||
| }: { | ||
| layout: Layout; | ||
| setLayout: (layout: Layout) => void; | ||
| }) => { | ||
| const iconClass = "w-5 h-5"; | ||
| return ( | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <Toggle | ||
| aria-label="Toggle layout" | ||
| variant="outline" | ||
| pressed={layout === getDefaultLayout()} | ||
| onPressedChange={(pressed) => | ||
| setLayout(pressed ? Layout.GRID : Layout.LIST) | ||
| } | ||
| > | ||
| {layout === Layout.GRID ? ( | ||
| <LayoutGridIcon className={iconClass} /> | ||
| ) : ( | ||
| <LayoutListIcon className={iconClass} /> | ||
| )} | ||
| </Toggle> | ||
| </TooltipTrigger> | ||
| <TooltipContent> | ||
| <p>Switch to {layout === Layout.GRID ? "list" : "grid"} view</p> | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * CardsLayout component that wraps its children in a grid or list layout based on the provided layout prop. It also saves the user's layout preference in localStorage. | ||
| * | ||
| * @param layout The layout to use for the cards, either "grid" or "list". | ||
| * @example Layout state should be managed this way in the parent component: | ||
| * const [layout, setLayout] = useState<Layout>(() => getDefaultLayout()); | ||
| * | ||
| * <CardsLayout layout={layout}> | ||
| * {children} | ||
| * </CardsLayout> | ||
| * | ||
| * The LayoutSwitcher component can be used to toggle between grid and list layouts, and it will update the layout state in the parent component accordingly. | ||
| * | ||
| * <LayoutSwitcher layout={layout} setLayout={setLayout} /> | ||
| * | ||
| * This implementation ensures that the user's layout preference is persisted across sessions and provides an easy way to switch between different layouts. | ||
| * @returns JSX.Element | ||
| */ | ||
| const CardsLayout = React.forwardRef<HTMLDivElement, CardsLayoutProps>( | ||
| ({ layout, className, children, ...props }, ref) => { | ||
| useEffect(() => { | ||
| localStorage.setItem("servicesLayout", layout); | ||
| }, [layout]); | ||
| return ( | ||
| <section className="flex flex-col gap-4"> | ||
| <div | ||
| className={cn( | ||
| layout === Layout.GRID | ||
| ? "gap-5 pb-10 grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 3xl:grid-cols-5" | ||
| : "flex flex-col gap-4 w-full", | ||
| className, | ||
| )} | ||
| ref={ref} | ||
| {...props} | ||
| > | ||
| {children} | ||
| </div> | ||
| </section> | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| CardsLayout.displayName = "CardsLayout"; | ||
| LayoutSwitcher.displayName = "LayoutSwitcher"; | ||
|
|
||
| export { CardsLayout, LayoutSwitcher }; | ||
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,72 @@ | ||
| import { Check } from "lucide-react"; | ||
| import { cn } from "@/lib/utils"; | ||
| import { | ||
| COLOR_THEMES, | ||
| type ColorTheme, | ||
| useColorTheme, | ||
| } from "./color-theme-provider"; | ||
|
|
||
| const THEME_META: Record<ColorTheme, { label: string; hex: string }> = { | ||
| zinc: { label: "Zinc", hex: "#71717a" }, | ||
| blue: { label: "Blue", hex: "#3b82f6" }, | ||
| violet: { label: "Violet", hex: "#8b5cf6" }, | ||
| pink: { label: "Pink", hex: "#ec4899" }, | ||
| rose: { label: "Rose", hex: "#f43f5e" }, | ||
| red: { label: "Red", hex: "#ef4444" }, | ||
| orange: { label: "Orange", hex: "#f97316" }, | ||
| amber: { label: "Amber", hex: "#f59e0b" }, | ||
| green: { label: "Green", hex: "#22c55e" }, | ||
| teal: { label: "Teal", hex: "#14b8a6" }, | ||
| }; | ||
|
|
||
| export function ColorThemePicker() { | ||
| const { colorTheme, setColorTheme } = useColorTheme(); | ||
|
|
||
| return ( | ||
| <div className="flex flex-wrap gap-4"> | ||
| {COLOR_THEMES.map((theme) => { | ||
| const isActive = colorTheme === theme; | ||
| const { label, hex } = THEME_META[theme]; | ||
| return ( | ||
| <button | ||
| key={theme} | ||
| type="button" | ||
| onClick={() => setColorTheme(theme)} | ||
| className="flex flex-col items-center gap-1.5 focus-visible:outline-none group" | ||
| > | ||
| <span | ||
| className={cn( | ||
| "relative flex h-8 w-8 items-center justify-center rounded-full transition-transform duration-150", | ||
| isActive ? "scale-110" : "group-hover:scale-105", | ||
| )} | ||
| style={{ | ||
| backgroundColor: hex, | ||
| outline: isActive | ||
| ? `2px solid ${hex}` | ||
| : "2px solid transparent", | ||
| outlineOffset: "2px", | ||
| }} | ||
| > | ||
| {isActive && ( | ||
| <Check | ||
| className="h-4 w-4 text-white drop-shadow-sm" | ||
| strokeWidth={2.5} | ||
| /> | ||
| )} | ||
| </span> | ||
| <span | ||
| className={cn( | ||
| "text-xs", | ||
| isActive | ||
| ? "font-medium text-foreground" | ||
| : "text-muted-foreground group-hover:text-foreground", | ||
| )} | ||
| > | ||
| {label} | ||
| </span> | ||
| </button> | ||
| ); | ||
| })} | ||
| </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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { createContext, useContext, useLayoutEffect, useState } from "react"; | ||
|
|
||
| export const COLOR_THEMES = [ | ||
| "zinc", | ||
| "blue", | ||
| "violet", | ||
| "pink", | ||
| "rose", | ||
| "red", | ||
| "orange", | ||
| "amber", | ||
| "green", | ||
| "teal", | ||
| ] as const; | ||
|
|
||
| export type ColorTheme = (typeof COLOR_THEMES)[number]; | ||
|
|
||
| const STORAGE_KEY = "dokploy-color-theme"; | ||
| const DEFAULT_THEME: ColorTheme = "zinc"; | ||
|
|
||
| interface ColorThemeContextValue { | ||
| colorTheme: ColorTheme; | ||
| setColorTheme: (theme: ColorTheme) => void; | ||
| } | ||
|
|
||
| const ColorThemeContext = createContext<ColorThemeContextValue>({ | ||
| colorTheme: DEFAULT_THEME, | ||
| setColorTheme: () => {}, | ||
| }); | ||
|
|
||
| export function ColorThemeProvider({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) { | ||
| const [colorTheme, setColorThemeState] = useState<ColorTheme>(DEFAULT_THEME); | ||
|
|
||
| useLayoutEffect(() => { | ||
| const stored = localStorage.getItem(STORAGE_KEY) as ColorTheme | null; | ||
| const theme = | ||
| stored && (COLOR_THEMES as readonly string[]).includes(stored) | ||
| ? stored | ||
| : DEFAULT_THEME; | ||
| setColorThemeState(theme); | ||
| applyTheme(theme); | ||
| }, []); | ||
|
|
||
| function setColorTheme(theme: ColorTheme) { | ||
| setColorThemeState(theme); | ||
| localStorage.setItem(STORAGE_KEY, theme); | ||
| applyTheme(theme); | ||
| } | ||
|
|
||
| return ( | ||
| <ColorThemeContext.Provider value={{ colorTheme, setColorTheme }}> | ||
| {children} | ||
| </ColorThemeContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| function applyTheme(theme: ColorTheme) { | ||
| if (theme === DEFAULT_THEME) { | ||
| document.documentElement.removeAttribute("data-color-theme"); | ||
| } else { | ||
| document.documentElement.setAttribute("data-color-theme", theme); | ||
| } | ||
| } | ||
|
|
||
| export function useColorTheme() { | ||
| return useContext(ColorThemeContext); | ||
| } |
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.