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

Color attribute: add color as an attribute to our components #7467

Closed
16 tasks done
brandyscarney opened this issue Jul 29, 2016 · 14 comments
Closed
16 tasks done

Color attribute: add color as an attribute to our components #7467

brandyscarney opened this issue Jul 29, 2016 · 14 comments
Assignees
Milestone

Comments

@brandyscarney
Copy link
Member

brandyscarney commented Jul 29, 2016

This makes dynamically changing attributes easier for the user, and it will be easier to manage internally. For example:

<button primary>Button</button>

will become

<button color="primary">Button</button>

Edit: I realized button is probably a bad example since it already has this attribute, but this will benefit components like ion-navbar as well:

<ion-navbar color="secondary">
   ...
</ion-navbar>

or

<ion-navbar [color]="barColor">
   ...
</ion-navbar>
@Component({
  templateUrl: 'build/pages/about/about.html'
})
export class AboutPage {
  barColor: string;

  constructor(private nav: NavController, platform: Platform) {
    this.barColor = platform.is('android') ? 'primary' : 'light';
  }
}

Edit: Components that will have the color input:

  • Badge
  • Button
  • Checkbox
  • Chip
  • Icon
  • Item (Item, Item Divider, List Header)
  • Label
  • Navbar
  • Radio
  • Searchbar
  • Segment
  • Spinner
  • Tabs
  • Toggle
  • Toolbar
  • Typography (headers, paragraphs, spans, etc.)
@brandyscarney brandyscarney self-assigned this Jul 29, 2016
@szerner
Copy link

szerner commented Jul 30, 2016

For 'dynamic theming' (at runtime) it would be nice to be able to write

[color]="themeColor"

or when theming is realized with normal classes:

[class]="themeClass"

@brandyscarney
Copy link
Member Author

brandyscarney commented Jul 30, 2016

@szerner Yes that is how this attribute would work. :) Updated issue to show a better example.

@brandyscarney brandyscarney added this to the 2.0.0-beta.12 milestone Aug 1, 2016
@joekukish
Copy link

@brandyscarney what about variant instead of color. It expresses better the purpose.

@szerner
Copy link

szerner commented Aug 14, 2016

I would appreciate the possibility to set the colors of the <ion-searchbar> component icons on the fly. Currently we can use some ionic Sass variables to define the colors for some of them (except the cancel-button icon, for this one I couldn't find any Sass variable) at build time, but we cannot set the colors at runtime (user defined theme).

But this might be non trivial, since the color seems to be "hard coded" into the icons SVG definition.
So I don't know, if it's possible at all to style their color via CSS. But I had to ask :-)

@brandyscarney
Copy link
Member Author

Thanks for the recommendation @joekukish. We are going to stick with color as we believe this is more universally understood. 😄

Hi @szerner, could you open a separate issue for this and I can look into it? Right now I am adding the color input to the searchbar itself, but we may need to rethink and discuss how this works. Thanks!

@joekukish
Copy link

color does not transmit the semantic of it. Either way thank you for considering it.

@szerner
Copy link

szerner commented Aug 22, 2016

@brandyscarney I opened a new issue #7826 for my suggestion.

brandyscarney added a commit that referenced this issue Aug 23, 2016
brandyscarney added a commit that referenced this issue Aug 23, 2016
…ly adding the color to the component

BREAKING CHANGES:

Colors should be passed in the `color` input on components, not added
individually as an attribute on the component.

For example:

```
<ion-tabs primary>
```

Becomes

```
<ion-tabs color=”primary”>
```

Or to bind an expression to color:

```
<ion-navbar [color]="barColor">
   ...
</ion-navbar>
```

```ts
@component({
  templateUrl: 'build/pages/about/about.html'
})
export class AboutPage {
  barColor: string;

  constructor(private nav: NavController, platform: Platform) {
    this.barColor = platform.is('android') ? 'primary' : 'light';
  }
}
```

Reason for this change:
It was difficult to dynamically add colors to components, especially if
the name of the color attribute was unknown in the template.
This change keeps the css flat since we aren’t chaining color
attributes on components and instead we assign a class to the component
which includes the color’s name.
This allows you to easily toggle a component between multiple colors.
Speeds up performance because we are no longer reading through all of
the attributes to grab the color ones.

references #7467
closes #7087 closes #7401 closes #7523
@guillenotfound
Copy link
Contributor

I think that might be useful to have ion-content here too, so we can customize it background :D

@albrecht-jun-zhang
Copy link

albrecht-jun-zhang commented Dec 1, 2016

color="primary" does enable dynamically changing color of button, but how do I dynamically change "full" attribute e.g. <button full="true/false">

@brandyscarney
Copy link
Member Author

@albrecht-jun-zhang You can use property binding for full as well:

<button ion-button [full]="isFull">Full</button>

See: https://angular.io/docs/ts/latest/guide/template-syntax.html#!#property-binding

@akkii922
Copy link

akkii922 commented Mar 5, 2017

@brandyscarney One question please.
So this will change the theme across the application or just current page?
Because i need to change the theme of the application from one click.
Is there any solution for that?

@Iyashu5040
Copy link

@akkii922 A good solution to that would be to have an injectable class for the state of the theming variables. You then inject the state in the constructor of each controller and reference the state object properties on each page using things like [color].

@kristoff2016
Copy link

Hello,
How about alert is there any way that I could change button Color attribute ?

 let alert = this.alertCtrl.create({
      title: 'Almost There!',
      subTitle: 'Please pass your phone to your staff to receive stamp',
      buttons: [{
        text: 'Next',
        cssClass: 'next-button',
        handler:()=>{
          this.navCtrl.push(RedeemStampInputPage);
        }
      }]
    });
    alert.present();

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 1, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants