-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(selection-list): Selection-list initial version all code(without demo) #5562
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
Merged
mmalerba
merged 13 commits into
angular:master
from
sllethe:selection-list-initialVersionAllcode
Aug 12, 2017
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
114cbd9
# This is a combination of 4 commits.
sllethe 341e9da
add lib files for sticky-header
sllethe 7f72853
fix after rebase
sllethe 9a87582
73975a9
3328d6e
remove unused import
sllethe 748cfca
1d64782
7a30b48
022caa3
63111b6
9f8a170
ae84d3b
Deleted unused import
sllethe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="mat-list-item-content" [class.mat-list-item-content-reverse]="checkboxPosition == 'after'" [class.mat-list-item-disabled]="disabled"> | ||
<div class="mat-list-item-ripple" md-ripple | ||
[mdRippleTrigger]="_getHostElement()" | ||
[mdRippleDisabled]="!isRippleEnabled()"> | ||
</div> | ||
|
||
<md-pseudo-checkbox [state]="selected ? 'checked' : 'unchecked'" #autocheckbox [disabled]="disabled"></md-pseudo-checkbox> | ||
<div class="mat-list-text"><ng-content></ng-content></div> | ||
|
||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { | ||
AfterContentInit, | ||
Component, | ||
ContentChildren, | ||
ElementRef, | ||
Input, | ||
Optional, | ||
QueryList, | ||
Renderer2, | ||
ViewEncapsulation, | ||
ChangeDetectionStrategy, | ||
OnDestroy, | ||
EventEmitter, | ||
Output, | ||
HostBinding, | ||
ChangeDetectorRef | ||
} from '@angular/core'; | ||
import {coerceBooleanProperty, MdLine, MdLineSetter} from '../core'; | ||
import {FocusableOption} from '../core/a11y/focus-key-manager'; | ||
import {MdSelectionList} from './selection-list'; | ||
|
||
export interface MdSelectionListOptionEvent { | ||
option: MdListOption; | ||
} | ||
|
||
const FOCUSED_STYLE: string = 'mat-list-item-focus'; | ||
|
||
/** | ||
* Component for list-options of selection-list. Each list-option can automatically | ||
* generate a checkbox and can put current item into the selectionModel of selection-list | ||
* if the current item is checked. | ||
*/ | ||
@Component({ | ||
moduleId: module.id, | ||
selector: 'md-list-option, mat-list-option', | ||
host: { | ||
'role': 'option', | ||
'class': 'mat-list-item mat-list-option', | ||
'(focus)': '_handleFocus()', | ||
'(blur)': '_handleBlur()', | ||
'(click)': '_handleClick()', | ||
'tabindex': '-1', | ||
'[attr.aria-selected]': 'selected.toString()', | ||
'[attr.aria-disabled]': 'disabled.toString()', | ||
}, | ||
templateUrl: 'list-option.html', | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class MdListOption implements AfterContentInit, OnDestroy, FocusableOption { | ||
private _lineSetter: MdLineSetter; | ||
private _disableRipple: boolean = false; | ||
private _selected: boolean = false; | ||
/** Whether the checkbox is disabled. */ | ||
private _disabled: boolean = false; | ||
private _value: any; | ||
|
||
/** Whether the option has focus. */ | ||
_hasFocus: boolean = false; | ||
|
||
/** | ||
* Whether the ripple effect on click should be disabled. This applies only to list items that are | ||
* part of a selection list. The value of `disableRipple` on the `md-selection-list` overrides | ||
* this flag | ||
*/ | ||
@Input() | ||
get disableRipple() { return this._disableRipple; } | ||
set disableRipple(value: boolean) { this._disableRipple = coerceBooleanProperty(value); } | ||
|
||
@ContentChildren(MdLine) _lines: QueryList<MdLine>; | ||
|
||
/** Whether the label should appear before or after the checkbox. Defaults to 'after' */ | ||
@Input() checkboxPosition: 'before' | 'after' = 'after'; | ||
|
||
/** Whether the option is disabled. */ | ||
@Input() | ||
get disabled() { return (this.selectionList && this.selectionList.disabled) || this._disabled; } | ||
set disabled(value: any) { this._disabled = coerceBooleanProperty(value); } | ||
|
||
@Input() | ||
get value() { return this._value; } | ||
set value( val: any) { this._value = coerceBooleanProperty(val); } | ||
|
||
@Input() | ||
get selected() { return this._selected; } | ||
set selected( val: boolean) { this._selected = coerceBooleanProperty(val); } | ||
|
||
/** Emitted when the option is focused. */ | ||
onFocus = new EventEmitter<MdSelectionListOptionEvent>(); | ||
|
||
/** Emitted when the option is selected. */ | ||
@Output() selectChange = new EventEmitter<MdSelectionListOptionEvent>(); | ||
|
||
/** Emitted when the option is deselected. */ | ||
@Output() deselected = new EventEmitter<MdSelectionListOptionEvent>(); | ||
|
||
/** Emitted when the option is destroyed. */ | ||
@Output() destroyed = new EventEmitter<MdSelectionListOptionEvent>(); | ||
|
||
constructor(private _renderer: Renderer2, | ||
private _element: ElementRef, | ||
private _changeDetector: ChangeDetectorRef, | ||
@Optional() public selectionList: MdSelectionList) { } | ||
|
||
|
||
ngAfterContentInit() { | ||
this._lineSetter = new MdLineSetter(this._lines, this._renderer, this._element); | ||
|
||
if (this.selectionList.disabled) { | ||
this.disabled(true); | ||
} | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.destroyed.emit({option: this}); | ||
} | ||
|
||
toggle(): void { | ||
this.selected = !this.selected; | ||
this.selectionList.selectedOptions.toggle(this); | ||
this._changeDetector.markForCheck(); | ||
} | ||
|
||
/** Allows for programmatic focusing of the option. */ | ||
focus(): void { | ||
this._element.nativeElement.focus(); | ||
this.onFocus.emit({option: this}); | ||
} | ||
|
||
/** Whether this list item should show a ripple effect when clicked. */ | ||
isRippleEnabled() { | ||
return !this.disableRipple && !this.selectionList.disableRipple; | ||
} | ||
|
||
_handleClick() { | ||
if (!this.disabled) { | ||
this.toggle(); | ||
} | ||
} | ||
|
||
_handleFocus() { | ||
this._hasFocus = true; | ||
this._renderer.addClass(this._element.nativeElement, FOCUSED_STYLE); | ||
} | ||
|
||
_handleBlur() { | ||
this._renderer.removeClass(this._element.nativeElement, FOCUSED_STYLE); | ||
} | ||
|
||
/** Retrieves the DOM element of the component host. */ | ||
_getHostElement(): HTMLElement { | ||
return this._element.nativeElement; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do position, box-sizing, and height need to be here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted position, box-sizing, and height