forked from aeharding/voyager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add appearance page, add font size adjust (aeharding#54)
* Add appearance page and customizable font size * Add layout tweaks for large font size
- Loading branch information
Showing
14 changed files
with
269 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Global, css } from "@emotion/react"; | ||
import { useAppSelector } from "./store"; | ||
|
||
export default function GlobalStyles() { | ||
const { fontSizeMultiplier, useSystemFontSize } = useAppSelector( | ||
(state) => state.appearance.font | ||
); | ||
|
||
const baseFontStyles = useSystemFontSize | ||
? css` | ||
font: -apple-system-body; | ||
` | ||
: css` | ||
font-size: ${fontSizeMultiplier}rem; | ||
`; | ||
|
||
return ( | ||
<Global | ||
styles={css` | ||
html { | ||
${baseFontStyles} | ||
ion-content ion-item { | ||
font-size: 1rem; | ||
} | ||
} | ||
`} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import styled from "@emotion/styled"; | ||
import { css } from "@emotion/react"; | ||
import { IonLabel, IonList, IonRange, IonToggle } from "@ionic/react"; | ||
import { InsetIonItem } from "../../../pages/profile/ProfileFeedItemsPage"; | ||
import { useAppDispatch, useAppSelector } from "../../../store"; | ||
import { setFontSizeMultiplier, setUseSystemFontSize } from "./appearanceSlice"; | ||
|
||
const ListHeader = styled.div` | ||
font-size: 0.8em; | ||
margin: 32px 0 -8px 32px; | ||
text-transform: uppercase; | ||
color: var(--ion-color-medium); | ||
`; | ||
|
||
const Range = styled(IonRange)` | ||
--bar-background: var(--ion-color-medium); | ||
::part(tick) { | ||
background: var(--ion-color-medium); | ||
} | ||
`; | ||
|
||
const A = styled.div<{ small?: boolean }>` | ||
font-size: 1.3em; | ||
padding: 0 0.5rem; | ||
font-weight: 500; | ||
${({ small }) => | ||
small && | ||
css` | ||
font-size: 0.8em; | ||
`} | ||
`; | ||
|
||
const HelperText = styled.div` | ||
margin: 0 32px; | ||
font-size: 0.9em; | ||
color: var(--ion-color-medium); | ||
`; | ||
|
||
export default function TextSize() { | ||
const dispatch = useAppDispatch(); | ||
const { fontSizeMultiplier, useSystemFontSize } = useAppSelector( | ||
(state) => state.appearance.font | ||
); | ||
|
||
return ( | ||
<> | ||
<ListHeader> | ||
<IonLabel>Text size</IonLabel> | ||
</ListHeader> | ||
<IonList inset> | ||
<InsetIonItem> | ||
<IonLabel>Use System Text Size</IonLabel> | ||
<IonToggle | ||
checked={useSystemFontSize} | ||
onIonChange={(e) => | ||
dispatch(setUseSystemFontSize(e.detail.checked)) | ||
} | ||
/> | ||
</InsetIonItem> | ||
<InsetIonItem> | ||
<Range | ||
disabled={useSystemFontSize} | ||
ticks | ||
snaps | ||
min={0.8} | ||
max={1.6} | ||
step={0.1} | ||
value={fontSizeMultiplier} | ||
onIonInput={(e) => { | ||
dispatch(setFontSizeMultiplier(e.detail.value as number)); | ||
}} | ||
> | ||
<A slot="start" small> | ||
A | ||
</A> | ||
<A slot="end">A</A> | ||
</Range> | ||
</InsetIonItem> | ||
</IonList> | ||
<HelperText>Default is two ticks from the left.</HelperText> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { PayloadAction, createSlice } from "@reduxjs/toolkit"; | ||
import { get, set } from "../storage"; | ||
import { merge } from "lodash"; | ||
|
||
const STORAGE_KEYS = { | ||
FONT: { | ||
FONT_SIZE_MULTIPLIER: "appearance--font-size-multiplier", | ||
USE_SYSTEM: "appearance--font-use-system", | ||
}, | ||
} as const; | ||
|
||
interface AppearanceState { | ||
font: { | ||
fontSizeMultiplier: number; | ||
useSystemFontSize: boolean; | ||
}; | ||
} | ||
|
||
const initialState: AppearanceState = { | ||
font: { | ||
fontSizeMultiplier: 1, | ||
useSystemFontSize: false, | ||
}, | ||
}; | ||
|
||
const stateFromStorage: AppearanceState = merge(initialState, { | ||
font: { | ||
fontSizeMultiplier: get(STORAGE_KEYS.FONT.FONT_SIZE_MULTIPLIER), | ||
useSystemFontSize: get(STORAGE_KEYS.FONT.USE_SYSTEM), | ||
}, | ||
}); | ||
|
||
export const appearanceSlice = createSlice({ | ||
name: "appearance", | ||
initialState: stateFromStorage, | ||
reducers: { | ||
setFontSizeMultiplier(state, action: PayloadAction<number>) { | ||
state.font.fontSizeMultiplier = action.payload; | ||
|
||
set(STORAGE_KEYS.FONT.FONT_SIZE_MULTIPLIER, action.payload); | ||
}, | ||
setUseSystemFontSize(state, action: PayloadAction<boolean>) { | ||
state.font.useSystemFontSize = action.payload; | ||
|
||
set(STORAGE_KEYS.FONT.USE_SYSTEM, action.payload); | ||
}, | ||
|
||
resetAppearance: () => initialState, | ||
}, | ||
}); | ||
|
||
export const { setFontSizeMultiplier, setUseSystemFontSize } = | ||
appearanceSlice.actions; | ||
|
||
export default appearanceSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export function get(key: string): any { | ||
const data = localStorage.getItem(key); | ||
if (!data) return; | ||
return JSON.parse(data); | ||
} | ||
|
||
export function set(key: string, value: unknown) { | ||
localStorage.setItem(key, JSON.stringify(value)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
IonBackButton, | ||
IonButtons, | ||
IonHeader, | ||
IonPage, | ||
IonTitle, | ||
IonToolbar, | ||
} from "@ionic/react"; | ||
import AppContent from "../../features/shared/AppContent"; | ||
import TextSize from "../../features/settings/appearance/TextSize"; | ||
|
||
export default function AppearancePage() { | ||
return ( | ||
<IonPage className="grey-bg"> | ||
<IonHeader> | ||
<IonToolbar> | ||
<IonButtons slot="start"> | ||
<IonBackButton defaultHref="/settings" text="Settings" /> | ||
</IonButtons> | ||
|
||
<IonTitle>Appearance</IonTitle> | ||
</IonToolbar> | ||
</IonHeader> | ||
<AppContent scrollY> | ||
<TextSize /> | ||
</AppContent> | ||
</IonPage> | ||
); | ||
} |
Oops, something went wrong.