Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add control on bar height #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const { password } = this.state;
- isRequired: false
- default: []

#### `barHeight`: number
- isRequired: false
- default: 2

#### `barColors`: string[]
- isRequired: false
- default: ['#ddd', '#ef4836', '#f6b44d', '#2b90ef', '#25c281']
Expand Down
1 change: 1 addition & 0 deletions dist/Item.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ interface PasswordStrengthBarItemProps {
score: number;
itemNum: number;
barColors: string[];
height?: number;
}
declare const Item: React.FunctionComponent<PasswordStrengthBarItemProps>;
export default Item;
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface PasswordStrengthBarState {
export interface PasswordStrengthBarProps {
className?: string;
style?: CSSProperties;
barHeight?: number;
scoreWordClassName?: string;
scoreWordStyle?: CSSProperties;
password: string;
Expand Down
3 changes: 3 additions & 0 deletions lib/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface PasswordStrengthBarItemProps {
score: number;
itemNum: number;
barColors: string[];
height?: number;
}

const itemStyle: CSSProperties = {
Expand All @@ -19,6 +20,7 @@ const Item: React.FunctionComponent<PasswordStrengthBarItemProps> = ({
score,
itemNum,
barColors,
height = itemStyle.height,
}) => {
let bgColor = barColors[0];
if (score >= itemNum) {
Expand All @@ -29,6 +31,7 @@ const Item: React.FunctionComponent<PasswordStrengthBarItemProps> = ({
<div
style={{
...itemStyle,
height: height,
backgroundColor: bgColor,
}}
/>
Expand Down
5 changes: 4 additions & 1 deletion lib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface PasswordStrengthBarState {
export interface PasswordStrengthBarProps {
className?: string;
style?: CSSProperties;
barHeight?: number;
scoreWordClassName?: string;
scoreWordStyle?: CSSProperties;
password: string;
Expand Down Expand Up @@ -58,6 +59,7 @@ class PasswordStrengthBar extends React.Component<
public static defaultProps: PasswordStrengthBarProps = {
className: undefined,
style: undefined,
barHeight: 2,
scoreWordClassName: undefined,
scoreWordStyle: undefined,
password: '',
Expand Down Expand Up @@ -109,6 +111,7 @@ class PasswordStrengthBar extends React.Component<
const {
className,
style,
barHeight,
scoreWordClassName,
scoreWordStyle,
password,
Expand All @@ -127,7 +130,7 @@ class PasswordStrengthBar extends React.Component<
{[1, 2, 3, 4].map((el: number) => (
<Fragment key={`password-strength-bar-item-${el}`}>
{el > 1 && <div style={spaceStyle} />}
<Item score={score} itemNum={el} barColors={barColors} />
<Item score={score} itemNum={el} barColors={barColors} height={barHeight}/>
</Fragment>
))}
</div>
Expand Down