Skip to content

Adding Switch podkit component to prebuild settings page #19171

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

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-radio-group": "^1.1.3",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@stripe/react-stripe-js": "^1.7.2",
"@stripe/stripe-js": "^1.29.0",
Expand Down
46 changes: 46 additions & 0 deletions components/dashboard/src/components/podkit/switch/Switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import React from "react";
import * as SwitchPrimitives from "@radix-ui/react-switch";
import { cn } from "@podkit/lib/cn";

export const Switch = React.forwardRef<
React.ElementRef<typeof SwitchPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
>(({ className, ...props }, ref) => {
return (
<SwitchPrimitives.Root
className={cn(
// this gives the switch a line-height of 24px that matches the height of our base font size
"my-0.5",
"peer inline-flex h-[20px] w-[36px] shrink-0 cursor-pointer items-center",
"rounded-2xl transition-colors",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
// TODO: do proper disabled state that match designs
"disabled:cursor-default disabled:opacity-50",
// TODO: try and make kumquat-gradient work here for the bg
// checked state colors
"data-[state=checked]:bg-kumquat-dark",
// unchecked state colors
"data-[state=unchecked]:bg-pk-surface-labels data-[state=unchecked]:dark:bg-pk-surface-labels-dark",
className,
)}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb
className={cn(
"pointer-events-none block h-[16px] w-[16px] rounded-full",
"bg-pk-surface-primary dark:bg-pk-surface-primary-dark drop-shadow ring-0",
// Positioning
"transition-transform data-[state=checked]:translate-x-[17px] data-[state=unchecked]:translate-x-[3px]",
)}
/>
</SwitchPrimitives.Root>
);
});
Switch.displayName = SwitchPrimitives.Root.displayName;
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,47 @@
* See License.AGPL.txt in the project root for license information.
*/

import { FC } from "react";
import { FC, useState } from "react";
import { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
import { ConfigurationSettingsField } from "./ConfigurationSettingsField";
import { Heading3, Subheading } from "@podkit/typography/Headings";
import { Switch } from "@podkit/switch/Switch";
import { TextMuted } from "@podkit/typography/TextMuted";

type Props = {
configuration: Configuration;
};
export const ConfigurationDetailPrebuilds: FC<Props> = ({ configuration }) => {
// TODO: hook this up to just use configuration as state and wire up optimistic update for mutation
const [enabled, setEnabled] = useState(!!configuration.prebuildSettings?.enabled);

return (
<>
<ConfigurationSettingsField>
<Heading3>Prebuilds</Heading3>
<Subheading className="max-w-lg">
Prebuilds reduce wait time for new workspaces. Enabling requires permissions to configure repository
webhooks.{" "}
<a href="/docs/configure/projects/prebuilds" className="gp-link">
Learn more
</a>
.
</Subheading>
<Subheading className="max-w-lg">Prebuilds reduce wait time for new workspaces.</Subheading>

<div className="flex gap-4 mt-6">
{/* TODO: wrap this in a SwitchInputField that handles the switch, label and description and htmlFor/id automatically */}
<Switch checked={enabled} onCheckedChange={setEnabled} id="prebuilds-enabled" />
<div className="flex flex-col">
<label className="font-semibold" htmlFor="prebuilds-enabled">
Prebuilds are enabled
</label>
<TextMuted>
Enabling requires permissions to configure repository webhooks.{" "}
<a
href="https://www.gitpod.io/docs/configure/projects/prebuilds"
className="gp-link"
target="_blank"
rel="noopener noreferrer"
>
Learn more
</a>
.
</TextMuted>
</div>
</div>
</ConfigurationSettingsField>
</>
);
Expand Down
61 changes: 50 additions & 11 deletions components/dashboard/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@
// tailwind.config.js
const colors = require("tailwindcss/colors");

const podkitColors = {
black: "#161616",
white: "#FFFFFF",
gray: {
900: "#12100C",
850: "#151310",
800: "#23211E",
750: "#2C2B28",
700: "#514F4D",
600: "#565451",
500: "#666564",
450: "#999795",
400: "#747372",
300: "#DADADA",
200: "#ECE7E5",
100: "#F5F4F4",
50: "#F9F9F9",
},
};

module.exports = {
jit: true,
content: ["./public/**/*.html", "./src/**/*.{js,ts,tsx}"],
Expand All @@ -21,23 +41,42 @@ module.exports = {
teal: colors.teal,
sky: colors.sky,
rose: colors.rose,
"gitpod-black": "#161616",
"gitpod-black": podkitColors.black,
"gitpod-red": "#CE4A3E",
"kumquat-dark": "#FF8A00",
"kumquat-base": "#FFAE33",
"kumquat-ripe": "#FFB45B",
"kumquat-light": "#FFE4BC",
"kumquat-gradient": "linear-gradient(137.41deg, #FFAD33 14.37%, #FF8A00 91.32%)",
"gray-900": "#12100C",
"gray-800": "#23211E",
"gray-700": "#514F4D",
"gray-600": "#565451",
"gray-500": "#666564",
"gray-400": "#999795",
"gray-300": "#DADADA",
"gray-200": "#ECE7E5",
"gray-100": "#F5F4F4",
"gray-50": "#F9F9F9",
gray: podkitColors.gray,
// Podkit colors - eventually we'll only use these colors
// Once migrated, we can remove the colors above and shift this up under theme directly instead of extend
"pk-content": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First step in setting up the new colors for the design system. This will let us reference contextual class names in our podkit components.

primary: podkitColors.gray["900"],
"primary-dark": podkitColors.gray["200"],
secondary: podkitColors.gray["600"],
"secondary-dark": podkitColors.gray["450"],
tertiary: podkitColors.gray["400"],
"tertiary-dark": podkitColors.gray["500"],
disabled: podkitColors.gray["450"],
"disabled-dark": podkitColors.gray["600"],
"invert-primary": podkitColors.gray["200"],
"invert-primary-dark": podkitColors.gray["900"],
"invert-secondary": podkitColors.gray["300"],
"invert-secondary-dark": podkitColors.gray["600"],
},
"pk-surface": {
primary: podkitColors.white,
"primary-dark": podkitColors.gray["850"],
secondary: podkitColors.gray["50"],
"secondary-dark": podkitColors.gray["800"],
tertiary: podkitColors.gray["100"],
"tertiary-dark": podkitColors.gray["750"],
labels: podkitColors.gray["200"],
"labels-dark": podkitColors.gray["700"],
invert: podkitColors.gray["850"],
"invert-dark": podkitColors.gray["50"],
},
},
container: {
center: true,
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,20 @@
"@babel/runtime" "^7.13.10"
"@radix-ui/react-compose-refs" "1.0.1"

"@radix-ui/react-switch@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@radix-ui/react-switch/-/react-switch-1.0.3.tgz#6119f16656a9eafb4424c600fdb36efa5ec5837e"
integrity sha512-mxm87F88HyHztsI7N+ZUmEoARGkC22YVW5CaC+Byc+HRpuvCrOBPTAnXgf+tZ/7i0Sg/eOePGdMhUKhPaQEqow==
dependencies:
"@babel/runtime" "^7.13.10"
"@radix-ui/primitive" "1.0.1"
"@radix-ui/react-compose-refs" "1.0.1"
"@radix-ui/react-context" "1.0.1"
"@radix-ui/react-primitive" "1.0.3"
"@radix-ui/react-use-controllable-state" "1.0.1"
"@radix-ui/react-use-previous" "1.0.1"
"@radix-ui/react-use-size" "1.0.1"

"@radix-ui/react-tooltip@^1.0.7":
version "1.0.7"
resolved "https://registry.yarnpkg.com/@radix-ui/react-tooltip/-/react-tooltip-1.0.7.tgz#8f55070f852e7e7450cc1d9210b793d2e5a7686e"
Expand Down