■ ■ ■ ■ ■ ■
packages/web/src/components/ui/Hero/Hero.tsx
1 | | - | import React from 'react'; |
| 1 | + | import React, { useState } from 'react'; |
2 | 2 | | import styles from './Hero.module.scss'; |
3 | 3 | | import Container from '../Container/Container'; |
4 | 4 | | import Chip from '../Chip/Chip'; |
| skipped 1 lines |
6 | 6 | | import { Icon } from '../Icon/Icon'; |
7 | 7 | | |
8 | 8 | | export type HeroProps = { |
9 | | - | inputText?: string; |
10 | 9 | | loading?: boolean; |
11 | 10 | | suggestions?: string[]; |
| 11 | + | onSubmit?: (site: string) => void; |
12 | 12 | | }; |
13 | 13 | | |
14 | | - | export default function Hero({ inputText, suggestions, loading = false }: HeroProps) { |
| 14 | + | export default function Hero({ suggestions, onSubmit = () => {}, loading = false }: HeroProps) { |
| 15 | + | const [inputText, setInputText] = useState(''); |
15 | 16 | | return ( |
16 | 17 | | <section className={styles.hero}> |
17 | 18 | | <Header variant='homepage' /> |
| skipped 7 lines |
25 | 26 | | </p> |
26 | 27 | | |
27 | 28 | | <div className={styles.search}> |
28 | | - | <input |
29 | | - | type='text' |
30 | | - | className={styles.input} |
31 | | - | value={inputText} |
32 | | - | placeholder='Start analyzing...' |
33 | | - | /> |
34 | | - | <button type='submit' className={styles.submit}> |
35 | | - | {/* TODO: use SVG loading component */} |
36 | | - | {!loading ? ( |
37 | | - | <Icon |
38 | | - | kind='arrow' |
39 | | - | className={styles.submitIcon} |
40 | | - | width={32} |
41 | | - | height={32} |
42 | | - | color='#fff' |
43 | | - | /> |
44 | | - | ) : ( |
45 | | - | <span className={styles.loader} /> |
46 | | - | )} |
47 | | - | </button> |
| 29 | + | <form |
| 30 | + | onSubmit={(e) => { |
| 31 | + | onSubmit(inputText); |
| 32 | + | e.preventDefault(); |
| 33 | + | return false; |
| 34 | + | }} |
| 35 | + | > |
| 36 | + | <input |
| 37 | + | type='text' |
| 38 | + | className={styles.input} |
| 39 | + | value={inputText} |
| 40 | + | onChange={(e) => setInputText(e.currentTarget.value)} |
| 41 | + | placeholder='Start analyzing...' |
| 42 | + | /> |
| 43 | + | <button type='submit' className={styles.submit}> |
| 44 | + | {/* TODO: use SVG loading component */} |
| 45 | + | {!loading ? ( |
| 46 | + | <Icon |
| 47 | + | kind='arrow' |
| 48 | + | className={styles.submitIcon} |
| 49 | + | width={32} |
| 50 | + | height={32} |
| 51 | + | color='#fff' |
| 52 | + | /> |
| 53 | + | ) : ( |
| 54 | + | <span className={styles.loader} /> |
| 55 | + | )} |
| 56 | + | </button> |
| 57 | + | </form> |
48 | 58 | | </div> |
49 | 59 | | |
50 | 60 | | {suggestions && ( |
| skipped 14 lines |