Add types constants. (#50)

* Add types constants.
Remove extra space in documentation

* remove unnecesary file
This commit is contained in:
Alejandro Ñáñez Ortiz 2018-03-07 18:37:44 -05:00 committed by Gustav Hansen
parent 25a027d26e
commit 7741dd2fcc
4 changed files with 39 additions and 16 deletions

View file

@ -8,9 +8,9 @@
## Install
### Automatic
### Automatic
``` bash
```bash
# install the cli app
npm install -g create-proton-app
# create your project
@ -24,4 +24,4 @@ You can alternatively use `npx` if you prefer.
### Manual
The old manual instructions are still available [here](manual_install.md)
The old manual instructions are still available [here](manual_install.md)

View file

@ -8,8 +8,17 @@ import {
MenuBar,
} from './';
import { Menu } from '../';
import {
ITEM,
CHECK,
QUIT,
PREFERENCES,
ABOUT,
SEPARATOR
} from '../constants/types';
import PropTypes from 'prop-types';
const functionMappings = {
onChange: 'onChanged',
onClose: 'onClosing',
@ -103,17 +112,17 @@ class DesktopComponent {
// we assume we are a ComboBox.Item, and just append the child
parent.element.append(this.props.children);
} else if (parent instanceof MenuBar) {
if (this.props.type === 'Item') {
if (this.props.type === ITEM) {
this.element = parent.element.appendItem(this.props.children);
} else if (this.props.type === 'Check') {
} else if (this.props.type === CHECK) {
this.element = parent.element.appendCheckItem(this.props.children);
} else if (this.props.type === 'Quit') {
} else if (this.props.type === QUIT) {
this.element = parent.element.appendQuitItem();
} else if (this.props.type === 'Preferences') {
} else if (this.props.type === PREFERENCES) {
this.element = parent.element.appendPreferencesItem();
} else if (this.props.type === 'About') {
} else if (this.props.type === ABOUT) {
this.element = parent.element.appendAboutItem();
} else if (this.props.type === 'Separator') {
} else if (this.props.type === SEPARATOR) {
parent.element.appendSeparator();
}
} else if (this instanceof Menu) {

View file

@ -2,6 +2,14 @@ import DesktopComponent, {
universalPropTypes,
universalDefaultProps,
} from './DesktopComponent';
import {
ITEM,
CHECK,
QUIT,
PREFERENCES,
ABOUT,
SEPARATOR
} from '../constants/types';
import libui from 'libui-node';
import PropTypes from 'prop-types';
@ -57,12 +65,12 @@ MenuBar.Item.PropTypes = {
children: PropTypes.string,
checked: PropTypes.bool,
type: PropTypes.oneOf([
'Check',
'Quit',
'About',
'Preferences',
'Separator',
'Item',
CHECK,
QUIT,
ABOUT,
PREFERENCES,
SEPARATOR,
ITEM,
]),
onClick: PropTypes.func,
...universalPropTypes,
@ -71,7 +79,7 @@ MenuBar.Item.PropTypes = {
MenuBar.Item.defaultProps = {
children: '',
checked: false,
type: 'Item',
type: ITEM,
onClick: () => {},
...universalDefaultProps,
};

6
src/constants/types.js Normal file
View file

@ -0,0 +1,6 @@
export const ITEM = 'Item';
export const CHECK = 'Check';
export const QUIT = 'Quit';
export const PREFERENCES = 'Preferences';
export const ABOUT = 'About';
export const SEPARATOR = 'Separator';