/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import React, { useState } from 'react'; import { makeStyles, createStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import DialogTitle from '@material-ui/core/DialogTitle'; import DialogContent from '@material-ui/core/DialogContent'; import DialogActions from '@material-ui/core/DialogActions'; import Dialog from '@material-ui/core/Dialog'; import Switch from '@material-ui/core/Switch'; import IconButton from '@material-ui/core/IconButton'; import FilterListIcon from '@material-ui/icons/FilterList'; import { List, ListItemSecondaryAction, ListItemText } from '@material-ui/core'; import ListItem from '@material-ui/core/ListItem'; import { langCodeToName } from '../util/language'; const useStyles = makeStyles(() => createStyles({ paper: { maxHeight: 435, width: '80%', }, })); interface IProps { shownLangs: string[] setShownLangs: (arg0: string[]) => void allLangs: string[] } export default function ExtensionLangSelect(props: IProps) { const { shownLangs, setShownLangs, allLangs } = props; // hold a copy and only sate state on parent when OK pressed, improves performance const [mShownLangs, setMShownLangs] = useState(shownLangs); const classes = useStyles(); const [open, setOpen] = useState(false); const handleCancel = () => { setOpen(false); }; const handleOk = () => { setOpen(false); setShownLangs(mShownLangs); }; const handleChange = (event: React.ChangeEvent, lang: string) => { const { checked } = event.target as HTMLInputElement; if (checked) { setMShownLangs([...mShownLangs, lang]); } else { const clone = JSON.parse(JSON.stringify(mShownLangs)); clone.splice(clone.indexOf(lang), 1); setMShownLangs(clone); } }; return ( <> setOpen(true)} aria-label="display more actions" edge="end" color="inherit" > Enabled Languages {allLangs.map((lang) => ( handleChange(e, lang)} /> ))} ); }