JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q51195F
  • License MIT

A lightweight React toast/snackbar UI component for notifications.

Package Exports

  • cy-toast

Readme

πŸ“œ cy-toast

μ½”λ“œμž‡ 쀑급 ν”„λ‘œμ νŠΈμš© toast/snackbar 라이브러리 νŒ¨ν‚€μ§€μž…λ‹ˆλ‹€.



✨ Features

  • headless ui둜 자유둜운 μ»€μŠ€ν„°λ§ˆμ΄μ§• 제곡
  • React 기반 lightweight toast μ‹œμŠ€ν…œ
  • open/close μ• λ‹ˆλ©”μ΄μ…˜μ„ μœ„ν•œ μƒνƒœ κ°’ 제곡
  • 각 Toast의 μˆœμ„œλ₯Ό 기반으둜 μ• λ‹ˆλ©”μ΄μ…˜ μ»€μŠ€ν„°λ§ˆμ΄μ§• κ°€λŠ₯
  • μˆ˜λ™/μžλ™ λ‹«κΈ° 지원 (duration=0으둜 λ¬΄ν•œ 지속 κ°€λŠ₯)



πŸ’‘ Install

npm install cy-toast



πŸ”¨ Usage

1. ToastRender 루트 μ»΄ν¬λ„ŒνŠΈ 등둝

// RootLayout.tsx or toast μ‚¬μš©ν•  μ»΄ν¬λ„ŒνŠΈμ— ToastRender μ»΄ν¬λ„ŒνŠΈ 등둝
import { ToastRender } from 'cy-toast';

const TestComponent = () => {
  return (
    <ToastRender/> {/*ToastRender μ»΄ν¬λ„ŒνŠΈ μΆ”κ°€*/}
    <Page/>
  )
}

2. ν† μŠ€νŠΈ μ‚¬μš© (κΈ°λ³Έ ν…μŠ€νŠΈ)

import { toast } from 'cy-toast';

toast.run(
  ({ close }) => (
    <div className="toast">
      μ €μž₯λ˜μ—ˆμŠ΅λ‹ˆλ‹€! <button onClick={close}>λ‹«κΈ°</button>
    </div>
  ),
  { duration: 3000 }
);

3. ν† μŠ€νŠΈ μ‚¬μš© (μ‚¬μš©μž μ •μ˜ μ»΄ν¬λ„ŒνŠΈ)

import { toast } from 'cy-toast';
import clsx from 'clsx';

toast.run(
  ({ close, isClosing, isOpening, index }) => (
    <div
      className={clsx(
        'toast-base',
        isClosing &&
          index < 3 &&
          'animation-slide-down-out pointer-events-none',
        isOpening && 'animation-slide-down-in',
        index === 1 && 'translate-y-[10px] scale-90',
        index === 2 && 'translate-y-[15px] scale-80',
        index >= 3 && 'translate-y-[20px] scale-70 opacity-0'
      )}
    >
      <Icon />λ‚΄ μœ„ν‚€ 링크가 λ³΅μ‚¬λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
      <button onClick={close}>λ‹«κΈ°</button>
    </div>
  ),
  { duration: 10000 }
);



πŸš€ API

λ§€κ°œλ³€μˆ˜ νƒ€μž… μ„€λͺ…
content (context: ToastContext) => React.ReactNode ν‘œμ‹œν•  ν† μŠ€νŠΈ JSXλ₯Ό λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜
options { duration?: number; closeDuration?: number; openDuration?: number } μ• λ‹ˆλ©”μ΄μ…˜ 및 μœ μ§€ μ‹œκ°„ μ˜΅μ…˜ (0 μ§€μ • μ‹œ μžλ™ μ’…λ£Œ μ—†μŒ)



🧩 ToastContext νƒ€μž… ν† μŠ€νŠΈ 컨텐츠에 μ „λ‹¬λ˜λŠ” κ°μ²΄λŠ” λ‹€μŒκ³Ό 같은 κ΅¬μ‘°μž…λ‹ˆλ‹€.

interface ToastContext {
  close: () => void; // μˆ˜λ™ λ‹«κΈ° ν•¨μˆ˜
  isClosing: boolean; // λ‹«νžˆλŠ” 쀑 μ—¬λΆ€ (trueλ©΄ λ‹«νžˆλŠ” μ• λ‹ˆλ©”μ΄μ…˜)
  isOpening: boolean; // μ—΄λ¦¬λŠ” 쀑 μ—¬λΆ€ (trueλ©΄ μ—΄λ¦¬λŠ” μ• λ‹ˆλ©”μ΄μ…˜)
  index: number; // ν† μŠ€νŠΈ ν‘œμ‹œ μˆœμ„œ (μ΅œμ‹ μ΄ 0)
}

πŸ§ͺ 예제

toast.run(({ close, isOpening, isClosing, index }) => (
  <div
    className={clsx(
      'toast-base',
      isOpening && 'fade-in',
      isClosing && 'fade-out',
      index === 1 && 'translate-y-[10px]',
      index >= 2 && 'translate-y-[20px] opacity-80'
    )}
  >
    ν† μŠ€νŠΈ λ©”μ‹œμ§€μž…λ‹ˆλ‹€!
    <button onClick={close}>λ‹«κΈ°</button>
  </div>
));