mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 04:53:58 +08:00
fix(segment): add disabled property to segment and segment button
rename Sass variables for opacity for consistency references #5639
This commit is contained in:
@ -8,11 +8,14 @@ $segment-button-ios-background-color: transparent !default;
|
|||||||
$segment-button-ios-background-color-activated: $toolbar-ios-active-color !default;
|
$segment-button-ios-background-color-activated: $toolbar-ios-active-color !default;
|
||||||
|
|
||||||
$segment-button-ios-text-color: color-contrast($colors-ios, $segment-button-ios-background-color-activated) !default;
|
$segment-button-ios-text-color: color-contrast($colors-ios, $segment-button-ios-background-color-activated) !default;
|
||||||
$segment-button-ios-activated-transition: 100ms all linear !default;
|
$segment-button-ios-transition-activated: 100ms all linear !default;
|
||||||
$segment-button-ios-hover-transition: 100ms all linear !default;
|
$segment-button-ios-transition-hover: 100ms all linear !default;
|
||||||
$segment-button-ios-active-transition: 100ms all linear !default;
|
$segment-button-ios-transition-active: 100ms all linear !default;
|
||||||
$segment-button-ios-hover-opacity: .1 !default;
|
|
||||||
$segment-button-ios-active-opacity: .16 !default;
|
$segment-button-ios-opacity-hover: .1 !default;
|
||||||
|
$segment-button-ios-opacity-active: .16 !default;
|
||||||
|
$segment-button-ios-opacity-activated: 1 !default;
|
||||||
|
$segment-button-ios-opacity-disabled: .3 !default;
|
||||||
|
|
||||||
$segment-button-ios-border-width: 1px !default;
|
$segment-button-ios-border-width: 1px !default;
|
||||||
$segment-button-ios-height: 3.2rem !default;
|
$segment-button-ios-height: 3.2rem !default;
|
||||||
@ -55,18 +58,18 @@ $segment-button-ios-toolbar-icon-line-height: 2.4rem !default;
|
|||||||
&.segment-activated {
|
&.segment-activated {
|
||||||
color: $segment-button-ios-text-color;
|
color: $segment-button-ios-text-color;
|
||||||
background-color: $segment-button-ios-background-color-activated;
|
background-color: $segment-button-ios-background-color-activated;
|
||||||
opacity: 1;
|
opacity: $segment-button-ios-opacity-activated;
|
||||||
transition: $segment-button-ios-activated-transition;
|
transition: $segment-button-ios-transition-activated;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover:not(.segment-activated) {
|
&:hover:not(.segment-activated) {
|
||||||
background-color: rgba($segment-button-ios-background-color-activated, $segment-button-ios-hover-opacity);
|
background-color: rgba($segment-button-ios-background-color-activated, $segment-button-ios-opacity-hover);
|
||||||
transition: $segment-button-ios-hover-transition;
|
transition: $segment-button-ios-transition-hover;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:active:not(.segment-activated) {
|
&:active:not(.segment-activated) {
|
||||||
background-color: rgba($segment-button-ios-background-color-activated, $segment-button-ios-active-opacity);
|
background-color: rgba($segment-button-ios-background-color-activated, $segment-button-ios-opacity-active);
|
||||||
transition: $segment-button-ios-active-transition;
|
transition: $segment-button-ios-transition-active;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:first-of-type {
|
&:first-of-type {
|
||||||
@ -87,6 +90,12 @@ $segment-button-ios-toolbar-icon-line-height: 2.4rem !default;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.segment-button-disabled {
|
||||||
|
color: rgba($segment-button-ios-background-color-activated, $segment-button-ios-opacity-disabled);
|
||||||
|
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
|
||||||
ion-segment {
|
ion-segment {
|
||||||
@ -117,16 +126,18 @@ $segment-button-ios-toolbar-icon-line-height: 2.4rem !default;
|
|||||||
|
|
||||||
@mixin ios-segment-button($color-name, $color-base, $color-contrast) {
|
@mixin ios-segment-button($color-name, $color-base, $color-contrast) {
|
||||||
|
|
||||||
ion-segment[#{$color-name}] .segment-button {
|
ion-segment[#{$color-name}] {
|
||||||
|
|
||||||
|
.segment-button {
|
||||||
border-color: $color-base;
|
border-color: $color-base;
|
||||||
color: $color-base;
|
color: $color-base;
|
||||||
|
|
||||||
&:hover:not(.segment-activated) {
|
&:hover:not(.segment-activated) {
|
||||||
background-color: rgba($color-base, $segment-button-ios-hover-opacity);
|
background-color: rgba($color-base, $segment-button-ios-opacity-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
&:active:not(.segment-activated) {
|
&:active:not(.segment-activated) {
|
||||||
background-color: rgba($color-base, $segment-button-ios-active-opacity);
|
background-color: rgba($color-base, $segment-button-ios-opacity-active);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.segment-activated {
|
&.segment-activated {
|
||||||
@ -135,6 +146,12 @@ $segment-button-ios-toolbar-icon-line-height: 2.4rem !default;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.segment-button-disabled {
|
||||||
|
color: rgba($color-base, $segment-button-ios-opacity-disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ $segment-button-md-border-color-activated: $toolbar-md-active-color !default
|
|||||||
$segment-button-md-border-bottom-width: 2px !default;
|
$segment-button-md-border-bottom-width: 2px !default;
|
||||||
$segment-button-md-border-bottom-color: rgba(#000, .10) !default;
|
$segment-button-md-border-bottom-color: rgba(#000, .10) !default;
|
||||||
|
|
||||||
|
$segment-button-md-opacity: .7 !default;
|
||||||
|
$segment-button-md-opacity-activated: 1 !default;
|
||||||
|
$segment-button-md-opacity-disabled: .3 !default;
|
||||||
|
|
||||||
$segment-button-md-padding: 0 6px !default;
|
$segment-button-md-padding: 0 6px !default;
|
||||||
$segment-button-md-height: 4.2rem !default;
|
$segment-button-md-height: 4.2rem !default;
|
||||||
$segment-button-md-line-height: 4rem !default;
|
$segment-button-md-line-height: 4rem !default;
|
||||||
@ -37,7 +41,7 @@ $segment-button-md-icon-line-height: $segment-button-md-line-height !d
|
|||||||
|
|
||||||
color: $segment-button-md-text-color-activated;
|
color: $segment-button-md-text-color-activated;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
opacity: .7;
|
opacity: $segment-button-md-opacity;
|
||||||
transition: 100ms all linear;
|
transition: 100ms all linear;
|
||||||
|
|
||||||
ion-icon {
|
ion-icon {
|
||||||
@ -48,10 +52,16 @@ $segment-button-md-icon-line-height: $segment-button-md-line-height !d
|
|||||||
&.activated,
|
&.activated,
|
||||||
&.segment-activated {
|
&.segment-activated {
|
||||||
border-color: $segment-button-md-border-color-activated;
|
border-color: $segment-button-md-border-color-activated;
|
||||||
opacity: 1;
|
opacity: $segment-button-md-opacity-activated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.segment-button-disabled {
|
||||||
|
opacity: $segment-button-md-opacity-disabled;
|
||||||
|
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
|
||||||
ion-segment {
|
ion-segment {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {Directive, Component, ElementRef, Renderer, Optional, EventEmitter, Input, Output, HostListener, ContentChildren, QueryList, ViewEncapsulation} from 'angular2/core';
|
import {Directive, Component, ElementRef, Renderer, Optional, EventEmitter, Input, Output, HostListener, ContentChildren, QueryList, ViewEncapsulation} from 'angular2/core';
|
||||||
import {NgControl} from 'angular2/common';
|
import {NgControl} from 'angular2/common';
|
||||||
|
|
||||||
import {isPresent} from '../../util/util';
|
import {isTrueProperty, isPresent} from '../../util/util';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,6 +56,7 @@ import {isPresent} from '../../util/util';
|
|||||||
encapsulation: ViewEncapsulation.None,
|
encapsulation: ViewEncapsulation.None,
|
||||||
})
|
})
|
||||||
export class SegmentButton {
|
export class SegmentButton {
|
||||||
|
private _disabled: boolean = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @input {string} the value of the segment button. Required.
|
* @input {string} the value of the segment button. Required.
|
||||||
@ -69,6 +70,26 @@ export class SegmentButton {
|
|||||||
|
|
||||||
constructor(private _renderer: Renderer, private _elementRef: ElementRef) {}
|
constructor(private _renderer: Renderer, private _elementRef: ElementRef) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
get disabled(): boolean {
|
||||||
|
return this._disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
set disabled(val: boolean) {
|
||||||
|
this._disabled = isTrueProperty(val);
|
||||||
|
this.setCssClass('segment-button-disabled', this._disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
setCssClass(cssClass: string, shouldAdd: boolean) {
|
||||||
|
this._renderer.setElementClass(this._elementRef.nativeElement, cssClass, shouldAdd);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* On click of a SegmentButton
|
* On click of a SegmentButton
|
||||||
@ -146,6 +167,7 @@ export class SegmentButton {
|
|||||||
selector: 'ion-segment'
|
selector: 'ion-segment'
|
||||||
})
|
})
|
||||||
export class Segment {
|
export class Segment {
|
||||||
|
private _disabled: boolean = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -170,6 +192,25 @@ export class Segment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
get disabled(): boolean {
|
||||||
|
return this._disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
set disabled(val: boolean) {
|
||||||
|
this._disabled = isTrueProperty(val);
|
||||||
|
|
||||||
|
if (this._buttons) {
|
||||||
|
let buttons = this._buttons.toArray();
|
||||||
|
for (let button of buttons) {
|
||||||
|
button.setCssClass('segment-button-disabled', this._disabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* Write a new value to the element.
|
* Write a new value to the element.
|
||||||
@ -199,6 +240,11 @@ export class Segment {
|
|||||||
if (isPresent(this.value)) {
|
if (isPresent(this.value)) {
|
||||||
button.isActive = (button.value === this.value);
|
button.isActive = (button.value === this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isTrueProperty(this._disabled)) {
|
||||||
|
button.setCssClass('segment-button-disabled', this._disabled);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ $segment-button-wp-background-color: transparent !default;
|
|||||||
|
|
||||||
$segment-button-wp-opacity: .5 !default;
|
$segment-button-wp-opacity: .5 !default;
|
||||||
$segment-button-wp-opacity-activated: 1 !default;
|
$segment-button-wp-opacity-activated: 1 !default;
|
||||||
|
$segment-button-wp-opacity-disabled: .3 !default;
|
||||||
|
|
||||||
$segment-button-wp-buttons-justify-content: flex-start !default;
|
$segment-button-wp-buttons-justify-content: flex-start !default;
|
||||||
|
|
||||||
@ -50,6 +51,12 @@ ion-segment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.segment-button-disabled {
|
||||||
|
opacity: $segment-button-wp-opacity-disabled;
|
||||||
|
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
|
||||||
ion-segment {
|
ion-segment {
|
||||||
|
@ -13,15 +13,20 @@ class MyApp {
|
|||||||
modelStyle: string = 'B';
|
modelStyle: string = 'B';
|
||||||
appType: string = 'free';
|
appType: string = 'free';
|
||||||
icons: string = 'camera';
|
icons: string = 'camera';
|
||||||
|
isDisabled: boolean = true;
|
||||||
|
|
||||||
myForm;
|
myForm;
|
||||||
|
|
||||||
constructor(fb: FormBuilder) {
|
constructor(fb: FormBuilder) {
|
||||||
this.myForm = fb.group({
|
this.myForm = fb.group({
|
||||||
mapStyle: ['hybrid', Validators.required]
|
mapStyle: ['active', Validators.required]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleDisabled() {
|
||||||
|
this.isDisabled = !this.isDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
onSegmentChanged(segmentButton) {
|
onSegmentChanged(segmentButton) {
|
||||||
console.log("Segment changed to", segmentButton.value);
|
console.log("Segment changed to", segmentButton.value);
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,14 @@
|
|||||||
|
|
||||||
<form (submit)="doSubmit($event)" [ngFormModel]="myForm">
|
<form (submit)="doSubmit($event)" [ngFormModel]="myForm">
|
||||||
<ion-segment ngControl="mapStyle" danger>
|
<ion-segment ngControl="mapStyle" danger>
|
||||||
<ion-segment-button value="standard" class="e2eSegmentStandard">
|
<ion-segment-button value="active" class="e2eSegmentStandard">
|
||||||
Standard
|
Active
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
<ion-segment-button value="hybrid">
|
<ion-segment-button value="disabled" [disabled]="isDisabled">
|
||||||
Hybrid
|
Disabled
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
<ion-segment-button value="sat">
|
<ion-segment-button value="inactive" disabled="false">
|
||||||
Satellite
|
Inactive
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
</ion-segment>
|
</ion-segment>
|
||||||
</form>
|
</form>
|
||||||
@ -74,7 +74,7 @@
|
|||||||
<ion-segment-button value="C" class="e2eSegmentModelC">
|
<ion-segment-button value="C" class="e2eSegmentModelC">
|
||||||
Model C
|
Model C
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
<ion-segment-button value="D">
|
<ion-segment-button value="D" [disabled]="isDisabled">
|
||||||
Model D
|
Model D
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
</ion-segment>
|
</ion-segment>
|
||||||
@ -89,6 +89,8 @@
|
|||||||
<ion-icon name="bookmark"></ion-icon>
|
<ion-icon name="bookmark"></ion-icon>
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
</ion-segment>
|
</ion-segment>
|
||||||
|
|
||||||
|
<button block dark (click)="toggleDisabled()">Toggle Disabled</button>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
||||||
<ion-toolbar position="bottom" primary>
|
<ion-toolbar position="bottom" primary>
|
||||||
@ -100,7 +102,7 @@
|
|||||||
Toolbar
|
Toolbar
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
<ion-segment-button value="top" class="e2eSegmentTopGrossing">
|
<ion-segment-button value="top" class="e2eSegmentTopGrossing">
|
||||||
Default Segment
|
Light Segment
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
</ion-segment>
|
</ion-segment>
|
||||||
</ion-toolbar>
|
</ion-toolbar>
|
||||||
@ -108,7 +110,7 @@
|
|||||||
<ion-toolbar position="bottom">
|
<ion-toolbar position="bottom">
|
||||||
<ion-segment [(ngModel)]="appType" danger>
|
<ion-segment [(ngModel)]="appType" danger>
|
||||||
<ion-segment-button value="paid">
|
<ion-segment-button value="paid">
|
||||||
Light
|
Default
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
<ion-segment-button value="free">
|
<ion-segment-button value="free">
|
||||||
Toolbar
|
Toolbar
|
||||||
@ -120,15 +122,15 @@
|
|||||||
</ion-toolbar>
|
</ion-toolbar>
|
||||||
|
|
||||||
<ion-toolbar position="bottom">
|
<ion-toolbar position="bottom">
|
||||||
<ion-segment [(ngModel)]="appType" dark>
|
<ion-segment [(ngModel)]="appType" dark [disabled]="isDisabled">
|
||||||
<ion-segment-button value="paid">
|
<ion-segment-button value="paid">
|
||||||
Light
|
Default
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
<ion-segment-button value="free">
|
<ion-segment-button value="free">
|
||||||
Toolbar
|
Toolbar
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
<ion-segment-button value="top">
|
<ion-segment-button value="top">
|
||||||
Default Segment
|
Dark Segment
|
||||||
</ion-segment-button>
|
</ion-segment-button>
|
||||||
</ion-segment>
|
</ion-segment>
|
||||||
</ion-toolbar>
|
</ion-toolbar>
|
||||||
|
Reference in New Issue
Block a user