feat: better colorpicker

This commit is contained in:
Lewis Crichton 2023-09-09 10:43:07 +01:00
parent 51059c29e7
commit 9fdd2c7c17
No known key found for this signature in database
2 changed files with 33 additions and 8 deletions

View file

@ -56,6 +56,7 @@ const InviteActions = findByPropsLazy("resolveInvite");
const TrashIcon = findByCodeLazy("M5 6.99902V18.999C5 20.101 5.897 20.999"); const TrashIcon = findByCodeLazy("M5 6.99902V18.999C5 20.101 5.897 20.999");
const CogWheel = findByCodeLazy("18.564C15.797 19.099 14.932 19.498 14 19.738V22H10V19.738C9.069"); const CogWheel = findByCodeLazy("18.564C15.797 19.099 14.932 19.498 14 19.738V22H10V19.738C9.069");
const FileInput: FileInput = findByCodeLazy("activateUploadDialogue="); const FileInput: FileInput = findByCodeLazy("activateUploadDialogue=");
const EditPencil = findByCodeLazy("M19.2929 9.8299L19.9409 9.18278C21.353 7.77064", '["color","height","width"]');
// TinyColor is completely unmangled and it's duplicated in two modules! Fun! // TinyColor is completely unmangled and it's duplicated in two modules! Fun!
const TinyColor: tinycolor.Constructor = findByCodeLazy("this._gradientType="); const TinyColor: tinycolor.Constructor = findByCodeLazy("this._gradientType=");
const TextAreaProps = findLazy(m => typeof m.textarea === "string"); const TextAreaProps = findLazy(m => typeof m.textarea === "string");
@ -114,6 +115,8 @@ function Validators({ themeLinks }: { themeLinks: string[]; }) {
function ColorPicker(props: ColorPickerProps) { function ColorPicker(props: ColorPickerProps) {
const [color, setColor] = useState(props.value); const [color, setColor] = useState(props.value);
const correctedColor = color ? `#${color.toString(16).padStart(6, "0")}` : "#000000";
return ( return (
<Popout <Popout
renderPopout={() => ( renderPopout={() => (
@ -121,14 +124,15 @@ function ColorPicker(props: ColorPickerProps) {
)} )}
> >
{popoutProps => ( {popoutProps => (
<div {...popoutProps} style={{ <div {...popoutProps} className={cl("usercss-swatch")} style={{
width: "2em", backgroundColor: correctedColor,
height: "2em", borderColor: correctedColor
cursor: "pointer", }}>
backgroundColor: color ? `#${color.toString(16).padStart(6, "0")}` : "var(--background-secondary)", <EditPencil
borderRadius: ".125em", className={cl("usercss-swatch-pencil")}
border: "1px solid var(--background-tertiary)", color={TinyColor(correctedColor).isLight() ? "var(--primary-530)" : "var(--white-500)"}
}}></div> />
</div>
)} )}
</Popout> </Popout>
); );

View file

@ -27,3 +27,24 @@
.vc-settings-theme-author::before { .vc-settings-theme-author::before {
content: "by "; content: "by ";
} }
.vc-settings-theme-usercss-swatch {
display: flex;
align-items: center;
justify-content: center;
width: 69px;
height: 50px;
box-sizing: border-box;
position: relative;
border: 1px solid;
border-radius: 4px;
cursor: pointer;
}
.vc-settings-theme-usercss-swatch-pencil {
position: absolute;
top: 4px;
right: 4px;
width: 14px;
height: 14px;
}