Struggling with integrating a mixin in your Polymer project?

I'm experiencing difficulties trying to implement a mixin in Polymer. I have created --test-theme, but it seems that the style is not being applied inside the element. Any suggestions on where I might be making a mistake?

story-card.html

<dom-module id="story-card">

  <style>
    :host {
      display: block;
      box-sizing: border-box;
    }
    #story-card {
      min-height: 5em;
      max-width: 45%;
      margin-left: auto;
      margin-right: auto;
      padding: 1em;
    }
    #story-card .story-content {
      font-family: 'Roboto', sans-serif;
      font-size: 1.2em;
      @apply(--test-theme);
    }
    #story-card .story-button-container {
      font-family: 'Roboto', sans-serif;
      font-size: 1.2em;
      margin-bottom: 1em;
      width: 100%;
      overflow: auto;
      white-space: nowrap;
    }
    #story-card .story-button-container .fab-button {
      float: right;
      display: inline-block;
      margin-left: 0.5em;
      margin-bottom: 0.1em;
      --paper-fab-background: rgb(233, 74, 47);
    }
  </style>

  <template>

    <paper-material id="story-card" elevation="3">

      <div class="story-button-container">

        <paper-fab icon="delete" class="fab-button" elevated="2" disabled$="[[signedIn]]" animated></paper-fab>

        <paper-fab icon="create" class="fab-button" elevated="2" disabled$="[[signedIn]]" on-click="editClickHandler" animated></paper-fab>

      </div>

      <span class="story-content" hidden$="[[!editing]]">{{storyContent}}</span>

      <paper-textarea label="Edit Card" value="{{storyContent}}" hidden$="[[editing]]"></paper-textarea>

    </paper-material>

  </template>

</dom-module>

<script>
  Polymer({
    is: 'story-card',
    properties: {
      storyContent: {
        type: String,
        value: ''
      },
      signedIn: {
        type: Boolean,
        value: false
      }
    },
    // Element Lifecycle
    ready: function() {

      this.editing = true;

    },
    editClickHandler: function () {
      this.editing = !this.editing;
    }
  });
</script>

index.html

    <html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="mobile-web-app-capable" content="yes">
    <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
    <link rel="import" href="../story-card.html">

    <style is="custom-style">
    story-card {
      --test-theme: {
          font-family: Verdana;
          font-size: 5em;
        };
    }
    </style>

    <title>story-card Demo</title>

  </head>

  <body>

    <template is="dom-bind" id="app">

      <p>An example of <code>&lt;story-card&gt;</code>:</p>

      <story-card class="story-card" story-content="[[storyContent]]"></story-card>

    </template>

    <script>
      ( function ( document ) {
        var app = document.querySelector( '#app' );
        app.storyContent = "Test content";
      })( document );
    </script>

  </body>

</html>

I anticipated that the text Test Content would appear larger and in verdana, however, it seems to be using the style within the element instead of applying the style in index.html. Any tips on how I can resolve this issue?

Answer №1

When assigning properties, use the correct syntax:

Instead of --test-theme {, write it as --test-theme: {

After simplification from #story-card .story-content { ... to .story-content { ...,

The issue is resolved when running your test.

To view the updated code example, visit the link below:

http://jsbin.com/zozute/edit?html,output

I will investigate further to determine the underlying cause of this behavior.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

problem with arranging photos and captions

When viewing this page in a narrow browser window, an issue arises with how the photo captions are displayed at the bottom of the page. It's evident that the caption extends past the right edge of the photo. My preference would be for the photo and c ...

I created an image that can be clicked on, but unfortunately it only functions properly on the

I am currently working on creating an image that can be clicked to cycle through different images all within the same frame. While I have managed to get it to work, I am facing a limitation where it only responds to one click. count = 1; function myF ...

Creating a div element with a fixed size that remains the same regardless of its content

Check out the code snippet below for displaying an image and title: <div id="eventsCollapsed" class="panel-collapse collapse" ng-controller="videoController"> <div class="panel-body"> <div ...

Stopping the parent onclick event from propagating to a child element within a bootstrap modal

I am currently working with angularjs and bootstrap, incorporating nested onclick events using Angular's ng-click in various HTML elements. One is located in a table header to display different sort icons and execute the sorting logic when the header ...

Steps for modifying the CSS style of a div element following an onclick event:

<html> <head> <style type="text/css"> .step_box { border: 1.0px solid rgb(204, 204, 204); border-radius: 10.0px 10.0px 10.0px 10.0px; } .step_box:hover{ background: rgb(184, 225, 252); } .selected { background-color : #fff000; ...

Experiencing an issue with referrer: The global symbol needs an explicit package name

my $refer = $ENV{HTTP_REFERER}; my $gk1 = substr($str1, -4); if ($gk1 = .swf) { my $antigk = "gk detected"; } else { my $antigk = $link; } I am encountering issues with this code after making some modifications. What could be causing the errors? I ...

Guide on attaching an event to every dynamically created element in JavaScript

I'm currently generating 'li' elements dynamically using a loop and running into issues when it comes to assigning events to each generated element. My goal is to assign an onclick event to every li element that is created. Check out the co ...

Limit the display of an element to a single occurrence by utilizing jQuery cookies

I have a unique piece of HTML and JS code that showcases an eye-catching modal box. This remarkable feature is present on every page of my website. However, to enhance the user experience, I would like to ensure that this div element is displayed only once ...

The issue with Angular.js webpage routing seems to persist in my single-page application (SPA) despite my utilization of ng-view

I'm having trouble inserting a view into my index.html using $routeProvider and ng-view from the AngularJS libraries. Can anyone assist me in figuring out why it's not being inserted? Below is the code for my index.html, views, and app.js files: ...

Center an element on the screen by dynamically adjusting its position according to the media query

As I work on creating a responsive website that can adapt to screens of various devices, I am facing a challenge. Each device has a different number of pixels, making it difficult to centrally position a div dynamically. Currently, I am using margin-left: ...

Enhance the appearance of your Vuejs application with conditional style formatting

I want to enhance a basic table by applying conditional CSS styles to the cells based on their values. For example: If area1 == 'one', then assign the td-one CSS style. <tr v-for="version in versions" :key="version.id"> < ...

Tricky problem with z-index - how to position a CSS3 triangle under the menu

Hey there, thank you for taking the time to look into my issue. I'm currently working on a menu design that I would like to resemble this example: The key feature here is creating triangular shapes on either side and positioning them beneath the men ...

Combining 2 rows in an HTML table: A step-by-step guide

Can anyone help me figure out how to merge the first row and second row of a table in HTML? I have already merged two rows, but I am having trouble merging the first and second rows together. This is how I want my rows to be merged: |-------------------- ...

How can you trigger a modal to appear when an image is clicked?

There are images inside <div> tags. When one of the images is clicked, a modal appears to display information about the specific image. Each modal has a unique id or class, such as modal4. My example: <image type="image" src="Images/Drake.jpg" ...

I am struggling to remove the div from its normal flow as it stubbornly remains positioned below

Is there a way to add a "contact" card to my website's right-top corner in a sticky position? I currently have a div block in that area which is blocking the contact card. Can anyone suggest a solution for this? https://i.stack.imgur.com/umC7B.jpg &l ...

Revamp HTML <font size=1-7> with the use of CSS or JavaScript

I've been developing a prototype application that incorporates a plugin utilizing the deprecated HTML feature. Can I set custom pixel sizes for each font size ranging from 1 to 7? Currently, I'm contemplating using CSS zoom/scale properties, bu ...

Switching from a vertical to horizontal tab layout in Angular 4 Material 2 using MD-Gridlist

I'm currently trying to modify the tabbing functionality within an MD-Gridlist so that it tabs horizontally instead of vertically. I've experimented with tab indexes but haven't had any success. My goal is to enable horizontal tabbing throug ...

Build a dynamic table by leveraging JSON with the power of JavaScript and HTML

I'm currently working on creating a table where information is stored and updated (not appended) in a JSON file using JavaScript and HTML. The structure of my JSON data looks like this: [{ "A": { "name": "MAK", "height": 170, ...

Color the text differently if the values are not the same (CSS and jQuery only)

In my code snippet below, you can see a set of HTML elements with specific classes and values: <div class="verizon-data-duplicate-device-key-89148000004605691537 k-content k-state-active" style="float: left; opacity: 1; display: block; ...

Performing date comparison in JavaScript with varying date formats

My system includes a table that retrieves dates from an FTP location. On the user interface page, there is a form that gathers all details related to a specific FTP date. However, I am facing difficulties in comparing the FTP dates with those specified in ...