[TIL] 라이브러리

우기·2023년 3월 28일
0
post-thumbnail

📒 오늘 공부한 내용

🔍수업목차

[12-1] 라이브러리
[12-2] 별점 구현하기
[12-3] 경고창 모달로 변경하기
[12-4] 주소 및 우편번호
[12-5] 캐러셀 이미지 (React-slick)

✅ 라이브러리


  • ant-Design 사이트
  • Material-ui 사이트
  • Ant-Design과 Material-UI는 디자이너의 도움 없이 개발자가 스스로 디자인된 컴포넌트를 만들 수 있도록 도와주는 UI 프레임워크다.

✅ 별점 구현하기


import { Rate } from "antd";
import { useState } from "react";

export default function Star() {
  const [value, setValue] = useState(3);

  function handleChange(value: number) {
    setValue(value);
  }

  return <Rate onChange={handleChange} value={value} />;
}

✅ 경고창 모달로 변경하기


  • alert()를 대신 Modal을 이용해서 더 다양한 기능과 디자인으로 경고창을 만들 수 있다.
import { useState } from 'react';
import { Modal, Wrapper, ModalWrapper } from '../../src/test2';
export default function ModalTest() {
	const [isTrue, setIsTrue] = useState(false);

	const handleModal = () => {
		setIsTrue((prev) => !prev);
	};

	return (
		<>
			<Wrapper>
				<button onClick={handleModal}>나와라 모달</button>
				{isTrue && (
					<ModalWrapper>
						<Modal>
							<button onClick={handleModal}>모달 닫기</button>
						</Modal>
					</ModalWrapper>
				)}
			</Wrapper>
		</>
	);
}
import styled from '@emotion/styled';

export const Wrapper = styled.div`
	width: 100vw;
	height: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
`;
export const ModalWrapper = styled.div`
	position: absolute;
	display: flex;
	justify-content: center;
	width: 100vw;
	height: 100vh;
	background: black;
	opacity: 0.7;
`;
export const Modal = styled.div`
	position: absolute;
	display: flex;
	justify-content: center;
	align-items: center;
	background-color: white;
	top: 100px;
	width: 300px;
	height: 300px;
	border: 1px solid black;
	border-radius: 20px;
`;
  • Modal은 보통 다른 Tag들 보다 앞에 있어야 하기 때문에 position:absolute 속성을 주게 된다.

💡 UI 프레임워크의 종류

Ant-Design Material-UI 이외에도
React Bootstrap Semantic-UI등이 있다.
각 프레임워크마다 스타일이 조금씩 다르니 원하는 프레임워크를 선택하여 사용해야된다.

✅ 주소 및 우편번호


  • 도로명 주소를 알려주는 라이브러리도 있다.
  • reat-daum-postcode npm 링크
  • 아래 명령어로 설치
    yarn add react-daum-postcode

✅ 캐러셀 이미지 (React-slick)


profile
개발 블로그

0개의 댓글