일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- java #자바 #생활코딩
- PYTHON
- 다이나믹프로그래밍
- 투포인터
- 파이썬 #백준 #알고리즘 #코딩테스트
- Dijkstra
- 백트랙킹
- 자바 #java
- BFS
- 파이썬 #알고리즘 #코딩테스트 #프로그래머스
- css #생활코딩 #웹
- react #리액트 #동빈나 #나동빈 #유튜브강의
- css #웹 #생활코딩
- 프로그래머스
- DFS
- 알고리즘
- 재귀
- 코딩테스트
- 프로그래머스 #파이썬 #알고리즘 #코딩테스트
- 백준 #파이썬 #알고리즘 #코딩테스트
- react #리액트 #동빈나
- 백준
- 백준 #알고리즘 #파이썬 #코딩테스트
- java #자바
- 다익스트라
- java #자바 #동빈나
- java #자바 #나동빈
- 파이썬
- dp
- 프로그래머스 #파이썬 #코딩테스트 #알고리즘
Archives
- Today
- Total
커리까지
[동빈나] 16강 - Material UI 모달(Modal) 디자인 구현하기 본문
728x90
SMALL
- 다이얼로그 라이브러리를 사용하면 팝업으로 표현가능
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogTitle from '@material-ui/core/DialogTitle';
import DialogContent from '@material-ui/core/DialogContent';
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
import { withStyles } from '@material-ui/core/styles';
- CustomerAdd.js에 import 해줌
constructor(props) {
super(props);
this.state = {
file: null,
userName: '',
birthday: '',
gender: '',
job: '',
fileName: '',
open: false
}
}
- open을 추가함
- 다이얼로그가 열렸는지 판단
handleClickOpen = () => {
this.setState({
open: true
});
}
- 고객 추가 팝업 창이 띄워지도록
handleClose = () => {
this.setState({
file: null,
userName: '',
birthday: '',
gender: '',
job: '',
fileName: '',
open: false
})
}
- 모달 창이 꺼지면 다시 초기화하기
render() {
const { classes } = this.props;
return (
<div>
<Button variant="contained" color="primary" onClick={this.handleClickOpen}>
고객 추가하기
</Button>
<Dialog open={this.state.open} onClose={this.handleClose}>
<DialogTitle>고객 추가</DialogTitle>
<DialogContent>
<input className={classes.hidden} accept="image/*" id="raised-button-file" type="file" file={this.state.file} value={this.state.fileName} onChange={this.handleFileChange}/><br/>
<label htmlFor="raised-button-file">
<Button variant="contained" color="primary" component="span" name="file">
{this.state.fileName === "" ? "프로필 이미지 선택" : this.state.fileName}
</Button>
</label>
<br/>
<TextField label="이름" type="text" name="userName" value={this.state.userName} onChange={this.handleValueChange}/><br/>
<TextField label="생년월일" type="text" name="birthday" value={this.state.birthday} onChange={this.handleValueChange}/><br/>
<TextField label="성별" type="text" name="gender" value={this.state.gender} onChange={this.handleValueChange}/><br/>
<TextField label="직업" type="text" name="job" value={this.state.job} onChange={this.handleValueChange}/><br/>
</DialogContent>
<DialogActions>
<Button variant="contained" color="primary" onClick={this.handleFormSubmit}>추가</Button>
<Button variant="outlined" color="primary" onClick={this.handleClose}>닫기</Button>
</DialogActions>
</Dialog>
</div>
)
}
다이얼로그는 open값이 true면 나오고 false면 안 보인다.
다이얼로그 컨텐츠 안에 우리가 input으로 넣었던것을 testfield로 넣어줌
- label로 어떤 것을 기입해야 하는지 알려줄 수 있음
다이얼로그 액션스안에 데이터가 진짜 추가되도록 설정해줌
constructor(props) {
super(props);
this.state = {
open: false
}
}
handleClickOpen = () => {
this.setState({
open: true
});
}
handleClose = () => {
this.setState({
open: false
})
}
render() {
return (
<div>
<Button variant="contained" color="secondary" onClick={this.handleClickOpen}>삭제</Button>
<Dialog open={this.state.open} onClose={this.handleClose}>
<DialogTitle onClose={this.handleClose}>
삭제 경고
</DialogTitle>
<DialogContent>
<Typography gutterBottom>
선택한 고객 정보가 삭제됩니다.
</Typography>
</DialogContent>
<DialogActions>
<Button variant="contained" color="primary" onClick={(e) => {this.deleteCustomer(this.props.id)}}>삭제</Button>
<Button variant="outlined" color="primary" onClick={this.handleClose}>닫기</Button>
</DialogActions>
</Dialog>
</div>
)
}
- CustomerDelete.js에서도 추가해준다.
- 삭제를 클릭했을 때 모달창이 나와야 한다.
728x90
LIST
'react' 카테고리의 다른 글
syntaxerror: unexpected token < in json at position 0 (0) | 2021.07.04 |
---|---|
[동빈나] 17강 - AppBar 및 웹 폰트를 적용하여 디자인 개편하기 (0) | 2021.07.04 |
[동빈나] 15강 - 고객(Customer) 정보 삭제 기능 구현하기 (0) | 2021.07.04 |
[동빈나] 14강 - 부모 컴포넌트의 상태(State) 변경을 통한 고객 정보 갱신 (0) | 2021.07.04 |
[동빈나] 13강 - Node.js Express에서 파일 업로드 요청 처리 및 DB에 데이터 삽입 (0) | 2021.07.03 |