Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting additional cards to print #275

Merged
merged 17 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ function App() {
hiddenSSID: false,
// Settings: Portrait orientation
portrait: false,
// Settings: Additional cards
additionalCards: 0,
// Settings: Show tip (legend) on card
hideTip: false,
});
const [errors, setErrors] = useState({
ssidError: '',
Expand Down Expand Up @@ -120,6 +124,13 @@ function App() {
const onHiddenSSIDChange = (hiddenSSID) => {
setSettings({ ...settings, hiddenSSID });
};
const onAdditionalCardsChange = (additionalCardsStr) => {
const amount = parseInt(additionalCardsStr);
amount >= 0 && setSettings({ ...settings, additionalCards: amount });
};
const onHideTipChange = (hideTip) => {
setSettings({ ...settings, hideTip });
};
const onFirstLoad = () => {
html.style.direction = htmlDirection();
firstLoad.current = false;
Expand Down Expand Up @@ -153,15 +164,17 @@ function App() {
</Paragraph>
</Pane>

<WifiCard
settings={settings}
ssidError={errors.ssidError}
passwordError={errors.passwordError}
eapIdentityError={errors.eapIdentityError}
onSSIDChange={onSSIDChange}
onEapIdentityChange={onEapIdentityChange}
onPasswordChange={onPasswordChange}
/>
<Pane>
<WifiCard
settings={settings}
ssidError={errors.ssidError}
passwordError={errors.passwordError}
eapIdentityError={errors.eapIdentityError}
onSSIDChange={onSSIDChange}
onEapIdentityChange={onEapIdentityChange}
onPasswordChange={onPasswordChange}
/>
</Pane>

<Settings
settings={settings}
Expand All @@ -173,6 +186,8 @@ function App() {
onOrientationChange={onOrientationChange}
onHidePasswordChange={onHidePasswordChange}
onHiddenSSIDChange={onHiddenSSIDChange}
onAdditionalCardsChange={onAdditionalCardsChange}
onHideTipChange={onHideTipChange}
/>

<Button
Expand All @@ -184,6 +199,21 @@ function App() {
>
{t('button.print')}
</Button>
<Pane id="print-area">
{settings.additionalCards >= 0 &&
[...Array(settings.additionalCards + 1)].map((el, idx) => (
<WifiCard
key={`card-nr-${idx}`}
settings={settings}
ssidError={errors.ssidError}
passwordError={errors.passwordError}
eapIdentityError={errors.eapIdentityError}
onSSIDChange={onSSIDChange}
onEapIdentityChange={onEapIdentityChange}
onPasswordChange={onPasswordChange}
/>
))}
</Pane>
</Pane>
);
}
Expand Down
21 changes: 20 additions & 1 deletion src/components/Settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Checkbox, Pane, RadioGroup, SelectField } from 'evergreen-ui';
import {
Checkbox,
Pane,
RadioGroup,
SelectField,
TextInputField,
} from 'evergreen-ui';
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import i18n from '../i18n';
Expand Down Expand Up @@ -62,6 +68,19 @@ export const Settings = (props) => {
checked={props.settings.hiddenSSID}
onChange={() => props.onHiddenSSIDChange(!props.settings.hiddenSSID)}
/>

<Checkbox
label={t('cards.tip.hide')}
checked={props.settings.hideTip}
onChange={() => props.onHideTipChange(!props.settings.hideTip)}
/>
<TextInputField
type="number"
width={300}
label={t('cards.additional')}
value={props.settings.additionalCards}
onChange={(e) => props.onAdditionalCardsChange(e.target.value)}
/>
<RadioGroup
label={t('wifi.password.encryption')}
size={16}
Expand Down
181 changes: 89 additions & 92 deletions src/components/WifiCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,84 +72,83 @@ export const WifiCard = (props) => {
};

return (
<Pane>
<Card
id="print-area"
elevation={3}
style={{ maxWidth: props.settings.portrait ? portraitWidth() : '100%' }}
<Card
className="card-print"
elevation={3}
style={{ maxWidth: props.settings.portrait ? portraitWidth() : '100%' }}
>
<Pane display="flex" paddingBottom={12}>
<img alt="icon" src={logo} width="24" height="24" />
<Heading
size={700}
paddingRight={10}
paddingLeft={10}
textAlign={props.settings.portrait ? 'center' : 'unset'}
>
{t('wifi.login')}
</Heading>
</Pane>

<Pane
className="details"
style={{ flexDirection: props.settings.portrait ? 'column' : 'row' }}
>
<Pane display="flex" paddingBottom={12}>
<img alt="icon" src={logo} width="24" height="24" />
<Heading
size={700}
paddingRight={10}
paddingLeft={10}
textAlign={props.settings.portrait ? 'center' : 'unset'}
>
{t('wifi.login')}
</Heading>
</Pane>
<QRCode
className="qrcode"
style={{ marginBottom: props.settings.portrait ? '1em' : '0' }}
value={qrvalue}
size={150}
/>

<Pane
className="details"
style={{ flexDirection: props.settings.portrait ? 'column' : 'row' }}
>
<QRCode
className="qrcode"
style={{ padding: '1em' }}
value={qrvalue}
size={150}
<Pane width={'100%'}>
<TextareaField
id="ssid"
type="text"
marginBottom={5}
autoComplete="off"
autoCorrect="off"
autoCapitalize="none"
spellCheck={false}
maxLength="32"
label={t('wifi.name')}
placeholder={t('wifi.name.placeholder')}
value={props.settings.ssid}
onChange={(e) => props.onSSIDChange(e.target.value)}
isInvalid={!!props.ssidError}
validationMessage={!!props.ssidError && props.ssidError}
/>
{props.settings.encryptionMode === 'WPA2-EAP' && (
<>
<TextareaField
id="eapmethod"
type="text"
marginBottom={5}
readOnly={true}
spellCheck={false}
label={eapMethodFieldLabel()}
value={props.settings.eapMethod}
/>

<Pane width={'100%'}>
<TextareaField
id="ssid"
type="text"
marginBottom={5}
autoComplete="off"
autoCorrect="off"
autoCapitalize="none"
spellCheck={false}
maxLength="32"
label={t('wifi.name')}
placeholder={t('wifi.name.placeholder')}
value={props.settings.ssid}
onChange={(e) => props.onSSIDChange(e.target.value)}
isInvalid={!!props.ssidError}
validationMessage={!!props.ssidError && props.ssidError}
/>
<TextareaField
id="eapmethod"
type="text"
marginBottom={5}
readOnly={true}
spellCheck={false}
className={`
${props.settings.encryptionMode !== 'WPA2-EAP' && 'hidden'}
`}
label={eapMethodFieldLabel()}
value={props.settings.eapMethod}
/>
<TextareaField
id="identity"
type="text"
marginBottom={5}
autoComplete="off"
autoCorrect="off"
autoCapitalize="none"
spellCheck={false}
className={`
${props.settings.encryptionMode !== 'WPA2-EAP' && 'hidden'}
`}
label={eapIdentityFieldLabel()}
placeholder={t('wifi.identity.placeholder')}
value={props.settings.eapIdentity}
onChange={(e) => props.onEapIdentityChange(e.target.value)}
isInvalid={!!props.eapIdentityError}
validationMessage={
!!props.eapIdentityError && props.eapIdentityError
}
/>
<TextareaField
id="identity"
type="text"
marginBottom={5}
autoComplete="off"
autoCorrect="off"
autoCapitalize="none"
spellCheck={false}
label={eapIdentityFieldLabel()}
placeholder={t('wifi.identity.placeholder')}
value={props.settings.eapIdentity}
onChange={(e) => props.onEapIdentityChange(e.target.value)}
isInvalid={!!props.eapIdentityError}
validationMessage={
!!props.eapIdentityError && props.eapIdentityError
}
/>
</>
)}
{!(props.settings.hidePassword || !props.settings.encryptionMode) && (
<TextareaField
id="password"
type="text"
Expand All @@ -158,36 +157,34 @@ export const WifiCard = (props) => {
autoCorrect="off"
autoCapitalize="none"
spellCheck={false}
className={`
${
(props.settings.hidePassword ||
!props.settings.encryptionMode) &&
'hidden'
}
`}
height={
props.settings.portrait && props.settings.password.length > 40
? '5em'
: 'auto'
}
marginBottom={5}
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}
/>
</Pane>
)}
</Pane>
<hr />
<Paragraph>
<CameraIcon />
<MobilePhoneIcon />
<Text size={300} paddingRight={8} paddingLeft={8}>
{t('wifi.tip')}
</Text>
</Paragraph>
</Card>
</Pane>
</Pane>
{!props.settings.hideTip && (
<>
<hr />
<Paragraph>
<CameraIcon />
<MobilePhoneIcon />
<Text size={300} paddingRight={8} paddingLeft={8}>
{t('wifi.tip')}
</Text>
</Paragraph>
</>
)}
</Card>
);
};
24 changes: 18 additions & 6 deletions src/components/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
src: url(./SourceSerif4-Semibold.otf);
}

#print-area {
.card-print {
border-color: #aaa;
margin-bottom: 1em;
margin-top: 2em;
padding: 1em;
}

#print-area {
display: none;
}

.details {
display: flex;
align-items: center;
}

.qrcode {
margin-bottom: 1em;
max-width: 175px;
padding: 1em;
}

.hidden {
Expand Down Expand Up @@ -64,13 +68,21 @@ button {
#print-area * {
visibility: visible;
}
#print-area {
border-style: dashed;
box-shadow: none;
}
#print-area {
position: absolute;
left: 0;
top: 0;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
row-gap: 0em;
}
.card-print {
border-style: dashed;
box-shadow: none;
margin-bottom: 0;
margin-top: 0;
break-inside: avoid;
page-break-inside: avoid;
}
}
2 changes: 2 additions & 0 deletions src/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const Translations = [
'wifi.login': 'WiFi Login',
'wifi.name': 'Network name',
'wifi.name.hiddenSSID': 'Hidden SSID',
'cards.additional': 'Additional cards to print',
'cards.tip.hide': 'Hide tip (legend)',
'wifi.name.placeholder': 'WiFi Network name',
'wifi.password': 'Password',
'wifi.password.placeholder': 'Password',
Expand Down
Loading