PasswordStrength.tsx 918 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as 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 < 4) {
  14. strengthText = "strength: weak sauce.";
  15. strengthClass = "password-strength-bad";
  16. }
  17. if (this.props.password.length <= 8) {
  18. strengthText = "strength: you can do better.";
  19. strengthClass = "password-strength-ok";
  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. });