-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(checkbox): added checkbox component (#4)
- Loading branch information
1 parent
a61fb90
commit edab661
Showing
24 changed files
with
1,991 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,45 @@ | ||
import { Component, NgModule, ViewEncapsulation } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
|
||
import { McCheckboxModule } from '../../lib/checkbox'; | ||
|
||
|
||
/* tslint:disable:no-trailing-whitespace */ | ||
@Component({ | ||
selector: 'app', | ||
styleUrls: ['./styles.css'], | ||
encapsulation: ViewEncapsulation.None, | ||
template: require('./template.html') | ||
}) | ||
export class DemoComponent { | ||
checked: boolean[] = [true, true, false]; | ||
indeterminate: boolean = true; | ||
disabled: boolean = false; | ||
labelPosition = 'after'; | ||
|
||
onCheckboxChange(val) { | ||
console.log('onCheckboxChange', val); | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [ | ||
DemoComponent | ||
], | ||
imports: [ | ||
BrowserModule, | ||
FormsModule, | ||
McCheckboxModule | ||
], | ||
bootstrap: [ | ||
DemoComponent | ||
] | ||
}) | ||
export class DemoModule { | ||
} | ||
|
||
platformBrowserDynamic() | ||
.bootstrapModule(DemoModule) | ||
.catch((error) => console.error(error)); |
This file contains 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,2 @@ | ||
@import '~@ptsecurity/mosaic-icons/dist/styles/mc-icons'; | ||
@import '../../lib/core/theming/prebuilt/default-theme'; |
This file contains 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,32 @@ | ||
<div class="mc-body"> | ||
<p> | ||
<mc-checkbox> Default</mc-checkbox> | ||
</p> | ||
|
||
<p> | ||
<mc-checkbox [(ngModel)]="checked[0]"> Checked</mc-checkbox> | ||
|
||
</p> | ||
|
||
<p> | ||
<mc-checkbox [(ngModel)]="checked[2]" [indeterminate]="true"> Indeterminate | ||
</mc-checkbox> | ||
</p> | ||
|
||
<p> | ||
<mc-checkbox [disabled]="true"> Default disabled</mc-checkbox> | ||
</p> | ||
|
||
|
||
<p> | ||
<mc-checkbox [(ngModel)]="checked" disabled="disabled"> Checked disabled | ||
</mc-checkbox> | ||
</p> | ||
|
||
<p> | ||
<mc-checkbox [(ngModel)]="checked[2]" [indeterminate]="true" disabled="disabled"> Indeterminate disabled | ||
</mc-checkbox> | ||
</p> | ||
|
||
|
||
</div> |
This file contains 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 @@ | ||
Please see the official documentation at https://github.com/positive-js/mosaic |
This file contains 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,129 @@ | ||
@import '../core/theming/theming'; | ||
@import '../core/styles/typography/typography-utils'; | ||
@import '../core/styles/variables'; | ||
|
||
@mixin mc-checkbox-theme($theme) { | ||
$hover-lighten: 5%; | ||
// main | ||
$primary: map-get($theme, primary); | ||
$second: map-get($theme, second); | ||
$background: map-get($theme, background); | ||
$foreground: map-get($theme, foreground); | ||
|
||
// focus inset shadow color | ||
$focus-border-box-shadow: inset 0 0 0 1px map-get($background, background); | ||
|
||
// background | ||
$toggle-background-unchecked: $background; | ||
$toggle-background-checked: map-get($primary, 500); | ||
$toggle-background-checked-hover: lighten($toggle-background-checked, $hover-lighten); | ||
$toggle-background-disabled: map-get($second, 40); | ||
$toggle-background-hover: map-get($background, hover); | ||
|
||
// border | ||
$toggle-border-color-checked: map-get($primary, 600); | ||
$toggle-border-color-checked-hover: lighten($toggle-border-color-checked, $hover-lighten); | ||
$toggle-border-color-unchecked: map-get($second, 300); | ||
$toggle-border-color-focus: map-get($primary, 500); | ||
$toggle-border-color-disabled: map-get($second, 100); | ||
|
||
// icon | ||
$icon-color-checked: map-get($background, background); | ||
$icon-color-disabled: map-get($second, 200); | ||
|
||
// label | ||
$label-color-disabled: map-get($foreground, disabled-text); | ||
$label-color: map-get($foreground, text); | ||
|
||
.mc-checkbox-label { | ||
color: $label-color; | ||
} | ||
|
||
.mc-checkbox-frame { | ||
border-color: $toggle-border-color-unchecked; | ||
} | ||
|
||
.mc-checkbox-checkmark, | ||
.mc-checkbox-mixedmark { | ||
color: $icon-color-checked; | ||
} | ||
|
||
.mc-checkbox:not(.mc-checkbox-disabled) { | ||
.mc-checkbox-input { | ||
&:hover { | ||
+ .mc-checkbox-frame { | ||
background-color: $toggle-background-hover; | ||
} | ||
} | ||
|
||
&:focus { | ||
+ .mc-checkbox-frame { | ||
border-color: $toggle-border-color-focus; | ||
} | ||
} | ||
} | ||
|
||
&.mc-checkbox-checked, | ||
&.mc-checkbox-indeterminate { | ||
.mc-checkbox-input { | ||
&:focus { | ||
+ .mc-checkbox-frame { | ||
border-color: $toggle-border-color-focus; | ||
box-shadow: $focus-border-box-shadow; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
.mc-checkbox-checked:not(.mc-checkbox-disabled), | ||
.mc-checkbox-indeterminate:not(.mc-checkbox-disabled) { | ||
.mc-checkbox-frame { | ||
background: $toggle-background-checked; | ||
border-color: $toggle-border-color-checked; | ||
} | ||
.mc-checkbox-input { | ||
&:hover { | ||
+ .mc-checkbox-frame { | ||
background: $toggle-background-checked-hover; | ||
border-color: $toggle-border-color-checked-hover; | ||
} | ||
} | ||
&:focus:hover { | ||
+ .mc-checkbox-frame { | ||
border-color: $toggle-border-color-focus; | ||
box-shadow: $focus-border-box-shadow; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.mc-checkbox-disabled { | ||
.mc-checkbox-frame { | ||
border-color: $toggle-border-color-disabled; | ||
background-color: $toggle-background-disabled; | ||
} | ||
|
||
.mc-checkbox-label { | ||
color: $label-color-disabled; | ||
} | ||
|
||
.mc-checkbox-checkmark, | ||
.mc-checkbox-mixedmark { | ||
color: $icon-color-disabled; | ||
} | ||
} | ||
} | ||
|
||
@mixin mc-checkbox-typography($config) { | ||
.mc-checkbox { | ||
font-family: mc-font-family($config); | ||
font-size: mc-font-size($config, body); | ||
line-height: mc-line-height($config, body); | ||
} | ||
|
||
.mc-checkbox-layout .mc-checkbox-label { | ||
line-height: mc-line-height($config, body); | ||
font-size: mc-font-size($config, body); | ||
} | ||
} |
This file contains 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,17 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
|
||
/** | ||
* Checkbox click action when user click on input element. | ||
* noop: Do not toggle checked or indeterminate. | ||
* check: Only toggle checked status, ignore indeterminate. | ||
* check-indeterminate: Toggle checked status, set indeterminate to false. Default behavior. | ||
* undefined: Same as `check-indeterminate`. | ||
*/ | ||
export type McCheckboxClickAction = 'noop' | 'check' | 'check-indeterminate' | undefined; | ||
|
||
/** | ||
* Injection token that can be used to specify the checkbox click behavior. | ||
*/ | ||
export const MC_CHECKBOX_CLICK_ACTION = | ||
new InjectionToken<McCheckboxClickAction>('mc-checkbox-click-action'); |
This file contains 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,15 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { McCommonModule } from '@ptsecurity/mosaic/core'; | ||
|
||
import { McCheckbox } from './checkbox'; | ||
import { McCheckboxRequiredValidator } from './checkbox-required-validator'; | ||
|
||
|
||
@NgModule({ | ||
imports: [CommonModule, McCommonModule], | ||
exports: [McCheckbox, McCheckboxRequiredValidator, McCommonModule], | ||
declarations: [McCheckbox, McCheckboxRequiredValidator] | ||
}) | ||
export class McCheckboxModule { | ||
} |
This file contains 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,30 @@ | ||
import { | ||
Directive, | ||
forwardRef, | ||
Provider | ||
} from '@angular/core'; | ||
import { | ||
CheckboxRequiredValidator, | ||
NG_VALIDATORS | ||
} from '@angular/forms'; | ||
|
||
|
||
export const MC_CHECKBOX_REQUIRED_VALIDATOR: Provider = { | ||
provide: NG_VALIDATORS, | ||
useExisting: forwardRef(() => McCheckboxRequiredValidator), | ||
multi: true | ||
}; | ||
|
||
/** | ||
* Validator for Mosaic checkbox's required attribute in template-driven checkbox. | ||
* Current CheckboxRequiredValidator only work with `input type=checkbox` and does not | ||
* work with `mc-checkbox`. | ||
*/ | ||
@Directive({ | ||
selector: `mc-checkbox[required][formControlName], | ||
mc-checkbox[required][formControl], mc-checkbox[required][ngModel]`, | ||
providers: [MC_CHECKBOX_REQUIRED_VALIDATOR], | ||
host: { '[attr.required]': 'required ? "" : null' } | ||
}) | ||
export class McCheckboxRequiredValidator extends CheckboxRequiredValidator { | ||
} |
Oops, something went wrong.