-
-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to unify selector creation for settings
- Loading branch information
1 parent
2964664
commit 1a100e5
Showing
15 changed files
with
98 additions
and
108 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
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
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
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,65 @@ | ||
import styled from "@emotion/styled"; | ||
import { | ||
ActionSheetButton, | ||
IonActionSheetCustomEvent, | ||
OverlayEventDetail, | ||
} from "@ionic/core"; | ||
import { IonActionSheet, IonItem, IonLabel } from "@ionic/react"; | ||
import { Dictionary, startCase } from "lodash"; | ||
import { useState } from "react"; | ||
import { useAppDispatch } from "../../../store"; | ||
import { ActionCreatorWithPayload } from "@reduxjs/toolkit"; | ||
|
||
const InsetIonItem = styled(IonItem)` | ||
--background: var(--ion-tab-bar-background, var(--ion-color-step-50, #fff)); | ||
`; | ||
|
||
export interface SettingSelectorProps<T> { | ||
title: string; | ||
selected: T; | ||
set_selected: ActionCreatorWithPayload<T>; | ||
options: Dictionary<string>; | ||
} | ||
|
||
export default function SettingSelector<T extends string>({ | ||
title, | ||
selected, | ||
set_selected, | ||
options, | ||
}: SettingSelectorProps<T>) { | ||
const [open, setOpen] = useState(false); | ||
const dispatch = useAppDispatch(); | ||
|
||
const buttons: ActionSheetButton<T>[] = Object.values(options).map(function ( | ||
v | ||
) { | ||
return { | ||
text: startCase(v), | ||
data: v, | ||
} as ActionSheetButton<T>; | ||
}); | ||
|
||
return ( | ||
<InsetIonItem button onClick={() => setOpen(true)}> | ||
<IonLabel>{title}</IonLabel> | ||
<IonLabel slot="end" color="medium"> | ||
{startCase(selected)} | ||
</IonLabel> | ||
<IonActionSheet | ||
cssClass="left-align-buttons" | ||
isOpen={open} | ||
onDidDismiss={() => setOpen(false)} | ||
onWillDismiss={(e: IonActionSheetCustomEvent<OverlayEventDetail>) => { | ||
if (e.detail.data) { | ||
dispatch(set_selected(e.detail.data)); | ||
} | ||
}} | ||
header={title} | ||
buttons={buttons.map((b) => ({ | ||
...b, | ||
role: selected === b.data ? "selected" : undefined, | ||
}))} | ||
/> | ||
</InsetIonItem> | ||
); | ||
} |
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,8 @@ | ||
import styled from "@emotion/styled"; | ||
|
||
export const ListHeader = styled.div` | ||
font-size: 0.8em; | ||
margin: 32px 0 -8px 32px; | ||
text-transform: uppercase; | ||
color: var(--ion-color-medium); | ||
`; |