Skip to content
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

feat: add optional color for slide-toggle when unactivated #90

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
<mat-hint>The toggle color</mat-hint>
</mat-form-field>
</mat-list-item>
<mat-list-item role="listitem" class="color-config-container">
<mat-form-field class="full-width">
<input
matInput
type="color"
placeholder="Unchecked Color"
[formControl]="uncheckedColorFormControl"
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/> could be moved to the previous line

<mat-hint>The toggle unchecked color</mat-hint>
</mat-form-field>
</mat-list-item>
<mat-list-item role="listitem" class="disabled-config-container">
<mat-checkbox
class="full-width"
Expand All @@ -50,6 +61,7 @@
class="widget"
[checked]="checked"
[color]="colorFormControl.value"
[uncheckedColor]="uncheckedColorFormControl.value"
[disabled]="disabled"
[title]="titleFormControl.value"
(toggleChange)="checked = $event"
Expand All @@ -64,6 +76,7 @@
<span>&lt;gor-slide-toggle</span>
<span> [checked]=&quot;{{checked}}&quot;</span>
<span> [color]=&quot;{{colorFormControl.value}}&quot;</span>
<span> [uncheckedColor]=&quot;{{uncheckedColorFormControl.value}}&quot;</span>
<span> [disabled]=&quot;{{disabled}}&quot;</span>
<span> [title]=&quot;{{titleFormControl.value}}&quot;&gt;</span>
<span>&lt;/gor-slide-toggle&gt;</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FormControl } from "@angular/forms";
export class SlideToggleComponent implements OnInit {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnInit interface can be removed

checked = true;
colorFormControl = new FormControl("#08B25A");
uncheckedColorFormControl = new FormControl("#000000")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing ;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please add the access modifier for these properties

disabled = false;
titleFormControl = new FormControl("click me");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
[id]="toggle?.cod"
[checked]="toggle?.checked"
[color]="toggle?.color"
[uncheckedColor]="toggle?.uncheckedColor"
[title]="toggle?.title"
(toggleChange)="toggleChange(toggle?.cod, $event)"
ngDefaultControl
></gor-slide-toggle>
</div>
</ng-container>
</div>
</ng-container>
</ng-container>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline at end of file

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="toggle" [ngClass]="{ disabled: disabled }">
<label class="switch">
<input type="checkbox" [checked]="checked" (change)="changeChecked()" />
<span class="slider round" [style.backgroundColor]="checked ? color : ''">
<span class="slider round" [style.backgroundColor]="checked ? color : uncheckedColor">
<span class="slider-before" [ngClass]="{ active: checked }"></span>
</span>
</label>
<span class="title">{{ title }}</span>
</div>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline at end of file

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export class SlideToggleComponent {
@Input() public color = '';

/**
* The toggle color when unchecked.
*/
@Input() public uncheckedColor = '';

guilhermejcgois marked this conversation as resolved.
Show resolved Hide resolved
/**

* The toggle disable state.
*/
@Input() public disabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ export interface ToggleData {


/**
* The custom color for the toggle.
* The custom color for the toggle when activated.
* @Optional
*/
color?: string;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove extra empty line

/**
* The custom color for the toggle when unactivated.
* @Optional
*/
uncheckedColor?: string;
guilhermejcgois marked this conversation as resolved.
Show resolved Hide resolved
}
74 changes: 74 additions & 0 deletions libs/ui-toolkit/slide-toggle/src/lib/slide-toggle.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { storiesOf, moduleMetadata } from '@storybook/angular';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice stories, keep up the good work

import { CommonModule } from '@angular/common';
import { SlideToggleComponent } from './slide-toggle.component';
import { SlideToggleGroupComponent } from './slide-toggle-group.component';
import { ToggleData } from './slide-toggle.model';
import { text, withKnobs, boolean } from '@storybook/addon-knobs';

storiesOf('slide-toggle', module)
.addDecorator(
moduleMetadata({
imports: [CommonModule],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this import is necessary

declarations: [SlideToggleComponent, SlideToggleGroupComponent],
})
)
.addDecorator(withKnobs)
.add(
'three different cases about slide-toggle',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary should be descriptive of functionality being demonstrated - in this case, color configurations

() => {
const data: Array<ToggleData> = [{
cod: "1",
checked: true,
title: "activate color",
color: "#10c0c6",
uncheckedColor: ""
},
{
cod: "2",
checked: true,
title: "both colors",
color: "#10c0c6",
uncheckedColor: "#456888"
},
{
cod: "3",
checked: false,
title: "UNACTIVATE COLOR",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the title be 'Inactive'?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe 'unchecked', to keep consistency with component property

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep text capitalization consistent across titles

color: "",
uncheckedColor: "#456888"
Copy link
Contributor

@oliveira-gust oliveira-gust Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check code identation in all this file

}
];

const labels = ['title'];

return {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra empty line

template: `
<gor-slide-toggle-group
[data]='${JSON.stringify(data)}'
[labels]='${JSON.stringify(labels)}'
>
</gor-slide-toggle-group>
`
}}
)

.add('editable', () => ({
props: {
cod: text("cod","1"),
checked: boolean("checked", true),
title: text("title", "slide-toggle"),
color: text("color", "#10c0c6"),
uncheckedColor: text("uncheckedColor", "#456888"),
},
template: `
<gor-slide-toggle
[id]="cod"
[checked]="checked"
[color]="color"
[uncheckedColor]="uncheckedColor"
[title]="title"
>
</gor-slide-toggle>
`
}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline at end of file