From 4a9289f66f80092ca0ecf69ab68a953b974bdccd Mon Sep 17 00:00:00 2001 From: Lex <41524861+Phoenix4O4@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:22:33 +0300 Subject: [PATCH] [TGUI] Color Picker (#1602) * fix color input * small optimisation * better optimisation * more optimisation --- tgui/packages/tgui/components/Interactive.tsx | 10 +- .../tgui/interfaces/ColorPickerModal.tsx | 960 +++++++++--------- 2 files changed, 506 insertions(+), 464 deletions(-) diff --git a/tgui/packages/tgui/components/Interactive.tsx b/tgui/packages/tgui/components/Interactive.tsx index a768d7dccf8..cb334d55f9a 100644 --- a/tgui/packages/tgui/components/Interactive.tsx +++ b/tgui/packages/tgui/components/Interactive.tsx @@ -50,7 +50,7 @@ const getRelativePosition = ( export interface InteractiveProps { onMove: (interaction: Interaction) => void; onKey: (offset: Interaction) => void; - children: ReactNode[]; + children: ReactNode; // Change from ReactNode[] to ReactNode style?: React.CSSProperties; } @@ -74,7 +74,6 @@ export class Interactive extends Component { }; handleMove = (event: MouseEvent) => { - // Prevent text selection event.preventDefault(); const isDown = event.buttons > 0; @@ -121,10 +120,11 @@ export class Interactive extends Component { } render() { + const { style, children, ...rest } = this.props; return (
{ tabIndex={0} role="slider" > - {this.props.children} + {children}
); } diff --git a/tgui/packages/tgui/interfaces/ColorPickerModal.tsx b/tgui/packages/tgui/interfaces/ColorPickerModal.tsx index 8177b609114..f8dfc403a6e 100644 --- a/tgui/packages/tgui/interfaces/ColorPickerModal.tsx +++ b/tgui/packages/tgui/interfaces/ColorPickerModal.tsx @@ -16,18 +16,11 @@ import { } from 'common/color'; import { clamp } from 'common/math'; import { classes } from 'common/react'; -import React, { - FocusEvent, - FormEvent, - useCallback, - useEffect, - useState, -} from 'react'; -import { Interactive } from 'tgui/components/Interactive'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; +import { Interaction, Interactive } from 'tgui/components/Interactive'; import { useBackend } from '../backend'; import { - Autofocus, Box, Button, Flex, @@ -37,11 +30,12 @@ import { Stack, Tooltip, } from '../components'; +import { Autofocus } from '../components/Autofocus'; import { Window } from '../layouts'; import { InputButtons } from './common/InputButtons'; import { Loader } from './common/Loader'; -type ColorPickerData = { +interface ColorPickerData { autofocus: boolean; buttons: string[]; message: string; @@ -50,9 +44,11 @@ type ColorPickerData = { timeout: number; title: string; default_color: string; -}; +} + +interface ColorPickerModalProps {} -export const ColorPickerModal = () => { +export const ColorPickerModal: React.FC = () => { const { data } = useBackend(); const { timeout, message, autofocus, default_color = '#000000' } = data; let { title } = data; @@ -107,374 +103,444 @@ export const ColorPickerModal = () => { ); }; -export const ColorPresets = ({ setColor, setShowPresets }) => { - return ( - <> -