Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(desktop): add brand swatches to hex color input
Richie McIlroya6399c540564
diff --git a/apps/desktop/src/routes/editor/text-style.tsx b/apps/desktop/src/routes/editor/text-style.tsxindex eea166b5e..805399fd6 100644--- a/apps/desktop/src/routes/editor/text-style.tsx+++ b/apps/desktop/src/routes/editor/text-style.tsx@@ -3,6 +3,8 @@ import {getHexColorDigitCount,normalizeOpaqueHexColor,} from "~/utils/hex-color";+import type { OrganizationBrandColorSwatch } from "~/utils/organization-branding";+import { BrandColorsDropdown } from "./BrandColorsDropdown";import { getColorPreviewBorderColor } from "./color-utils";import { TextInput } from "./TextInput";@@ -46,6 +48,7 @@ export function getTextWeightLabel(weight: number | null | undefined) {export function HexColorInput(props: {value: string;onChange: (value: string) => void;+ brandColorSwatches?: OrganizationBrandColorSwatch[];}) {const [text, setText] = createWritableMemo(() => props.value);let prevColor = props.value;@@ -61,57 +64,71 @@ export function HexColorInput(props: {return false;};+ const selectBrandColor = (color: string) => {+ setText(color);+ prevColor = color;+ props.onChange(color);+ };+return (- <div class="flex flex-row items-center gap-[0.75rem] relative">- <button- type="button"- class="size-[2rem] rounded-[0.5rem]"- style={{- "background-color": text(),- "box-shadow": `inset 0 0 0 1px ${getColorPreviewBorderColor(text())}`,- }}- onClick={() => colorInput.click()}- />- <input- ref={colorInput}- type="color"- class="absolute left-0 bottom-0 size-[2rem] opacity-0"- value={text()}- onChange={(e) => {- setText(e.target.value);- props.onChange(e.target.value);- }}- />- <TextInput- class="w-[5rem] p-[0.375rem] border border-gray-3 text-gray-12 rounded-[0.5rem] bg-gray-2"- value={text()}- onFocus={() => {- prevColor = props.value;- }}- onKeyDown={(e) => {- if (e.key === "Enter") {- e.preventDefault();- if (!commitValue(e.currentTarget.value)) {- setText(prevColor);+ <div class="flex flex-col gap-2">+ <div class="flex flex-row items-center gap-[0.75rem] relative">+ <button+ type="button"+ class="size-[2rem] rounded-[0.5rem]"+ style={{+ "background-color": text(),+ "box-shadow": `inset 0 0 0 1px ${getColorPreviewBorderColor(+ text(),+ )}`,+ }}+ onClick={() => colorInput.click()}+ />+ <input+ ref={colorInput}+ type="color"+ class="absolute left-0 bottom-0 size-[2rem] opacity-0"+ value={text()}+ onChange={(e) => {+ setText(e.target.value);+ props.onChange(e.target.value);+ }}+ />+ <TextInput+ class="w-[5rem] p-[0.375rem] border border-gray-3 text-gray-12 rounded-[0.5rem] bg-gray-2"+ value={text()}+ onFocus={() => {+ prevColor = props.value;+ }}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ if (!commitValue(e.currentTarget.value)) {+ setText(prevColor);+ }+ e.currentTarget.blur();}- e.currentTarget.blur();- }- }}- onInput={(e) => {- setText(e.currentTarget.value);- if (getHexColorDigitCount(e.currentTarget.value) !== 6) return;+ }}+ onInput={(e) => {+ setText(e.currentTarget.value);+ if (getHexColorDigitCount(e.currentTarget.value) !== 6) return;- const normalized = normalizeOpaqueHexColor(e.currentTarget.value);- if (normalized) {- props.onChange(normalized);- }- }}- onBlur={(e) => {- if (!commitValue(e.target.value)) {- setText(prevColor);- props.onChange(props.value);- }- }}+ const normalized = normalizeOpaqueHexColor(e.currentTarget.value);+ if (normalized) {+ props.onChange(normalized);+ }+ }}+ onBlur={(e) => {+ if (!commitValue(e.target.value)) {+ setText(prevColor);+ props.onChange(props.value);+ }+ }}+ />+ </div>+ <BrandColorsDropdown+ swatches={props.brandColorSwatches ?? []}+ onSelect={selectBrandColor}/></div>);