Files
Homarr/components/SearchBar/SearchBar.tsx

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-04-27 14:14:10 +02:00
import { Input, TextInput, Text, ActionIcon, useMantineTheme } from '@mantine/core';
2022-04-27 20:10:51 +02:00
import { useForm } from '@mantine/hooks';
2022-04-27 14:14:10 +02:00
import { showNotification } from '@mantine/notifications';
import { useState, useEffect } from 'react';
import { Search, ArrowRight, ArrowLeft } from 'tabler-icons-react';
import { Config, loadConfig } from '../../tools/config';
export default function SearchBar(props: any) {
const theme = useMantineTheme();
const [config, setConfig] = useState<Config>({
searchBar: true,
2022-04-27 20:10:51 +02:00
searchUrl : 'https://www.google.com/search?q=',
});
const querryUrl = config.searchUrl || 'https://www.google.com/search?q=';
const form = useForm({
initialValues: {
querry: '',
},
2022-04-27 14:14:10 +02:00
});
useEffect(() => {
const config = loadConfig('settings');
if (config) {
showNotification({
autoClose: 1000,
title: <Text>Config loaded</Text>,
message: undefined,
});
setConfig(config);
}
}, []);
2022-04-27 20:10:51 +02:00
if (!config.searchBar) {
return null;
}
2022-04-27 14:14:10 +02:00
return (
2022-04-27 20:10:51 +02:00
<form onSubmit={form.onSubmit((values) => window.open(`${querryUrl}${values.querry}`))}>
<TextInput
icon={<Search size={18} />}
radius="xl"
size="md"
placeholder="Search the web"
rightSectionWidth={42}
{...props}
{...form.getInputProps('querry')}
/>
</form>
2022-04-27 14:14:10 +02:00
);
}