2023-09-15 20:42:38 -07:00
|
|
|
import { ReactNode } from 'react';
|
2023-03-30 06:44:33 -07:00
|
|
|
import { SettingsOptions } from '/@/renderer/features/settings/components/settings-option';
|
2024-05-05 13:25:05 -07:00
|
|
|
import { useSettingSearchContext } from '/@/renderer/features/settings/context/search-context';
|
|
|
|
|
import { Divider } from '@mantine/core';
|
2023-03-30 06:44:33 -07:00
|
|
|
|
|
|
|
|
export type SettingOption = {
|
2023-09-15 20:42:38 -07:00
|
|
|
control: ReactNode;
|
|
|
|
|
description: string | ReactNode;
|
2023-07-01 19:10:05 -07:00
|
|
|
isHidden?: boolean;
|
|
|
|
|
note?: string;
|
|
|
|
|
title: string;
|
2023-03-30 06:44:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface SettingsSectionProps {
|
2024-05-05 13:25:05 -07:00
|
|
|
divider?: boolean;
|
2023-07-01 19:10:05 -07:00
|
|
|
options: SettingOption[];
|
2023-03-30 06:44:33 -07:00
|
|
|
}
|
|
|
|
|
|
2024-05-05 13:25:05 -07:00
|
|
|
export const SettingsSection = ({ divider, options }: SettingsSectionProps) => {
|
|
|
|
|
const keyword = useSettingSearchContext();
|
|
|
|
|
const hasKeyword = keyword !== '';
|
|
|
|
|
|
|
|
|
|
const values = options.filter(
|
|
|
|
|
(o) => !o.isHidden && (!hasKeyword || o.title.toLocaleLowerCase().includes(keyword)),
|
|
|
|
|
);
|
|
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
|
|
|
|
<>
|
2024-05-05 13:25:05 -07:00
|
|
|
{values.map((option) => (
|
|
|
|
|
<SettingsOptions
|
|
|
|
|
key={`option-${option.title}`}
|
|
|
|
|
{...option}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
{divider !== false && values.length > 0 && <Divider />}
|
2023-07-01 19:10:05 -07:00
|
|
|
</>
|
|
|
|
|
);
|
2023-03-30 06:44:33 -07:00
|
|
|
};
|