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

96 lines
3.3 KiB
TypeScript
Raw Normal View History

import { Flex, Select, Stack, Switch, 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 { useTranslation } from 'next-i18next';
import { useEffect, useRef } from 'react';
2023-07-21 18:08:40 +09:00
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);
const { t } = useTranslation('layout/modals/add-app');
2023-02-20 22:11:30 +01:00
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">
<Stack spacing="xs">
<Flex gap={5} mb="xs">
<IconSelector
defaultValue={form.values.appearance.iconUrl}
onChange={(value) => {
form.setFieldValue('appearance.iconUrl', value);
disallowAppNameProgagation();
}}
value={form.values.appearance.iconUrl}
ref={iconSelectorRef}
/>
</Flex>
<Select
label={t('appearance.appNameStatus.label')}
description={t('appearance.appNameStatus.description')}
data={[
{ value: 'normal', label: t('appearance.appNameStatus.dropdown.normal') as string },
{ value: 'hover', label: t('appearance.appNameStatus.dropdown.hover') as string },
{ value: 'hidden', label: t('appearance.appNameStatus.dropdown.hidden') as string },
]}
{...form.getInputProps('appearance.appNameStatus')}
onChange={(value) => {
form.setFieldValue('appearance.appNameStatus', value);
}}
/>
{form.values.appearance.appNameStatus === 'normal' && (
<Select
label={t('appearance.positionAppName.label')}
description={t('appearance.positionAppName.description')}
data={[
{ value: 'column', label: t('appearance.positionAppName.dropdown.top') as string },
{
value: 'row-reverse',
label: t('appearance.positionAppName.dropdown.right') as string,
},
{
value: 'column-reverse',
label: t('appearance.positionAppName.dropdown.bottom') as string,
},
{ value: 'row', label: t('appearance.positionAppName.dropdown.left') as string },
]}
{...form.getInputProps('appearance.positionAppName')}
onChange={(value) => {
form.setFieldValue('appearance.positionAppName', value);
}}
/>
)}
</Stack>
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('', '-');