Skip to content

Commit f968396

Browse files
committed
[WIP]
1 parent d4f34ba commit f968396

File tree

7 files changed

+677
-9
lines changed

7 files changed

+677
-9
lines changed

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@emotion/server": "^11.11.0",
5959
"@emotion/styled": "^11.14.1",
6060
"@loadable/component": "^5.16.7",
61+
"@melloware/coloris": "^0.25.0",
6162
"@vidstack/react": "^1.12.13",
6263
"ace-builds": "^1.x",
6364
"actioncable": "~5.0.7",

client/src/global/components/form/BaseInput/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class FormBaseInput extends PureComponent {
119119
<InputComponent
120120
ref={input => {
121121
this.inputElement = input;
122+
if (this.props.colorRef) this.props.colorRef.current = input;
122123
}}
123124
id={id}
124125
name={this.props.name}
Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,60 @@
1-
import { useId } from "react";
2-
import PropTypes from "prop-types";
1+
import { useId, useEffect, useRef, useState } from "react";
2+
import Coloris from "@melloware/coloris";
3+
import setter from "../setter";
34
import * as Styled from "./styles";
45

5-
export default function ColorInput({ defaultValue, ...props }) {
6+
function ColorInput({ defaultValue, ...props }) {
67
const id = useId();
8+
const inputRef = useRef();
9+
const colorRef = useRef(props.value || defaultValue);
710

8-
const renderValue = value => value ?? defaultValue;
11+
const inputId = `color-input-${id}`;
12+
13+
useEffect(() => {
14+
Coloris.init();
15+
16+
document.addEventListener("coloris:pick", event => {
17+
const isTarget = event.detail.currentEl.id === inputId;
18+
if (isTarget) colorRef.current = event.detail.color;
19+
});
20+
}, [inputId]);
21+
22+
useEffect(() => {
23+
if (inputRef.current) {
24+
Coloris({
25+
el: inputRef.current,
26+
format: "mixed",
27+
formatToggle: true,
28+
themeMode: "dark",
29+
clearButton: true,
30+
closeButton: true,
31+
defaultColor: defaultValue,
32+
margin: 5
33+
});
34+
35+
inputRef.current.addEventListener("close", () => {
36+
props.onChange({ target: { value: colorRef.current } });
37+
});
38+
}
39+
}, [inputRef, defaultValue, colorRef, props.onChange]);
40+
41+
console.log(props.placeholder);
42+
43+
const renderValue = () => colorRef.current || defaultValue;
944
return (
1045
<Styled.ColorInput
11-
inputType="color"
12-
id={`color-input-${id}`}
46+
id={inputId}
47+
colorRef={inputRef}
1348
idForError={`color-input-error-${id}`}
1449
idForInstructions={`color-input-instructions-${id}`}
15-
renderValue={renderValue}
50+
placeholder={defaultValue}
51+
// renderValue={renderValue}
1652
{...props}
53+
$defaultColor={defaultValue}
1754
/>
1855
);
1956
}
2057

58+
export default setter(ColorInput);
59+
2160
ColorInput.displayName = "Form.ColorInput";

client/src/global/components/form/ColorInput/styles.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import styled from "@emotion/styled";
2-
import BaseInput from "../BaseInput";
2+
import { FormBaseInput } from "../BaseInput";
3+
4+
export const ColorInput = styled(FormBaseInput)`
5+
--ColorInput-default-color: ${({ $defaultColor }) => $defaultColor};
36
4-
export const ColorInput = styled(BaseInput)`
57
input[type="color"] {
68
width: 24px;
79
height: 24px;

0 commit comments

Comments
 (0)