How to get Google fonts (Varela Round) to work in Polymer 1.1 web component? -


question:

in polymer 1.1 context, how include external font (like google font, or font-awesome) used dom-module?

i aware polymer favours using style-module. i'm aware technique preload font html , import dom-module. still can't work.

goal of <circle-x></circle-x> component:

my dom-module give circles these images <h1> below styled. under flexbox structure lay them out responsively according how many circles there are.

enter image description here

what tried (tldr version) used rel="import" font.html style-module <circle-x> components, can't use font style (it works when used sans-serif), means selector right. google-inspected , google-font stylesheet loaded in <circle-x> component page.

what tried (detail):

<!-- file structure --> + circle-x.html + typography-x.html + varela-round.html + bower-components + - polymer     - polymer.html + - webcomponentsjs        - webcomponents.js 

in polymer files, noticed there's file called roboto.html, made file similar that.

<!-- varela-round.html --> <link rel="import" ref="https://fonts.googleapis.com/css?family=varela+round> 

then there's typography.html reference roberto.html

<!-- typography.html --> <link rel="import" href="../polymer/polymer.html"> <link rel="import" href="../font-roboto/roboto.html">  <style is="custom-style">  :root {     --paper-font-common-base: {       font-family: 'roboto', 'noto', sans-serif;       -webkit-font-smoothing: antialiased;     }; } 

and made own version of typography-x.html varela round font:

<!-- typography-x.html --> <link rel="import" href="bower_components/polymer/polymer.html"> <link rel="import" href="varela-round.html"> <style is="custom-style">     :root {         --circle-x-font-base: {             font-family: 'varela round';         };     } </style> 

now in own module, called circle-x.html, try use font, no luck.

<head>       <script src="bower_components/webcomponentsjs/webcomponents.js"></script>    <link rel="import" href="bower_components/polymer/polymer.html"> <link rel="import" href="typography-x.html"> </head>     <dom-module id="circle-x">     <template>         <style is="custom-style">              .font{                 font-family: var(--circle-x-font-base, sans-serif);                 color: var(--circle-x-color, #353b39);                 font-size: var(--circle-x-font-size, 2rem);                 margin: 1rem auto 2rem;             }              .wrapper{                 display: flex;                 flex-wrap: wrap;                 width: 200px;                 margin: 20px;                 height: 250px;             }             .img{                 position: relative;                 width:200px;                 height:200px;                 border-radius: 50%;                 background-color: #e2e4e3;                 box-shadow: 2px 2px 2px gray;             }             .img img{                 width:100px;                 height:100px;             }             .img:hover{                 box-shadow: 5px 5px 5px gray;                 cursor: pointer;             }             .placeholder{                 position: absolute;                 right:50px;                 bottom:50px;             }         </style>         <div class="wrapper">             <a href="{{href}}" class="img">                 <img class="placeholder" src="{{img}}">             </a>             <h2 class="font">{{text}}</h2>         </div>     </template> </dom-module> <script>     polymer({             is: "circle-x",             properties:{                 img: {                     type:string,                     value:"http://www.placehold.it/100x100?text=img"                 },                 href: {                     type:string,                     value:"http://lightandlovehome.org"                 },                 text: {                     type:string,                     value: "test"                 }             }     }); </script> 

ultimately, want set default font other roberto sets of elements, , use css variable change them when need to. reading, have watched/ read lot of youtube videos, articles, , polymer site/documentation can't find solution.

i twitter @ebidel , said should use import , gave me link, felt did. https://github.com/polymerelements/font-roboto/blob/master/roboto.html

so there's 3 problems.

the first font not being loaded because has wrong rel. shouldn't rel="import" should rel="stylesheet"

<link href='https://fonts.googleapis.com/css?family=varela+round' rel='stylesheet' type='text/css'> 

the second you're creating mixin trying use regular custom property. read through guide again: https://www.polymer-project.org/1.0/docs/devguide/styling.html#xscope-styling-details

you want do:

--circle-x-font-base: 'varela round' 

instead of

--circle-x-font-base: {   font-family: 'varela round' } 

but third problem way crazier , not fault. looks custom properties shim won't apply values string "var" in them.

--circle-x-font-base: varela round 

will silently fail because has word "var" in it. try different font name doesn't contain word "var" , you'll see applied. opened github issue this: https://github.com/polymer/polymer/issues/2660


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -