Declare component prop types on console
This commit is contained in:
parent
46228c6b18
commit
25111f9de4
7 changed files with 103 additions and 35 deletions
|
@ -1,14 +1,15 @@
|
||||||
import './console.scss';
|
import './console.scss';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Input from './console/input';
|
import PropTypes from 'prop-types';
|
||||||
import Completion from './console/completion';
|
import Input from './console/Input';
|
||||||
import Message from './console/message';
|
import Completion from './console/Completion';
|
||||||
|
import Message from './console/Message';
|
||||||
import * as consoleActions from '../../console/actions/console';
|
import * as consoleActions from '../../console/actions/console';
|
||||||
|
|
||||||
const COMPLETION_MAX_ITEMS = 33;
|
const COMPLETION_MAX_ITEMS = 33;
|
||||||
|
|
||||||
class ConsoleComponent extends React.Component {
|
class Console extends React.Component {
|
||||||
onBlur() {
|
onBlur() {
|
||||||
if (this.props.mode === 'command' || this.props.mode === 'find') {
|
if (this.props.mode === 'command' || this.props.mode === 'find') {
|
||||||
return this.props.dispatch(consoleActions.hideCommand());
|
return this.props.dispatch(consoleActions.hideCommand());
|
||||||
|
@ -137,5 +138,15 @@ class ConsoleComponent extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.propTypes = {
|
||||||
|
mode: PropTypes.string,
|
||||||
|
onBlur: PropTypes.func,
|
||||||
|
onKeyDown: PropTypes.func,
|
||||||
|
onInput: PropTypes.func,
|
||||||
|
consoleText: PropTypes.string,
|
||||||
|
messageText: PropTypes.string,
|
||||||
|
children: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => state;
|
const mapStateToProps = state => state;
|
||||||
export default connect(mapStateToProps)(ConsoleComponent);
|
export default connect(mapStateToProps)(Console);
|
|
@ -1,29 +1,9 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import CompletionItem from './CompletionItem';
|
||||||
|
import CompletionTitle from './CompletionTitle';
|
||||||
|
|
||||||
const CompletionTitle = (props) => {
|
class Completion extends React.Component {
|
||||||
return <li className='vimvixen-console-completion-title' >{props.title}</li>;
|
|
||||||
};
|
|
||||||
|
|
||||||
const CompletionItem = (props) => {
|
|
||||||
let className = 'vimvixen-console-completion-item';
|
|
||||||
if (props.highlight) {
|
|
||||||
className += ' vimvixen-completion-selected';
|
|
||||||
}
|
|
||||||
return <li
|
|
||||||
className={className}
|
|
||||||
style={{ backgroundImage: 'url(' + props.icon + ')' }}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className='vimvixen-console-completion-item-caption'
|
|
||||||
>{props.caption}</span>
|
|
||||||
<span
|
|
||||||
className='vimvixen-console-completion-item-url'
|
|
||||||
>{props.url}</span>
|
|
||||||
</li>;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class CompletionComponent extends React.Component {
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.state = { viewOffset: 0, select: -1 };
|
this.state = { viewOffset: 0, select: -1 };
|
||||||
|
@ -63,9 +43,13 @@ class CompletionComponent extends React.Component {
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
||||||
for (let group of this.props.completions) {
|
for (let group of this.props.completions) {
|
||||||
eles.push(<CompletionTitle title={ group.name }/>);
|
eles.push(<CompletionTitle
|
||||||
|
key={`group-${index}`}
|
||||||
|
title={ group.name }
|
||||||
|
/>);
|
||||||
for (let item of group.items) {
|
for (let item of group.items) {
|
||||||
eles.push(<CompletionItem
|
eles.push(<CompletionItem
|
||||||
|
key={`item-${index}`}
|
||||||
icon={item.icon}
|
icon={item.icon}
|
||||||
caption={item.caption}
|
caption={item.caption}
|
||||||
url={item.url}
|
url={item.url}
|
||||||
|
@ -86,4 +70,17 @@ class CompletionComponent extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CompletionComponent;
|
Completion.propTypes = {
|
||||||
|
select: PropTypes.number,
|
||||||
|
size: PropTypes.number,
|
||||||
|
completions: PropTypes.arrayOf(PropTypes.shape({
|
||||||
|
name: PropTypes.string,
|
||||||
|
items: PropTypes.arrayOf(PropTypes.shape({
|
||||||
|
icon: PropTypes.string,
|
||||||
|
caption: PropTypes.string,
|
||||||
|
url: PropTypes.string,
|
||||||
|
})),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Completion;
|
28
src/console/components/console/CompletionItem.jsx
Normal file
28
src/console/components/console/CompletionItem.jsx
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
const CompletionItem = (props) => {
|
||||||
|
let className = 'vimvixen-console-completion-item';
|
||||||
|
if (props.highlight) {
|
||||||
|
className += ' vimvixen-completion-selected';
|
||||||
|
}
|
||||||
|
return <li
|
||||||
|
className={className}
|
||||||
|
style={{ backgroundImage: 'url(' + props.icon + ')' }}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className='vimvixen-console-completion-item-caption'
|
||||||
|
>{props.caption}</span>
|
||||||
|
<span
|
||||||
|
className='vimvixen-console-completion-item-url'
|
||||||
|
>{props.url}</span>
|
||||||
|
</li>;
|
||||||
|
};
|
||||||
|
|
||||||
|
CompletionItem.propTypes = {
|
||||||
|
highlight: PropTypes.bool,
|
||||||
|
caption: PropTypes.string,
|
||||||
|
url: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CompletionItem;
|
14
src/console/components/console/CompletionTitle.jsx
Normal file
14
src/console/components/console/CompletionTitle.jsx
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
const CompletionTitle = (props) => {
|
||||||
|
return <li className='vimvixen-console-completion-title'>
|
||||||
|
{props.title}
|
||||||
|
</li>;
|
||||||
|
};
|
||||||
|
|
||||||
|
CompletionTitle.propTypes = {
|
||||||
|
title: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CompletionTitle;
|
|
@ -1,6 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
export default class InputComponent extends React.Component {
|
class Input extends React.Component {
|
||||||
focus() {
|
focus() {
|
||||||
this.input.focus();
|
this.input.focus();
|
||||||
}
|
}
|
||||||
|
@ -30,3 +31,13 @@ export default class InputComponent extends React.Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Input.propTypes = {
|
||||||
|
mode: PropTypes.string,
|
||||||
|
value: PropTypes.string,
|
||||||
|
onBlur: PropTypes.func,
|
||||||
|
onKeyDown: PropTypes.func,
|
||||||
|
onInput: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Input;
|
|
@ -1,6 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
export default function Message(props) {
|
const Message = (props) => {
|
||||||
switch (props.mode) {
|
switch (props.mode) {
|
||||||
case 'error':
|
case 'error':
|
||||||
return (
|
return (
|
||||||
|
@ -15,4 +16,10 @@ export default function Message(props) {
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Message.propTypes = {
|
||||||
|
children: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Message;
|
|
@ -4,7 +4,7 @@ import { createStore, applyMiddleware } from 'redux';
|
||||||
import promise from 'redux-promise';
|
import promise from 'redux-promise';
|
||||||
import * as consoleActions from 'console/actions/console';
|
import * as consoleActions from 'console/actions/console';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
import Console from './components/console';
|
import Console from './components/Console';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
|
|
Reference in a new issue