UNPKG

6.12 kBMarkdownView Raw
1# react-social-icons   ![build status](https://img.shields.io/github/workflow/status/jaketrent/react-social-icons/Build,%20Test,%20Publish/master) ![package version](https://img.shields.io/npm/v/react-social-icons) ![package size](https://img.shields.io/bundlephobia/minzip/react-social-icons) ![weekly downloads](https://img.shields.io/npm/dw/react-social-icons) ![type definitions](https://img.shields.io/npm/types/react-social-icons)
2
3A set of beautiful svg social icons. Easily used in React. No images or external css dependencies. Svg paths provided by Squarespace.
4
5![social network icons](https://i.imgur.com/xQ0Aqng.png)
6
7## Install
8
9```
10npm install react-social-icons
11```
12
13## Usage
14
15Pass in the `url` prop of your social network, and the icon will be rendered.
16
17```js
18import React from 'react';
19import ReactDOM from 'react-dom';
20import { SocialIcon } from 'react-social-icons';
21ReactDOM.render(<SocialIcon url="https://twitter.com/jaketrent" />, document.body);
22```
23
24See more [usage options on the example site](https://jaketrent.github.io/react-social-icons/).
25
26This library supports [TypeScript](https://www.typescriptlang.org/) since v5.2.0.
27([type declarations](https://github.com/jaketrent/react-social-icons/blob/master/src/react-social-icons.d.ts))
28
29## Prop Types
30
31| Property | Type | Required | Description |
32| :--------- | :----- | :------: | :---------- |
33| url | String | No | The rendered component will link to this url and show the social network's icon.
34| network | String | No | Override which network icon to render (defaults to the url's social network)
35| bgColor | String | No | Override the background fill color (defaults to social network's color)
36| fgColor | String | No | Override the icon's fill color (defaults to transparent)
37| label | String | No | Set the `aria-label` attribute on the rendered anchor tag (defaults to the social network's name)
38| className | String | No | Specify a class to attach to the rendered anchor tag
39| defaultSVG | Object | No | Override the default icon for when a url is not matched to a social network. Requires string properties `icon`, `mask`, and `color`. (defaults to network `'sharethis'`)
40| style | Object | No | Override style properties passed to the rendered anchor tag |
41
42## Contributing
43
44### How to add new icons
45
46Icons are stored in `src\_networks-db.js`
47
48For example:
49
50```
51facebook: {
52 icon:
53 'M34.1,47V33.3h4.6l0.7-5.3h-5.3v-3.4c0-1.5,0.4-2.6,2.6-2.6l2.8,0v-4.8c-0.5-0.1-2.2-0.2-4.1-0.2 c-4.1,0-6.9,2.5-6.9,7V28H24v5.3h4.6V47H34.1z',
54 mask:
55 'M0,0v64h64V0H0z M39.6,22l-2.8,0c-2.2,0-2.6,1.1-2.6,2.6V28h5.3l-0.7,5.3h-4.6V47h-5.5V33.3H24V28h4.6V24 c0-4.6,2.8-7,6.9-7c2,0,3.6,0.1,4.1,0.2V22z',
56 color: '#3b5998'
57},
58```
59
60To add a new icon, you first need to find a copy of that icon as an svg file,
61and a hex code for the social network's main color. Check the network's own
62style guidelines or website for the official icon and color.
63
64The 'icon' and 'mask' properties for each network in `networks-db.js` should
65contain the vector information for the svg. The 'icon' is the foreground, so
66the path for describes the shape of the icon itself. This will be transparent
67by default. The 'mask' is the background area, so the path for this describes
68the area between the surrounding circle and the icon shape. By default this
69will take the color you provide in the 'color' property. The 'color' property
70will set the background color for the icon. This should be the main color
71associated with the social network.
72
73An easy way to generate the path for the 'mask' is to begin with
74'M0,0v64h64V0H0z', which defines the circular border, and follow this with the
75exact same path that you used for the 'icon'.
76
77Depending on the svg file that you start with, you may need to edit attributes
78in the svg file such as width, height, and viewbox (see
79https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial) in order to put the
80icon in the centre of the circular border. You can then use a tool such as
81https://www.iloveimg.com/resize-image to rewrite the svg path so you have a
82nice simple path to use here in the 'icon' and 'mask', without needing those
83extra attributes.
84
85### Using Inkscape
86
87These steps should work for most logos. Feel free to tweak any of the steps to
88make the final svg look neater:
89
901. Open the SVG in Inkscape's editor and select `File > Document Properties` in
91 the menu bar. Change the page's width and height to 64px.
922. Select the icon and click `Object > Transform` in the menu bar. Choose the
93 "Scale" tab, check the box "Scale proportionally", set the height and width
94 to be within 32px, and click the "Apply" button
953. Select the icon and click `Object > Align and Distribute` in the menu bar.
96 Set relative to "Page" in the dropdown menu and click the buttons "Center on
97 vertical axis" and "Center on horizontal axis".
984. Create a square starting at the origin with a width of 64px. Select
99 `Object > Lower to Bottom` in the menu. Select `Path > Object to Path` in
100 the menu.
1015. Select both the square and icon. Click `Path > Exclusion` in the menu. You
102 must convert all objects to paths and remove all groups before you can
103 perform the Exclusion operation.
1046. Select `File > Save a Copy` in the menu. Open the saved svg file in a text
105 editor, find the `path` element, and copy the `d` attribute's value.
1067. In the `react-social-icons` repository, open the `src/_networks-db.js` file
107 and add a new entry in the object whose key has the same name as the social
108 network's domain name. Set the property `icon` to `"M 0,0 H 64 V 64 H 0 Z"`.
109 Set the property `mask` to the copied value from Step 6. Set the property
110 `color` to the social network's brand color.
1118. Commit your changes and preview the new icon by running `npm start` and
112 visiting `http://localhost:1234` in your web browser. Once you're happy with
113 the result, create a PR against master at
114 https://github.com/jaketrent/react-social-icons, where it will be reviewed
115 and merged. Thank you for contributing!