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(design): add input component #3376

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 11 additions & 1 deletion apps/design-land/src/app/input/input.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ <h3>Disabled</h3>

<design-land-example-viewer-container example="input-disabled"></design-land-example-viewer-container>

<h3>Input With Hint</h3>
<p>The input in this example has a hint.</p>

<design-land-example-viewer-container example="input-hint"></design-land-example-viewer-container>

<h3>With Reactive Forms</h3>
<p>The input in this example uses the <code>ReactiveFormsModule</code> to display errors.</p>

<design-land-example-viewer-container example="input-error"></design-land-example-viewer-container>
<design-land-example-viewer-container example="input-error"></design-land-example-viewer-container>

<h3>Password With Reactive Forms</h3>
<p>This is a special case where hints and errors for passwords are displayed.</p>

<design-land-example-viewer-container example="password-with-form-field"></design-land-example-viewer-container>
4 changes: 4 additions & 0 deletions libs/design/input/examples/src/examples.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { BasicInputComponent } from './basic-input/basic-input.component';
import { InputDisabledComponent } from './input-disabled/input-disabled.component';
import { InputErrorComponent } from './input-error/input-error.component';
import { InputHintComponent } from './input-hint/input-hint.component';
import { InputWithFormFieldComponent } from './input-with-form-field/input-with-form-field.component';
import { PasswordWithFormFieldComponent } from './password-with-form-field/password-with-form-field.component';

export const INPUT_EXAMPLES = [
BasicInputComponent,
InputWithFormFieldComponent,
InputDisabledComponent,
InputErrorComponent,
PasswordWithFormFieldComponent,
InputHintComponent,
];
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<daff-form-field>
<input disabled daff-input type="text" placeholder="Email" name="email" />
<input daff-input type="text" name="email" id="disabled-input" disabled/>
<label for="disabled-input">Label</label>
</daff-form-field>
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ import {
imports: [DaffFormFieldModule, DaffInputModule],
})
export class InputDisabledComponent {

isDisabled = true;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<daff-form-field>
<input daff-input type="text" placeholder="Email" name="email" [formControl]="control" />
<input daff-input type="text" placeholder="Email" name="email" [formControl]="control" id="error-input"/>
<label for="error-input">Label</label>
@if (control.errors?.required) {
<daff-error-message>Email is a required field.</daff-error-message>
}
@if (control.errors?.email) {
<daff-error-message>Email is not valid.</daff-error-message>
}
<div class="hint">Hint goes here.</div>
</daff-form-field>
<p>Value: {{ control.value }} </p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<daff-form-field>
<input daff-input type="text" placeholder="Email" name="email" id="input-hint"/>
<label for="input-hint">Label</label>
<div class="hint">Hint goes here.</div>
</daff-form-field>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
ChangeDetectionStrategy,
Component,
} from '@angular/core';

import {
DaffFormFieldModule,
DaffInputModule,
} from '@daffodil/design';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'input-hint',
templateUrl: './input-hint.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffFormFieldModule,
DaffInputModule,
],
})
export class InputHintComponent {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<daff-form-field>
<input daff-input type="text" placeholder="Email" name="email" />
</daff-form-field>
<fa-icon [icon]="faUser" class="prefix"></fa-icon>
<input daff-input type="text" name="email" id="input" />
<label for="input">Label</label>
<fa-icon [icon]="faCircleXmark" class="suffix"></fa-icon>
</daff-form-field>
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ import {
ChangeDetectionStrategy,
Component,
} from '@angular/core';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import {
faUser,
faCircleXmark,
} from '@fortawesome/free-solid-svg-icons';

import {
DaffFormFieldModule,
DaffInputModule,
} from '@daffodil/design';


@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'input-with-form-field',
templateUrl: './input-with-form-field.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [DaffFormFieldModule, DaffInputModule],
imports: [DaffFormFieldModule, DaffInputModule, FontAwesomeModule],
})
export class InputWithFormFieldComponent {

faUser = faUser;
faCircleXmark = faCircleXmark;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<daff-form-field>
<input daff-input type="password" placeholder="Password" name="password" id="password-input" />
<!-- <input daff-input type="text" name="email" id="input"/> -->
<label for="password-input">Label</label>
</daff-form-field>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
ChangeDetectionStrategy,
Component,
} from '@angular/core';
import {
ReactiveFormsModule,
UntypedFormControl,
} from '@angular/forms';

import {
DaffFormFieldModule,
DaffInputModule,
} from '@daffodil/design';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'password-with-form-field',
templateUrl: './password-with-form-field.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [DaffFormFieldModule, DaffInputModule, ReactiveFormsModule],
})
export class PasswordWithFormFieldComponent {
control: UntypedFormControl = new UntypedFormControl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
:host {
display: block;
font-size: t.$small-font-size;
margin-top: 5px;
margin-top: 4px;
padding-left: 16px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { NgControl } from '@angular/forms';
* in javascript, they get thrown out by the typescript compiler and cannot
* be used for the necessary dependency injection.
*/
export abstract class DaffFormFieldControl {
export abstract class DaffFormFieldControl<T> {
readonly ngControl: NgControl | null;

readonly controlType?: any;

readonly focused: boolean;

abstract focus(event?: Event): void;

readonly value: T;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,33 @@
.daff-form-field {
&__control {
background: $base;
border: 1px solid theming.daff-illuminate($base, $neutral, 3);
color: theming.daff-illuminate($base-contrast, $neutral, 4);
border: 1px solid theming.daff-illuminate($base, $neutral, 6);
color: theming.daff-illuminate($base, $neutral, 6);

&:focus {
border: 1px solid $base-contrast;
&.daff-focus {
border: 1px solid theming.daff-color($primary, 'default');
}

&.daff-error {
border: 1px solid theming.daff-color(theming.$daff-red, 60);

&:focus {
border: 1px solid theming.daff-color(theming.$daff-red, 60);
}
}

&.daff-valid {
> * {
color: $base-contrast;
}
}

&:has(*:disabled),
&:has(*.isDisabled) {
border: 1px solid theming.daff-illuminate($base, $neutral, 4);
color: theming.daff-illuminate($base, $neutral, 4);
}

*:disabled,
.isDisabled {
background-color: transparent;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
<div class="daff-form-field__control" [class.daff-error]="isError" [class.daff-valid]="isValid" [class.daff-focus]="isFocused">
<ng-content></ng-content>
<div class="daff-form-field__icon" *ngIf="_control.controlType === 'native-select'">
<fa-icon [icon]="faChevronDown"></fa-icon>
</div>
<div
class="daff-form-field__control"
[class.daff-focus]="isFocused"
[class.daff-error]="isError"
[class.daff-valid]="isValid"
[class.daff-filled]="isFilled"
>
<span class="daff-form-field__icon daff-form-field__icon--prefix">
<ng-content select=".prefix"></ng-content>
</span>
<ng-content></ng-content>
<div
class="daff-form-field__icon"
*ngIf="_control.controlType === 'native-select'"
>
<fa-icon [icon]="faChevronDown"></fa-icon>
</div>
<span class="daff-form-field__icon daff-form-field__icon--suffix">
<ng-content select=".suffix"></ng-content>
</span>
</div>
<ng-content select="daff-error-message"></ng-content>
@if (_control?.ngControl?.touched) {
<ng-content select="daff-error-message"></ng-content>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,81 @@
position: relative;

&__control {
border-radius: 3px;
display: inline-block;
font-size: 1rem;
border-radius: 4px;
display: flex;
font-size: 16px;
height: inherit;
line-height: 1.5rem;
padding: 10px 15px;
line-height: 16px;
padding: 8px 16px;
max-width: 320px;
width: 100%;
position: relative;

label {
position: absolute;
left: 16px;
top: 50%;
transform: translateY(-50%);
transition: all 0.2s ease;
pointer-events: none;
}

input {
padding-top: 16px;

&:placeholder-shown ~ label,
&:focus ~ label {
top: 6px;
font-size: 12px;
transform: none;
}
}

&.daff-filled label {
top: 6px;
font-size: 12px;
transform: none;
}
}

&__icon {
display: inline-block;
pointer-events: none;
position: absolute;
right: 15px;
}
top: 50%;
transform: translateY(-50%);

&--prefix {
left: 16px;
}

&--suffix {
right: 16px;
}
}

:has(fa-icon.prefix) > label,
:has(fa-icon.prefix) > input {
padding-left: 28px;
}

.hint {
position: absolute;
top: 100%;
left: 16px;
margin-top: 8px;
font-size: 12px;
}

&:has(.hint) {
margin-bottom: 24px;

daff-error-message {
margin-top: 24px;
}

&:has(daff-error-message) {
margin-bottom: 0px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('@daffodil/design | DaffFormFieldComponent | Usage', () => {
let component: DaffFormFieldComponent;
let fixture: ComponentFixture<WrapperComponent>;
let formFieldControlElement: HTMLElement;
let control: DaffFormFieldControl;
let control: DaffFormFieldControl<unknown>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand Down
Loading
Loading