From 093f025de3e97339750dc3df5be626a0315507dc Mon Sep 17 00:00:00 2001 From: Ben Woodward Date: Thu, 5 Aug 2021 12:12:17 -0700 Subject: Style and code refactor (#166) * Move all settings below card * refactor components; lifting state up * background color * Evergreen components for everything * password error * Tighten card size * Simply hide password to basic toggle, never disable * Hide password label, too * Maximize mobile portrait width * Make wifi tip smaller * Small style tweaks * Copy: update password length error text to include helpful instructions This will need a backfill for other translations * Remove unused css * Use empty string for EncryptionMode=None value * Remove light.min.css * Include logo on wificard * Cleanup after rebase * Clean-up comments on state * Padding for mobile --- src/components/WifiCard.js | 148 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/components/WifiCard.js (limited to 'src/components/WifiCard.js') diff --git a/src/components/WifiCard.js b/src/components/WifiCard.js new file mode 100644 index 0000000..645dfa1 --- /dev/null +++ b/src/components/WifiCard.js @@ -0,0 +1,148 @@ +import { + CameraIcon, + Card, + Heading, + MobilePhoneIcon, + Pane, + Paragraph, + Text, + TextareaField, +} from 'evergreen-ui'; +import QRCode from 'qrcode.react'; +import { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import logo from '../../src/images/wifi.png'; +import './style.css'; + +export const WifiCard = (props) => { + const { t } = useTranslation(); + const [qrvalue, setQrvalue] = useState(''); + + const escape = (v) => { + const needsEscape = ['"', ';', ',', ':', '\\']; + + let escaped = ''; + for (const c of v) { + if (needsEscape.includes(c)) { + escaped += `\\${c}`; + } else { + escaped += c; + } + } + return escaped; + }; + + useEffect(() => { + const ssid = escape(props.settings.ssid); + const password = !props.settings.encryptionMode + ? '' + : escape(props.settings.password); + setQrvalue( + `WIFI:T:${props.settings.encryptionMode};S:${ssid};P:${password};;` + ); + }, [props.settings]); + + const portraitWidth = () => { + const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); + return isMobile ? '100%' : '280px'; + }; + + const passwordFieldLabel = () => { + const hiddenPassword = + props.settings.hidePassword || !props.settings.encryptionMode; + return hiddenPassword ? '' : t('wifi.password'); + }; + + return ( + + + + icon + + {t('wifi.login')} + + + + + + + + props.onSSIDChange(e.target.value)} + isInvalid={!!props.ssidError} + validationMessage={!!props.ssidError && props.ssidError} + /> + 40 + ? '5em' + : 'auto' + } + label={passwordFieldLabel()} + placeholder={t('wifi.password.placeholder')} + value={props.settings.password} + onChange={(e) => props.onPasswordChange(e.target.value)} + isInvalid={!!props.passwordError} + validationMessage={!!props.passwordError && props.passwordError} + /> + + +
+ + + + + {t('wifi.tip')} + + +
+
+ ); +}; -- cgit v1.2.3