Skip to content

Commit

Permalink
fix(back-button): get the back button color working
Browse files Browse the repository at this point in the history
refactors the structure / classes of back button to match the default
button more
  • Loading branch information
brandyscarney committed Apr 9, 2018
1 parent 5f9b74c commit 5f4250b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 16 deletions.
14 changes: 13 additions & 1 deletion core/src/components/back-button/back-button.ios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// iOS Back Button
// --------------------------------------------------

.back-button-ios .back-button-inner {
.back-button-ios {
@include padding(0);
@include margin(2px, 0, 0, 0);

Expand Down Expand Up @@ -37,3 +37,15 @@

pointer-events: none;
}


// Generate iOS Back Button Colors
// --------------------------------------------------

@each $color-name, $color-value in $colors-ios {
$base-color: ion-color($colors-ios, $color-name, base, ios);

.back-button-ios-#{$color-name} {
color: $base-color;
}
}
14 changes: 13 additions & 1 deletion core/src/components/back-button/back-button.md.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// MD Back Button
// --------------------------------------------------

.back-button-md .back-button-inner {
.back-button-md {
@include margin(2px, 6px, 0, 0);
@include padding(0, 5px);

Expand Down Expand Up @@ -38,3 +38,15 @@

pointer-events: none;
}


// Generate Material Design Back Button Colors
// --------------------------------------------------

@each $color-name, $color-value in $colors-md {
$base-color: ion-color($colors-md, $color-name, base, md);

.back-button-md-#{$color-name} {
color: $base-color;
}
}
2 changes: 1 addition & 1 deletion core/src/components/back-button/back-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
font-kerning: none;
}

.back-button .button-inner {
.back-button-inner {
display: flex;

flex-flow: row nowrap;
Expand Down
45 changes: 33 additions & 12 deletions core/src/components/back-button/back-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Element, Prop } from '@stencil/core';
import { Config } from '../../index';
import { openURL } from '../../utils/theme';
import { createThemedClasses, getElementClassMap, openURL } from '../../utils/theme';

@Component({
tag: 'ion-back-button',
Expand All @@ -14,6 +14,17 @@ import { openURL } from '../../utils/theme';
})
export class BackButton {

@Element() el: HTMLElement;

@Prop({ context: 'config' }) config: Config;

/**
* The color to use from your Sass `$colors` map.
* Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`.
* For more information, see [Theming your App](/docs/theming/theming-your-app).
*/
@Prop() color: string;

/**
* The mode determines which platform styles to use.
* Possible values are: `"ios"` or `"md"`.
Expand All @@ -22,18 +33,20 @@ export class BackButton {
@Prop() mode: 'ios' | 'md';

/**
* The text property is used to provide custom text for the back button while using the
* default look-and-feel.
* The url to navigate back to by default when there is no history.
*/
@Prop() text: string|undefined;
@Prop() defaultHref: string;

/**
* The icon name to use for the back button.
*/
@Prop() icon: string;

@Prop() defaultHref: string;

@Prop({ context: 'config' }) config: Config;
/**
* The text to display in the back button.
*/
@Prop() text: string | undefined;

@Element() el: HTMLElement;

private onClick(ev: Event) {
const nav = this.el.closest('ion-nav');
Expand All @@ -56,14 +69,22 @@ export class BackButton {
render() {
const backButtonIcon = this.icon || this.config.get('backButtonIcon', 'arrow-back');
const backButtonText = this.text != null ? this.text : this.config.get('backButtonText', 'Back');
const themedClasses = createThemedClasses(this.mode, this.color, 'back-button');

const backButtonClasses = {
...themedClasses,
...getElementClassMap(this.el.classList),
};

return (
<button
class='back-button-inner'
class={backButtonClasses}
onClick={(ev) => this.onClick(ev)}>
{ backButtonIcon && <ion-icon name={backButtonIcon}/> }
{ this.mode === 'ios' && backButtonText && <span class='button-text'>{backButtonText}</span> }
{ this.mode === 'md' && <ion-ripple-effect tapClick={true}/> }
<span class='back-button-inner'>
{ backButtonIcon && <ion-icon name={backButtonIcon}/> }
{ this.mode === 'ios' && backButtonText && <span class='button-text'>{backButtonText}</span> }
{ this.mode === 'md' && <ion-ripple-effect tapClick={true}/> }
</span>
</button>
);
}
Expand Down
31 changes: 30 additions & 1 deletion core/src/components/back-button/test/preview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,48 @@ <h1>Page Two</h1>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button color="danger" text="Text!" icon="add"></ion-back-button>
<ion-back-button text="Text!" icon="add"></ion-back-button>
</ion-buttons>
<ion-title>Page Three</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<h1>Page Three</h1>
<p>Custom back button</p>
<ion-button class="next">Go to Page Four</ion-button>
</ion-content>
`;

// okay cool, we're in the DOM now
await nav.push(thirdPage);

const nextButton = thirdPage.querySelector('ion-button .next');
nextButton.addEventListener('click', async () => {
await goToPageFour(nav);
});
}

async function goToPageFour(nav) {
const fourthPage = document.createElement('div');
fourthPage.classList.add('fourth-page');
fourthPage.innerHTML = `
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-menu-button auto-hide="false"></ion-menu-button>
<ion-back-button color="danger"></ion-back-button>
</ion-buttons>
<ion-title>Page Four</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<h1>Page Four</h1>
<p>Back button and menu button</p>
</ion-content>
`;

// okay cool, we're in the DOM now
await nav.push(fourthPage);
}
</script>
</html>

0 comments on commit 5f4250b

Please sign in to comment.