diff --git a/README.md b/README.md index 7c5e411..401f8ee 100644 --- a/README.md +++ b/README.md @@ -61,13 +61,13 @@ export default Example; ## 👀 Props -| Prop | Description | Type | Default | -| --------------- | --------------------------- | -------------------- | --------------------------------------------- | -| `data` | Share Object | `{text, url, title}` | `{text: "", url: currentURL, title: "Share"}` | -| `sites` | sites | `string[]` | all platforms (see list below for key list) | -| `closeText` | translate close | `string` | localise close text | -| `onClick` | callback on sucessful share | | | -| `disableNative` | disables native share | `boolean` | `false` | +| Prop | Description | Type | Default | +| --------------- | ---------------------------- | -------------------- | --------------------------------------------- | +| `data` | Share Object | `{text, url, title}` | `{text: "", url: currentURL, title: "Share"}` | +| `sites` | sites | `string[]` | all platforms (see list below for key list) | +| `closeText` | translate close | `string` | localise close text | +| `onClick` | callback on successful share | `() => void` | | +| `disableNative` | disables native share | `boolean` | `false` | ## 🌎 Sites diff --git a/src/components/icon/list.tsx b/src/components/icon/list.tsx index d832008..a09cf14 100644 --- a/src/components/icon/list.tsx +++ b/src/components/icon/list.tsx @@ -1,10 +1,8 @@ import React from "react"; -import { IconItem } from "../../interfaces"; +import { IconItem, Site } from "../../interfaces"; -export interface IconListObject { - [key: string]: IconItem; -} +export type IconListObject = Record; const externalOpen = (URL) => window.open(URL, "_blank", "noopener"); diff --git a/src/interfaces.ts b/src/interfaces.ts index c8b7d0d..71808a6 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,3 +1,5 @@ +import { ReactElement } from "react"; + export interface ShareData { text?: string; title?: string; @@ -5,32 +7,44 @@ export interface ShareData { } export interface RWebShareProps { - children: any; + children: ReactElement; closeText?: string; data: ShareData; - sites?: string[]; - onClick?; - disableNative?; + sites?: Site[]; + onClick?: () => void; + disableNative?: boolean; } export interface SocialIconsProps { - onClose; + onClose: IconProps["onClose"]; closeText?: string; - sites: string[]; + sites: Site[]; data: Required; - onClick?; + onClick?: IconProps["onClick"]; } export interface IconProps { - onClose; - name: string; + onClose: () => void; + name: Site; data: Required; - onClick?; + onClick?: (name: Site) => void; } export interface IconItem { path: JSX.Element; - e; + e: (url: string, text: string, title: string) => void; color: string; viewBox?: string; } + +export type Site = + | "facebook" + | "twitter" + | "whatsapp" + | "reddit" + | "telegram" + | "linkedin" + | "mail" + | "copy" + | "vk" + | "okru"; diff --git a/src/sharer.tsx b/src/sharer.tsx index 18fbc63..9b04436 100644 --- a/src/sharer.tsx +++ b/src/sharer.tsx @@ -7,9 +7,9 @@ import { IconList } from "./components/icon/list"; import { Portal } from "./components/portal"; import { SocialIcons } from "./components/social-icons"; import { useDisclosure } from "./hooks/use-disclosure"; -import type { RWebShareProps } from "./interfaces"; +import type { RWebShareProps, Site } from "./interfaces"; -const defaultSites = Object.keys(IconList).slice(0, 8); +const defaultSites = Object.keys(IconList).slice(0, 8) as Site[]; export const RWebShare = memo((props: RWebShareProps) => { const { onOpen, onClose, isOpen } = useDisclosure(); @@ -31,7 +31,7 @@ export const RWebShare = memo((props: RWebShareProps) => { if (window.navigator.share && !props.disableNative) { try { await window.navigator.share(shareData); - props.onClick(); + props.onClick?.(); } catch (e) { console.warn(e); }