Skip to content

Commit eaac9c4

Browse files
authored
ntp: prep a re-usable switch (#1339)
1 parent 2012858 commit eaac9c4

File tree

7 files changed

+256
-236
lines changed

7 files changed

+256
-236
lines changed

special-pages/pages/onboarding/app/Components.js

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import { h } from 'preact';
1212
import { Background } from './components/Background';
1313
import { settingsRowItems } from './data';
1414
import { Summary } from './pages/Summary';
15-
import { Switch } from './components/Switch';
16-
import { useState } from 'preact/hooks';
15+
import { Switch } from '../../../shared/components/Switch/Switch.js';
1716
import { Typed } from './components/Typed';
1817
import { CleanBrowsing } from './pages/CleanBrowsing';
1918
import { useTypedTranslation } from './types';
@@ -27,20 +26,6 @@ function noop(name) {
2726
};
2827
}
2928

30-
function NewCheck({ variant }) {
31-
const [selected, setSelected] = useState(false);
32-
return (
33-
<Switch
34-
pending={false}
35-
variant={variant}
36-
ariaLabel={'op'}
37-
checked={selected}
38-
onChecked={() => setSelected(true)}
39-
onUnchecked={() => setSelected(false)}
40-
/>
41-
);
42-
}
43-
4429
export function Components() {
4530
const { t } = useTypedTranslation();
4631
return (
@@ -77,27 +62,14 @@ export function Components() {
7762
<CleanBrowsing onNextPage={console.log} />
7863
</div>
7964
<div>
80-
<ButtonBar>
81-
<NewCheck variant={'windows'} />
82-
<NewCheck variant={'apple'} />
83-
</ButtonBar>
84-
<ButtonBar>
85-
<Switch
86-
pending={false}
87-
ariaLabel={'op'}
88-
checked={true}
89-
onChecked={noop('onChecked')}
90-
onUnchecked={noop('onUnchecked')}
91-
/>
92-
<Switch
93-
pending={false}
94-
ariaLabel={'op'}
95-
variant={'apple'}
96-
checked={true}
97-
onChecked={noop('onChecked')}
98-
onUnchecked={noop('onUnchecked')}
99-
/>
100-
</ButtonBar>
65+
<p>On Light</p>
66+
<AllSwitches theme={'light'} />
67+
</div>
68+
<div>
69+
<p>On Dark</p>
70+
<div style="background: #333; padding: 1rem;">
71+
<AllSwitches theme={'dark'} />
72+
</div>
10173
</div>
10274
<ButtonBar>
10375
<Button size="large">L Button</Button>
@@ -287,3 +259,50 @@ export function Components() {
287259
</main>
288260
);
289261
}
262+
263+
/**
264+
* @param {object} props
265+
* @param {'light' | 'dark'} props.theme
266+
*/
267+
function AllSwitches({ theme = 'light' }) {
268+
return (
269+
<ButtonBar>
270+
<Switch
271+
pending={false}
272+
ariaLabel={'op'}
273+
checked={true}
274+
onChecked={noop('onChecked')}
275+
onUnchecked={noop('onUnchecked')}
276+
platformName={'macos'}
277+
theme={theme}
278+
/>
279+
<Switch
280+
pending={false}
281+
ariaLabel={'op'}
282+
checked={false}
283+
onChecked={noop('onChecked')}
284+
onUnchecked={noop('onUnchecked')}
285+
platformName={'macos'}
286+
theme={theme}
287+
/>
288+
<Switch
289+
pending={false}
290+
ariaLabel={'op'}
291+
platformName={'windows'}
292+
checked={true}
293+
onChecked={noop('onChecked')}
294+
onUnchecked={noop('onUnchecked')}
295+
theme={theme}
296+
/>
297+
<Switch
298+
pending={false}
299+
ariaLabel={'op'}
300+
platformName={'windows'}
301+
checked={false}
302+
onChecked={noop('onChecked')}
303+
onUnchecked={noop('onUnchecked')}
304+
theme={theme}
305+
/>
306+
</ButtonBar>
307+
);
308+
}

special-pages/pages/onboarding/app/components/Switch.module.css

Lines changed: 0 additions & 186 deletions
This file was deleted.

special-pages/pages/onboarding/app/components/v3/SettingsStep.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { ListItem } from '../../components/ListItem';
66
import { BounceIn, Check, FadeIn } from '../../components/Icons';
77
import { Stack } from '../../components/Stack';
88
import { Button, ButtonBar } from './Buttons';
9-
import { Switch } from '../../components/Switch';
9+
import { Switch } from '../../../../../shared/components/Switch/Switch.js';
1010
import { PlainList } from '../../components/List';
1111
import { SlideIn } from './Animation';
12+
import { useEnv } from '../../../../../shared/components/EnvironmentProvider.js';
1213

1314
/**
1415
* @param {object} props
@@ -73,6 +74,8 @@ export function SettingsStep({ data }) {
7374
export function SettingListItem({ index, item, dispatch }) {
7475
const data = item.data;
7576
const { t } = useTypedTranslation();
77+
const { isDarkMode } = useEnv();
78+
const platformName = /** @type {'macos'|'windows'} */ (usePlatformName());
7679

7780
const accept = () => {
7881
dispatch({
@@ -122,6 +125,8 @@ export function SettingListItem({ index, item, dispatch }) {
122125
checked={enabled}
123126
onChecked={accept}
124127
onUnchecked={deny}
128+
platformName={platformName}
129+
theme={isDarkMode ? 'dark' : 'light'}
125130
/>
126131
)}
127132
</FadeIn>

special-pages/pages/onboarding/app/pages/SettingsStep.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { Stack } from '../components/Stack';
77
import { Button, ButtonBar } from '../components/Buttons';
88
import { useGlobalDispatch, useGlobalState } from '../global';
99
import { useRollin } from '../hooks/useRollin';
10-
import { Switch } from '../components/Switch';
10+
import { Switch } from '../../../../shared/components/Switch/Switch.js';
1111
import { useTypedTranslation } from '../types';
1212
import { RiveAnimation } from '../components/RiveAnimation';
1313
import { useEnv } from '../../../../shared/components/EnvironmentProvider';
14+
import { usePlatformName } from '../components/SettingsProvider.js';
1415

1516
/**
1617
* @param {object} props
@@ -96,6 +97,8 @@ export function SettingsStep({ onNextPage, data, metaData, subtitle }) {
9697
export function SettingListItem({ index, item, dispatch }) {
9798
const data = item.data;
9899
const { t } = useTypedTranslation();
100+
const platformName = /** @type {'macos'|'windows'} */ (usePlatformName());
101+
const { isDarkMode } = useEnv();
99102

100103
const accept = () => {
101104
dispatch({
@@ -145,6 +148,8 @@ export function SettingListItem({ index, item, dispatch }) {
145148
checked={enabled}
146149
onChecked={accept}
147150
onUnchecked={deny}
151+
platformName={platformName}
152+
theme={isDarkMode ? 'dark' : 'light'}
148153
/>
149154
)}
150155
</FadeIn>
@@ -170,8 +175,6 @@ export function SettingListItem({ index, item, dispatch }) {
170175
return { kind: 'button-bar' };
171176
})();
172177

173-
const { isDarkMode } = useEnv();
174-
175178
return (
176179
<ListItem
177180
key={data.id}

special-pages/pages/onboarding/app/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { stepDefinitions as defaultStepDefinitions } from './data';
77
export class Settings {
88
/**
99
* @param {object} params
10-
* @param {{name: ImportMeta['platform']}} [params.platform]
10+
* @param {{name: 'macos' | 'windows'}} [params.platform]
1111
* @param {import('./types.js').Step['id'][]} [params.order] - determine the order of screens
1212
* @param {'v1'|'v2'|'v3'} [params.orderName] - determine the order of screens
1313
* @param {import('./types.js').Step['id'][]} [params.exclude] - a list of screens to exclude

0 commit comments

Comments
 (0)