-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHome.js
57 lines (52 loc) · 1.52 KB
/
Home.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { useState } from 'react'
import { x } from '@xstyled/styled-components'
import { useJsBarcodeEan13 } from './components/Barcode'
import { PageContainer } from './components/PageContainer'
import { Input } from './components/Input'
import { Label } from './components/Label'
export function Home() {
const [ean13, setEan13] = useState('')
const [error, setError] = useState(false)
useJsBarcodeEan13(ean13, setError)
function onInputChange({ target }) {
const matchNumber = target.value.match(/^[0-9]{1,13}$/g)
setEan13(matchNumber?.[0] || '')
}
return (
<PageContainer>
<x.h1 fontFamily="inhenrit">Barcode pour mon papa ♥️</x.h1>
<x.div
display="flex"
justifyContent="center"
alignItems="flex-end"
columnGap="24px"
w="100%"
mt={3}
>
<Label htmlFor="ean13">
Code EAN13
<Input
type="text"
id="ean13"
value={ean13}
onChange={onInputChange}
/>
</Label>
</x.div>
<x.div textAlign="center" mt={4} h={40} p={3} w={1}>
{error ? (
<p>
Le barcode ne peut pas être généré :{' '}
<x.span color="red">code invalide</x.span>
</p>
) : ean13.length === 13 ? (
<img id="barcode" alt="generated-barcode" />
) : (
<p>
Remplissez le champ avec 13 chiffres pour générer le code barre.
</p>
)}
</x.div>
</PageContainer>
)
}