PasswordStrength.tsx 957 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import * as React from 'react';
  2. import * as ReactDOM from 'react-dom';
  3. import coreModule from '../core_module';
  4. export interface IProps {
  5. password: string;
  6. }
  7. export class PasswordStrength extends React.Component<IProps, any> {
  8. constructor(props) {
  9. super(props);
  10. }
  11. render() {
  12. let strengthText = "strength: strong like a bull.";
  13. let strengthClass = "password-strength-good";
  14. if (this.props.password.length < 4) {
  15. strengthText = "strength: weak sauce.";
  16. strengthClass = "password-strength-bad";
  17. }
  18. if (this.props.password.length <= 8) {
  19. strengthText = "strength: you can do better.";
  20. strengthClass = "password-strength-ok";
  21. }
  22. return (
  23. <div className={`password-strength small ${strengthClass}`}>
  24. <em>{strengthText}</em>
  25. </div>
  26. );
  27. }
  28. }
  29. coreModule.directive('passwordStrength', function(reactDirective) {
  30. return reactDirective(PasswordStrength, ['password']);
  31. });