MCPcopy
hub / github.com/CapSoftware/Cap / HexColorInput

Function HexColorInput

apps/desktop/src/routes/editor/ConfigSidebar.tsx:3126–3194  ·  view source on GitHub ↗
(props: {
	value: string;
	onChange: (value: string) => void;
	brandColorSwatches?: OrganizationBrandColorSwatch[];
})

Source from the content-addressed store, hash-verified

3124}
3125
3126function HexColorInput(props: {
3127 value: string;
3128 onChange: (value: string) => void;
3129 brandColorSwatches?: OrganizationBrandColorSwatch[];
3130}) {
3131 const [text, setText] = createWritableMemo(() => props.value);
3132 let prevColor = props.value;
3133 let colorInput: HTMLInputElement | undefined;
3134 const selectBrandColor = (color: string) => {
3135 setText(color);
3136 prevColor = color;
3137 props.onChange(color);
3138 };
3139
3140 return (
3141 <div class="flex flex-col gap-2">
3142 <div class="flex items-center gap-3">
3143 <div class="relative">
3144 <button
3145 type="button"
3146 class="size-[2rem] rounded-[0.5rem] cursor-pointer transition-[box-shadow]"
3147 style={{
3148 "background-color": text(),
3149 "box-shadow": `inset 0 0 0 1px ${getColorPreviewBorderColor(
3150 text(),
3151 )}`,
3152 }}
3153 onClick={() => colorInput?.click()}
3154 />
3155 <input
3156 ref={(el) => {
3157 colorInput = el;
3158 }}
3159 type="color"
3160 class="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
3161 value={text()}
3162 onInput={(e) => {
3163 const next = e.currentTarget.value;
3164 setText(next);
3165 prevColor = next;
3166 props.onChange(next);
3167 }}
3168 />
3169 </div>
3170 <TextInput
3171 class="flex-1 px-3 py-2 rounded-lg border border-gray-3 bg-gray-2 text-sm text-gray-12"
3172 value={text()}
3173 onFocus={() => {
3174 prevColor = props.value;
3175 }}
3176 onInput={(e) => {
3177 setText(e.currentTarget.value);
3178 }}
3179 onBlur={(e) => {
3180 const next =
3181 normalizeOpaqueHexColor(e.currentTarget.value) ?? prevColor;
3182 setText(next);
3183 prevColor = next;

Callers

nothing calls this directly

Calls 3

normalizeOpaqueHexColorFunction · 0.90
textFunction · 0.70

Tested by

no test coverage detected