Convert to ts (#386)

Converts email validator and  Avatar component to typescript
This commit is contained in:
Mike Stone 2016-11-09 17:54:34 -05:00 committed by Mike Arpaia
parent 995d86e902
commit 37df94f7fa
7 changed files with 50 additions and 43 deletions

View File

@ -1,32 +0,0 @@
import React, { PropTypes } from 'react';
import classnames from 'classnames';
import userInterface from '../../interfaces/user';
const Avatar = ({ size, className, style, user }) => {
const { gravatarURL } = user;
const isSmall = size && size.toLowerCase() === 'small';
const avatarClasses = classnames(
'avatar',
{ 'avatar--small': isSmall },
className
);
return (
<img
alt="User avatar"
src={gravatarURL}
className={avatarClasses}
style={style}
/>
);
};
Avatar.propTypes = {
size: PropTypes.string,
className: PropTypes.string,
style: PropTypes.object, // eslint-disable-line react/forbid-prop-types
user: userInterface.isRequired,
};
export default Avatar;

View File

@ -0,0 +1,38 @@
import * as React from 'react';
const classnames = require('classnames');
interface IAvatarUserInterface {
gravatarURL: string;
}
interface IAvatarInterface {
className?: string;
size?: string;
user: IAvatarUserInterface;
}
interface IAvatarState {}
const baseClass = 'avatar';
class Avatar extends React.Component<IAvatarInterface, IAvatarState> {
render (): JSX.Element {
const { className, size, user } = this.props;
const isSmall = size && size.toLowerCase() === 'small';
const avatarClasses = classnames(baseClass, {
[`${baseClass}--${size}`]: isSmall,
className,
});
const { gravatarURL } = user;
return (
<img
alt='User Avatar'
className={avatarClasses}
src={gravatarURL}
/>
);
}
}
export default Avatar;

View File

@ -1 +1 @@
export default from './Avatar';
export default from './Avatar.tsx';

View File

@ -1,9 +1 @@
const EMAIL_REGEX = /\S+@\S+\.\S+/;
export default (email) => {
if (EMAIL_REGEX.test(email)) {
return true;
}
return false;
};
export default from './valid_email.ts';

View File

@ -0,0 +1,9 @@
const EMAIL_REGEX = /\S+@\S+\.\S+/;
export default (email: string): boolean => {
if (EMAIL_REGEX.test(email)) {
return true;
}
return false;
};

View File

@ -45,7 +45,7 @@
"moment": "^2.15.1",
"nock": "^8.0.0",
"node-bourbon": "^4.2.8",
"node-sass": "^3.10.0",
"node-sass": "^3.10.1",
"normalizr": "^2.2.1",
"postcss-functions": "^2.1.0",
"postcss-loader": "^0.8.0",