I can not get the paper tabs selection bar to change color when I invoke changeColor(). Am I doing something wrong?
<dom-module id="paper-tabs-custom">
<style>
paper-tabs {
--paper-tabs-selection-bar-color: white;
}
paper-tab {
--paper-tab-content-unselected: {
opacity: 1.0;
}
}
paper-tab {
font-weight: 700;
}
paper-tab[name="portfolio"] {
width: 161px;
}
</style>
<template>
<paper-tabs noink="true"
attr-for-selected="name"
selected="{{setSelected}}">
<paper-tab data-name="home" data-px="240" name="home" on-tap="jumpToPage">
HOME
</paper-tab>
<paper-tab data-name="portfolio" data-px="180" name="portfolio" on-tap="jumpToPage">
PORTFOLIO
</paper-tabs>
</template>
<script>
Polymer({
is: "paper-tabs-custom",
changeColor: function() {
this.customStyle['--paper-tabs-selection-bar-color'] = 'black';
this.updateStyles();
}
});
</script>
</dom-module>
Yes, you need to set the property on <paper-tabs> directly and call updateStyles directly on it as well. Might be that just calling updateStyles on it directly will do the trick, but I am quite sure that's where the mistake is.
this.$.tabs.customStyle['--paper-tabs-selection-bar-color'] = 'black';
this.$.tabs.updateStyles();
Related
I am trying to create a simple app. It has a profile button, and when the profile button is pressed I would like it to be routed to the Userprofile page. I am quite new to Polymer and routing in general, and would appreciate if some could advice what I am doing wrong. Here is my code snippet. I am using polymer 1.6, and using app-route, app-location. I have defined them, and am using iron-pages to select the route (NOT SURE IF THAT IS CORRECT).
cst-tririga-ux.html
<!-- POLYMER IMPORTS -->
<link rel='import' href='../paper-icon-button/paper-icon-button.html'>
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-badge/paper-badge.html">
<!-- APP TOOLBAR -->
<link rel="import" href='app-layout.html'>
<!-- IRON IMPORTS -->
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../iron-pages/iron-pages.html">
<!-- TRIRIGA IMPORTS -->
<link rel="import" href="../triplat-view-behavior/triplat-view-behavior.html">
<link rel="import" href="../triplat-signout-button/triplat-signout-button.html">
<link rel="import" href="../triplat-ds/triplat-ds.html">
<!-- CUSTOM COMPONENTS -->
<link rel="import" href="profile/user-profile.html">
<link rel="import" href="notifications/notifications-view.html">
<dom-module id="cst-tririga-ux">
<template>
<style>
paper-input-container.my-class {
--paper-input-container-color: red;
--paper-input-container-focus-color: blue;
--paper-input-container-invalid-color: green;
--paper-input-container-input-color: black;
}
paper-badge {
--paper-badge-margin-left: -8px;
--paper-badge-margin-bottom: -12px;
--paper-badge-background: #D50000;
};
html, body {
margin: 0;
font-family: 'Roboto', 'Noto', sans-serif;
-webkit-font-smoothing: antialiased;
background: #f1f1f1;
max-height: 368px;
}
paper-icon-button {
--paper-icon-button-ink-color: white;
}
paper-icon-button + [main-title] {
margin-left: 24px;
}
app-header {
#apply(--layout-fixed-top);
color: #fff;
--app-header-background-rear-layer: {
background-color: #ef6c00;
};
}
app-drawer {
--app-drawer-scrim-background: rgba(0, 0, 100, 0.8);
--app-drawer-content-container: {
background-color: #f4f6f7;
}
}
app-toolbar {
/* Toolbar is the main header, so give it some color */
background-color: #1E88E5;
font-family: 'Roboto', Helvetica, sans-serif;
color: white;
--app-toolbar-font-size: 24px;
}
</style>
<!-- DECLARATIONS -->
<triplat-ds id="currentDS" name="currentUser" data="{{currentUser}}"></triplat-ds>
<triplat-ds id="myNotificationsDS" name="myNotifications" data="{{myNotifications}}"></triplat-ds>
<app-location use-hash-as-path route="{{route}}"></app-location>
<app-route route="{{route}}" pattern="/:view" data="{{routeData}}" tail="{{subroute}}"></app-route>
<body>
<app-header reveals>
<app-toolbar>
<paper-icon-button icon="menu" onclick="drawer.toggle()"></paper-icon-button>
<div main-title>Spork</div>
<paper-icon-button icon="account-circle" id="profile" on-tap="redirectToProfile"></paper-icon-button>
<paper-icon-button icon="mail" id="notifications"></paper-icon-button>
<paper-badge for="notifications" label="{{myNotifications.length}}"></paper-badge>
<triplat-signout-button></triplat-signout-button>
</app-toolbar>
<iron-pages selected="[[routeData.view]]" attr-for-selected="name">
<user-profile name="profile" route="{{subroute}}"></user-profile>
<notifications-view name="notifications" route="{{subroute}}"></notifications-view>
</iron-pages>
</app-header>
<app-drawer id="drawer" swipe-open>
<paper-menu selected="0">
<paper-item>Item One</paper-item>
<paper-item>Item Two</paper-item>
<paper-item>Item Three</paper-item>
</paper-menu>
</app-drawer>
</body>
</template>
<dom-module>
<script>
Polymer({
is: "cst-tririga-ux",
behaviors: [TriPlatViewBehavior],
// Display in browser title.
ready: function() {
var __dictionary__title = "Prudential CRE";
document.title = __dictionary__title;
},
redirectToProfile : function(el) {
var currUser = this.currentUser;
location.pathname = "/#/profile"
}
});
</script>
The user-profile and the notifications-view are just templates. Currently, when I am clicking on the my-profile button. Nothing seems to be happening. Not sure what I am doing wrong. Here is my user-profile.html
<dom-module id="user-profile">
<template>
<div>My user page</div>
</template>
</dom-module>
<script>
Polymer({
is: "user-profile",
});
</script>
I'm working on a project in polymer and while I was busy, I get this error:
Property 'response' bound to attribute 'last-response' not found in 'properties' for element 'menu-kaart'
Since I am new to polymer, I don't know what to do. I searched over the internet and I can't find the solution.
Here is the code:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html">
<dom-module id="menu-kaart">
<template>
<style>
:host {
display: block;
background-color: maroon;
padding: 15px;
color: deepskyblue;
}
body {
margin: 0px;
}
h1 {
color: antiquewhite;
text-decoration: none;
}
h3, p {
color: antiquewhite;
}
div {
color: white;
}
</style>
<iron-ajax
auto
url="/cgi-bin/menulezen.py"
handle-as="json"
last-response="{{response}}">
</iron-ajax>
<h1>Menukaart</h1>
<template is="dom-repeat" items="{{response}}">
<div>
<h3>{{item.Gerecht}}</h3>
<p>Ingredienten: {{item.Ingredienten}} <br>
Opmerkingen: {{item.Opmerkingen}}</p>
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'menu-kaart',
properties: {
}
</script>
Try modifying your script tag to
<script>
Polymer({
is: 'menu-kaart',
properties: {
response: {
type: Object
}
}
</script>
I'd also recommend you to upgrade your Polymer version to latest 1.x i.e. 1.8 or something relatively newer as Polymer has done a lot of fixes/changes since 1.3.
Lastly, i'll recommend you to read some documentations or some video tutorials to have a better understanding of Polymer
I don't want to use JQuery to do this. Currently, I've created a listview using Polymer. I'm using <template is="dom-repeat"> inside a parent div with a class of list.
The CSS is as follows. As I add new items to the list, I would like the list to scroll to the bottom automatically. Is that possible?
.list {
#apply(--layout-flex);
#apply(--layout-vertical);
position: relative;
overflow: auto;
}
You can set the div's scrollTop to scrollHeight in order to automatically scroll to the bottom:
HTMLImports.whenReady(() => {
Polymer({
is: 'x-foo',
properties: {
items: {
type: Array,
value: () => []
}
},
_addItem: function() {
this.push('items', this.items.length+1);
Polymer.RenderStatus.afterNextRender(this, () => {
this.$.list.scrollTop = this.$.list.scrollHeight;
});
}
});
});
<head>
<base href="https://polygit.org/polymer+1.7.0/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="polymer/polymer.html">
</head>
<body>
<x-foo></x-foo>
<dom-module id="x-foo">
<template>
<style>
#list {
border: solid 1px gray;
width: 100%;
height: 100px;
overflow: auto;
}
</style>
<button on-tap="_addItem">Add item</button>
<div id="list">
<template is="dom-repeat" items="[[items]]">
<div>[[item]]</div>
</template>
</div>
</template>
</dom-module>
</body>
codepen
Is it possible to use paper-tabs to swich between neon-animated pages? I followed this blog post to write the following code that should work according to the tutorial, however, it doesn't.
...
<paper-tabs selected="{{data.tabName}}" attr-for-selected="key" sticky>
<paper-tab key='foo'>Foo</paper-tab>
<paper-tab key='bar'>Bar</paper-tab>
<paper-tab key='baz'>Baz</paper-tab>
</paper-tabs>
</app-header>
<app-location route="{{route}}"></app-location>
<app-route route="{{route}}" pattern="/tabs/:tabName" data="{{data}}"></app-route>
<neon-animated-pages selected="{{data.tabName}}"
attr-for-selected="key"
entry-animation="slide-from-left-animation"
exit-animation="slide-right-animation">
<neon-animatable key='foo'> Foo </neon-animatable>
<neon-animatable key='bar'> Bar </neon-animatable>
<neon-animatable key='baz'> Baz </neon-animatable>
</neon-animated-pages>
I tried to use data-binding from paper-tabs in the app-header to neon-animatable-pages, is there still some js required?
Thanks in advance,
Stefan
As I see, problem is just by clicking on the tab it does not trigger route change so it wouldn't select the desired page. You could use links in the paper-tab elements to trigger this route change. From the docs:
To use links in tabs, add link attribute to paper-tab and put an element in paper-tab with a tabindex of -1.
So here is a complete example:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/app-route/app-route.html">
<link rel="import" href="../../bower_components/app-route/app-location.html">
<link rel="import" href="../../bower_components/paper-tabs/paper-tabs.html">
<link rel="import" href="../../bower_components/neon-animation/neon-animated-pages.html">
<link rel="import" href="../../bower_components/neon-animation/neon-animatable.html">
<link rel="import" href="../../bower_components/neon-animation/animations/slide-from-left-animation.html">
<link rel="import" href="../../bower_components/neon-animation/animations/slide-right-animation.html">
<dom-module id="my-app">
<template>
<style>
:host {
display: block;
}
paper-tabs {
background-color: grey;
--paper-tabs-selection-bar-color: white;
}
paper-tab[link] a {
#apply(--layout-horizontal);
#apply(--layout-center-center);
color: white;
text-decoration: none;
}
.page {
width: 100vw;
height: 50vh;
color: black;
font-size: 36px;
text-align: center;
vertical-align: middle;
line-height: 50vh;
}
.p1 {
background-color: yellow;
}
.p2 {
background-color: red;
}
.p3 {
background-color: cyan;
}
</style>
<app-location route="{{route}}"></app-location>
<app-route
route="{{route}}"
pattern="/:tab"
data="{{data}}"
tail="{{tail}}">
</app-route>
<div class="container">
<paper-tabs selected="{{tab}}" attr-for-selected="name">
<paper-tab name="foo" link>Foo</paper-tab>
<paper-tab name="bar" link>Bar</paper-tab>
<paper-tab name="baz" link>Baz</paper-tab>
</paper-tabs>
<neon-animated-pages selected="{{tab}}"
attr-for-selected="name"
entry-animation="slide-from-left-animation"
exit-animation="slide-right-animation">
<neon-animatable class="page p1" name="foo">Foo</neon-animatable>
<neon-animatable class="page p2" name="bar">Bar</neon-animatable>
<neon-animatable class="page p3" name="baz">Baz</neon-animatable>
</neon-animated-pages>
</div>
</template>
<script>
Polymer({
is: 'my-app',
properties: {
tab: {
type: String,
reflectToAttribute: true,
observer: '_tabChanged'
}
},
observers: [
'_routeTabChanged(data.tab)'
],
_tabChanged: function(tab) {
console.log('tab changed: ' + tab);
},
_routeTabChanged: function(tab) {
this.tab = tab || 'foo';
},
});
</script>
</dom-module>
Hey i'm trying to create a simple drag and drop. Is that possible to style an element dynamically. My code will be more explicit:
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="wireframe-view">
<template>
<div on-tap="handleTap"
style$=width:{{ width }}px; background-color:red;
>Hello, World</div>
</template>
<script>
Polymer({
is: "wireframe-view",
handleTap: function() {
this.width = 200;
}
});
</script>
This should change the width in my "style" propertie :/
If the property value contains spaces quotes are required.
style$="width:{{ width }}px; background-color:red";
Here is a method for dynamically updating the style based on the value of a bound data attribute.
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="conditional-css-example">
<style>
#tapContainer {
width: 100px;
background-color:white;
}
#tapContainer[data-tap-status$="tapped"] {
width: 200px;
background-color:red;
}
</style>
<template>
<div id="tapContainer" data-tap-status$="[[tapStatus]]" on-tap="handleTap">Tap Me!</div>
</template>
<script>
Polymer({
is: "conditional-css-example",
properties: {
tapStatus: String;
},
handleTap: function() {
this.tapStatus='tapped';
}
});
</script>