File

src/components/share-button/share-button.tsx

Metadata

tag share-button

Index

Properties
Methods

Methods

Async handleNativeShare
handleNativeShare(beer)
Parameters :
Name Optional
beer No
Returns : any
handleTradShare
handleTradShare(beer)
Parameters :
Name Optional
beer No
Returns : void
render
render()
Returns : any
Async share
share(beer)
Parameters :
Name Optional
beer No
Returns : any

Properties

alertCtrl
alertCtrl: HTMLIonAlertControllerElement
Type : HTMLIonAlertControllerElement
Decorators :
@Prop({connect: 'ion-alert-controller'})
beer
beer: any
Type : any
Decorators :
@Prop()
import { Component, Prop } from '@stencil/core';


@Component({
  tag: 'share-button'
})
export class ShareButton {

  @Prop() beer: any;
  @Prop({ connect: 'ion-alert-controller' }) alertCtrl: HTMLIonAlertControllerElement;

  async share(beer) {
    if ((navigator as any).share) {
      // have to catch here as web share
      // is available on desktop chrome
      // but fails
      try {
        this.handleNativeShare(beer);
      } catch (e) {
        this.handleTradShare(beer);
      }
    } else {
      this.handleTradShare(beer);
    }
  }

  handleTradShare(beer) {
    window.open(`http://twitter.com/share?text=Check this out!&url=${window.location.href}/detail/${beer.id}`);
  }

  async handleNativeShare(beer) {
    (navigator as any).share({
      title: document.title,
      text: 'Check out this cool beer',
      url: `${window.location.href}/detail/${beer.id}`
    })
  }

  render() {
    return (
      <ion-button color='secondary' onClick={() => this.share(this.beer)} fill='clear' icon-only>
        <ion-icon name='share'></ion-icon>
      </ion-button>
    );
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""