feishin/src/renderer/features/settings/components/settings-section.tsx

39 lines
1.1 KiB
TypeScript
Raw Normal View History

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';
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 {
divider?: boolean;
2023-07-01 19:10:05 -07:00
options: SettingOption[];
2023-03-30 06:44:33 -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 (
<>
{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
};