-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(toggle): allow configuration of default options
- Loading branch information
Dima Karimov
committed
Aug 20, 2021
1 parent
b5af611
commit 52eec97
Showing
12 changed files
with
214 additions
and
35 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
projects/demo/src/modules/components/toggle/examples/2/index.html
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,13 @@ | ||
<form [formGroup]="testForm"> | ||
<div> | ||
<tui-toggle formControlName="testValue1" size="m" [showIcons]="true"> | ||
</tui-toggle> | ||
<tui-toggle | ||
class="tui-space_left-1" | ||
formControlName="testValue2" | ||
size="l" | ||
[showIcons]="true" | ||
> | ||
</tui-toggle> | ||
</div> | ||
</form> |
40 changes: 40 additions & 0 deletions
40
projects/demo/src/modules/components/toggle/examples/2/index.ts
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,40 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl, FormGroup} from '@angular/forms'; | ||
import { | ||
ToggleOptions, | ||
TUI_TOGGLE_DEFAULT_OPTIONS, | ||
TUI_TOGGLE_OPTIONS, | ||
} from '@taiga-ui/kit'; | ||
import {changeDetection} from '../../../../../change-detection-strategy'; | ||
import {encapsulation} from '../../../../../view-encapsulation'; | ||
|
||
const options: ToggleOptions = { | ||
icons: { | ||
toggleOff: ({$implicit}) => | ||
$implicit === 'm' ? 'tuiIconChevronRight' : 'tuiIconChevronRightLarge', | ||
toggleOn: ({$implicit}) => | ||
$implicit === 'm' ? 'tuiIconChevronLeft' : 'tuiIconChevronLeftLarge', | ||
}, | ||
}; | ||
|
||
@Component({ | ||
selector: 'tui-toggle-example-2', | ||
templateUrl: './index.html', | ||
changeDetection, | ||
encapsulation, | ||
providers: [ | ||
{ | ||
provide: TUI_TOGGLE_OPTIONS, | ||
useValue: { | ||
...TUI_TOGGLE_DEFAULT_OPTIONS, | ||
...options, | ||
}, | ||
}, | ||
], | ||
}) | ||
export class TuiToggleExample2 { | ||
testForm = new FormGroup({ | ||
testValue1: new FormControl(true), | ||
testValue2: new FormControl(false), | ||
}); | ||
} |
25 changes: 25 additions & 0 deletions
25
projects/demo/src/modules/components/toggle/examples/import/define-options.txt
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,25 @@ | ||
import { | ||
ToggleOptions, | ||
TUI_TOGGLE_DEFAULT_OPTIONS, | ||
TUI_TOGGLE_OPTIONS, | ||
} from '@taiga-ui/kit'; | ||
|
||
... | ||
const options: ToggleOptions = { | ||
icons: { | ||
toggleOff: ({$implicit}) => | ||
$implicit === 'm' ? 'tuiIconChevronRight' : 'tuiIconChevronRightLarge', | ||
toggleOn: ({$implicit}) => | ||
$implicit === 'm' ? 'tuiIconChevronLeft' : 'tuiIconChevronLeftLarge', | ||
}, | ||
}; | ||
|
||
@NgModule({ | ||
providers: [{ | ||
provide: TUI_TOGGLE_OPTIONS, | ||
useValue: { | ||
...TUI_TOGGLE_DEFAULT_OPTIONS, | ||
...options, | ||
} | ||
}], | ||
... |
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './toggle.component'; | ||
export * from './toggle.module'; | ||
export * from './toggle-options'; |
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,28 @@ | ||
import {InjectionToken} from '@angular/core'; | ||
import {TuiContextWithImplicit} from '@taiga-ui/cdk'; | ||
import {TuiSizeL} from '@taiga-ui/core'; | ||
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; | ||
|
||
export interface ToggleOptions { | ||
readonly icons: Readonly<{ | ||
toggleOff: PolymorpheusContent<TuiContextWithImplicit<TuiSizeL>>; | ||
toggleOn: PolymorpheusContent<TuiContextWithImplicit<TuiSizeL>>; | ||
}>; | ||
} | ||
|
||
/** Default values for the toggle options. */ | ||
export const TUI_TOGGLE_DEFAULT_OPTIONS: ToggleOptions = { | ||
icons: { | ||
toggleOff: ({$implicit}) => | ||
$implicit === 'm' ? 'tuiIconToggleOff' : 'tuiIconToggleOffLarge', | ||
toggleOn: ({$implicit}) => | ||
$implicit === 'm' ? 'tuiIconToggleOn' : 'tuiIconToggleOnLarge', | ||
}, | ||
}; | ||
|
||
export const TUI_TOGGLE_OPTIONS = new InjectionToken<ToggleOptions>( | ||
'Default parameters for toggle component', | ||
{ | ||
factory: () => TUI_TOGGLE_DEFAULT_OPTIONS, | ||
}, | ||
); |
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
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 |
---|---|---|
|
@@ -128,6 +128,10 @@ | |
} | ||
} | ||
|
||
.icon-wrapper { | ||
display: flex; | ||
} | ||
|
||
.icon { | ||
opacity: 0.8; | ||
|
||
|
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