Skip to content

Commit 13c7ef0

Browse files
committed
[grid] Adding component to handle pwd dialog for VNC
[skip ci]
1 parent 3762f33 commit 13c7ef0

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
import React from 'react'
19+
import {
20+
Button,
21+
Dialog,
22+
DialogActions,
23+
DialogContent,
24+
DialogContentText,
25+
DialogTitle,
26+
FormControl,
27+
Input,
28+
InputAdornment,
29+
InputLabel,
30+
makeStyles
31+
} from '@material-ui/core'
32+
import clsx from 'clsx'
33+
import { createStyles, Theme } from '@material-ui/core/styles'
34+
import IconButton from '@material-ui/core/IconButton'
35+
import { Visibility, VisibilityOff } from '@material-ui/icons'
36+
37+
const useStyles = makeStyles((theme: Theme) =>
38+
createStyles({
39+
root: {
40+
display: 'flex',
41+
flexWrap: 'wrap',
42+
},
43+
margin: {
44+
margin: theme.spacing(1),
45+
},
46+
withoutLabel: {
47+
marginTop: theme.spacing(3),
48+
},
49+
textField: {
50+
width: '25ch',
51+
},
52+
}),
53+
)
54+
55+
interface State {
56+
amount: string;
57+
password: string;
58+
weight: string;
59+
weightRange: string;
60+
showPassword: boolean;
61+
}
62+
63+
const PasswordDialog = (props) => {
64+
const { title, children, open, setOpen, onConfirm } = props
65+
const classes = useStyles()
66+
const [values, setValues] = React.useState<State>({
67+
amount: '',
68+
password: '',
69+
weight: '',
70+
weightRange: '',
71+
showPassword: false,
72+
})
73+
const handleChange = (prop: keyof State) => (event: React.ChangeEvent<HTMLInputElement>) => {
74+
setValues({ ...values, [prop]: event.target.value })
75+
}
76+
const handleClickShowPassword = () => {
77+
setValues({ ...values, showPassword: !values.showPassword })
78+
}
79+
80+
const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
81+
event.preventDefault()
82+
}
83+
return (
84+
<Dialog open={open}
85+
onClose={() => setOpen(false)}
86+
aria-labelledby={'password-dialog'}
87+
>
88+
<DialogTitle id={'password-dialog'}>{title}</DialogTitle>
89+
<DialogContent>
90+
<DialogContentText>
91+
{children}
92+
</DialogContentText>
93+
<FormControl className={clsx(classes.margin, classes.textField)}>
94+
<InputLabel
95+
htmlFor="standard-adornment-password">
96+
Password
97+
</InputLabel>
98+
<Input
99+
id="standard-adornment-password"
100+
autoFocus
101+
margin="dense"
102+
type={values.showPassword ? 'text' : 'password'}
103+
value={values.password}
104+
fullWidth
105+
onChange={handleChange('password')}
106+
endAdornment={
107+
<InputAdornment position="end">
108+
<IconButton
109+
aria-label="toggle password visibility"
110+
onClick={handleClickShowPassword}
111+
onMouseDown={handleMouseDownPassword}
112+
>
113+
{values.showPassword ? <Visibility/> : <VisibilityOff/>}
114+
</IconButton>
115+
</InputAdornment>
116+
}
117+
/>
118+
</FormControl>
119+
</DialogContent>
120+
<DialogActions>
121+
<Button variant={'contained'}
122+
onClick={() => setOpen(false)}
123+
color={'secondary'}>
124+
Cancel
125+
</Button>
126+
<Button variant={'contained'}
127+
onClick={() => {
128+
setOpen(false)
129+
onConfirm(values.password)
130+
}}
131+
color={'primary'}
132+
>
133+
Accept
134+
</Button>
135+
</DialogActions>
136+
</Dialog>
137+
)
138+
}
139+
140+
export default PasswordDialog

0 commit comments

Comments
 (0)