Skip to content

Commit 38134db

Browse files
authored
Merge pull request #133 from jav7zaid/master
feat(password): implement input type='password' capability
2 parents f93951d + 2558034 commit 38134db

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/PasswordText/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import PropTypes from 'prop-types';
2+
import React from 'react';
3+
import classnames from 'classnames';
4+
5+
const Password = React.forwardRef(
6+
({ id, label, invalid, className, required, children, style, placeholder, ...rest }, ref) => {
7+
return (
8+
<hx-password-control
9+
class={classnames(className, { hxInvalid: invalid })}
10+
style={style}
11+
ref={ref}
12+
>
13+
<input {...rest} id={id} required={required} placeholder={placeholder} type="password" />
14+
<label
15+
className={classnames({
16+
hxRequired: required,
17+
})}
18+
htmlFor={id}
19+
>
20+
{label}
21+
</label>
22+
{children}
23+
</hx-password-control>
24+
);
25+
}
26+
);
27+
28+
Password.displayName = 'Password';
29+
30+
Password.propTypes = {
31+
id: PropTypes.string.isRequired,
32+
className: PropTypes.string,
33+
style: PropTypes.object,
34+
children: PropTypes.node,
35+
disabled: PropTypes.bool,
36+
invalid: PropTypes.bool,
37+
required: PropTypes.bool,
38+
label: PropTypes.string,
39+
name: PropTypes.string,
40+
placeholder: PropTypes.string,
41+
onChange: PropTypes.func,
42+
};
43+
44+
export default Password;

src/PasswordText/stories.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import { action } from '@storybook/addon-actions';
3+
import { boolean, text } from '@storybook/addon-knobs/react';
4+
import { addParameters, storiesOf } from '@storybook/react';
5+
import Password from './index';
6+
import { callback, InputContainer } from '../storyUtils';
7+
8+
addParameters({
9+
jsx: { skip: 2 },
10+
});
11+
12+
storiesOf('Password', module).add('All Knobs', () => {
13+
let disabled = boolean('disabled', false);
14+
let required = boolean('required', false);
15+
let invalid = boolean('invalid', false);
16+
let label = text('label', 'Password Text Label');
17+
let placeholder = text('placeholder', 'Enter Password');
18+
19+
return (
20+
<>
21+
<InputContainer>
22+
<Password
23+
id="passwordInputDemo"
24+
{...(label && { label })}
25+
{...(disabled && { disabled })}
26+
{...(required && { required })}
27+
{...(invalid && { invalid })}
28+
{...(placeholder && { placeholder })}
29+
onChange={callback(action('onChange'))}
30+
/>
31+
</InputContainer>
32+
</>
33+
);
34+
});

0 commit comments

Comments
 (0)