|
| 1 | +--- |
| 2 | +title: <ShareBlockAside /> |
| 3 | +description: ShareBlockAside is a dynamic container with additional buttons floating aside the content. |
| 4 | +cover: cover.png |
| 5 | +--- |
| 6 | + |
| 7 | +## Demo |
| 8 | + |
| 9 | +[Live demo](../live-share-block-aside) |
| 10 | + |
| 11 | +## Description |
| 12 | + |
| 13 | +`ShareBlockAside` is a built-in, ready-to-use 'share' block component. |
| 14 | + |
| 15 | +It renders two block of share buttons, one is static placed inside/under the content, the second one is floating aside. |
| 16 | + |
| 17 | +The floating buttons appear only when there is a free space aside. |
| 18 | + |
| 19 | +The components script automatically hide the floating block whenever the static block is visible in the viewport. Set the `pageHeaderSelector` prop to turn on similar behavior for the title of the web page. |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +Let's create a share block using `ShareBlockAside` with buttons for five networks. |
| 24 | + |
| 25 | +**Step 1.** Import the icons. As usual, we are going to use icons provided by [react-icons](https://github.com/react-icons/react-icons). |
| 26 | + |
| 27 | +```javascript |
| 28 | +import FaTwitter from "react-icons/lib/fa/twitter"; |
| 29 | +import FaFacebook from "react-icons/lib/fa/facebook"; |
| 30 | +import FaGooglePlus from "react-icons/lib/fa/google-plus"; |
| 31 | +import FaEnvelope from "react-icons/lib/fa/envelope"; |
| 32 | +import FaPinterest from "react-icons/lib/fa/pinterest"; |
| 33 | +import FaLinkedin from "react-icons/lib/fa/linkedin"; |
| 34 | +``` |
| 35 | + |
| 36 | +**Step 2.** Import the `react-custom-share` components: a button and a block. Notice that we will use `ShareButtonRectangle` as a button component to render the items of the block. |
| 37 | + |
| 38 | +```javascript |
| 39 | +import { ShareButtonRectangle, ShareBlockAside } from "react-custom-share"; |
| 40 | +``` |
| 41 | + |
| 42 | +**Step 3.** Prepare an object with props for the `ShareBlockAside` component. The `url`, `button` and `buttons` are required props. |
| 43 | + |
| 44 | +```javascript |
| 45 | +const shareBlockProps = { |
| 46 | + url: "https://github.com/greglobinski/react-custom-share", |
| 47 | + button: ShareButtonRectangle, |
| 48 | + buttons: [ |
| 49 | + { network: "Twitter", icon: FaTwitter }, |
| 50 | + { network: "Facebook", icon: FaFacebook }, |
| 51 | + { network: "GooglePlus", icon: FaGooglePlus }, |
| 52 | + { network: "Email", icon: FaEnvelope }, |
| 53 | + { |
| 54 | + network: "Pinterest", |
| 55 | + icon: FaPinterest, |
| 56 | + media: |
| 57 | + "https://raw.githubusercontent.com/greglobinski/react-custom-share/master/static/react-custom-share.gif" |
| 58 | + } |
| 59 | + ], |
| 60 | + text: "Give it a try - react-custom-share component", |
| 61 | + longtext: |
| 62 | + "Social sharing buttons for React. Use one of the build-in themes or create a custom one from the scratch.", |
| 63 | + header: "Share it", |
| 64 | + pageHeaderSelector: ".header" |
| 65 | +}; |
| 66 | +``` |
| 67 | + |
| 68 | +Take a look at the new prop `pageHeaderSelector`. It's a distinctive prop of `ShareBlockAside`. If set the floating buttons will be hidden when the page header is visible in the viewport. |
| 69 | + |
| 70 | +**Step 4.** Add `ShareBlockAside` to your app. Remember to pass all prepared props to the component. |
| 71 | + |
| 72 | +```javascript |
| 73 | +<ShareBlockAside {...shareBlockProps} /> |
| 74 | +``` |
| 75 | + |
| 76 | +**Full code** |
| 77 | + |
| 78 | +```javascript |
| 79 | +import React from "react"; |
| 80 | +import ReactDOM from "react-dom"; |
| 81 | +import FaTwitter from "react-icons/lib/fa/twitter"; |
| 82 | +import FaFacebook from "react-icons/lib/fa/facebook"; |
| 83 | +import FaGooglePlus from "react-icons/lib/fa/google-plus"; |
| 84 | +import FaEnvelope from "react-icons/lib/fa/envelope"; |
| 85 | +import FaPinterest from "react-icons/lib/fa/pinterest"; |
| 86 | +import FaLinkedin from "react-icons/lib/fa/linkedin"; |
| 87 | + |
| 88 | +import { ShareButton, ShareBlockAside } from "react-custom-share"; |
| 89 | + |
| 90 | +const App = props => { |
| 91 | + const shareBlockProps = { |
| 92 | + url: "https://github.com/greglobinski/react-custom-share", |
| 93 | + button: ShareButtonRectangle, |
| 94 | + buttons: [ |
| 95 | + { network: "Twitter", icon: FaTwitter }, |
| 96 | + { network: "Facebook", icon: FaFacebook }, |
| 97 | + { network: "GooglePlus", icon: FaGooglePlus }, |
| 98 | + { network: "Email", icon: FaEnvelope }, |
| 99 | + { |
| 100 | + network: "Pinterest", |
| 101 | + icon: FaPinterest, |
| 102 | + media: |
| 103 | + "https://raw.githubusercontent.com/greglobinski/react-custom-share/master/static/react-custom-share.gif" |
| 104 | + }, |
| 105 | + { network: "Linkedin", icon: FaLinkedin } |
| 106 | + ], |
| 107 | + text: "Give it a try - react-custom-share component", |
| 108 | + longtext: |
| 109 | + "Social sharing buttons for React. Use one of the build-in themes or create a custom one from the scratch.", |
| 110 | + header: "Share it", |
| 111 | + pageHeaderSelector: ".header" |
| 112 | + }; |
| 113 | + |
| 114 | + return <ShareBlockAside {...shareBlockProps} />; |
| 115 | +}; |
| 116 | + |
| 117 | +ReactDOM.render(<App />, document.getElementById("root")); |
| 118 | +``` |
| 119 | + |
| 120 | +## ShareBlockStandard's props |
| 121 | + |
| 122 | +* **header** - the inline share block's title | _string_ | optional |
| 123 | +* **debounce**: wait option for the `debounce` method applied to `window.resize` event | number _(milliseconds)_ | optional | default: 250 |
| 124 | +* **pageHeaderSelector**: selector for `document.querySelector()` pointing the header of the web page | _string_ | optional |
| 125 | +* other props the same as `ShareBlock` |
0 commit comments