import React from 'react'; import PropTypes from 'prop-types'; import { Link } from 'react-router'; import { List, ListItem, ListItemContent, Button, Icon, Switch, MenuItem } from 'react-mdl'; import styles from './common.scss'; export { styles }; export const shorten = (str, len = 50) => (str && str.length > len ? `${str.substring(0, len)}...` : str); export const AppsLinkList = ({ apps }) => ( {apps.length > 0 && apps.map(({ appName, description = '-', icon = 'apps' }) => ( {appName} {description} ))} ); AppsLinkList.propTypes = { apps: PropTypes.array.isRequired, }; export const HeaderTitle = ({ title, actions, subtitle }) => (
{title}
{subtitle && {subtitle}}
{actions &&
{actions}
}
); HeaderTitle.propTypes = { title: PropTypes.string, subtitle: PropTypes.string, actions: PropTypes.any, }; export const DataTableHeader = ({ title, actions }) => (

{title}

{actions &&
{actions}
}
); DataTableHeader.propTypes = { title: PropTypes.string, actions: PropTypes.any, }; export const FormButtons = ({ submitText = 'Create', onCancel }) => (
 
); FormButtons.propTypes = { submitText: PropTypes.string, onCancel: PropTypes.func.isRequired, }; export const SwitchWithLabel = ({ onChange, checked, children, ...switchProps }) => ( {children} ); SwitchWithLabel.propTypes = { checked: PropTypes.bool, onChange: PropTypes.func, }; export const TogglesLinkList = ({ toggles }) => ( {toggles.length > 0 && toggles.map(({ name, description = '-', icon = 'toggle' }) => ( {name} ))} ); TogglesLinkList.propTypes = { toggles: PropTypes.array, }; export function getIcon(type) { switch (type) { case 'feature-updated': return 'autorenew'; case 'feature-created': return 'add'; case 'feature-deleted': return 'remove'; case 'feature-archived': return 'archived'; default: return 'star'; } } export const IconLink = ({ url, icon }) => ( ); IconLink.propTypes = { url: PropTypes.string, icon: PropTypes.string, }; export const DropdownButton = ({ label, id }) => ( ); DropdownButton.propTypes = { label: PropTypes.string, id: PropTypes.string, }; export const MenuItemWithIcon = ({ icon, label, disabled, ...menuItemProps }) => ( {label} ); MenuItemWithIcon.propTypes = { icon: PropTypes.string, label: PropTypes.string, disabled: PropTypes.bool, }; const badNumbers = [NaN, Infinity, -Infinity]; export function calc(value, total, decimal) { if (typeof value !== 'number' || typeof total !== 'number' || typeof decimal !== 'number') { return null; } if (total === 0) { return 0; } badNumbers.forEach(number => { if ([value, total, decimal].indexOf(number) > -1) { return number; } }); return (value / total * 100).toFixed(decimal); } export function getDisplayName(WrappedComponent) { return WrappedComponent.displayName || WrappedComponent.name || 'Component'; };