1
votes

I'm using Polymer 1.0 Starter Kit. I'm trying to change toolbar's background and color when changing routes.

<paper-scroll-header-panel main id="headerPanelMain" condenses keep-condensed-header
    header-height="256" condensed-header-height="100">
    <paper-toolbar>
      <paper-icon-button id="paperToggle" icon="menu" paper-drawer-toggle></paper-icon-button>
      <span class="space"></span>
      <!-- Toolbar icons -->
      <nt-toolbar-icons></nt-toolbar-icons>
      <!-- Application name -->
      <div class="middle middle-container">
        <div class="app-name">[[route.title]]</div>
      </div>
      <!-- Application sub title -->
      <div class="bottom bottom-container">
        <div class="bottom-title">[[route.subline]]</div>
      </div>
    </paper-toolbar>
    <div style="height: 1400px;">
      <iron-pages attr-for-selected="data-route" selected="{{route.name}}">
        <section data-route="home">
          {{route.title}} /
        </section>
        <section data-route="users">
          users {{route.params.type}}
        </section>
      </iron-pages>
    </div>
  </paper-scroll-header-panel>
</paper-drawer-panel>

Route is defined in elements/routing.html

page('/', function() {
    app.route = {
      name: 'home',
      title: 'noTos+',
      subline: ''
    }
  });

In my shared-styles.html my toolbar is defined this way:

paper-scroll-header-panel#headerPanelMain {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: var(--paper-grey-200, #eee);

      /* background for toolbar when it is at its full size */
      --paper-scroll-header-panel-full-header: {
        background-image: url(../images/headers/bg4.jpg);
      }
      /* background for toolbar when it is condensed */
      --paper-scroll-header-panel-condensed-header: {
        background-color: var(--paper-light-blue-600);
      }
    }

But now I want this color/background-scheme to be changed when the route is changed. I've tried adding data-route$="[[route.name]]" to paper-scroll-header-panel. Then I've changed shared-styles.html with the [data-route="home"] selector:

paper-scroll-header-panel#headerPanelMain[data-route="home"] {
    --paper-scroll-header-panel-full-header: {
        background-image: url(../images/headers/bg3.jpg); //BG CHANGES HERE
      }
}

But this doesn't work. Any other ideas?

2

2 Answers

1
votes

Custom styles are only applied at creation time. If you have dynamic changes like you do here, you need to call updateStyles on you custom element or Polymer.updateStyles for a global update. In your case, you would do that when the route changes. You can find more info in the documentation.

1
votes

you can do the following.

<paper-toolbar id="mainToolbar" class="tall" style$={{computedStyleHandler(color)}}>


computedStyleHandler: function(color){
  return 'background-color:' + color + ';'
}