-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kit):
Toggle
allow configuring default options (#635)
Co-authored-by: Dima Karimov <[email protected]>
- Loading branch information
Showing
13 changed files
with
295 additions
and
24 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
<form [formGroup]="testForm"> | ||
<div> | ||
<tui-toggle formControlName="testValue1"></tui-toggle> | ||
<tui-toggle | ||
class="tui-space_left-1" | ||
formControlName="testValue2" | ||
size="l" | ||
> | ||
</tui-toggle> | ||
</div> | ||
</form> |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
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: Partial<ToggleOptions> = { | ||
icons: { | ||
toggleOff: ({$implicit}) => | ||
$implicit === 'm' ? 'tuiIconChevronRight' : 'tuiIconChevronRightLarge', | ||
toggleOn: ({$implicit}) => | ||
$implicit === 'm' ? 'tuiIconChevronLeft' : 'tuiIconChevronLeftLarge', | ||
}, | ||
showIcons: true, | ||
}; | ||
|
||
@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: Partial<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-options'; | ||
export * from './toggle.component'; | ||
export * from './toggle.module'; |
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,36 @@ | ||
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>>; | ||
}>; | ||
readonly singleColor: boolean; | ||
readonly showIcons: boolean; | ||
readonly size: TuiSizeL; | ||
} | ||
|
||
/** Default values for the toggle options. */ | ||
export const TUI_TOGGLE_DEFAULT_OPTIONS: ToggleOptions = { | ||
icons: { | ||
toggleOff({$implicit}: TuiContextWithImplicit<TuiSizeL>): string { | ||
return $implicit === 'm' ? 'tuiIconToggleOff' : 'tuiIconToggleOffLarge'; | ||
}, | ||
toggleOn({$implicit}: TuiContextWithImplicit<TuiSizeL>): string { | ||
return $implicit === 'm' ? 'tuiIconToggleOn' : 'tuiIconToggleOnLarge'; | ||
}, | ||
}, | ||
singleColor: false, | ||
showIcons: false, | ||
size: 'm', | ||
}; | ||
|
||
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
Oops, something went wrong.