diff options
| author | Ben Woodward <ben@bdw.to> | 2021-07-11 10:49:28 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-11 10:49:28 -0700 |
| commit | d2dd54caca19d3660e49c729828d52aa2bbb5716 (patch) | |
| tree | ac08cce8dfe4ab541fe82ea7b4034cff2cf0a10a /src | |
| parent | 3c777e31e5f01b543a8bf213c6c9733920ee53fb (diff) | |
Portrait orientation (#35)
* Portrait orientation
Adds a rotate button that toggle landscape and portrait orientation.
Fixes #30
* Fix QRCode padding in portait orientation
* Default to portrait on small screens
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Card.js | 49 | ||||
| -rw-r--r-- | src/components/style.css | 37 | ||||
| -rw-r--r-- | src/style.css | 4 |
3 files changed, 61 insertions, 29 deletions
diff --git a/src/components/Card.js b/src/components/Card.js index bbf29f9..4ec4430 100644 --- a/src/components/Card.js +++ b/src/components/Card.js | |||
| @@ -1,13 +1,15 @@ | |||
| 1 | import QRCode from 'qrcode.react'; | 1 | import QRCode from 'qrcode.react'; |
| 2 | import { useEffect, useState } from 'react'; | 2 | import { useEffect, useRef, useState } from 'react'; |
| 3 | import './style.css'; | 3 | import './style.css'; |
| 4 | 4 | ||
| 5 | export const Card = () => { | 5 | export const Card = () => { |
| 6 | const firstLoad = useRef(true); | ||
| 7 | const [qrvalue, setQrvalue] = useState(''); | ||
| 6 | const [network, setNetwork] = useState({ | 8 | const [network, setNetwork] = useState({ |
| 7 | ssid: '', | 9 | ssid: '', |
| 8 | password: '', | 10 | password: '', |
| 9 | }); | 11 | }); |
| 10 | const [qrvalue, setQrvalue] = useState(''); | 12 | const [portrait, setPortrait] = useState(false); |
| 11 | 13 | ||
| 12 | const escape = (v) => { | 14 | const escape = (v) => { |
| 13 | const needsEscape = ['"', ';', ',', ':', '\\']; | 15 | const needsEscape = ['"', ';', ',', ':', '\\']; |
| @@ -33,6 +35,11 @@ export const Card = () => { | |||
| 33 | }; | 35 | }; |
| 34 | 36 | ||
| 35 | useEffect(() => { | 37 | useEffect(() => { |
| 38 | if (firstLoad.current && window.innerWidth < 500) { | ||
| 39 | firstLoad.current = false; | ||
| 40 | setPortrait(true); | ||
| 41 | } | ||
| 42 | |||
| 36 | const ssid = escape(network.ssid); | 43 | const ssid = escape(network.ssid); |
| 37 | const password = escape(network.password); | 44 | const password = escape(network.password); |
| 38 | setQrvalue(`WIFI:T:WPA;S:${ssid};P:${password};;`); | 45 | setQrvalue(`WIFI:T:WPA;S:${ssid};P:${password};;`); |
| @@ -40,16 +47,24 @@ export const Card = () => { | |||
| 40 | 47 | ||
| 41 | return ( | 48 | return ( |
| 42 | <div> | 49 | <div> |
| 43 | <fieldset id="print-area"> | 50 | <fieldset |
| 44 | <legend></legend> | 51 | id="print-area" |
| 45 | 52 | style={{ maxWidth: portrait ? '350px' : '100%' }} | |
| 46 | <h1>WiFi Login</h1> | 53 | > |
| 47 | <hr /> | 54 | <h1 style={{ textAlign: portrait ? 'center' : 'left' }}>WiFi Login</h1> |
| 48 | 55 | ||
| 49 | <div className="details"> | 56 | <div |
| 50 | <QRCode className="qrcode" value={qrvalue} size={175} /> | 57 | className="details" |
| 58 | style={{ flexDirection: portrait ? 'column' : 'row' }} | ||
| 59 | > | ||
| 60 | <QRCode | ||
| 61 | className="qrcode" | ||
| 62 | style={{ paddingRight: portrait ? '' : '1em' }} | ||
| 63 | value={qrvalue} | ||
| 64 | size={175} | ||
| 65 | /> | ||
| 51 | 66 | ||
| 52 | <div className="text"> | 67 | <div className="inputs"> |
| 53 | <label>Network name</label> | 68 | <label>Network name</label> |
| 54 | <textarea | 69 | <textarea |
| 55 | id="ssid" | 70 | id="ssid" |
| @@ -63,6 +78,10 @@ export const Card = () => { | |||
| 63 | <textarea | 78 | <textarea |
| 64 | id="password" | 79 | id="password" |
| 65 | type="text" | 80 | type="text" |
| 81 | style={{ | ||
| 82 | height: | ||
| 83 | portrait && network.password.length > 40 ? '5em' : 'auto', | ||
| 84 | }} | ||
| 66 | maxLength="63" | 85 | maxLength="63" |
| 67 | placeholder="Password" | 86 | placeholder="Password" |
| 68 | value={network.password} | 87 | value={network.password} |
| @@ -80,8 +99,14 @@ export const Card = () => { | |||
| 80 | Point your phone's camera at the QR Code to connect automatically | 99 | Point your phone's camera at the QR Code to connect automatically |
| 81 | </p> | 100 | </p> |
| 82 | </fieldset> | 101 | </fieldset> |
| 83 | <div className="print-btn"> | 102 | |
| 84 | <button onClick={onPrint}>Print</button> | 103 | <div className="buttons"> |
| 104 | <button id="rotate" onClick={() => setPortrait(!portrait)}> | ||
| 105 | Rotate | ||
| 106 | </button> | ||
| 107 | <button id="print" onClick={onPrint}> | ||
| 108 | |||
| 109 | </button> | ||
| 85 | </div> | 110 | </div> |
| 86 | </div> | 111 | </div> |
| 87 | ); | 112 | ); |
diff --git a/src/components/style.css b/src/components/style.css index 4feb1d6..c1b78be 100644 --- a/src/components/style.css +++ b/src/components/style.css | |||
| @@ -1,20 +1,23 @@ | |||
| 1 | @import url('https://fonts.googleapis.com/css?family=Source+Code+Pro'); | 1 | @import url('https://fonts.googleapis.com/css?family=Source+Code+Pro'); |
| 2 | 2 | ||
| 3 | #print-area { | 3 | #print-area { |
| 4 | border-color: #aaa; | ||
| 5 | border-style: dashed; | ||
| 6 | margin-bottom: 2em; | ||
| 4 | margin-top: 2em; | 7 | margin-top: 2em; |
| 5 | padding: 1em; | 8 | padding: 1em; |
| 6 | } | 9 | } |
| 10 | |||
| 7 | .details { | 11 | .details { |
| 8 | display: flex; | 12 | display: flex; |
| 9 | padding: 1em; | 13 | align-items: center; |
| 10 | } | 14 | } |
| 11 | .details .text { | 15 | |
| 12 | margin: 0; | 16 | .qrcode { |
| 13 | } | 17 | margin-bottom: 1em; |
| 14 | .details .text * { | ||
| 15 | margin: 0 1em; | ||
| 16 | } | 18 | } |
| 17 | .details .text textarea { | 19 | |
| 20 | textarea { | ||
| 18 | background-color: #fff; | 21 | background-color: #fff; |
| 19 | border: solid 1px #ddd; | 22 | border: solid 1px #ddd; |
| 20 | font-family: 'Source Code Pro', serif; | 23 | font-family: 'Source Code Pro', serif; |
| @@ -24,14 +27,22 @@ | |||
| 24 | overflow: hidden; | 27 | overflow: hidden; |
| 25 | resize: none; | 28 | resize: none; |
| 26 | } | 29 | } |
| 27 | .print-btn { | 30 | |
| 28 | padding-top: 2em; | 31 | button { |
| 29 | } | ||
| 30 | .print-btn button { | ||
| 31 | color: #fff; | ||
| 32 | height: 50px; | 32 | height: 50px; |
| 33 | width: 180px; | 33 | width: 180px; |
| 34 | } | ||
| 35 | |||
| 36 | button#print { | ||
| 37 | color: #fff; | ||
| 34 | background-color: #0074d9; | 38 | background-color: #0074d9; |
| 39 | border-color: #0074d9; | ||
| 40 | } | ||
| 41 | |||
| 42 | button#rotate { | ||
| 43 | color: #fff; | ||
| 44 | background-color: #6c757d; | ||
| 45 | border-color: #6c757d; | ||
| 35 | } | 46 | } |
| 36 | 47 | ||
| 37 | @media print { | 48 | @media print { |
| @@ -42,7 +53,7 @@ | |||
| 42 | #print-area * { | 53 | #print-area * { |
| 43 | visibility: visible; | 54 | visibility: visible; |
| 44 | } | 55 | } |
| 45 | #print-area input { | 56 | #print-area textarea { |
| 46 | border: none; | 57 | border: none; |
| 47 | } | 58 | } |
| 48 | #print-area { | 59 | #print-area { |
diff --git a/src/style.css b/src/style.css index b7819af..f29d097 100644 --- a/src/style.css +++ b/src/style.css | |||
| @@ -4,7 +4,3 @@ body { | |||
| 4 | .tag { | 4 | .tag { |
| 5 | line-height: 1.6; | 5 | line-height: 1.6; |
| 6 | } | 6 | } |
| 7 | fieldset { | ||
| 8 | border-style: dashed; | ||
| 9 | border-color: #aaa; | ||
| 10 | } | ||
