GithubHelp home page GithubHelp logo

meteor-template-styles's Introduction

Template styles

Make your template styles reactive.

##Installation##

meteor add mpowaga:template-styles

##Example##

<template name="hello">
  <button>Click me</button>
  <p class="message">You've pressed the button {{counter}} times.</p>
</template>
Template.hello.styles({
  '.message': function() {
    if (Session.get('counter') % 2 == 0) {
      return { color: 'red' };
    }
  },

  'button': {
    fontSize: function() {
      return Session.get('counter') + 10 + 'px';
    }
  }
});

Template.hello.events({
  'click button': function() {
    Session.set('counter', Session.get('counter') + 1);
  }
})

##Stoping computation##

computation object is passed to every function call.

e.g.

Template.hello.styles({
  'button': function(computation) {
    var counter = Session.get('counter');

    if (counter > 30) {
      return computation.stop();
    }

    return {
      fontSize: counter + 10 + 'px'
    };
  }
});

##Details##

styles function takes an object which keys are valid css selectors. Value of this object should be a function that returns an object with css attribute-value pairs. It can be also an object which keys are css attributes and value is specified as function that returns css value. Alternatively you can create an array of both.

e.g.

Template.hello.styles({
  'button': [
    function() {
      if (Session.get('counter') % 2 == 0) {
        return { color: 'red' };
      }
    },

    {
      fontSize: function() {
        return Session.get('counter') + 10 + 'px';
      }
    }
  ]
})

Attribute names and values will be passed to jquery.css method.

meteor-template-styles's People

Contributors

mpowaga avatar

Stargazers

#кодеротбога avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.