Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit 5ab9461

Browse files
mmwMateusz Wijas
authored andcommitted
allow overriding CSS namespace (#66)
1 parent 3b523be commit 5ab9461

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ Using in a __Universal JS App__ (server-side rendering):
9292

9393
- An array of strings that zxcvbn will treat as an extra dictionary.
9494

95+
#### namespaceClassName (Default: 'ReactPasswordStrength')
96+
97+
- Used to control the CSS class namespace. CSS classes created by RPS will be prepended with this string.
98+
- If you change this prop you have to provide all CSS and it's recommended to import RSP from the universal JS build (`react-password-strength/dist/universal`)
99+
95100
### Classes
96101

97-
_All styling is applied with CSS classes to allow custom styling and overriding._
102+
_All styling is applied with CSS classes to allow custom styling and overriding. Note that if you change the `namespaceClassName` prop the below classnames will be affected._
98103
- `ReactPasswordStrength` - namespace class and component wrapper
99104
- `is-strength-{0-4}` - modifier class indicating password strength
100105
- `ReactPasswordStrength-input` - password input field

src/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default class ReactPasswordStrength extends Component {
1414
inputProps: PropTypes.object,
1515
minLength: PropTypes.number,
1616
minScore: PropTypes.number,
17+
namespaceClassName: PropTypes.string,
1718
scoreWords: PropTypes.array,
1819
style: PropTypes.object,
1920
tooShortWord: PropTypes.string,
@@ -26,6 +27,7 @@ export default class ReactPasswordStrength extends Component {
2627
defaultValue: '',
2728
minLength: 5,
2829
minScore: 2,
30+
namespaceClassName: 'ReactPasswordStrength',
2931
scoreWords: ['weak', 'weak', 'okay', 'good', 'strong'],
3032
tooShortWord: 'too short',
3133
userInputs: [],
@@ -89,17 +91,18 @@ export default class ReactPasswordStrength extends Component {
8991
render() {
9092
const { score, password, isValid } = this.state;
9193
const {
92-
scoreWords,
93-
inputProps,
9494
className,
95+
inputProps,
96+
minLength,
97+
namespaceClassName,
98+
scoreWords,
9599
style,
96100
tooShortWord,
97-
minLength,
98101
} = this.props;
99102

100-
const inputClasses = [ 'ReactPasswordStrength-input' ];
103+
const inputClasses = [ `${namespaceClassName}-input` ];
101104
const wrapperClasses = [
102-
'ReactPasswordStrength',
105+
namespaceClassName,
103106
className ? className : '',
104107
password.length > 0 ? `is-strength-${score}` : '',
105108
];
@@ -130,8 +133,8 @@ export default class ReactPasswordStrength extends Component {
130133
value={password}
131134
/>
132135

133-
<div className="ReactPasswordStrength-strength-bar" />
134-
<span className="ReactPasswordStrength-strength-desc">{strengthDesc}</span>
136+
<div className={`${namespaceClassName}-strength-bar`} />
137+
<span className={`${namespaceClassName}-strength-desc`}>{strengthDesc}</span>
135138
</div>
136139
);
137140
}

0 commit comments

Comments
 (0)