- Notifications
You must be signed in to change notification settings - Fork1.1k
chore: migrate appearanceform to Tailwind and shadcn#20204
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,15 @@ | ||
Comment on lines -1 to -7 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. that's a satisfying chunk of imports to watch vanish | ||
| import { | ||
| type TerminalFontName, | ||
| TerminalFontNames, | ||
| type UpdateUserAppearanceSettingsRequest, | ||
| } from "api/typesGenerated"; | ||
| import { ErrorAlert } from "components/Alert/ErrorAlert"; | ||
| import { PreviewBadge } from "components/Badges/Badges"; | ||
| import { Label } from "components/Label/Label"; | ||
| import { RadioGroup, RadioGroupItem } from "components/RadioGroup/RadioGroup"; | ||
| import { Spinner } from "components/Spinner/Spinner"; | ||
| import type { FC } from "react"; | ||
| import { DEFAULT_THEME } from "theme"; | ||
| import { | ||
| DEFAULT_TERMINAL_FONT, | ||
| terminalFontLabels, | ||
| @@ -67,67 +61,65 @@ export const AppearanceForm: FC<AppearanceFormProps> = ({ | ||
| <Section | ||
| title={ | ||
| <div className="flex flex-row items-center gap-2"> | ||
| <span>Theme</span> | ||
| <Spinner loading={isUpdating} size="sm" /> | ||
| </div> | ||
| } | ||
| layout="fluid" | ||
| className="mb-12" | ||
| > | ||
| <div className="flex flex-row flex-wrap gap-4"> | ||
| <AutoThemePreviewButton | ||
| displayName="Auto" | ||
| active={currentTheme === "auto"} | ||
| themes={["dark", "light"]} | ||
| onSelect={() => onChangeTheme("auto")} | ||
| /> | ||
| <ThemePreviewButton | ||
| displayName="Dark" | ||
| active={currentTheme === "dark"} | ||
| theme="dark" | ||
| onSelect={() => onChangeTheme("dark")} | ||
| /> | ||
| <ThemePreviewButton | ||
| displayName="Light" | ||
| active={currentTheme === "light"} | ||
| theme="light" | ||
| onSelect={() => onChangeTheme("light")} | ||
| /> | ||
| </div> | ||
| </Section> | ||
| <Section | ||
| title={ | ||
| <div className="flex flex-row items-center gap-2"> | ||
| <span id="fonts-radio-buttons-group-label">Terminal Font</span> | ||
| <Spinner loading={isUpdating} size="sm" /> | ||
| </div> | ||
| } | ||
| layout="fluid" | ||
| > | ||
| <RadioGroup | ||
| aria-labelledby="fonts-radio-buttons-group-label" | ||
Contributor
| ||
| defaultValue={currentTerminalFont} | ||
| name="fonts-radio-buttons-group" | ||
| onValueChange={(value) => | ||
| onChangeTerminalFont(toTerminalFontName(value)) | ||
| } | ||
| > | ||
| {TerminalFontNames.filter((name) => name !== "").map((name) => ( | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Do we need this ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It looks like TerminalFontName in typesGenerated comes from codersdk/users.go with an empty string option. So it seems like we need to filter out the empty string if we don't want to display that. | ||
| <div key={name} className="flex items-center space-x-2"> | ||
| <RadioGroupItem value={name} id={name} /> | ||
| <Label | ||
| htmlFor={name} | ||
| className="cursor-pointer font-normal" | ||
| style={{ fontFamily: terminalFonts[name] }} | ||
| > | ||
| {terminalFontLabels[name]} | ||
| </Label> | ||
| </div> | ||
| ))} | ||
| </RadioGroup> | ||
| </Section> | ||
| </form> | ||
| ); | ||
| @@ -139,8 +131,10 @@ function toTerminalFontName(value: string): TerminalFontName { | ||
| : ""; | ||
| } | ||
| type ThemeMode = "dark" | "light"; | ||
| interface AutoThemePreviewButtonProps extends Omit<ThemePreviewProps, "theme"> { | ||
| themes: [ThemeMode, ThemeMode]; | ||
| onSelect?: () => void; | ||
| } | ||
| @@ -163,13 +157,15 @@ const AutoThemePreviewButton: FC<AutoThemePreviewButtonProps> = ({ | ||
| value={displayName} | ||
| checked={active} | ||
| onChange={onSelect} | ||
| className="sr-only" | ||
| /> | ||
| <label | ||
| htmlFor={displayName} | ||
| className={cn("relative cursor-pointer", className)} | ||
| > | ||
| <ThemePreview | ||
| className="absolute" | ||
| style={{ | ||
| // Slightly past the bounding box to avoid cutting off the outline | ||
| clipPath: "polygon(-5% -5%, 50% -5%, 50% 105%, -5% 105%)", | ||
| }} | ||
| @@ -210,9 +206,9 @@ const ThemePreviewButton: FC<ThemePreviewButtonProps> = ({ | ||
| value={displayName} | ||
| checked={active} | ||
| onChange={onSelect} | ||
| className="sr-only" | ||
| /> | ||
| <label htmlFor={displayName} className={cn("cursor-pointer",className)}> | ||
| <ThemePreview | ||
| active={active} | ||
| preview={preview} | ||
| @@ -228,152 +224,65 @@ interface ThemePreviewProps { | ||
| active?: boolean; | ||
| preview?: boolean; | ||
| className?: string; | ||
| style?: React.CSSProperties; | ||
| displayName: string; | ||
| theme:ThemeMode; | ||
| } | ||
| const ThemePreview: FC<ThemePreviewProps> = ({ | ||
| active, | ||
| preview, | ||
| className, | ||
| style, | ||
| displayName, | ||
| theme, | ||
| }) => { | ||
| return ( | ||
| <div className={theme}> | ||
| <div | ||
| className={cn( | ||
| "w-56 overflow-clip rounded-md border border-border border-solid bg-surface-primary text-content-primary select-none", | ||
| active && "outline outline-2 outline-content-link", | ||
| className, | ||
| )} | ||
| style={style} | ||
| > | ||
| <divclassName="bg-surface-primary text-content-primary"> | ||
| <divclassName="bg-surface-secondary flex items-center justify-between px-2.5 py-1.5 mb-2 border-0 border-b border-border border-solid"> | ||
| <divclassName="flex items-center gap-1.5"> | ||
| <divclassName="bg-content-primary h-1.5 w-5 rounded" /> | ||
| <divclassName="bg-content-secondary h-1.5 w-5 rounded" /> | ||
| <divclassName="bg-content-secondary h-1.5 w-5 rounded" /> | ||
| </div> | ||
| <divclassName="flex items-center gap-1.5"> | ||
| <divclassName="bg-green-400 h-1.5 w-3 rounded" /> | ||
| <divclassName="bg-content-primary h-2 w-2 rounded-full" /> | ||
| </div> | ||
| </div> | ||
| <div className="w-32 mx-auto"> | ||
| <div className="bg-content-primary h-2 w-11 rounded mb-1.5" /> | ||
| <div className="border border-solid rounded-t overflow-clip"> | ||
| <div className="bg-surface-secondary h-2.5 -m-px" /> | ||
| <div className="h-4 border-0 border-t border-border border-solid"> | ||
| <div className="bg-content-disabled h-1.5 w-8 rounded mt-1 ml-1" /> | ||
| </div> | ||
| <div className="h-4 border-0 border-t border-border border-solid"> | ||
| <div className="bg-content-disabled h-1.5 w-8 rounded mt-1 ml-1" /> | ||
| </div> | ||
| <div className="h-4 border-0 border-t border-border border-solid"> | ||
| <div className="bg-content-disabled h-1.5 w-8 rounded mt-1 ml-1" /> | ||
| </div> | ||
| <div className="h-4 border-0 border-t border-border border-solid"> | ||
| <div className="bg-content-disabled h-1.5 w-8 rounded mt-1 ml-1" /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <divclassName="flex items-center justify-between border-0 border-t border-border border-solid px-3 py-1 text-sm"> | ||
| <span>{displayName}</span> | ||
| {preview && <PreviewBadge />} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
Uh oh!
There was an error while loading.Please reload this page.