예쁜 alert

OUO·2022년 2월 14일
0
post-thumbnail

https://sweetalert2.github.io/#download

sweetalert라는 alert 사용시 예쁜 알림을 줄수 있는 사이트이다
이번 파이널 프로젝트에서는 따로 알림을 줄 필요성이 있는 기능이 없어서
사용을 못할거 같지만 다른 프로젝트에서 꼭 사용해 보고 싶다!

sweetalert 사용법

1. API를 태그 안에 추가 한다

<link rel="stylesheet" href="@sweetalert2/themes/dark/dark.css">
<script src="sweetalert2/dist/sweetalert2.min.js"></script>

2. 희망하는 sweetalert 창을 선택하여 코드 변형 후 사용한다

Swal.fire('Any fool can use a computer')

Swal.fire(
  'The Internet?',
  'That thing is still around?',
  'question'
)

Swal.fire({
  icon: 'error',
  title: 'Oops...',
  text: 'Something went wrong!',
  footer: '<a href="">Why do I have this issue?</a>'
})

![]

Swal.fire({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  icon: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!'
}).then((result) => {
  if (result.isConfirmed) {
    Swal.fire(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  }
})

Swal.fire({
  title: 'Submit your Github username',
  input: 'text',
  inputAttributes: {
    autocapitalize: 'off'
  },
  showCancelButton: true,
  confirmButtonText: 'Look up',
  showLoaderOnConfirm: true,
  preConfirm: (login) => {
    return fetch(`//api.github.com/users/${login}`)
      .then(response => {
        if (!response.ok) {
          throw new Error(response.statusText)
        }
        return response.json()
      })
      .catch(error => {
        Swal.showValidationMessage(
          `Request failed: ${error}`
        )
      })
  },
  allowOutsideClick: () => !Swal.isLoading()
}).then((result) => {
  if (result.isConfirmed) {
    Swal.fire({
      title: `${result.value.login}'s avatar`,
      imageUrl: result.value.avatar_url
    })
  }
})
profile
develoops!er

0개의 댓글