emilkowalski / sonner

An opinionated toast component for React.
https://sonner.emilkowal.ski
MIT License
8.62k stars 271 forks source link

Feature Request: Enhanced Offset Interface to config #510

Open jiwon79 opened 23 hours ago

jiwon79 commented 23 hours ago

The current offset property in the Toaster only accepts a string or number to set the --offset CSS property. This limitation means the horizontal and vertical offsets must use the same value. I would like to suggest an interface that allows different values for horizontal and vertical offsets.

Proposed interface:

type Offset =
  | string
  | number
  | {
    horizontal?: string | number;
    vertical?: string | number;
  }

f this type of interface seems acceptable, would it be alright for me to implement it? Alternatively, if you think another format would be better, I’d really appreciate your feedback.

jiwon79 commented 23 hours ago

+) workaround (only applicable when the position is set to right):

By specifying --width in the style and setting a different width for the actual component in toastOptions, it’s possible to adjust the horizontal offset.

<Toaster
  style={{ '--width': '300px' }}
  toastOptions={{
    unstyled: true,
    classNames: {
      success: 'w-100px'
    }
  }}
/>