Declare component prop types on console

jh-changes
Shin'ya Ueoka 6 years ago
parent 46228c6b18
commit 25111f9de4
  1. 21
      src/console/components/Console.jsx
  2. 49
      src/console/components/console/Completion.jsx
  3. 28
      src/console/components/console/CompletionItem.jsx
  4. 14
      src/console/components/console/CompletionTitle.jsx
  5. 13
      src/console/components/console/Input.jsx
  6. 11
      src/console/components/console/Message.jsx
  7. 2
      src/console/index.jsx

@ -1,14 +1,15 @@
import './console.scss';
import { connect } from 'react-redux';
import React from 'react';
import Input from './console/input';
import Completion from './console/completion';
import Message from './console/message';
import PropTypes from 'prop-types';
import Input from './console/Input';
import Completion from './console/Completion';
import Message from './console/Message';
import * as consoleActions from '../../console/actions/console';
const COMPLETION_MAX_ITEMS = 33;
class ConsoleComponent extends React.Component {
class Console extends React.Component {
onBlur() {
if (this.props.mode === 'command' || this.props.mode === 'find') {
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;
export default connect(mapStateToProps)(ConsoleComponent);
export default connect(mapStateToProps)(Console);

@ -1,29 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import CompletionItem from './CompletionItem';
import CompletionTitle from './CompletionTitle';
const CompletionTitle = (props) => {
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 {
class Completion extends React.Component {
constructor() {
super();
this.state = { viewOffset: 0, select: -1 };
@ -63,9 +43,13 @@ class CompletionComponent extends React.Component {
let index = 0;
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) {
eles.push(<CompletionItem
key={`item-${index}`}
icon={item.icon}
caption={item.caption}
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;

@ -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;

@ -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 PropTypes from 'prop-types';
export default class InputComponent extends React.Component {
class Input extends React.Component {
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 PropTypes from 'prop-types';
export default function Message(props) {
const Message = (props) => {
switch (props.mode) {
case 'error':
return (
@ -15,4 +16,10 @@ export default function Message(props) {
</p>
);
}
}
};
Message.propTypes = {
children: PropTypes.string,
};
export default Message;

@ -4,7 +4,7 @@ import { createStore, applyMiddleware } from 'redux';
import promise from 'redux-promise';
import * as consoleActions from 'console/actions/console';
import { Provider } from 'react-redux';
import Console from './components/console';
import Console from './components/Console';
import React from 'react';
import ReactDOM from 'react-dom';