From f2d4bd2c6f1d4500d70d1ba0a1a7cd76b19f0dd3 Mon Sep 17 00:00:00 2001 From: Vadim Dalecky Date: Tue, 13 Mar 2018 22:19:31 +0000 Subject: [PATCH] feat: add sheet() addon --- addon/sheet.js | 32 ++++++++++++++++++++++++++++++++ lib/index.js | 1 + 2 files changed, 33 insertions(+) create mode 100644 addon/sheet.js diff --git a/addon/sheet.js b/addon/sheet.js new file mode 100644 index 00000000..5a8d03b5 --- /dev/null +++ b/addon/sheet.js @@ -0,0 +1,32 @@ +'use strict'; + +var hash = require('../lib/hash').hash; + +exports.addonSheet = function (renderer) { + renderer.sheet = function (map, block) { + var result = {}; + + if (!block) { + block = hash(map); + } + + for (var elementModifier in map) { + var styles = map[elementModifier]; + + Object.defineProperty(result, elementModifier, { + configurable: true, + get: function () { + var classNames = this.rule(styles, block + '-' + elementModifier); + + Object.defineProperty(result, elementModifier, { + value: classNames, + }); + + return classNames; + }, + }); + } + + return result; + }; +}; diff --git a/lib/index.js b/lib/index.js index 31598c15..cf995df8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -8,6 +8,7 @@ var isClient = typeof window === 'object'; exports.create = function (h) { var renderer = { + h: h, raw: '', cns: {}, pfx: '_',