π react-toastify λ?
react νλ‘μ νΈμμ μμμλμ λ§λ€ μ μλλ‘ ν΄μ£Όλ Node.js ν¨ν€μ§
react-toastify μ¬μ© κ²°κ³Ό
react-toastify μ€μΉ
npm i react-toastify
π react-toastify μ¬μ©λ²
// App.js
// λͺ¨λ λΆλ¬μ€κΈ°
import { toast, ToastContainer } from "react-toastify"
export default function App () {
// toastify μλ μ€ν ν¨μ λ§λ€κΈ°
const notify = () => toast("Toastify Alert!")
// λ²νΌ ν΄λ¦μ notify ν¨μ μ€ννκΈ°
// μλ μ€νμ νμλ 컨ν
μ΄λ λ£μ΄μ£ΌκΈ°
return <div>
<button onClick={notify}
<ToastContainer/>
</div>
}
λ€μν μλ μ¬μ©νκΈ°
// μ±κ³΅ μλ ( μ΄λ‘μ μ°½ )
const success = () => toast.success("Success!");
// μ€ν¨ μλ ( λΉ¨κ°μ μ°½ )
const error = () => toast.error("Error!");
// κ²½κ³ μλ ( λ
Έλμ μ°½ )
const warning = () => toast.warning("Warnning!");
// μ 보 μλ
const info = () => toast.info("Info...");
μλ μΈλΆ μ€μ νκΈ°
1. 컨ν μ΄λμμ μ€μ νκΈ°
<ToastContainer
position="top-center"
pauseOnFocusLoss
draggable
pauseOnHover
/>
2. toast ν¨μμμ μ€μ νκΈ°
const notify = () => toast("Notify!", { position:"top-center" })
μΈλΆ μ€μ μ΅μ
μ΄λ¦ | κΈ°λ₯ | μΈλΆ μ΅μ | κΈ°λ³Έ κ° |
position | μλ μμΉ μ§μ | "top-left", "top-right", "top-center", "bottom-left", "bottom-right", "bottom-center" |
"top-right" |
autoClose | μλ off μκ° | 1 μ΄μμ μ«μ ( 1000 = 1μ΄ ) | {3000} |
hideProgressBar | μ§ν μκ° λ° μ¨κΉ | {true} (μ¨κΉ), {false} (νμ) | {false} |
newestOnTop | μλ‘μ΄ μλ μμΉ μ€μ | {true} (μμͺ½), {false} (μλμͺ½) | {false} |
closeOnClick | ν΄λ¦μΌλ‘ μλ off | {true} (λκΈ°), {false} (λμ§ μκΈ°) | {false} |
rtl | μλ μ’μ° λ°μ | {true} (λ°μ ), {false} (λ°μ μν¨) | {false} |
pauseOnFocusLoss | νλ©΄ λ²μ΄λλ©΄ μλ μ μ§ | {true} (μ μ§), {false} (μ μ§ μν¨) | {true} |
draggable | λλκ·Έ κ°λ₯ | {true} (κ°λ₯), {false} (λΆκ°λ₯) | {false} |
pauseOnHover | λ§μ°μ€ μ¬λ¦¬λ©΄ μλ μ μ§ | {true} (μ μ§), {false} (μ μ§ μν¨) | {true} |
transition | μλ μ λλ©μ΄μ μ§μ | Slide, Bounce, Zoom, Flip ( λͺ¨λ import νμ ) | {Bounce} |
limit | μλ κ°μ μ ν | 1 μ΄μμ μ«μ ( 1 = 1κ° ) | μ ν μμ |
π react-toastify μ€νμΌ λ°κΎΈκΈ°
// css νμΌ
:root {
/* ν
λ§λ³ μμ λ°κΎΈκΈ° */
--toastify-color-light: #fff;
--toastify-color-dark: #121212;
--toastify-color-info: #3498db;
--toastify-color-success: #07bc0c;
--toastify-color-warning: #f1c40f;
--toastify-color-error: #e74c3c;
--toastify-color-transparent: rgba(255, 255, 255, 0.7);
/* ν
λ§λ³ μμ΄μ½ μμ λ°κΎΈκΈ° */
--toastify-icon-color-info: var(--toastify-color-info);
--toastify-icon-color-success: var(--toastify-color-success);
--toastify-icon-color-warning: var(--toastify-color-warning);
--toastify-icon-color-error: var(--toastify-color-error);
/* κΈ°λ³Έ μ μ© μ€νμΌ λ°κΎΈκΈ° */
--toastify-toast-width: 320px;
--toastify-toast-background: #fff;
--toastify-toast-min-height: 64px;
--toastify-toast-max-height: 800px;
--toastify-font-family: sans-serif;
--toastify-z-index: 9999;
--toastify-text-color-light: #757575;
--toastify-text-color-dark: #fff;
//Used only for colored theme
--toastify-text-color-info: #fff;
--toastify-text-color-success: #fff;
--toastify-text-color-warning: #fff;
--toastify-text-color-error: #fff;
--toastify-spinner-color: #616161;
--toastify-spinner-color-empty-area: #e0e0e0;
// Used when no type is provided
// toast("**hello**")
--toastify-color-progress-light: linear-gradient(
to right,
#4cd964,
#5ac8fa,
#007aff,
#34aadc,
#5856d6,
#ff2d55
);
// Used when no type is provided
--toastify-color-progress-dark: #bb86fc;
--toastify-color-progress-info: var(--toastify-color-info);
--toastify-color-progress-success: var(--toastify-color-success);
--toastify-color-progress-warning: var(--toastify-color-warning);
--toastify-color-progress-error: var(--toastify-color-error);
}
λ°μν