UNPKG

@gongt/ts-stl-client

Version:
51 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const create_logger_1 = require("@gongt/ts-stl-library/debug/create-logger"); const levels_1 = require("@gongt/ts-stl-library/debug/levels"); exports.prefixAll = require('inline-style-prefixer/static'); const warn = create_logger_1.createLogger(levels_1.LOG_LEVEL.WARN, 'auto-style'); function AutoStyle(styleMap) { Object.keys(styleMap).forEach((key) => { styleMap[key] = exports.prefixAll(styleMap[key]); if (key === 'default') { return; } styleMap[key] = Object.assign({}, styleMap.default, styleMap[key]); }); return (target, propertyKey) => { const stateKey = 's_' + propertyKey.toString(); if (!target.state) { target.state = {}; } Object.defineProperty(target, propertyKey, { get() { return styleMap[this.state[stateKey] || 'default']; }, set(type) { if (!styleMap[type]) { warn('styleMap "%s.%s" do not have key "%s"', target.constructor.name, propertyKey, type); } this.setState({ [stateKey]: type }); }, }); }; } exports.AutoStyle = AutoStyle; function AutoStyleProp(styleMap) { Object.keys(styleMap).forEach((key) => { if (key === 'default') { return; } styleMap[key] = Object.assign({}, styleMap.default, styleMap[key]); }); return (target, propertyKey) => { const stateKey = 's_' + propertyKey.toString(); Object.defineProperty(target, propertyKey, { get() { return styleMap[this.props[stateKey] || 'default']; }, }); }; } exports.AutoStyleProp = AutoStyleProp; //# sourceMappingURL=auto-style.js.map