|
1 |
| -# PACKAGE-NAME |
| 1 | +# react-share |
2 | 2 |
|
3 | 3 | [![NPM version][npm-image]][npm-url]
|
4 | 4 | [![Actions Status][ci-image]][ci-url]
|
5 | 5 | [![PR Welcome][npm-downloads-image]][npm-downloads-url]
|
6 | 6 |
|
7 |
| -Package one-liner overview. |
| 7 | +An all-in-one React library to implement custom Page Sharing Meta and Social Media Sharing Buttons. |
8 | 8 |
|
9 | 9 | ## Introduction
|
10 | 10 |
|
11 |
| -Package introduction, couple of paragraphs. |
12 |
| - |
13 |
| -```javascript |
14 |
| -import useLibrary from "@phntms/PACKAGE-NAME"; |
15 |
| - |
16 |
| -const { something } = useLibrary({ |
17 |
| - argument1: "something", |
18 |
| - argument2: "something else", |
19 |
| -}); |
20 |
| -``` |
| 11 | +Designed to use and extend [OpenGraph](https://ogp.me/) standards. Alongside, full sharing support to the following social media platforms; ... . |
21 | 12 |
|
22 | 13 | ## Installation
|
23 | 14 |
|
24 | 15 | Install this package with `npm`.
|
25 | 16 |
|
26 | 17 | ```bash
|
27 |
| -npm i @phntms/PACKAGE-NAME |
| 18 | +npm i @phntms/react-share |
28 | 19 | ```
|
29 | 20 |
|
30 | 21 | ## Usage
|
31 | 22 |
|
32 |
| -Example 1 description. |
| 23 | +Example usage in Next.js: |
33 | 24 |
|
34 | 25 | ```JSX
|
35 |
| -import React from 'react'; |
36 |
| -import useLibrary from '@phntms/PACKAGE-NAME'; |
37 |
| - |
38 |
| -const SomeExample = () = { |
39 |
| - const { something } = useApi({ |
40 |
| - argument1: "something", |
41 |
| - argument2: "something else", |
42 |
| - }); |
43 |
| - |
44 |
| - return ( |
45 |
| - <> |
46 |
| - <h1>Result</h2> |
47 |
| - <p>{something}</p> |
48 |
| - </> |
49 |
| - ); |
50 |
| -} |
| 26 | +import { MetaHeadEmbed, TwitterHeadEmbed } from "@phntms/react-share"; |
| 27 | +import type { AppProps } from "next/app"; |
| 28 | + |
| 29 | +const App = ({ Component }: AppProps) => ( |
| 30 | + <> |
| 31 | + <Head> |
| 32 | + <MetaHeadEmbed |
| 33 | + titleTemplate="[siteTitle] | [pageTitle]" |
| 34 | + siteTitle="PHANTOM" |
| 35 | + pageTitle="Our Work" |
| 36 | + canonicalUrl="https://phantom.land/" |
| 37 | + pageURL="https://phantom.land/work/" |
| 38 | + description="Transforming challenges of all shapes and sizes into inventive, engaging and performance driven solutions that change the game." |
| 39 | + keywords={["creative-agency", "phantom", "work"]} |
| 40 | + imageUrl="https://bit.ly/3wiUOuk" |
| 41 | + imageAlt="PHANTOM logo." |
| 42 | + /> |
| 43 | + <TwitterHeadEmbed |
| 44 | + useLargeCard |
| 45 | + title="PHANTOM" |
| 46 | + description="Transforming challenges of all shapes and sizes into inventive, engaging and performance driven solutions that change the game." |
| 47 | + siteUsername="@phntmLDN" |
| 48 | + creatorUsername="@phntmLDN" |
| 49 | + /> |
| 50 | + </Head> |
| 51 | + <Component /> |
| 52 | + </> |
| 53 | +); |
| 54 | + |
| 55 | +export default App; |
51 | 56 | ```
|
52 | 57 |
|
53 |
| -Example 2 description. |
| 58 | +### <MetaHeadEmbed /> |
54 | 59 |
|
55 |
| -```JSX |
56 |
| -import React from 'react'; |
57 |
| -import useLibrary from '@phntms/PACKAGE-NAME'; |
58 |
| - |
59 |
| -const SomeExample2 = () = { |
60 |
| - const { something } = useApi({ |
61 |
| - argument1: "something", |
62 |
| - argument2: "something else", |
63 |
| - }); |
64 |
| - |
65 |
| - return ( |
66 |
| - <> |
67 |
| - <h1>Result</h2> |
68 |
| - <p>{something}</p> |
69 |
| - </> |
70 |
| - ); |
71 |
| -} |
| 60 | +| Property | Type | Required | Notes | |
| 61 | +| ----------------- | -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| 62 | +| **pageTitle** | string | **Yes** | Every page should have a unique title that describes the page, such as 'Home', 'About' etc. | |
| 63 | +| **siteTitle** | string | **Yes** | Title of the site, usually the organization / brand name. | |
| 64 | +| **titleTemplate** | string | **No** | Title template used to display `pageTitle` and `siteTitle` in a template, displays the values using corresponding `[pageTitle]` and `[siteTitle]`. Example template: "[pageTitle] | [siteTitle]". | |
| 65 | +| **description** | string | **Yes** | A one to two sentence description of your webpage. Keep it within 160 characters, and write it to catch the user's attention. | |
| 66 | +| **pageUrl** | string | **Yes** | Url of site page being shared. | |
| 67 | +| **canonicalUrl** | string | **Yes** | The canonical URL of your webpage that will be used as its default app URL. | |
| 68 | +| **keywords** | string|string[] | **Yes** | List of SEO keywords describing what your webpage does. For example, `"your, tags"` or `["your", "tags"]`. | |
| 69 | +| **imageUrl** | string | **Yes** | Image url of asset to share. Recommended aspect ratio for landscape is 1.9:1 (1200x630) or for squares 1:1 (1200x1200). For more info, visit [here](https://iamturns.com/open-graph-image-size/). | |
| 70 | +| **imageAlt** | string | **Yes** | Image alt for users who are visually impaired. | |
| 71 | +| **locale** | string | **No** | The locale these tags are marked up in, such as; `en_GB`, `fr_FR` and `es_ES`. Defaults to `en_US`. | |
| 72 | + |
| 73 | +To add all page meta properties, add `MetaHeadEmbed` to the `head` of the page. |
| 74 | + |
| 75 | +**Note**: `imageUrl` and `canonicalUrl` must start with `https://`, else they won't work. |
| 76 | + |
| 77 | +### <TwitterHeadEmbed /> |
| 78 | + |
| 79 | +| Property | Type | Required | Notes | |
| 80 | +| ------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------ | |
| 81 | +| **useLargeCard** | boolean | **No** | Summary card type. If `true`, uses large card, and if `false` uses small card. Defaults to `false`. | |
| 82 | +| **title** | string | **Yes** | A concise title for the related content. | |
| 83 | +| **description** | string | **No** | A description that concisely summarizes the content as appropriate for presentation within a Tweet. Should not be the same as title. | |
| 84 | +| **siteUsername** | string | **No** | The Twitter @username the card should be attributed to. | |
| 85 | +| **creatorUsername** | string | **No** | The Twitter @username for the content creator / author. | |
| 86 | +| **imageUrl** | string | **No** | Image to show in card. Images must be less than 5MB in size. Supported file types; JPG, PNG, WEBP and GIF. | |
| 87 | +| **imageAlt** | string | **No** | Image alt for users who are visually impaired. Maximum 420 characters. | |
| 88 | + |
| 89 | +`TwitterHeadEmbed` _should_ be used alongside `MetaHeadEmbed` for full sharing support. |
| 90 | + |
| 91 | +**Note**: Image used should be different based on `useLargeCard`: |
| 92 | + |
| 93 | +- For large cards, use a 2:1 aspect ratio (300x157 px minium or 4096x4096 px maximum). |
| 94 | +- For small cards, use a 1:1 aspect ratio (144x144 px minium or 4096x4096 px maximum). |
| 95 | + |
| 96 | +### getFacebookUrl() |
| 97 | + |
| 98 | +| Parameter | Type | Required | Notes | |
| 99 | +| --------- | ------ | -------- | -------------------------------- | |
| 100 | +| url | string | **Yes** | URL of shared webpage. | |
| 101 | +| quote | string | **No** | Quote to show in Facebook card. | |
| 102 | +| hashtag | string | **No** | Hashtag to show in Facebook card | |
| 103 | + |
| 104 | +Basic component example usage: |
| 105 | + |
| 106 | +```jsx |
| 107 | +import { getFacebookUrl } from "@phntms/react-share"; |
| 108 | + |
| 109 | +const ShareToFacebook = () => ( |
| 110 | + <a |
| 111 | + href={getFacebookUrl({ |
| 112 | + url: "https://www.npmjs.com/package/@phntms/react-share", |
| 113 | + })} |
| 114 | + > |
| 115 | + Share to Facebook |
| 116 | + </a> |
| 117 | +); |
| 118 | + |
| 119 | +export default ShareToFacebook; |
72 | 120 | ```
|
73 | 121 |
|
74 |
| -## API |
| 122 | +### getLinkedinUrl() |
| 123 | + |
| 124 | +| Parameter | Type | Required | Notes | |
| 125 | +| --------- | ------ | -------- | ------------------------------------------------------------------------ | |
| 126 | +| url | string | **Yes** | URL of shared webpage. | |
| 127 | +| title | string | **No** | Title to show in card. | |
| 128 | +| summary | string | **No** | Description to show in card | |
| 129 | +| source | string | **No** | Source of the content (for example... your website or application name). | |
| 130 | + |
| 131 | +Basic component example usage: |
| 132 | + |
| 133 | +```jsx |
| 134 | +import { getLinkedinUrl } from "@phntms/react-share"; |
| 135 | + |
| 136 | +const ShareToLinkedin = () => ( |
| 137 | + <a |
| 138 | + href={getLinkedinUrl({ |
| 139 | + url: "https://www.npmjs.com/package/@phntms/react-share", |
| 140 | + })} |
| 141 | + > |
| 142 | + Share to Linkedin |
| 143 | + </a> |
| 144 | +); |
| 145 | + |
| 146 | +export default ShareToLinkedin; |
| 147 | +``` |
| 148 | + |
| 149 | +### getTwitterUrl() |
| 150 | + |
| 151 | +| Parameter | Type | Required | Notes | |
| 152 | +| --------- | ------ | -------- | -------------------------------- | |
| 153 | +| url | string | **Yes** | URL of shared webpage. | |
| 154 | +| text | string | **No** | Text to show in Twitter card. | |
| 155 | +| hashtags | string | **No** | Hashtags to show in Twitter card | |
| 156 | +| related | string | **No** | Accounts to recommend following. | |
| 157 | + |
| 158 | +Basic component example usage: |
| 159 | + |
| 160 | +```jsx |
| 161 | +import { getTwitterUrl } from "@phntms/react-share"; |
| 162 | + |
| 163 | +const ShareToTwitter = () => ( |
| 164 | + <a |
| 165 | + href={getTwitterUrl({ |
| 166 | + url: "https://www.npmjs.com/package/@phntms/react-share", |
| 167 | + })} |
| 168 | + > |
| 169 | + Share to Twitter |
| 170 | + </a> |
| 171 | +); |
| 172 | + |
| 173 | +export default ShareToTwitter; |
| 174 | +``` |
| 175 | + |
| 176 | +### getShareUrl() |
| 177 | + |
| 178 | +If you would rather have all share urls in one place, `getShareUrl()` can be used! It includes props from every social platform listed above, so simply pass in a `SocialPlatform`, and the platforms corresponding props. |
| 179 | + |
| 180 | +Example usage: |
| 181 | + |
| 182 | +```jsx |
| 183 | +import { getShareUrl } from "@phntms/react-share"; |
| 184 | + |
| 185 | +const Share = () => ( |
| 186 | + <a |
| 187 | + href={getShareUrl(SocialPlatforms.Facebook, { |
| 188 | + url: "https://www.npmjs.com/package/@phntms/react-share", |
| 189 | + })} |
| 190 | + > |
| 191 | + Share to Facebook |
| 192 | + </a> |
| 193 | + <a |
| 194 | + href={getShareUrl(SocialPlatforms.Linkedin, { |
| 195 | + url: "https://www.npmjs.com/package/@phntms/react-share", |
| 196 | + })} |
| 197 | + > |
| 198 | + Share to Linkedin |
| 199 | + </a> |
| 200 | + <a |
| 201 | + href={getShareUrl(SocialPlatforms.Twitter, { |
| 202 | + url: "https://www.npmjs.com/package/@phntms/react-share", |
| 203 | + })} |
| 204 | + > |
| 205 | + Share to Twitter |
| 206 | + </a> |
| 207 | +); |
| 208 | + |
| 209 | +export default Share; |
| 210 | +``` |
| 211 | + |
| 212 | +## Further Resources |
| 213 | + |
| 214 | +Useful resources for testing meta properties: |
75 | 215 |
|
76 |
| -### Input |
| 216 | +- [Meta Tags](https://metatags.io/) - With Meta Tags you can preview how your webpage will look on Google, Facebook, Twitter and more. |
| 217 | +- [Social Share Preview](https://chrome.google.com/webstore/detail/social-share-preview/ggnikicjfklimmffbkhknndafpdlabib?hl=en) - Chrome browser extension to live preview how the webpage will look when shared. Especially useful for testing when app is auth protected. |
77 | 218 |
|
78 |
| -- `argument1` : Required - Description of argument. |
79 |
| -- `argument2` : Optional - Description of argument. |
| 219 | +## 🍰 Requests and Contributing |
80 | 220 |
|
81 |
| -### Output |
| 221 | +If a social media platform you want to use isn't already supported, or found an issue? Get involved! Please contribute using the GitHub Flow. Create a branch, add commits, and open a Pull Request or submit a new issue. |
82 | 222 |
|
83 |
| -- `something`: Description of output. |
| 223 | +Please read `CONTRIBUTING` for details on our `CODE_OF_CONDUCT`, and the process for submitting pull requests to us! |
84 | 224 |
|
85 |
| -[npm-image]: https://img.shields.io/npm/v/@phntms/PACKAGE-NAME.svg?style=flat-square&logo=react |
86 |
| -[npm-url]: https://npmjs.org/package/@phntms/PACKAGE-NAME |
87 |
| -[npm-downloads-image]: https://img.shields.io/npm/dm/@phntms/PACKAGE-NAME.svg |
88 |
| -[npm-downloads-url]: https://npmcharts.com/compare/@phntms/PACKAGE-NAME?minimal=true |
89 |
| -[ci-image]: https://github.com/phantomstudios/PACKAGE-NAME/workflows/test/badge.svg |
90 |
| -[ci-url]: https://github.com/phantomstudios/PACKAGE-NAME/actions |
| 225 | +[npm-image]: https://img.shields.io/npm/v/@phntms/react-share.svg?style=flat-square&logo=react |
| 226 | +[npm-url]: https://npmjs.org/package/@phntms/react-share |
| 227 | +[npm-downloads-image]: https://img.shields.io/npm/dm/@phntms/react-share.svg |
| 228 | +[npm-downloads-url]: https://npmcharts.com/compare/@phntms/react-share?minimal=true |
| 229 | +[ci-image]: https://github.com/phantomstudios/react-share/workflows/test/badge.svg |
| 230 | +[ci-url]: https://github.com/phantomstudios/react-share/actions |
0 commit comments