Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isSupported for useShare function #176

Closed
anteriovieira opened this issue Nov 5, 2020 · 1 comment
Closed

Add isSupported for useShare function #176

anteriovieira opened this issue Nov 5, 2020 · 1 comment

Comments

@anteriovieira
Copy link
Member

anteriovieira commented Nov 5, 2020

@antfu what do you think about adding isSupported to useShare? This will break the current implementation.

export async function useShare(shareOpts: ShareOptions) {
  const _navigator = (window.navigator as NavigatorWithShare)
  const isSupported = _navigator && _navigator.share

  const share = () => {
    if (isSupported) {
      let granted = true

      if (shareOpts.files && _navigator.canShare)
        granted = _navigator.canShare({ files: shareOpts.files })

      if (granted)
        return _navigator.share(shareOpts)
    }
  }

  return {
    isSupported,
    share,
  }
}

Demo

<script>
import { useShare } from '@vueuse/core'

setup() {
   const { isSupported, share } = useShare({ title: 'Hello', text: 'Hello my friend!', url: location.href })
   return {
     isSupported
     share,
   }
},
</script>

<div>
    <button @click="share" :disabled="!isSupported">Share</button>
</div>
@antfu
Copy link
Member

antfu commented Nov 5, 2020

Sure! You can make a PR on dev branch which we are aiming to introduce breaking changes altogether.

@antfu antfu mentioned this issue Nov 6, 2020
16 tasks
@antfu antfu added the 4.0 label Nov 8, 2020
@antfu antfu closed this as completed Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants