iconoir/iconoir.com/components/CustomizationEditor.tsx

135 lines
3.5 KiB
TypeScript
Raw Normal View History

import React from 'react';
import styled from 'styled-components';
2023-01-11 19:08:14 +01:00
import { DEFAULT_CUSTOMIZATIONS, IconListCustomizations } from './IconList';
import { ColorButton, ColorInput } from './Input';
import { Slider } from './Slider';
import { Text13, Text15 } from './Typography';
feat: new website (#261) * add: website redesign and optimization * fix: additional improvements in home, support, and doc * fix: typography and spacing * fix: moved praise to support page * fix: redesigned support page * feat: added new pillars and paragraphs * fix: changed table colors * fix: shortened home * fix: small improvements to support page * fix: optimized mobile version * feat: added Ad on mobile * Remove outdated color prop from CurrentVersion * Small format fixes * fix: removed prefixes in Slider.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: removed prefixes in Button.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: removed unused const Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: correctly renamed const Overlay Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: applied same button style to the Copy button Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Removed unnecessary prefix properties, fixed transition Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Added non prefixed property in Stats.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Added transition effect on mouse out as well Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Removed a repeated property in Input.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Changed home title Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Changed icons to icon Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
2023-03-19 21:23:43 +01:00
import { media } from '../lib/responsive';
export interface CustomizationEditorProps {
customizations: IconListCustomizations;
// eslint-disable-next-line no-unused-vars
onChange: (customizations: IconListCustomizations) => void;
}
export function CustomizationEditor({
customizations,
onChange,
}: CustomizationEditorProps) {
const [, startTransition] = (React as any).useTransition();
const [color, setColor] = React.useState(customizations.hexColor);
const [size, setSize] = React.useState(customizations.size);
const [strokeWidth, setStrokeWidth] = React.useState(
customizations.strokeWidth,
);
2023-10-29 00:33:17 +02:00
React.useEffect(() => {
setColor(customizations.hexColor);
setSize(customizations.size);
setStrokeWidth(customizations.strokeWidth);
}, [customizations]);
function updateCustomizations(partial: Partial<IconListCustomizations>) {
startTransition(() => {
onChange({
...customizations,
...partial,
});
});
}
return (
<>
<CustomizationBox>
<Header>
<Text15 style={{ fontWeight: 700, color: 'var(--black)' }}>
Customize
</Text15>
<ResetButton onClick={() => onChange(DEFAULT_CUSTOMIZATIONS)}>
Reset
</ResetButton>
</Header>
<Field>
<Slider
label={'Optical Size'}
minValue={16}
maxValue={64}
value={[size]}
formatOptions={{ maximumFractionDigits: 0 }}
onChange={(values) => {
setSize(values[0]);
updateCustomizations({ size: values[0] });
}}
/>
</Field>
<Field>
<Slider
label={'Stroke Weight'}
minValue={0.5}
maxValue={3}
value={[strokeWidth]}
step={0.1}
formatOptions={{ maximumFractionDigits: 1 }}
onChange={(values) => {
setStrokeWidth(values[0]);
updateCustomizations({ strokeWidth: values[0] });
}}
/>
</Field>
<HorizontalField>
<Text13>Color</Text13>
<ColorInput
type={'color'}
value={color}
onChange={(e) => {
setColor(e.target.value);
updateCustomizations({ hexColor: e.target.value });
}}
/>
<ColorButton />
</HorizontalField>
</CustomizationBox>
</>
);
}
const CustomizationBox = styled.div`
background-color: var(--g7);
width: 84%;
padding: 8%;
border-radius: 10px;
2023-03-24 17:37:28 +01:00
margin: 24px 0;
feat: new website (#261) * add: website redesign and optimization * fix: additional improvements in home, support, and doc * fix: typography and spacing * fix: moved praise to support page * fix: redesigned support page * feat: added new pillars and paragraphs * fix: changed table colors * fix: shortened home * fix: small improvements to support page * fix: optimized mobile version * feat: added Ad on mobile * Remove outdated color prop from CurrentVersion * Small format fixes * fix: removed prefixes in Slider.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: removed prefixes in Button.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: removed unused const Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: correctly renamed const Overlay Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: applied same button style to the Copy button Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Removed unnecessary prefix properties, fixed transition Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Added non prefixed property in Stats.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Added transition effect on mouse out as well Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Removed a repeated property in Input.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Changed home title Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Changed icons to icon Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
2023-03-19 21:23:43 +01:00
display: none;
${media.md} {
display: block;
}
`;
const Header = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 30px;
feat: new website (#261) * add: website redesign and optimization * fix: additional improvements in home, support, and doc * fix: typography and spacing * fix: moved praise to support page * fix: redesigned support page * feat: added new pillars and paragraphs * fix: changed table colors * fix: shortened home * fix: small improvements to support page * fix: optimized mobile version * feat: added Ad on mobile * Remove outdated color prop from CurrentVersion * Small format fixes * fix: removed prefixes in Slider.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: removed prefixes in Button.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: removed unused const Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: correctly renamed const Overlay Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: applied same button style to the Copy button Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Removed unnecessary prefix properties, fixed transition Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Added non prefixed property in Stats.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Added transition effect on mouse out as well Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Removed a repeated property in Input.tsx Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Changed home title Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> * fix: Changed icons to icon Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
2023-03-19 21:23:43 +01:00
border-bottom: solid 1px var(--g6);
padding-bottom: 10px;
`;
const Field = styled.div`
2024-02-18 15:05:51 +01:00
margin-bottom: 18px;
`;
const HorizontalField = styled(Field)`
display: flex;
align-items: center;
justify-content: space-between;
`;
const ResetButton = styled(Field)`
&&& {
margin: initial;
text-decoration: underline;
color: var(--dark-gray);
font-size: 13px;
&:hover {
color: var(--black);
cursor: pointer;
}
}
`;