Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mentions/commands #742

Merged
merged 4 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,8 @@
},
"description": {
"name": "node",
"description": "The command's description",
"required": true
"description": "Optional command description",
"required": false
},
"param": {
"name": "node",
Expand All @@ -900,7 +900,7 @@
}
},
"required": true,
"description": "The list of commands. Must be an array of objects containing the following:\n{ title: Node, description: Node, param: Node (optional) }"
"description": "The list of commands. Must be an array of objects containing the following:\n\n{ title: Node, description: Node (optional), param: Node (optional), avatar: String (optional) }"
},
"value": {
"type": {
Expand Down
27 changes: 25 additions & 2 deletions docs/src/components/commands.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class CommandsDoc extends Component {
const commands = [
{
title: '/collapse',
description: 'collapse all images'
description: 'collapse all images',
avatar: 'https://avatars0.githubusercontent.com/u/14125280?v=3&s=400'
},
{
title: '/giphy',
Expand Down Expand Up @@ -101,6 +102,20 @@ class CommandsDoc extends Component {
description: 'mute the channel'
}
];
const mentions = [
{
title: '@IanCStewart',
avatar: 'https://avatars0.githubusercontent.com/u/14125280?v=3&s=400'
},
{
title: '@sjaakluthart',
avatar: 'https://avatars1.githubusercontent.com/u/6596471?v=3&s=400'
},
{
title: '@larstadema',
avatar: 'https://avatars2.githubusercontent.com/u/16486197?v=3&s=400'
},
];

return (
<article className="doc">
Expand All @@ -123,9 +138,17 @@ class CommandsDoc extends Component {
onMouseOver={this.handleMouseOver}
onSelect={this.handleSelect}
/>
<Commands
header="Mentions"
style={style.commands}
value={this.state.value}
commands={mentions}
onMouseOver={this.handleMouseOver}
onSelect={this.handleSelect}
/>
<MessageInput
onChange={this.changeValue}
placeholder="Type / to view and filter the commands"
placeholder="Type / to view and filter the commands, type @ to filter mentions"
value={this.state.command || this.state.value}
sendMessage={() => {}}
style={style.messageInput}
Expand Down
36 changes: 28 additions & 8 deletions src/commands/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ import isEmpty from 'lodash/isEmpty';
import onClickOutside from 'react-onclickoutside';
import themeable from '../themeable';
import getStyles from './get-styles';
import Avatar from '../avatar';
import styles from './styles';

const propTypes = {
/** Text to display in the header */
header: PropTypes.node,
/** The list of commands. Must be an array of objects containing the following:
* { title: Node, description: Node, param: Node (optional) }
*
* { title: Node, description: Node (optional), param: Node (optional), avatar: Node (optional) }
*/
commands: PropTypes.arrayOf(PropTypes.shape({
/** The command to execute */
title: PropTypes.node.isRequired,
/** The command's description */
description: PropTypes.node.isRequired,
/** Optional command description */
description: PropTypes.node,
/** Optional command parameter */
param: PropTypes.node
param: PropTypes.node,
/** Optional command avatar */
avatar: PropTypes.node,
})).isRequired,
/** Filter commands based on input value */
value: PropTypes.string.isRequired,
Expand Down Expand Up @@ -158,18 +163,33 @@ class Commands extends Component {
<header style={getStyles.header(color, headerStyle)}>{header}</header>
<section style={getStyles.commands()}>
{map(this.state.commands, command => (
<p
<div
onMouseOver={event => onMouseOver(event, command.title)}
style={getStyles.command()}
key={command.title}
onClick={event => this.handleSelect(event, command.title)}
>
<span>
<span style={styles.titleContainer}>
{
command.avatar
? <div style={styles.avatarContainer}>
{
typeof command.avatar === 'string'
? <Avatar image={command.avatar} style={styles.avatar} />
: command.avatar
}
</div>
: null
}
<strong style={getStyles.title(titleStyle)}>{command.title}</strong>
{command.param ? <span style={paramStyle}>[{command.param}]</span> : null}
</span>
<span style={getStyles.description(descriptionStyle)}>{command.description}</span>
</p>
{
command.description
? <span style={getStyles.description(descriptionStyle)}>{command.description}</span>
: null
}
</div>
))}
</section>
</section>
Expand Down
24 changes: 21 additions & 3 deletions src/commands/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ export default {
backgroundColor: colors.theme,
color: colors.white,
transition: 'background .3s ease-in-out',
padding: '10px',
padding: '8px',
height: '40px',
fontSize: '16px',
lineHeight: '24px',
boxSizing: 'border-box',
fontWeight: 'inherit'
},
commands: {
height: 'calc(100% - 40px)',
overflowY: 'scroll'
},
command: {
padding: '10px 20px 10px 10px',
padding: '8px 16px 8px 8px',
margin: 0,
fontSize: '14px',
cursor: 'pointer',
Expand All @@ -44,12 +47,27 @@ export default {
title: {
fontWeight: 'bolder',
marginRight: '5px',
fontSize: '14px'
fontSize: '14px',
lineHeight: '14px'
},
description: {
fontStyle: 'italic',
fontWeight: 'inherit',
fontSize: '14px',
lineHeight: '14px',
float: 'right'
},
titleContainer: {
display: 'flex',
alignItems: 'center'
},
avatarContainer: {
width: '30px',
height: '30px',
marginRight: '8px'
},
avatar: {
width: '100%',
height: '100%'
}
};