PasswordStrength.tsx 914 B

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