Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
DEFAULT_PARTNER_GROUP,
updateGroupSchema,
} from "@/lib/zod/schemas/groups";
import { GroupColorPicker } from "@/ui/partners/groups/group-color-picker";
import { GroupSettingsRow } from "@/ui/partners/groups/group-settings-row";
import { ColorPicker, RESOURCE_COLOR_SWATCHES } from "@/ui/shared/color-picker";
import { Button, CopyButton } from "@dub/ui";
import { cn } from "@dub/utils";
import slugify from "@sindresorhus/slugify";
Expand Down Expand Up @@ -133,9 +133,13 @@ function GroupSettingsForm({
control={control}
name="color"
render={({ field }) => (
<GroupColorPicker
color={field.value}
<ColorPicker
value={field.value ?? null}
onChange={field.onChange}
swatches={RESOURCE_COLOR_SWATCHES}
showDefault
variant="swatches"
className="size-5"
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useApiMutation } from "@/lib/swr/use-api-mutation";
import useWorkspace from "@/lib/swr/use-workspace";
import { createGroupSchema } from "@/lib/zod/schemas/groups";
import { RESOURCE_COLORS } from "@/ui/colors";
import { GroupColorPicker } from "@/ui/partners/groups/group-color-picker";
import { ColorPicker, RESOURCE_COLOR_SWATCHES } from "@/ui/shared/color-picker";
import { Button, Modal } from "@dub/ui";
import { cn } from "@dub/utils";
import slugify from "@sindresorhus/slugify";
Expand Down Expand Up @@ -92,9 +92,13 @@ function CreateGroupModalContent({ setIsOpen }: CreateGroupModalProps) {
control={control}
name="color"
render={({ field }) => (
<GroupColorPicker
color={field.value}
<ColorPicker
value={field.value}
onChange={field.onChange}
swatches={RESOURCE_COLOR_SWATCHES}
showDefault
variant="swatches"
className="size-5"
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import { updateProgramResourceAction } from "@/lib/actions/partners/program-reso
import useProgramResources from "@/lib/swr/use-program-resources";
import useWorkspace from "@/lib/swr/use-workspace";
import { ProgramResourceColor } from "@/lib/zod/schemas/program-resources";
import { ColorSelector } from "@/ui/shared/color-picker";
import { Button, Modal } from "@dub/ui";
import { cn } from "@dub/utils";
import { useAction } from "next-safe-action/hooks";
import {
Dispatch,
SetStateAction,
useCallback,
useEffect,
useMemo,
useState,
} from "react";
import { HexColorPicker } from "react-colorful";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import * as z from "zod/v4";
Expand Down Expand Up @@ -55,10 +54,6 @@ function ColorModalInner({
const { mutate } = useProgramResources();
const isEditing = Boolean(existingResource);

const [hexInputValue, setHexInputValue] = useState(
existingResource?.color || "#000000",
);

const {
register,
handleSubmit,
Expand All @@ -77,19 +72,6 @@ function ColorModalInner({

const selectedColor = watch("color");

// Keep hex input in sync with form value
useEffect(() => setHexInputValue(selectedColor), [selectedColor]);

const handleHexInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
setHexInputValue(value);

// Only update form value if it's a valid hex color
if (/^#?[0-9A-F]{6}$/i.test(value)) {
setValue("color", value.startsWith("#") ? value : `#${value}`);
}
};

const { executeAsync: executeAdd } = useAction(addProgramResourceAction, {
onSuccess: () => {
mutate();
Expand Down Expand Up @@ -160,33 +142,14 @@ function ColorModalInner({
<div className="bg-neutral-50 p-4 sm:p-6">
<div className="space-y-4">
<div>
<span className="mb-1 block text-sm font-medium text-neutral-700">
Color
</span>
<div className="flex justify-center [&_.react-colorful]:h-[180px] [&_.react-colorful]:w-full">
<HexColorPicker
color={selectedColor}
onChange={(color) =>
setValue("color", color, { shouldDirty: true })
}
/>
</div>
</div>

<label className="block">
<span className="mb-1 block text-sm font-medium text-neutral-700">
Hex
</span>
<input
type="text"
value={hexInputValue}
onChange={handleHexInputChange}
className={cn(
"block w-full rounded-md border-neutral-300 shadow-sm focus:border-neutral-500 focus:ring-neutral-500 sm:text-sm",
!/^#[0-9A-F]{6}$/i.test(hexInputValue) &&
"border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500",
)}
placeholder="#000000"
<ColorSelector
value={selectedColor}
onChange={(color) =>
color && setValue("color", color, { shouldDirty: true })
}
showPicker
showHexInput
className="w-full"
/>
<input
type="hidden"
Expand All @@ -197,7 +160,7 @@ function ColorModalInner({
{errors.color.message}
</p>
)}
</label>
</div>

<label className="block">
<span className="mb-1 block text-sm font-medium text-neutral-700">
Expand Down
6 changes: 3 additions & 3 deletions apps/web/lib/zod/schemas/tags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RESOURCE_COLORS } from "@/ui/colors";
import { TAG_COLORS } from "@/ui/colors";
import * as z from "zod/v4";
import { booleanQuerySchema, getPaginationQuerySchema } from "./misc";

Expand Down Expand Up @@ -40,7 +40,7 @@ export const getTagsCountQuerySchema = getTagsQuerySchema.omit({
});

// TODO: Remove "pink" after confirming we don't have any pink tags in the database
const tagColors = [...RESOURCE_COLORS, "pink"] as const;
const tagColors = [...TAG_COLORS, "pink"] as const;

export const tagColorSchema = z
.enum(tagColors, {
Expand All @@ -59,7 +59,7 @@ export const createTagBodySchema = z
.object({
name: tagName,
color: tagColorSchema.describe(
`The color of the tag. If not provided, a random color will be used from the list: ${RESOURCE_COLORS.join(", ")}.`,
`The color of the tag. If not provided, a random color will be used from the list: ${TAG_COLORS.join(", ")}.`,
),
tag: tagName.meta({
deprecated: true,
Expand Down
86 changes: 78 additions & 8 deletions apps/web/ui/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,118 @@ import { ResourceColorsEnum } from "../lib/types";
export const RESOURCE_COLORS_DATA = [
{
color: "red",
hex: "#FB2C36",
tagVariants: "bg-red-100 text-red-600",
groupVariants: "bg-red-600",
groupVariants: "bg-red-500",
},
{
color: "orange",
hex: "#FF6900",
tagVariants: "bg-orange-100 text-orange-600",
groupVariants: "bg-orange-500",
},
{
color: "amber",
hex: "#FD9A00",
tagVariants: "bg-amber-100 text-amber-600",
groupVariants: "bg-amber-500",
},
{
color: "yellow",
hex: "#EFB100",
tagVariants: "bg-yellow-100 text-yellow-600",
groupVariants: "bg-yellow-600",
groupVariants: "bg-yellow-500",
},
{
color: "lime",
hex: "#7CCF00",
tagVariants: "bg-lime-100 text-lime-600",
groupVariants: "bg-lime-500",
},
{
color: "green",
hex: "#00C951",
tagVariants: "bg-green-100 text-green-600",
groupVariants: "bg-green-600",
groupVariants: "bg-green-500",
},
{
color: "teal",
hex: "#00BBA7",
tagVariants: "bg-teal-100 text-teal-600",
groupVariants: "bg-teal-500",
},
{
color: "cyan",
hex: "#00B8DB",
tagVariants: "bg-cyan-100 text-cyan-600",
groupVariants: "bg-cyan-500",
},
{
color: "blue",
hex: "#2B7FFF",
tagVariants: "bg-blue-100 text-blue-600",
groupVariants: "bg-blue-600",
groupVariants: "bg-blue-500",
},
{
color: "indigo",
hex: "#615FFF",
tagVariants: "bg-indigo-100 text-indigo-600",
groupVariants: "bg-indigo-500",
},
{
color: "purple",
hex: "#AD46FF",
tagVariants: "bg-purple-100 text-purple-600",
groupVariants: "bg-purple-600",
groupVariants: "bg-purple-500",
},
{
color: "fuchsia",
hex: "#E12AFB",
tagVariants: "bg-fuchsia-100 text-fuchsia-600",
groupVariants: "bg-fuchsia-500",
},
{
color: "pink",
hex: "#F6339A",
tagVariants: "bg-pink-100 text-pink-600",
groupVariants: "bg-pink-500",
},
{
color: "brown",
hex: "#CA8365",
tagVariants: "bg-brown-100 text-brown-600",
groupVariants: "bg-brown-600",
groupVariants: "bg-brown-500",
},
{
color: "gray",
hex: "#525252",
tagVariants: "bg-gray-100 text-gray-600",
groupVariants: "bg-gray-600",
groupVariants: "bg-gray-500",
},
] as const;

export const RESOURCE_COLORS = RESOURCE_COLORS_DATA.map(
(color) => color.color,
) as [string, ...string[]];

// Tags keep the original 7-color set from before the palette was extended to 15
export const TAG_COLORS = [
"red",
"yellow",
"green",
"blue",
"purple",
"brown",
"gray",
] as const;

export const TAG_COLORS_DATA = RESOURCE_COLORS_DATA.filter(({ color }) =>
(TAG_COLORS as readonly string[]).includes(color),
);

export const getResourceColorData = (color: ResourceColorsEnum) => {
return RESOURCE_COLORS_DATA.find((c) => c.color === color);
};

export const RAINBOW_CONIC_GRADIENT =
"conic-gradient(in hsl, #ee535d 0deg, #e9d988 90deg, #9fe0b8 180deg, #bf87e4 270deg, #ee535d 360deg)";
"conic-gradient(from 180deg at 50% 50%, #6AED9F 23.078deg, #97A1F7 72deg, #EF4BD5 144deg, #F94562 216deg, #FCAE6A 288deg, #ECDF59 339.603deg)";
4 changes: 2 additions & 2 deletions apps/web/ui/links/tag-badge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ResourceColorsEnum } from "@/lib/types";
import { RESOURCE_COLORS } from "@/ui/colors";
import { TAG_COLORS } from "@/ui/colors";
import { useMediaQuery } from "@dub/ui";
import { cn, randomValue, truncate } from "@dub/utils";
import { Tag } from "lucide-react";
Expand Down Expand Up @@ -50,5 +50,5 @@ export default function TagBadge({
}

export function randomBadgeColor() {
return randomValue(RESOURCE_COLORS);
return randomValue([...TAG_COLORS]);
}
4 changes: 2 additions & 2 deletions apps/web/ui/modals/add-edit-tag-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mutatePrefix } from "@/lib/swr/mutate";
import useTags from "@/lib/swr/use-tags";
import useWorkspace from "@/lib/swr/use-workspace";
import { ResourceColorsEnum, TagProps } from "@/lib/types";
import { RESOURCE_COLORS_DATA } from "@/ui/colors";
import { TAG_COLORS_DATA } from "@/ui/colors";
import {
Button,
InfoTooltip,
Expand Down Expand Up @@ -169,7 +169,7 @@ function AddEditTagModal({
}}
className="mt-2 flex flex-wrap gap-3"
>
{RESOURCE_COLORS_DATA.map(({ color: colorOption, tagVariants }) => (
{TAG_COLORS_DATA.map(({ color: colorOption, tagVariants }) => (
<div key={colorOption} className="flex items-center">
<RadioGroupItem
value={colorOption}
Expand Down
12 changes: 8 additions & 4 deletions apps/web/ui/modals/link-qr-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ function LinkQRModalInner({
onClose={() => setShowLinkQRModal(false)}
logoSection={
<div>
<div className="flex items-center gap-1.5">
<label className="text-sm font-medium text-neutral-700">
<div className="flex items-center gap-1">
<label className="text-sm font-semibold text-neutral-800">
Logo
</label>
<InfoTooltip content="Display your logo in the center of the QR code. [Learn more.](https://dub.co/help/article/custom-qr-codes)" />
Expand All @@ -166,7 +166,9 @@ function LinkQRModalInner({
onClick={() => setData((d) => ({ ...d, hideLogo: false }))}
disabled={!isPro}
>
<span className="text-sm">Show</span>
<span className="text-sm font-medium text-neutral-800">
Show
</span>
</SegmentTab>
<SegmentTab
active={!!(data.hideLogo && isPro)}
Expand All @@ -189,7 +191,9 @@ function LinkQRModalInner({
<Crown className="text-content-default mr-1 size-4" />
</Tooltip>
)}
<span className="text-sm">Hide</span>
<span className="text-sm font-medium text-neutral-800">
Hide
</span>
</SegmentTab>
</SegmentedControl>
</div>
Expand Down
Loading
Loading