Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit 6369912

Browse files
committed
feat(SocialNetworksList): add List for displaying social icons
Provides a dedicated component for displaying Lists of social network buttons
1 parent e6ec9ed commit 6369912

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
```jsx
2+
<SocialNetworksList
3+
itemsObjects={[
4+
{ name: "twitter", to: "http://www.twitter.com" },
5+
{ name: "linkedin", to: "http://www.linkedin.com" },
6+
]}
7+
/>
8+
```
9+
10+
#### As buttons
11+
12+
```jsx
13+
<SocialNetworksList
14+
itemsObjects={[
15+
{ name: "twitter", label: "Follow", to: "http://www.twitter.com"},
16+
{ name: "linkedin", label: "Connect", color: "blue", to: "http://www.linkedin.com" },
17+
]}
18+
prefix="fa"
19+
asButtons
20+
/>
21+
```
22+
23+
#### Items as components
24+
25+
```jsx
26+
<SocialNetworksList
27+
items={[
28+
<a href="http://www.twitter.com">
29+
<Icon prefix="fa" name="twitter" />
30+
</a>,
31+
<a href="http://www.facebook.com">
32+
<Icon prefix="fa" name="facebook" />
33+
</a>,
34+
]}
35+
/>
36+
```;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// @flow
2+
3+
import * as React from "react";
4+
import cn from "classnames";
5+
import { List, Icon, Button } from "../";
6+
7+
type itemObject = {|
8+
name: string,
9+
label?: string,
10+
to?: string,
11+
tooltip?: string,
12+
color?: string,
13+
|};
14+
15+
type Props = {|
16+
+children?: React.Node,
17+
+className?: string,
18+
+asButtons?: boolean,
19+
+prefix?: string,
20+
+itemsObjects?: Array<itemObject>,
21+
+items?: Array<React.Node>,
22+
|};
23+
24+
function listItemFromObjectFactory(asButtons, iconPrefix) {
25+
return item => {
26+
const itemContent = asButtons ? (
27+
<Button to={item.to} social={item.name} color={item.color} size="sm">
28+
{item.label}
29+
</Button>
30+
) : (
31+
<a href={item.to} data-original-title={item.tooltip}>
32+
<Icon prefix={iconPrefix} name={item.name} />
33+
</a>
34+
);
35+
return <List.Item inline>{itemContent}</List.Item>;
36+
};
37+
}
38+
39+
function SocialNetworksList(props: Props): React.Node {
40+
const { children, className, asButtons, prefix = "fe" } = props;
41+
const classes = cn("social-links", className);
42+
43+
const getObjectListItem = listItemFromObjectFactory(asButtons, prefix);
44+
45+
const items =
46+
(props.itemsObjects && props.itemsObjects.map(getObjectListItem)) ||
47+
(props.items &&
48+
props.items.map(item => <List.Item inline>{item}</List.Item>)) ||
49+
children;
50+
51+
return (
52+
<List inline className={classes}>
53+
{items}
54+
</List>
55+
);
56+
}
57+
58+
SocialNetworksList.displayName = "SocialNetworksList";
59+
60+
export default SocialNetworksList;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @flow
2+
3+
import SocialNetworksList from "./SocialNetworksList.react";
4+
5+
export { SocialNetworksList as default };

src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export { default as Profile } from "./Profile";
2727
export { default as Progress } from "./Progress";
2828
export { default as ProgressCard } from "./ProgressCard";
2929
export { default as Site } from "./Site";
30+
export { default as SocialNetworksList } from "./SocialNetworksList";
3031
export { default as Stamp } from "./Stamp";
3132
export { default as StampCard } from "./StampCard";
3233
export { default as StatsCard } from "./StatsCard";

0 commit comments

Comments
 (0)