Skip to content

Commit f349199

Browse files
committed
Merge branch 'feature/mobile-preferences-number-widget' into chore/refactor-mobile-hooks
2 parents 1c4b234 + 88d7f9e commit f349199

File tree

3 files changed

+32
-81
lines changed

3 files changed

+32
-81
lines changed

client/components/mobile/Header.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import styled from 'styled-components';
33
import PropTypes from 'prop-types';
44
import { prop, remSize } from '../../theme';
55

6-
const background = prop('MobilePanel.default.background');
6+
const background = transparent => prop(transparent ? 'backgroundColor' : 'MobilePanel.default.background');
77
const textColor = prop('primaryTextColor');
88

99

1010
const HeaderDiv = styled.div`
1111
position: fixed;
1212
width: 100%;
13-
background: ${props => (props.transparent ? 'transparent' : background)};
13+
background: ${props => background(props.transparent === true)};
1414
color: ${textColor};
1515
padding: ${remSize(12)};
1616
padding-left: ${remSize(16)};

client/modules/Mobile/MobilePreferences.jsx

Lines changed: 27 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ const Content = styled.div`
2020
margin-top: ${remSize(68)};
2121
`;
2222

23-
24-
const SettingsHeader = styled(Header)`
25-
background: transparent;
26-
`;
27-
2823
const SectionHeader = styled.h2`
2924
color: ${prop('primaryTextColor')};
3025
padding-top: ${remSize(32)};
@@ -34,6 +29,23 @@ const SectionSubeader = styled.h3`
3429
color: ${prop('primaryTextColor')};
3530
`;
3631

32+
const optionsOnOff = (name, onLabel = 'On', offLabel = 'Off') => [
33+
{
34+
value: true, label: onLabel, ariaLabel: `${name} on`, name: `${name}`, id: `${name}-on`.replace(' ', '-')
35+
},
36+
{
37+
value: false, label: offLabel, ariaLabel: `${name} off`, name: `${name}`, id: `${name}-off`.replace(' ', '-')
38+
},
39+
];
40+
41+
const optionsPickOne = (name, ...options) => options.map(option => ({
42+
value: option,
43+
label: option,
44+
ariaLabel: `${option} ${name} on`,
45+
name: `${option} ${name}`,
46+
id: `${option}-${name}-on`.replace(' ', '-')
47+
}));
48+
3749

3850
const MobilePreferences = (props) => {
3951
const {
@@ -47,49 +59,21 @@ const MobilePreferences = (props) => {
4759
{
4860
title: 'Theme',
4961
value: theme,
50-
options: [
51-
{
52-
value: 'light', label: 'light', ariaLabel: 'light theme on', name: 'light theme', id: 'light-theme-on'
53-
},
54-
{
55-
value: 'dark', label: 'dark', ariaLabel: 'dark theme on', name: 'dark theme', id: 'dark-theme-on'
56-
},
57-
{
58-
value: 'contrast',
59-
label: 'contrast',
60-
ariaLabel: 'contrast theme on',
61-
name: 'contrast theme',
62-
id: 'contrast-theme-on'
63-
}
64-
],
62+
options: optionsPickOne('theme', 'light', 'dark', 'contrast'),
6563
onSelect: x => setTheme(x) // setTheme
6664
},
6765

6866
{
6967
title: 'Autosave',
7068
value: autosave,
71-
options: [
72-
{
73-
value: true, label: 'On', ariaLabel: 'autosave on', name: 'autosave', id: 'autosave-on'
74-
},
75-
{
76-
value: false, label: 'Off', ariaLabel: 'autosave off', name: 'autosave', id: 'autosave-off'
77-
},
78-
],
69+
options: optionsOnOff('autosave'),
7970
onSelect: x => setAutosave(x) // setAutosave
8071
},
8172

8273
{
8374
title: 'Word Wrap',
8475
value: linewrap,
85-
options: [
86-
{
87-
value: true, label: 'On', ariaLabel: 'linewrap on', name: 'linewrap', id: 'linewrap-on'
88-
},
89-
{
90-
value: false, label: 'Off', ariaLabel: 'linewrap off', name: 'linewrap', id: 'linewrap-off'
91-
},
92-
],
76+
options: optionsOnOff('linewrap'),
9377
onSelect: x => setLinewrap(x)
9478
}
9579
];
@@ -98,40 +82,19 @@ const MobilePreferences = (props) => {
9882
{
9983
title: 'Plain-text',
10084
value: textOutput,
101-
options: [
102-
{
103-
value: true, label: 'On', ariaLabel: 'text output on', name: 'text output', id: 'text-output-on'
104-
},
105-
{
106-
value: false, label: 'Off', ariaLabel: 'text output off', name: 'text output', id: 'text-output-off'
107-
},
108-
],
85+
options: optionsOnOff('text output'),
10986
onSelect: x => setTextOutput(x)
11087
},
11188
{
11289
title: 'Table-text',
11390
value: gridOutput,
114-
options: [
115-
{
116-
value: true, label: 'On', ariaLabel: 'table output on', name: 'table output', id: 'table-output-on'
117-
},
118-
{
119-
value: false, label: 'Off', ariaLabel: 'table output off', name: 'table output', id: 'table-output-off'
120-
},
121-
],
91+
options: optionsOnOff('table output'),
12292
onSelect: x => setGridOutput(x)
12393
},
12494
{
12595
title: 'Sound',
12696
value: soundOutput,
127-
options: [
128-
{
129-
value: true, label: 'On', ariaLabel: 'sound output on', name: 'sound output', id: 'sound-output-on'
130-
},
131-
{
132-
value: false, label: 'Off', ariaLabel: 'sound output off', name: 'sound output', id: 'sound-output-off'
133-
},
134-
],
97+
options: optionsOnOff('sound output'),
13598
onSelect: x => setSoundOutput(x)
13699
},
137100
];
@@ -140,38 +103,23 @@ const MobilePreferences = (props) => {
140103
{
141104
title: 'Line Numbers',
142105
value: lineNumbers,
143-
options: [
144-
{
145-
value: true, label: 'On', ariaLabel: 'line numbers on', name: 'line numbers', id: 'line-numbers-on'
146-
},
147-
{
148-
value: false, label: 'Off', ariaLabel: 'line numbers off', name: 'line numbers', id: 'line-numbers-off'
149-
},
150-
],
106+
options: optionsOnOff('line numbers'),
151107
onSelect: x => setLineNumbers(x)
152108
},
153109
{
154110
title: 'Lint Warning Sound',
155111
value: lintWarning,
156-
options: [
157-
{
158-
value: true, label: 'On', ariaLabel: 'lint warning on', name: 'lint warning', id: 'lint-warning-on'
159-
},
160-
{
161-
value: false, label: 'Off', ariaLabel: 'lint warning off', name: 'lint warning', id: 'lint-warning-off'
162-
},
163-
],
112+
options: optionsOnOff('lint warning'),
164113
onSelect: x => setLintWarning(x)
165114
},
166115
];
167116

168117
return (
169118
<Screen fullscreen>
170119
<section>
171-
<SettingsHeader transparent title="Preferences">
172-
120+
<Header transparent title="Preferences">
173121
<IconButton to="/mobile" icon={ExitIcon} aria-label="Return to ide view" />
174-
</SettingsHeader>
122+
</Header>
175123
<section className="preferences">
176124
<Content>
177125
<SectionHeader>General Settings</SectionHeader>

client/theme.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default {
6262
colors,
6363
...common,
6464
primaryTextColor: grays.dark,
65+
backgroundColor: grays.lighter,
6566

6667
Button: {
6768
default: {
@@ -101,6 +102,7 @@ export default {
101102
colors,
102103
...common,
103104
primaryTextColor: grays.lightest,
105+
backgroundColor: grays.darker,
104106

105107
Button: {
106108
default: {
@@ -140,6 +142,7 @@ export default {
140142
colors,
141143
...common,
142144
primaryTextColor: grays.lightest,
145+
backgroundColor: grays.darker,
143146

144147
Button: {
145148
default: {

0 commit comments

Comments
 (0)