Files
Homarr/src/components/Dashboard/Modals/EditAppModal/Tabs/AppereanceTab/AppereanceTab.tsx

56 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-02-20 22:11:30 +01:00
import { Flex, Tabs } from '@mantine/core';
2022-12-04 21:19:40 +01:00
import { UseFormReturnType } from '@mantine/form';
2023-02-20 22:11:30 +01:00
import { useDebouncedValue } from '@mantine/hooks';
import { useEffect, useRef } from 'react';
import { AppType } from '../../../../../../types/app';
import { IconSelector } from '../../../../../IconSelector/IconSelector';
2022-12-04 21:19:40 +01:00
interface AppearanceTabProps {
form: UseFormReturnType<AppType, (values: AppType) => AppType>;
disallowAppNameProgagation: () => void;
allowAppNamePropagation: boolean;
2022-12-04 21:19:40 +01:00
}
export const AppearanceTab = ({
form,
disallowAppNameProgagation,
allowAppNamePropagation,
}: AppearanceTabProps) => {
const iconSelectorRef = useRef();
2023-02-20 22:11:30 +01:00
const [debouncedValue] = useDebouncedValue(form.values.name, 500);
useEffect(() => {
if (allowAppNamePropagation !== true) {
return;
}
if (!iconSelectorRef.current) {
2023-02-20 22:11:30 +01:00
return;
}
const currentRef = iconSelectorRef.current as {
chooseFirstOrDefault: (debouncedValue: string) => void;
};
currentRef.chooseFirstOrDefault(debouncedValue);
2023-02-20 22:11:30 +01:00
}, [debouncedValue]);
2022-12-04 21:19:40 +01:00
return (
<Tabs.Panel value="appearance" pt="lg">
<Flex gap={5}>
<IconSelector
defaultValue={form.values.appearance.iconUrl}
onChange={(value) => {
form.setFieldValue('appearance.iconUrl', value);
disallowAppNameProgagation();
}}
value={form.values.appearance.iconUrl}
ref={iconSelectorRef}
/>
</Flex>
2022-12-04 21:19:40 +01:00
</Tabs.Panel>
);
};
2023-02-20 22:11:30 +01:00
const replaceCharacters = (value: string) => value.toLowerCase().replaceAll('', '-');