Compare commits
1 Commits
dev
...
feat/desig
Author | SHA1 | Date |
---|---|---|
Benjamin Bädorf | 18d4a90ab0 | 4 years ago |
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@ |
||||
<label |
||||
*ngFor="let option of options" |
||||
[class]="getClassListForItem(option)" |
||||
> |
||||
<input |
||||
class="op-option-list--input" |
||||
type="radio" |
||||
[attr.name]="name" |
||||
[value]="option.value" |
||||
[(ngModel)]="selected" |
||||
[disabled]="option.disabled" |
||||
/> |
||||
<div> |
||||
<p class="op-option-list--item-title">{{ option.title }}</p> |
||||
<p |
||||
*ngIf="option.description" |
||||
class="op-option-list--item-description" |
||||
[innerHTML]="option.description" |
||||
></p> |
||||
</div> |
||||
</label> |
@ -1,71 +0,0 @@ |
||||
import { |
||||
Component, |
||||
Input, |
||||
Output, |
||||
EventEmitter, |
||||
HostBinding, |
||||
forwardRef, |
||||
} from "@angular/core"; |
||||
import { |
||||
ControlValueAccessor, |
||||
NG_VALUE_ACCESSOR, |
||||
} from "@angular/forms"; |
||||
|
||||
export interface IOpOptionListOption<T> { |
||||
value:T; |
||||
title:string; |
||||
disabled?:boolean; |
||||
description?:string; |
||||
} |
||||
|
||||
export type IOpOptionListValue<T> = T|null; |
||||
|
||||
@Component({ |
||||
// Style is imported globally
|
||||
templateUrl: './option-list.component.html', |
||||
selector: 'op-option-list', |
||||
providers: [{ |
||||
provide: NG_VALUE_ACCESSOR, |
||||
useExisting: forwardRef(() => OpOptionListComponent), |
||||
multi: true, |
||||
}], |
||||
}) |
||||
export class OpOptionListComponent<T> implements ControlValueAccessor { |
||||
@HostBinding('class.op-option-list') className = true; |
||||
|
||||
@Input() options:IOpOptionListOption<T>[] = []; |
||||
@Input() name = `op-option-list-${+(new Date())}`; |
||||
@Output() selectedChange = new EventEmitter<T>(); |
||||
|
||||
private _selected:IOpOptionListValue<T> = null; |
||||
get selected() { |
||||
return this._selected; |
||||
} |
||||
set selected(value:IOpOptionListValue<T>) { |
||||
this._selected = value; |
||||
this.onChange(value); |
||||
} |
||||
|
||||
getClassListForItem(option:IOpOptionListOption<T>) { |
||||
return { |
||||
'op-option-list--item': true, |
||||
'op-option-list--item_selected': this.selected === option.value, |
||||
'op-option-list--item_disabled': !!option.disabled, |
||||
}; |
||||
} |
||||
|
||||
onChange = (_:IOpOptionListValue<T>) => {}; |
||||
onTouched = (_:IOpOptionListValue<T>) => {}; |
||||
|
||||
writeValue(value:IOpOptionListValue<T>) { |
||||
this._selected = value; |
||||
} |
||||
|
||||
registerOnChange(fn:any) { |
||||
this.onChange = fn; |
||||
} |
||||
|
||||
registerOnTouched(fn:any) { |
||||
this.onTouched = fn; |
||||
} |
||||
} |
@ -1,39 +0,0 @@ |
||||
.op-option-list |
||||
display: flex |
||||
flex-direction: column |
||||
font-size: 1rem |
||||
|
||||
// TODO: remove the [type] selector once globally overwriting styles are removed |
||||
&--input[type] |
||||
margin: 0 |
||||
margin-right: 0.5rem |
||||
|
||||
&--item |
||||
padding: 1rem 1rem 0.5rem 0.75rem |
||||
display: flex |
||||
border: 1px solid #cbd5e0 |
||||
background: #f7fafc |
||||
border-radius: 4px |
||||
|
||||
&:not(:last-child) |
||||
margin-bottom: 0.5rem |
||||
|
||||
&_selected |
||||
border: 1px solid #90cdf4 |
||||
background: #ebf8ff |
||||
|
||||
&_disabled |
||||
color: #959595 |
||||
|
||||
&-title, |
||||
&-description |
||||
margin: 0 |
||||
margin-bottom: 0.5rem |
||||
line-height: 1.2 |
||||
|
||||
&-title |
||||
font-weight: bold |
||||
font-size: 14px |
||||
|
||||
&-description |
||||
font-size: 12px |
Loading…
Reference in new issue