|
@@ -5,7 +5,7 @@ import styled from 'styled-components';
|
|
|
import { Row } from '../layout';
|
|
|
import { ColorPicker, ChromePickerColor } from './ColorPicker';
|
|
|
import { SliderInput } from '~/components/CodeBlocks/subcomponents';
|
|
|
-import { AnyGradientType } from '~/components/store';
|
|
|
+import { AnyGradientType, ColorStopType } from '~/components/store';
|
|
|
|
|
|
interface IGradientRow {
|
|
|
gradient: AnyGradientType;
|
|
@@ -14,30 +14,23 @@ interface IGradientRow {
|
|
|
}
|
|
|
export const GradientRow: React.FC<IGradientRow> = ({ gradient, selfIndex, updateSelf }) => {
|
|
|
const { type: gradientType, isVisible, stops } = gradient;
|
|
|
- // const [gradientType, setGradientType] = useState<string>('linear');
|
|
|
- // const [isVisible, setIsVisible] = useState<boolean>(true);
|
|
|
- // const [colors, setColors] = useState<ColorStopType[]>([
|
|
|
- // { color: { r: 0, g: 255, b: 255, a: 1 }, offset: 0 },
|
|
|
- // { color: { r: 0, g: 0, b: 0, a: 0 }, offset: 1.0 },
|
|
|
- // ]);
|
|
|
- // const [angle, setAngle] = useState<number>(0);
|
|
|
- // const [posX, setPosX] = useState<number>(50);
|
|
|
- // const [posY, setPosY] = useState<number>(50);
|
|
|
- const updateProp = (key: string, value: any) => {
|
|
|
+
|
|
|
+ const updateProp = (key: string, value: string | boolean | ColorStopType[] | number) => {
|
|
|
const newGradient = gradient;
|
|
|
newGradient[key] = value;
|
|
|
updateSelf(selfIndex, newGradient);
|
|
|
};
|
|
|
+
|
|
|
return (
|
|
|
<Form>
|
|
|
<Row>
|
|
|
- <VisibilityIcon onClick={() => setIsVisible((v) => !v)}>
|
|
|
+ <VisibilityIcon onClick={() => updateProp('isVisible', !isVisible)}>
|
|
|
{isVisible ? <EyeOutlined /> : <EyeInvisibleOutlined />}
|
|
|
</VisibilityIcon>
|
|
|
<Form.Item>
|
|
|
<Select
|
|
|
value={gradientType}
|
|
|
- onChange={(v: string) => setGradientType(v)}
|
|
|
+ onChange={(v: string) => updateProp('type', v)}
|
|
|
style={{ width: 130 }}
|
|
|
>
|
|
|
<Select.Option value="linear">linear</Select.Option>
|
|
@@ -50,14 +43,14 @@ export const GradientRow: React.FC<IGradientRow> = ({ gradient, selfIndex, updat
|
|
|
color={stops[0].color}
|
|
|
style={{ padding: 0 }}
|
|
|
onChange={(c: ChromePickerColor) =>
|
|
|
- setColors((colors) => [{ color: c.rgb, offset: 1 }, stops[1]])
|
|
|
+ updateProp('stops', [{ color: c.rgb, offset: 1 }, stops[1]])
|
|
|
}
|
|
|
/>
|
|
|
<ColorPicker
|
|
|
label="Color 2"
|
|
|
color={stops[stops.length - 1].color}
|
|
|
onChange={(c: ChromePickerColor) =>
|
|
|
- setColors((colors) => [stops[0], { color: c.rgb, offset: 1 }])
|
|
|
+ updateProp('stops', [stops[0], { color: c.rgb, offset: 1 }])
|
|
|
}
|
|
|
/>
|
|
|
</Row>
|
|
@@ -69,7 +62,7 @@ export const GradientRow: React.FC<IGradientRow> = ({ gradient, selfIndex, updat
|
|
|
min={0}
|
|
|
max={360}
|
|
|
tipFormatter={(v) => `${v}°`}
|
|
|
- onChange={(val: number) => setAngle(val)}
|
|
|
+ onChange={(val: number) => updateProp('angle', val)}
|
|
|
value={typeof gradient.angle === 'number' ? gradient.angle : 0}
|
|
|
/>
|
|
|
)}
|
|
@@ -80,7 +73,7 @@ export const GradientRow: React.FC<IGradientRow> = ({ gradient, selfIndex, updat
|
|
|
name="position X"
|
|
|
min={-50}
|
|
|
max={150}
|
|
|
- onChange={(val: number) => setPosX(val)}
|
|
|
+ onChange={(val: number) => updateProp('posX', val)}
|
|
|
value={typeof gradient.posX === 'number' ? gradient.posX : 0}
|
|
|
/>
|
|
|
<SliderInput
|
|
@@ -88,7 +81,7 @@ export const GradientRow: React.FC<IGradientRow> = ({ gradient, selfIndex, updat
|
|
|
name="position Y"
|
|
|
min={-50}
|
|
|
max={150}
|
|
|
- onChange={(val: number) => setPosY(val)}
|
|
|
+ onChange={(val: number) => updateProp('posY', val)}
|
|
|
value={typeof gradient.posY === 'number' ? gradient.posY : 0}
|
|
|
/>
|
|
|
</>
|