2023-08-06 19:36:36 +02:00
|
|
|
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';
|
2023-08-06 19:36:36 +02:00
|
|
|
import { useTranslation } from 'next-i18next';
|
2023-05-15 09:54:50 +02:00
|
|
|
import { useEffect, useRef } from 'react';
|
2023-07-21 18:08:40 +09:00
|
|
|
|
2022-12-18 22:27:01 +01:00
|
|
|
import { AppType } from '../../../../../../types/app';
|
2023-05-15 09:54:50 +02:00
|
|
|
import { IconSelector } from '../../../../../IconSelector/IconSelector';
|
2022-12-04 21:19:40 +01:00
|
|
|
|
|
|
|
|
interface AppearanceTabProps {
|
2022-12-18 22:27:01 +01:00
|
|
|
form: UseFormReturnType<AppType, (values: AppType) => AppType>;
|
|
|
|
|
disallowAppNameProgagation: () => void;
|
|
|
|
|
allowAppNamePropagation: boolean;
|
2022-12-04 21:19:40 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-11 19:32:51 +01:00
|
|
|
export const AppearanceTab = ({
|
|
|
|
|
form,
|
2022-12-18 22:27:01 +01:00
|
|
|
disallowAppNameProgagation,
|
|
|
|
|
allowAppNamePropagation,
|
2022-12-11 19:32:51 +01:00
|
|
|
}: AppearanceTabProps) => {
|
2023-05-15 09:54:50 +02:00
|
|
|
const iconSelectorRef = useRef();
|
2023-02-20 22:11:30 +01:00
|
|
|
const [debouncedValue] = useDebouncedValue(form.values.name, 500);
|
2023-08-06 19:36:36 +02:00
|
|
|
const { t } = useTranslation('layout/modals/add-app');
|
2023-02-20 22:11:30 +01:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (allowAppNamePropagation !== true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-15 09:54:50 +02:00
|
|
|
if (!iconSelectorRef.current) {
|
2023-02-20 22:11:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-15 09:54:50 +02:00
|
|
|
const currentRef = iconSelectorRef.current as {
|
|
|
|
|
chooseFirstOrDefault: (debouncedValue: string) => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
currentRef.chooseFirstOrDefault(debouncedValue);
|
2023-02-20 22:11:30 +01:00
|
|
|
}, [debouncedValue]);
|
2022-12-05 20:04:08 +01:00
|
|
|
|
2022-12-04 21:19:40 +01:00
|
|
|
return (
|
|
|
|
|
<Tabs.Panel value="appearance" pt="lg">
|
2023-08-06 19:36:36 +02:00
|
|
|
<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')}
|
2023-05-15 09:54:50 +02:00
|
|
|
onChange={(value) => {
|
2023-08-06 19:36:36 +02:00
|
|
|
form.setFieldValue('appearance.appNameStatus', value);
|
2023-05-15 09:54:50 +02:00
|
|
|
}}
|
2022-12-05 21:43:47 +01:00
|
|
|
/>
|
2023-08-06 19:36:36 +02:00
|
|
|
{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>
|
|
|
|
|
);
|
|
|
|
|
};
|
2022-12-05 20:04:08 +01:00
|
|
|
|
2023-02-20 22:11:30 +01:00
|
|
|
const replaceCharacters = (value: string) => value.toLowerCase().replaceAll('', '-');
|