File size: 1,531 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
// @flow
import * as React from "react";
import cn from "classnames";
import { List, Icon, Button } from "../";
type itemObject = {|
name: string,
label?: string,
to?: string,
tooltip?: string,
color?: string,
|};
type Props = {|
+children?: React.Node,
+className?: string,
+asButtons?: boolean,
+prefix?: string,
+itemsObjects?: Array<itemObject>,
+items?: Array<React.Node>,
|};
function listItemFromObjectFactory(
asButtons: boolean = false,
iconPrefix: string
) {
return (item: itemObject) => {
const itemContent = asButtons ? (
<Button to={item.to} social={item.name} color={item.color} size="sm">
{item.label}
</Button>
) : (
<a href={item.to} data-original-title={item.tooltip}>
<Icon prefix={iconPrefix} name={item.name} />
</a>
);
return <List.Item inline>{itemContent}</List.Item>;
};
}
function SocialNetworksList(props: Props): React.Node {
const {
children,
className,
asButtons,
prefix = "fe",
items,
itemsObjects,
} = props;
const classes = cn("social-links", className);
const getObjectListItem = listItemFromObjectFactory(asButtons, prefix);
const contents =
(itemsObjects && itemsObjects.map(getObjectListItem)) ||
(items && items.map(item => <List.Item inline>{item}</List.Item>)) ||
children;
return (
<List inline className={classes}>
{contents}
</List>
);
}
SocialNetworksList.displayName = "SocialNetworksList";
export default SocialNetworksList;
|