1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/common/index.js

99 lines
3.2 KiB
JavaScript
Raw Normal View History

2016-12-09 22:11:05 +01:00
const React = require('react');
import styles from './common.scss';
const {
List, ListItem, ListItemContent,
Button, Icon,
2016-12-10 12:21:27 +01:00
Switch,
} = require('react-mdl');
2016-12-09 22:11:05 +01:00
const { Link } = require('react-router');
2016-12-10 15:39:03 +01:00
export const shorten = (str, len = 50) => (str && str.length > len ? `${str.substring(0, len)}...` : str);
2016-12-09 22:11:05 +01:00
export const AppsLinkList = ({ apps }) => (
<List style={{ textAlign: 'left' }}>
{apps.length > 0 && apps.map(({ appName, description = '-', icon = 'apps' }) => (
<ListItem twoLine key={appName}>
2016-12-10 15:39:03 +01:00
<ListItemContent avatar={icon} subtitle={shorten(description)}>
2016-12-09 22:11:05 +01:00
<Link key={appName} to={`/applications/${appName}`}>
{appName}
</Link>
</ListItemContent>
</ListItem>
))}
</List>
);
export const HeaderTitle = ({ title, actions, subtitle }) => (
2016-12-10 12:21:27 +01:00
<div style={{ display: 'flex', borderBottom: '1px solid #f1f1f1', marginBottom: '10px', padding: '16px 20px ' }}>
2016-12-13 20:54:53 +01:00
<div style={{ flex: '2' }}>
2016-12-10 12:21:27 +01:00
<h6 style={{ margin: 0 }}>{title}</h6>
{subtitle && <small>{subtitle}</small>}
</div>
2016-12-13 19:56:52 +01:00
{actions && <div style={{ flex: '1', textAlign: 'right' }}>{actions}</div>}
2016-12-10 12:21:27 +01:00
</div>
);
export const FormButtons = ({ submitText = 'Create', onCancel }) => (
<div>
<Button type="submit" ripple raised primary icon="add">
<Icon name="add" />&nbsp;&nbsp;&nbsp;
{ submitText }
</Button>
&nbsp;
<Button type="cancel" ripple raised onClick={onCancel} style={{ float: 'right' }}>
<Icon name="cancel" />&nbsp;&nbsp;&nbsp;
Cancel
</Button>
</div>
);
2016-12-10 12:21:27 +01:00
export const SwitchWithLabel = ({ onChange, children, checked }) => (
<span>
<span style={{ cursor: 'pointer', display: 'inline-block', width: '45px' }}>
<Switch onChange={onChange} checked={checked} />
</span>
<span>{children}</span>
</span>
);
2016-12-10 13:49:22 +01:00
export const TogglesLinkList = ({ toggles }) => (
<List style={{ textAlign: 'left' }} className={styles.truncate}>
2016-12-10 13:49:22 +01:00
{toggles.length > 0 && toggles.map(({ name, description = '-', icon = 'toggle' }) => (
<ListItem twoLine key={name}>
<ListItemContent avatar={icon} subtitle={description}>
2016-12-10 13:54:02 +01:00
<Link key={name} to={`/features/edit/${name}`}>
2016-12-10 13:49:22 +01:00
{name}
</Link>
</ListItemContent>
</ListItem>
))}
</List>
);
2016-12-10 14:02:41 +01:00
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';
}
};
2016-12-10 15:10:03 +01:00
export const IconLink = ({ icon, children, ...props }) => (
<a {...props} style={{ textDecoration: 'none' }}>
<Icon name={icon} style={{ marginRight: '5px', verticalAlign: 'middle' }}/>
<span style={{ textDecoration: 'none', verticalAlign: 'middle' }}>{children}</span>
</a>
);
export const ExternalIconLink = ({ url, children }) => (
<IconLink icon="queue" href={url} target="_blank" rel="noopener">
{children}
</IconLink>
);