Skip to content

Improve types #95

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions src/components/icon/list.tsx
Original file line number Diff line number Diff line change
@@ -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<Site, IconItem>;

const externalOpen = (URL) => window.open(URL, "_blank", "noopener");

Expand Down
36 changes: 25 additions & 11 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
import { ReactElement } from "react";

export interface ShareData {
text?: string;
title?: string;
url?: string;
}

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<ShareData>;
onClick?;
onClick?: IconProps["onClick"];
}

export interface IconProps {
onClose;
name: string;
onClose: () => void;
name: Site;
data: Required<ShareData>;
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";
6 changes: 3 additions & 3 deletions src/sharer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down