t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.4k stars 2.84k forks source link

Code for example alerts #851

Open gkiely opened 6 years ago

gkiely commented 6 years ago

Hi guys, thanks for your work on SweetAlert.

I noticed some of the examples you have on the website: https://sweetalert.js.org/assets/images/modal-examples.png

It would be awesome if there were source code to show how to build these, I would love to use some of them!

Thanks.

whitehorsesoft commented 5 years ago

Just checking, is there one in particular you're interested in?

And, you've prob already seen this, but I'll point out there are several examples with source and interactive samples on the installation page at https://sweetalert.js.org/guides/#installation

LuizMoratelli commented 5 years ago

@gkiely as the @whitehorsesoft mentioned, there are several examples in the link: https://sweetalert.js.org/guides/#installation, rating, for example, is well at the bottom of the page:

import React from 'react'
import swal from '@sweetalert/with-react'

const onPick = value => {
  swal("Thanks for your rating!", `You rated us ${value}/3`, "success")
}

const MoodButton = ({ rating, onClick }) => (
  <button 
    data-rating={rating}
    className="mood-btn" 
    onClick={() => onClick(rating)}
  />
)

swal({
  text: "How was your experience getting help with this issue?",
  buttons: {
    cancel: "Close",
  },
  content: (
    <div>
      <MoodButton 
        rating={1} 
        onClick={onPick}
      />
      <MoodButton 
        rating={2} 
        onClick={onPick}
      />
      <MoodButton 
        rating={3} 
        onClick={onPick}
      />
    </div>
  )
})

Ps.: made using React.