Path: blob/trunk/javascript/grid-ui/src/components/LiveView/PasswordDialog.tsx
2887 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617import React, { useState } from 'react'18import {19Button,20Dialog,21DialogActions,22DialogContent,23DialogContentText,24DialogTitle,25FormControl,26Input,27InputAdornment,28InputLabel29} from '@mui/material'30import IconButton from '@mui/material/IconButton'31import { Visibility, VisibilityOff } from '@mui/icons-material'3233interface State {34amount: string35password: string36weight: string37weightRange: string38showPassword: boolean39}4041const PasswordDialog = (props) => {42const { title, children, open, openDialog, onConfirm, onCancel } = props43const [values, setValues] = useState<State>({44amount: '',45password: '',46weight: '',47weightRange: '',48showPassword: false49})5051const handleChange = (prop: keyof State) => (event: React.ChangeEvent<HTMLInputElement>) => {52setValues({ ...values, [prop]: event.target.value })53}54const handleClickShowPassword = () => {55setValues({ ...values, showPassword: !values.showPassword })56}5758const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {59event.preventDefault()60}6162const handleKeyDown = (event: React.KeyboardEvent): void => {63if (event.key === 'Enter') {64event.preventDefault()65onConfirm(values.password)66}67};6869return (70<Dialog71open={open}72onClose={() => openDialog(false)}73aria-labelledby='password-dialog'74>75<DialogTitle id='password-dialog'>{title}</DialogTitle>76<DialogContent>77<DialogContentText>78{children}79</DialogContentText>80<FormControl81sx={{ margin: 1, width: '25ch' }}82variant='standard'83>84<InputLabel85htmlFor='standard-adornment-password'86>87Password88</InputLabel>89<Input90id='standard-adornment-password'91autoFocus92margin='dense'93type={values.showPassword ? 'text' : 'password'}94value={values.password}95inputProps={{96onKeyDown: handleKeyDown97}}98fullWidth99onChange={handleChange('password')}100endAdornment={101<InputAdornment position='end'>102<IconButton103aria-label='toggle password visibility'104onClick={handleClickShowPassword}105onMouseDown={handleMouseDownPassword}106size='large'107>108{values.showPassword ? <Visibility /> : <VisibilityOff />}109</IconButton>110</InputAdornment>111}112/>113</FormControl>114</DialogContent>115<DialogActions>116<Button117variant='contained'118onClick={() => {119openDialog(false)120onCancel()121}}122color='secondary'123>124Cancel125</Button>126<Button127variant='contained'128onClick={() => {129// setOpen(false)130onConfirm(values.password)131}}132color='primary'133>134Accept135</Button>136</DialogActions>137</Dialog>138)139}140141export default PasswordDialog142143144