aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.js20
-rw-r--r--src/components/Card.js56
-rw-r--r--src/components/style.css5
3 files changed, 53 insertions, 28 deletions
diff --git a/src/App.js b/src/App.js
index ef4859c..0895668 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,25 +1,29 @@
1import React from 'react'; 1import React from 'react';
2import Card from './components/Card'; 2import { Card } from './components/Card';
3import './style.css'; 3import './style.css';
4 4
5function App() { 5function App() {
6 return ( 6 return (
7 <div className="App"> 7 <div className="App">
8 8 <h1>
9 <h1><span role="img" aria-label="antenna-bars">πŸ“Ά</span>&nbsp; WiFi Card</h1> 9 <span role="img" aria-label="antenna-bars">
10 πŸ“Ά
11 </span>
12 &nbsp; WiFi Card
13 </h1>
10 14
11 <p className="tag"> 15 <p className="tag">
12 Print a simple card with your WiFi login details. Tape it to the fridge, keep it in your wallet, etc. 16 Print a simple card with your WiFi login details. Tape it to the fridge,
17 keep it in your wallet, etc.
13 </p> 18 </p>
14 19
15 <p className="tag"> 20 <p className="tag">
16 Your WiFi information is never sent to the server. 21 Your WiFi information is never sent to the server. No tracking,
17 No tracking, analytics, or fingerprinting are used on this website. 22 analytics, or fingerprinting are used on this website. View the{' '}
18 View the <a href="https://github.com/bndw/wifi-card">source code</a>. 23 <a href="https://github.com/bndw/wifi-card">source code</a>.
19 </p> 24 </p>
20 25
21 <Card /> 26 <Card />
22
23 </div> 27 </div>
24 ); 28 );
25} 29}
diff --git a/src/components/Card.js b/src/components/Card.js
index 6c2c745..16f94a4 100644
--- a/src/components/Card.js
+++ b/src/components/Card.js
@@ -2,14 +2,16 @@ import React, { useState, useEffect } from 'react';
2import QRCode from 'qrcode.react'; 2import QRCode from 'qrcode.react';
3import './style.css'; 3import './style.css';
4 4
5const Card = () => { 5export const Card = () => {
6 const [ssid, setSsid] = useState(''); 6 const [network, setNetwork] = useState({
7 const [password, setPassword] = useState(''); 7 ssid: '',
8 password: '',
9 });
8 const [qrvalue, setQrvalue] = useState(''); 10 const [qrvalue, setQrvalue] = useState('');
9 11
10 const escape = (v) => { 12 const escape = (v) => {
11 const needsEscape = ['"', ';', ',', ':', '\\']; 13 const needsEscape = ['"', ';', ',', ':', '\\'];
12 14
13 let escaped = ''; 15 let escaped = '';
14 for (let i = 0; i < v.length; i++) { 16 for (let i = 0; i < v.length; i++) {
15 let c = v[i]; 17 let c = v[i];
@@ -20,14 +22,13 @@ const Card = () => {
20 } 22 }
21 23
22 return escaped; 24 return escaped;
23 } 25 };
24 26
25 useEffect(() => { 27 useEffect(() => {
26 let _ssid = escape(ssid), 28 const ssid = escape(network.ssid);
27 _password = escape(password); 29 const password = escape(network.password);
28 30 setQrvalue(`WIFI:T:WPA;S:${ssid};P:${password};;`);
29 setQrvalue(`WIFI:T:WPA;S:${_ssid};P:${_password};;`); 31 }, [network]);
30 }, [ssid, password]);
31 32
32 return ( 33 return (
33 <div> 34 <div>
@@ -35,26 +36,45 @@ const Card = () => {
35 <legend></legend> 36 <legend></legend>
36 37
37 <h1>WiFi Login</h1> 38 <h1>WiFi Login</h1>
38 <hr/> 39 <hr />
39 40
40 <div className="details"> 41 <div className="details">
41 <QRCode className="qrcode" value={qrvalue} size={175} /> 42 <QRCode className="qrcode" value={qrvalue} size={175} />
42 43
43 <div className="text"> 44 <div className="text">
44 <label>Network name</label> 45 <label>Network name</label>
45 <input id="ssid" type="text" maxLength="32" placeholder="WiFi Network name" value={ssid} onChange={event => setSsid(event.target.value)} /> 46 <input
47 id="ssid"
48 type="text"
49 maxLength="32"
50 placeholder="WiFi Network name"
51 value={network.ssid}
52 onChange={(e) => setNetwork({ ...network, ssid: e.target.value })}
53 />
46 <label>Password</label> 54 <label>Password</label>
47 <input id="password" type="text" maxLength="63" placeholder="Password" value={password} onChange={event => setPassword(event.target.value)} /> 55 <input
56 id="password"
57 type="text"
58 maxLength="63"
59 placeholder="Password"
60 value={network.password}
61 onChange={(e) =>
62 setNetwork({ ...network, password: e.target.value })
63 }
64 />
48 </div> 65 </div>
49 </div> 66 </div>
50 67
51 <p><span role="img" aria-label="mobile-phone">πŸ“ΈπŸ“±</span>Point your phone's camera at the QR Code to connect automatically</p> 68 <p>
69 <span role="img" aria-label="mobile-phone">
70 πŸ“ΈπŸ“±
71 </span>
72 Point your phone's camera at the QR Code to connect automatically
73 </p>
52 </fieldset> 74 </fieldset>
53 <div className="print-btn"> 75 <div className="print-btn">
54 <button onClick={window.print}>Print</button> 76 <button onClick={window.print}>Print</button>
55 </div> 77 </div>
56 </div> 78 </div>
57 ) 79 );
58} 80};
59
60export default Card;
diff --git a/src/components/style.css b/src/components/style.css
index 0f98052..d1440e2 100644
--- a/src/components/style.css
+++ b/src/components/style.css
@@ -8,7 +8,7 @@
8 display: flex; 8 display: flex;
9 padding: 1em; 9 padding: 1em;
10} 10}
11.details .text{ 11.details .text {
12 margin: 0; 12 margin: 0;
13} 13}
14.details .text * { 14.details .text * {
@@ -36,7 +36,8 @@
36 body * { 36 body * {
37 visibility: hidden; 37 visibility: hidden;
38 } 38 }
39 #print-area, #print-area * { 39 #print-area,
40 #print-area * {
40 visibility: visible; 41 visibility: visible;
41 } 42 }
42 #print-area input { 43 #print-area input {