Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(tags): add button to generate random color (#829)

Corentin Thomasset393a15593fdc
diff --git a/.changeset/cyan-animals-post.md b/.changeset/cyan-animals-post.md
new file mode 100644
index 00000000..0fb2fd14
--- /dev/null
+++ b/.changeset/cyan-animals-post.md
@@ -0,0 +1,5 @@
+---
+"@papra/app": patch
+---
+
+Added a button to generate a random color in the tag creation/edition modal.
diff --git a/apps/papra-client/src/locales/de.dictionary.ts b/apps/papra-client/src/locales/de.dictionary.ts
index 5b24f839..7df9cc49 100644
--- a/apps/papra-client/src/locales/de.dictionary.ts
+++ b/apps/papra-client/src/locales/de.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Helligkeit',
'color-picker.select-color': 'Farbe auswählen',
'color-picker.select-a-color': 'Eine Farbe auswählen',
+ 'color-picker.random-color': 'Zufällige Farbe',
// Subscriptions
diff --git a/apps/papra-client/src/locales/el.dictionary.ts b/apps/papra-client/src/locales/el.dictionary.ts
index ac873ce6..fd14666a 100644
--- a/apps/papra-client/src/locales/el.dictionary.ts
+++ b/apps/papra-client/src/locales/el.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Φωτεινότητα',
'color-picker.select-color': 'Επιλογή χρώματος',
'color-picker.select-a-color': 'Επιλέξτε χρώμα',
+ 'color-picker.random-color': 'Τυχαίο χρώμα',
// Subscriptions
diff --git a/apps/papra-client/src/locales/en.dictionary.ts b/apps/papra-client/src/locales/en.dictionary.ts
index db989360..6b9f1108 100644
--- a/apps/papra-client/src/locales/en.dictionary.ts
+++ b/apps/papra-client/src/locales/en.dictionary.ts
@@ -750,6 +750,7 @@ export const translations = {
'color-picker.lightness': 'Lightness',
'color-picker.select-color': 'Select color',
'color-picker.select-a-color': 'Select a color',
+ 'color-picker.random-color': 'Random color',
// Subscriptions
diff --git a/apps/papra-client/src/locales/es.dictionary.ts b/apps/papra-client/src/locales/es.dictionary.ts
index bf10a55f..5decf6ee 100644
--- a/apps/papra-client/src/locales/es.dictionary.ts
+++ b/apps/papra-client/src/locales/es.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Luminosidad',
'color-picker.select-color': 'Seleccionar color',
'color-picker.select-a-color': 'Selecciona un color',
+ 'color-picker.random-color': 'Color aleatorio',
// Subscriptions
diff --git a/apps/papra-client/src/locales/fr.dictionary.ts b/apps/papra-client/src/locales/fr.dictionary.ts
index 5c8c3e8e..6a042320 100644
--- a/apps/papra-client/src/locales/fr.dictionary.ts
+++ b/apps/papra-client/src/locales/fr.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Luminosité',
'color-picker.select-color': 'Sélectionner la couleur',
'color-picker.select-a-color': 'Sélectionner une couleur',
+ 'color-picker.random-color': 'Couleur aléatoire',
// Subscriptions
diff --git a/apps/papra-client/src/locales/it.dictionary.ts b/apps/papra-client/src/locales/it.dictionary.ts
index 5760c754..09dcdd21 100644
--- a/apps/papra-client/src/locales/it.dictionary.ts
+++ b/apps/papra-client/src/locales/it.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Luminosità',
'color-picker.select-color': 'Seleziona colore',
'color-picker.select-a-color': 'Seleziona un colore',
+ 'color-picker.random-color': 'Colore casuale',
// Subscriptions
diff --git a/apps/papra-client/src/locales/nl.dictionary.ts b/apps/papra-client/src/locales/nl.dictionary.ts
index 96844f2f..d442a0ad 100644
--- a/apps/papra-client/src/locales/nl.dictionary.ts
+++ b/apps/papra-client/src/locales/nl.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Helderheid',
'color-picker.select-color': 'Kleur selecteren',
'color-picker.select-a-color': 'Selecteer een kleur',
+ 'color-picker.random-color': 'Willekeurige kleur',
// Subscriptions
diff --git a/apps/papra-client/src/locales/pl.dictionary.ts b/apps/papra-client/src/locales/pl.dictionary.ts
index db598bea..28b8d498 100644
--- a/apps/papra-client/src/locales/pl.dictionary.ts
+++ b/apps/papra-client/src/locales/pl.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Jasność',
'color-picker.select-color': 'Wybierz kolor',
'color-picker.select-a-color': 'Wybierz kolor',
+ 'color-picker.random-color': 'Losowy kolor',
// Subscriptions
diff --git a/apps/papra-client/src/locales/pt-BR.dictionary.ts b/apps/papra-client/src/locales/pt-BR.dictionary.ts
index b1dd2ad0..b1f1a2f2 100644
--- a/apps/papra-client/src/locales/pt-BR.dictionary.ts
+++ b/apps/papra-client/src/locales/pt-BR.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Brilho',
'color-picker.select-color': 'Selecionar cor',
'color-picker.select-a-color': 'Selecione uma cor',
+ 'color-picker.random-color': 'Cor aleatória',
// Subscriptions
diff --git a/apps/papra-client/src/locales/pt.dictionary.ts b/apps/papra-client/src/locales/pt.dictionary.ts
index 99db086e..4d1f54bb 100644
--- a/apps/papra-client/src/locales/pt.dictionary.ts
+++ b/apps/papra-client/src/locales/pt.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Brilho',
'color-picker.select-color': 'Selecionar cor',
'color-picker.select-a-color': 'Selecione uma cor',
+ 'color-picker.random-color': 'Cor aleatória',
// Subscriptions
diff --git a/apps/papra-client/src/locales/ro.dictionary.ts b/apps/papra-client/src/locales/ro.dictionary.ts
index 63c8d51a..70a0db00 100644
--- a/apps/papra-client/src/locales/ro.dictionary.ts
+++ b/apps/papra-client/src/locales/ro.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Luminozitate',
'color-picker.select-color': 'Selectează culoarea',
'color-picker.select-a-color': 'Selectează o culoare',
+ 'color-picker.random-color': 'Culoare aleatorie',
// Subscriptions
diff --git a/apps/papra-client/src/locales/ru.dictionary.ts b/apps/papra-client/src/locales/ru.dictionary.ts
index eb17d6b1..f8a1101b 100644
--- a/apps/papra-client/src/locales/ru.dictionary.ts
+++ b/apps/papra-client/src/locales/ru.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': 'Яркость',
'color-picker.select-color': 'Выбрать цвет',
'color-picker.select-a-color': 'Выберите цвет',
+ 'color-picker.random-color': 'Случайный цвет',
// Subscriptions
diff --git a/apps/papra-client/src/locales/zh.dictionary.ts b/apps/papra-client/src/locales/zh.dictionary.ts
index cce3b8ad..0f8466dc 100644
--- a/apps/papra-client/src/locales/zh.dictionary.ts
+++ b/apps/papra-client/src/locales/zh.dictionary.ts
@@ -752,6 +752,7 @@ export const translations: Partial<TranslationsDictionary> = {
'color-picker.lightness': '亮度',
'color-picker.select-color': '选择颜色',
'color-picker.select-a-color': '选择一个颜色',
+ 'color-picker.random-color': '随机颜色',
// Subscriptions
diff --git a/apps/papra-client/src/modules/shared/colors/color-formats.ts b/apps/papra-client/src/modules/shared/colors/color-formats.ts
index 476abaad..389a92e2 100644
--- a/apps/papra-client/src/modules/shared/colors/color-formats.ts
+++ b/apps/papra-client/src/modules/shared/colors/color-formats.ts
@@ -1,3 +1,5 @@
+export const FFFFFF_IN_DECIMAL = 16777215;
+
export function getRgbChannelsFromHex(color: string) {
const [r, g, b] = color.match(/^#([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i)?.slice(1).map(c => Number.parseInt(c, 16)) ?? [0, 0, 0];
diff --git a/apps/papra-client/src/modules/ui/components/color-swatch-picker.tsx b/apps/papra-client/src/modules/ui/components/color-swatch-picker.tsx
index 7cb50cdd..f49a56f4 100644
--- a/apps/papra-client/src/modules/ui/components/color-swatch-picker.tsx
+++ b/apps/papra-client/src/modules/ui/components/color-swatch-picker.tsx
@@ -6,11 +6,13 @@ import { parseColor } from '@kobalte/core/colors';
import { cva } from 'class-variance-authority';
import { createSignal, For, splitProps } from 'solid-js';
import { useI18n } from '@/modules/i18n/i18n.provider';
+import { FFFFFF_IN_DECIMAL } from '@/modules/shared/colors/color-formats';
import { getLuminance } from '@/modules/shared/colors/luminance';
import { cn } from '@/modules/shared/style/cn';
import { Button } from './button';
import { Popover, PopoverContent, PopoverTrigger } from './popover';
import { TextField, TextFieldRoot } from './textfield';
+import { Tooltip, TooltipContent, TooltipTrigger } from './tooltip';
const Slider: Component<{
channel: 'hue' | 'saturation' | 'lightness';
@@ -127,6 +129,12 @@ export function ColorSwatchPicker(props: ColorSwatchPickerProps) {
return luminance > 0.179 ? 'black' : 'white';
}
+ function handleRandomColor() {
+ const randomColorDecimal = Math.floor(Math.random() * (FFFFFF_IN_DECIMAL + 1));
+ const randomColor = `#${randomColorDecimal.toString(16).padStart(6, '0').toUpperCase()}`;
+ local.onChange?.(randomColor);
+ }
+
return (
<div
class={cn(
@@ -173,6 +181,17 @@ export function ColorSwatchPicker(props: ColorSwatchPickerProps) {
</PopoverContent>
</Popover>
+ <Tooltip>
+ <TooltipContent>
+ {t('color-picker.random-color')}
+ </TooltipContent>
+
+ <TooltipTrigger>
+ <Button variant="ghost" size="icon" onClick={handleRandomColor} aria-label={t('color-picker.random-color')} disabled={local.disabled}>
+ <div class="i-tabler-refresh size-5 text-muted-foreground" />
+ </Button>
+ </TooltipTrigger>
+ </Tooltip>
</div>
);
}