Skip to content

Database diagrams editor that allows you to visualize and design your DB with a single query.

table colors picker

Guy Ben-Aharon2f2828bc3655
diff --git a/src/lib/colors.ts b/src/lib/colors.ts
index 7d42e4d3..9a04fd98 100644
--- a/src/lib/colors.ts
+++ b/src/lib/colors.ts
@@ -1,19 +1,19 @@
+export const colorOptions = [
+ '#ff6363', // A brighter red.
+ '#ff6b8a', // A vibrant pink.
+ '#c05dcf', // A rich purple.
+ '#b067e9', // A lighter purple.
+ '#8a61f5', // A bold indigo.
+ '#7175fa', // A lighter indigo.
+ '#8eb7ff', // A sky blue.
+ '#42e0c0', // A fresh aqua.
+ '#4dee8a', // A mint green.
+ '#9ef07a', // A lime green.
+ '#ffe374', // A warm yellow.
+ '#ff9f74', // A peachy orange.
+];
export const randomColor = () => {
- const colors = [
- '#ff6363', // A brighter red.
- '#ff6b8a', // A vibrant pink.
- '#c05dcf', // A rich purple.
- '#b067e9', // A lighter purple.
- '#8a61f5', // A bold indigo.
- '#7175fa', // A lighter indigo.
- '#8eb7ff', // A sky blue.
- '#42e0c0', // A fresh aqua.
- '#4dee8a', // A mint green.
- '#9ef07a', // A lime green.
- '#ffe374', // A warm yellow.
- '#ff9f74', // A peachy orange.
- ];
- return colors[Math.floor(Math.random() * colors.length)];
+ return colorOptions[Math.floor(Math.random() * colorOptions.length)];
};
export const greyColor = '#b0b0b0'; // A Cloudy Grey.
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 94b6f1d1..5c6cb23c 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -38,3 +38,14 @@ export const getOperatingSystem = (): 'mac' | 'windows' | 'unknown' => {
};
export const deepCopy = <T>(obj: T): T => JSON.parse(JSON.stringify(obj));
+
+export const debounce = <T extends (...args: Parameters<T>) => ReturnType<T>>(
+ func: T,
+ waitFor: number
+) => {
+ let timeout: NodeJS.Timeout;
+ return (...args: Parameters<T>): void => {
+ clearTimeout(timeout);
+ timeout = setTimeout(() => func(...args), waitFor);
+ };
+};
diff --git a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/color-picker/color-picker.tsx b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/color-picker/color-picker.tsx
new file mode 100644
index 00000000..f9d803e7
--- /dev/null
+++ b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/color-picker/color-picker.tsx
@@ -0,0 +1,46 @@
+import React from 'react';
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from '@/components/popover/popover';
+import { colorOptions } from '@/lib/colors';
+
+export interface ColorPickerProps {
+ color: string;
+ onChange: (color: string) => void;
+}
+
+export const ColorPicker = React.forwardRef<
+ React.ElementRef<typeof PopoverTrigger>,
+ ColorPickerProps
+>(({ color, onChange }, ref) => {
+ return (
+ <Popover>
+ <PopoverTrigger asChild ref={ref}>
+ <div
+ className="h-6 w-8 cursor-pointer rounded-md border-2 border-muted transition-shadow hover:shadow-md"
+ style={{
+ backgroundColor: color,
+ }}
+ />
+ </PopoverTrigger>
+ <PopoverContent className="w-fit">
+ <div className="grid grid-cols-4 gap-2">
+ {colorOptions.map((option) => (
+ <div
+ key={option}
+ className="size-8 cursor-pointer rounded-md border-2 border-muted transition-shadow hover:shadow-md"
+ style={{
+ backgroundColor: option,
+ }}
+ onClick={() => onChange(option)}
+ />
+ ))}
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+});
+
+ColorPicker.displayName = 'ColorPicker';
diff --git a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-list-item-content.tsx b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-list-item-content.tsx
index cbe64540..e16d8643 100644
--- a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-list-item-content.tsx
+++ b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-list-item-content.tsx
@@ -29,6 +29,7 @@ import {
SortableContext,
verticalListSortingStrategy,
} from '@dnd-kit/sortable';
+import { ColorPicker } from './color-picker/color-picker';
type AccordionItemValue = 'fields' | 'indexes';
@@ -231,7 +232,11 @@ export const TableListItemContent: React.FC<TableListItemContentProps> = ({
</Accordion>
<Separator className="" />
<div className="flex flex-1 items-center justify-between">
- <div>
+ <ColorPicker
+ color={color}
+ onChange={(color) => updateTable(table.id, { color })}
+ />
+ <div className="flex gap-1">
<Button
variant="outline"
className="h-8 p-2 text-xs"
@@ -240,8 +245,6 @@ export const TableListItemContent: React.FC<TableListItemContentProps> = ({
<FileKey2 className="h-4" />
{t('side_panel.tables_section.table.add_index')}
</Button>
- </div>
- <div>
<Button
variant="outline"
className="h-8 p-2 text-xs"