Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
💄 Move color picker save and reset buttons beside the swatch (#3632)
Luke Vella37ba40aa4b62
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsxindex ec88b5e54..e448dc9e1 100644--- a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx@@ -55,6 +55,7 @@ export function CustomBrandingSection({const hexColor = color.toString("hex");const isDefault =hexColor.toLowerCase() === DEFAULT_PRIMARY_COLOR.toLowerCase();+ const isDirty = hexColor.toLowerCase() !== currentColor.toLowerCase();const updateShowBranding = useMutation(mutationOptions(updateSpaceShowBrandingAction),@@ -155,8 +156,10 @@ export function CustomBrandingSection({value={color}onChange={setColor}disabled={disabled}+ isDirty={isDirty}isSaving={updateSpace.isPending}onSave={handleSave}+ saveBadge={space.tier !== "pro" ? <ProBadge /> : null}onReset={handleReset}showReset={!isDefault}aria-labelledby="primary-color-label"diff --git a/apps/web/src/app/[locale]/control-panel/branding/components/primary-color-field.tsx b/apps/web/src/app/[locale]/control-panel/branding/components/primary-color-field.tsxindex 0efd27218..fd9edb5e3 100644--- a/apps/web/src/app/[locale]/control-panel/branding/components/primary-color-field.tsx+++ b/apps/web/src/app/[locale]/control-panel/branding/components/primary-color-field.tsx@@ -30,6 +30,7 @@ export function PrimaryColorField({);const [color, setColor] = React.useState(() => parseColor(defaultValue));const hexColor = color.toString("hex");+ const isDirty = hexColor.toLowerCase() !== defaultValue.toLowerCase();const handleSave = () => {updateBranding.mutate(@@ -44,6 +45,7 @@ export function PrimaryColorField({value={color}onChange={setColor}disabled={disabled}+ isDirty={isDirty}isSaving={updateBranding.isPending}onSave={handleSave}aria-labelledby={labelledBy}diff --git a/apps/web/src/components/color-picker-with-save-button.tsx b/apps/web/src/components/color-picker-with-save-button.tsxindex 81392cb75..3cce27363 100644--- a/apps/web/src/components/color-picker-with-save-button.tsx+++ b/apps/web/src/components/color-picker-with-save-button.tsx@@ -3,22 +3,26 @@import { Button } from "@rallly/ui/button";import type { Color } from "@rallly/ui/color-picker";import { ColorPicker } from "@rallly/ui/color-picker";+import type React from "react";import { Trans, useTranslation } from "@/i18n/client";/**- * Color swatch that opens a picker popover with save and optional- * reset-to-default actions in its footer (pass `onReset` to show the- * reset button; `showReset` enables it).+ * Color swatch that opens a picker popover, with save and optional+ * reset-to-default actions beside it. Save shows while `isDirty`; reset+ * shows when `onReset` is passed and `showReset` is true. `saveBadge`+ * renders inside the save button, e.g. a plan badge.*- * The wrapper div matters: react-aria's ColorPicker renders no element of+ * The wrapper fieldset matters: react-aria's ColorPicker renders no element of* its own, so without it the swatch trigger would be a direct child of* Field, whose `*:w-auto` child selector collapses the button's width.*/export function ColorPickerWithSaveButton({value,onChange,+ isDirty,isSaving,onSave,+ saveBadge,onReset,showReset = false,disabled = false,@@ -26,8 +30,10 @@ export function ColorPickerWithSaveButton({}: {value: Color;onChange: (color: Color) => void;+ isDirty: boolean;isSaving: boolean;onSave: () => void;+ saveBadge?: React.ReactNode;onReset?: () => void;showReset?: boolean;disabled?: boolean;@@ -36,7 +42,29 @@ export function ColorPickerWithSaveButton({const { t } = useTranslation();return (- <div>+ // Named group so each row's save and reset buttons say which color+ // they act on when a page has more than one picker.+ <fieldset aria-labelledby={labelledBy} className="flex items-center gap-2">+ {onReset && showReset ? (+ <Button+ variant="ghost"+ onClick={onReset}+ disabled={disabled || isSaving}+ >+ <Trans i18nKey="reset" defaults="Reset" />+ </Button>+ ) : null}+ {isDirty ? (+ <Button+ variant="default"+ onClick={onSave}+ loading={isSaving}+ disabled={disabled || isSaving}+ >+ <Trans i18nKey="save" defaults="Save" />+ {saveBadge}+ </Button>+ ) : null}<ColorPickervalue={value}onChange={onChange}@@ -44,34 +72,7 @@ export function ColorPickerWithSaveButton({aria-labelledby={labelledBy}aria-label={t("chooseColor", { defaultValue: "Choose color" })}hexInputLabel={t("hexColor", { defaultValue: "Hex color" })}- footer={- <div className="flex justify-end gap-2">- {onReset ? (- <Button- size="sm"- variant="ghost"- onClick={onReset}- disabled={!showReset || disabled || isSaving}- >- <Trans i18nKey="reset" defaults="Reset" />- </Button>- ) : null}- {/* Not gated on isDirty: the hex field only commits on blur, so a- typed color hasn't reached `value` yet when the user clicks —- the click's mousedown commits it, then the handler saves. */}- <Button- size="sm"- variant="default"- className="flex-1"- onClick={onSave}- loading={isSaving}- disabled={disabled || isSaving}- >- <Trans i18nKey="save" defaults="Save" />- </Button>- </div>- }/>- </div>+ </fieldset>);}