Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,33 @@
<tr>
<td>defaultValue: string</td>
<td></td>
<td>Initial value of the password input, only when it is uncontrolled.</td>
</tr>
<tr>
<td>name: string</td>
<td></td>
<td>Name attribute of the input element.</td>
<td>
Initial value of the password input element, only when it is uncontrolled.
</td>
</tr>
<tr>
<td>label: string</td>
<td></td>
<td>Text to be placed above the password.</td>
</tr>
<tr>
<td>helperText: string</td>
<td>name: string</td>
<td></td>
<td>Helper text to be placed above the password.</td>
<td>Name attribute of the input element.</td>
</tr>
<tr>
<td>error: string</td>
<td>helperText: string</td>
<td></td>
<td>
If it is defined, the component will change its appearance, showing the
error below the password component. If it is not defined, the error
messages will be created internally by the component.
</td>
<td>Helper text to be placed above the password.</td>
</tr>
<tr>
<td>clearable: boolean</td>
<td>
<code>false</code>
</td>
<td>
If true, the input will have an action to clear the value entered in the
password.
If true, the password input will have an action to clear the entered
value.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -82,25 +75,25 @@
</td>
</tr>
<tr>
<td>margin: string | object</td>
<td>error: string</td>
<td></td>
<td>
Size of the margin to be applied to the component ('xxsmall' | 'xsmall' |
'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'). You can pass an
object with 'top', 'bottom', 'left' and 'right' properties in order to
specify different margin sizes.
If it is defined, the component will change its appearance, showing the
error below the password input component. If it is not defined, the error
messages will be managed internally, but never displayed on its own.
</td>
</tr>
<tr>
<td>pattern: string</td>
<td></td>
<td>
Regular expression that defines the valid format allowed by the password.
This will be checked when the input element loses the focus. If the value
entered does not match the pattern, the onBlur function will be called
with the value entered and the error informing that the value does not
match the pattern as parameters. If the pattern is accomplished, the error
parameter will be null.
Regular expression that defines the valid format allowed by the password
input. This will be checked both when the input element loses the focus
and while typing within it. If the string entered does not match the
pattern, the onBlur and onChange functions will be called with the current
value and an internal error informing that this value does not match the
pattern. If the pattern is met, the error parameter of both events will be
null.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -130,30 +123,40 @@
</td>
</tr>
<tr>
<td>size: string | object</td>
<td>autocomplete: string</td>
<td><code>'off'</code></td>
<td>
<code>'medium'</code>
HTML autocomplete attribute. Lets the user specify if any permission the
user agent has to provide automated assistance in filling out the input
value. Its value must be one of all the possible values of the HTML
autocomplete attribute: 'on', 'off', 'email', 'username', 'new-password',
...
</td>
</tr>
<tr>
<td>margin: string | object</td>
<td></td>
<td>
Size of the component ('small' | 'medium' | 'large' | 'fillParent').
Size of the margin to be applied to the component ('xxsmall' | 'xsmall' |
'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'). You can pass an
object with 'top', 'bottom', 'left' and 'right' properties in order to
specify different margin sizes.
</td>
</tr>
<tr>
<td>tabIndexValue: number</td>
<td>size: string</td>
<td>
<code>0</code>
<code>'medium'</code>
</td>
<td>
Size of the component ('small' | 'medium' | 'large' | 'fillParent').
</td>
<td>Value of the tabindex attribute.</td>
</tr>
<tr>
<td>autocomplete: string</td>
<td><code>'off'</code></td>
<td>tabIndex: number</td>
<td>
HTML autocomplete attribute. Lets the user specify if any permission the
user agent has to provide automated assistance in filling out the input
value. Its value must be one of all the possible values of the HTML
autocomplete attribute: 'on', 'off', 'email', 'username', 'new-password',
...
<code>0</code>
</td>
<td>Value of the tabindex attribute.</td>
</tr>
</dxc-table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export interface PasswordInputProperties {
margin?: Space | Spacing;
label?: string;
name?: string;
value?: string;
defaultValue?: string;
helperText?: string;
clearable?: boolean;
error?: string;
autocomplete?: string;
size?: "small" | "medium" | "large" | "fillParent";
tabIndexValue?: number;
minLength?: number;
maxLength?: number;
}

export type Space =
| "xxsmall"
| "xsmall"
| "small"
| "medium"
| "large"
| "xlarge"
| "xxlarge";

export type Spacing = {
top?: Space;
bottom?: Space;
left?: Space;
right?: Space;
};

export type EmittedValue = {
value: string;
error: string | null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import {
import { BehaviorSubject } from "rxjs";
import { DxcTextInputComponent } from "../dxc-text-input/dxc-text-input.component";
import { CssUtils } from "../utils";
import {
EmittedValue,
PasswordInputProperties,
Space,
Spacing,
} from "./dxc-passsword-input.types";
import { DxcPasswordInputHelper } from "./dxc-password-input.helper";

@Component({
Expand All @@ -23,22 +29,29 @@ import { DxcPasswordInputHelper } from "./dxc-password-input.helper";
})
export class DxcPasswordInputComponent implements OnInit, OnChanges {
@HostBinding("class") className;

@Input()
label: string;

@Input()
name: string;

@Input()
value: string;

@Input()
defaultValue: string;

@Input()
helperText: string;

/**
* Text to be placed above the password.
*/
@Input() label: string = "";
/**
* Name attribute of the input element.
*/
@Input() name: string = "";
/**
* Value of the input element. If undefined, the component will be uncontrolled and the value will be managed internally by the component.
*/
@Input() value: string;
/**
* Initial value of the password input, only when it is uncontrolled.
*/
@Input() defaultValue: string;
/**
* Helper text to be placed above the password.
*/
@Input() helperText: string = "";
/**
* If true, the password input will have an action to clear the entered value.
*/
@Input()
get clearable(): boolean {
return this._clearable;
Expand All @@ -47,50 +60,90 @@ export class DxcPasswordInputComponent implements OnInit, OnChanges {
this._clearable = coerceBooleanProperty(value);
}
private _clearable = false;

@Input()
error = "";

@Input()
pattern = "";

@Input()
margin: Object | string;

@Input()
minLength: number;

@Input()
maxLength: number;

@Input()
tabIndexValue: number;

@Input()
size: string = "medium";

@Input()
autocomplete: string = "off";

defaultInputs = new BehaviorSubject<any>({
/**
* If it is defined, the component will change its appearance, showing
* the error below the password input component. If it is not defined, the
* error messages will be managed internally, but never displayed on its own.
*/
@Input() error: string = "";
/**
* Regular expression that defines the valid format allowed by the
* password input. This will be checked both when the input element loses the
* focus and while typing within it. If the string entered does not match
* the pattern, the onBlur and onChange functions will be called with the
* current value and an internal error informing that this value does not
* match the pattern. If the pattern is met, the error parameter of both
* events will be null.
*/
@Input() pattern: string;
/**
* Specifies the minimun length allowed by the password input.
* This will be checked both when the input element loses the
* focus and while typing within it. If the string entered does not
* comply the minimum length, the onBlur and onChange functions will be called
* with the current value and an internal error informing that the value
* length does not comply the specified range. If a valid length is
* reached, the error parameter of both events will be null.
*/
@Input() minLength: number;
/**
* Specifies the maximum length allowed by the password input.
* This will be checked both when the input element loses the
* focus and while typing within it. If the string entered does not
* comply the maximum length, the onBlur and onChange functions will be called
* with the current value and an internal error informing that the value
* length does not comply the specified range. If a valid length is
* reached, the error parameter of both events will be null.
*/
@Input() maxLength: number;
/**
* HTML autocomplete attribute. Lets the user specify if any permission the user agent has to provide automated assistance in filling out the input value.
* Its value must be one of all the possible values of the HTML autocomplete attribute: 'on', 'off', 'email', 'username', 'new-password', ...
*/
@Input() autocomplete: string = "off";
/**
* Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
*/
@Input() margin: Space | Spacing;
/**
* Size of the component ('small' | 'medium' | 'large' | 'fillParent').
*/
@Input() size: "small" | "medium" | "large" | "fillParent" = "medium";
/**
* Value of the tabindex attribute.
*/
@Input() tabIndexValue: number = 0;

defaultInputs = new BehaviorSubject<PasswordInputProperties>({
error: "",
helperText: "",
value: undefined,
label: "",
margin: "",
margin: null,
tabIndexValue: 0,
size: "medium",
clearable: false,
name: null,
defaultValue: null,
autocomplete: "off",
minLength: null,
maxLength: null,
});

@Output()
onChange = new EventEmitter<any>();

@Output()
onBlur = new EventEmitter<any>();

@Output()
onError = new EventEmitter<any>(true);
/**
* This function will be called when the user types within the input
* element of the component. An object including the current value and
* the error (if the value entered is not valid) will be passed to this
* function. If there is no error, error will be null.
* */
@Output() onChange = new EventEmitter<EmittedValue>();
/**
* This function will be called when the input element loses the focus.
* An object including the input value and the error (if the value entered is
* not valid) will be passed to this function. If there is no error, error will be null.
*/
@Output() onBlur = new EventEmitter<EmittedValue>();

@ViewChild("dxcInput", { static: false })
dxcInputRef: DxcTextInputComponent;
Expand Down