Skip to content

Commit

Permalink
feat(design): add all basic form field inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
gracetxgao committed Dec 14, 2024
1 parent a8ea9b1 commit 6136791
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 25 deletions.
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,6 @@
<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>
<div class="error">Error message goes here.</div>
</daff-form-field>
<p>Value: {{ control.value }} </p>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<daff-form-field>
<input daff-input type="text" placeholder="Email" name="email" />
</daff-form-field>
<!-- <input daff-input type="text" placeholder="Email" name="email" [formControl]="control" id="input" /> -->
<input daff-input type="text" name="email" [formControl]="control" id="input"/>
<label for="input">Label</label>
</daff-form-field>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import {
ChangeDetectionStrategy,
Component,
} from '@angular/core';
import {
ReactiveFormsModule,
UntypedFormControl,
} from '@angular/forms';

import {
DaffFormFieldModule,
Expand All @@ -14,8 +18,8 @@ import {
templateUrl: './input-with-form-field.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [DaffFormFieldModule, DaffInputModule],
imports: [DaffFormFieldModule, DaffInputModule, ReactiveFormsModule],
})
export class InputWithFormFieldComponent {

control: UntypedFormControl = new UntypedFormControl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,37 @@
$neutral: core.daff-map-deep-get($theme, 'core.neutral');

.daff-form-field {
&:has(.error) .error {
color: theming.daff-color(theming.$daff-red, 60);
}

&__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(input:disabled) {
border: 1px solid theming.daff-illuminate($base, $neutral, 4);
color: theming.daff-illuminate($base, $neutral, 4);
}

input:disabled {
background-color: transparent;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<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"
[class.daff-disabled]="isDisabled"
>
<ng-content></ng-content>
<div
class="daff-form-field__icon"
*ngIf="_control.controlType === 'native-select'"
>
<fa-icon [icon]="faChevronDown"></fa-icon>
</div>
</div>
<ng-content select="daff-error-message"></ng-content>
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,60 @@
display: block;
position: relative;

&:has(.error) {
padding-bottom: 32px;
}

&__control {
border-radius: 3px;
border-radius: 4px;
display: inline-block;
font-size: 1rem;
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;
right: 16px;
}

.error {
position: absolute;
top: 100%;
left: 16px;
padding-top: 8px;
font-size: 12px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,24 @@ export class DaffFormFieldComponent implements DoCheck, AfterContentInit, AfterC
*/
isError = false;

/**
* Tracking property to keep a record of whether or not the
* form field contains any user input.
*/
isFilled = false;

/**
* Tracking property to keep a record of whether or not the
* form field should be marked as valid.
*/
isValid = false;

/**
* Tracking property to keep a record of whether or not the
* form field should be marked as disabled.
*/
// isDisabled = false;

/**
* @docs
*
Expand All @@ -79,6 +91,8 @@ export class DaffFormFieldComponent implements DoCheck, AfterContentInit, AfterC
if(this._control?.ngControl) {
this.isError = this._control.ngControl.errors && (this._control.ngControl.touched);
this.isValid = !this._control.ngControl.errors && this._control.ngControl.touched;
this.isFilled = !!this._control.ngControl.value;
// this.isDisabled = this._control.ngControl.disabled;
}
}

Expand Down

0 comments on commit 6136791

Please sign in to comment.