Skip to content

Commit

Permalink
fix: support array-as-value after prefixing
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 18, 2018
1 parent 005dd68 commit 5197e66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
11 changes: 7 additions & 4 deletions .storybook/inline-style-prefixer.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ addonPrefixer(renderer);
const {rule} = renderer;

const className1 = rule({
alignItems: 'center'
display: 'flex',
alignItems: 'center',
boxShadow: '0 0 5px red',
'text-shadow': '2px 2px #ff0000',
});

storiesOf('Addons/inline-style-prefixer', module)
.add('Default', () =>
h('div', {className: className1}, 'Hello world')
)
.add('Default', () =>
h('div', {className: className1}, 'Hello world')
)
13 changes: 10 additions & 3 deletions addon/inline-style-prefixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@ var matchCallback = function (match) {
exports.addon = function (renderer) {
var decl = renderer.decl;

renderer.toCamel = function (prop) {
renderer.camel = function (prop) {
return prop.replace(CAMEL_REGEX, matchCallback);
};

renderer.prefix = function (prop, value) {
var obj = {};
obj[renderer.toCamel(prop)] = value;
obj[renderer.camel(prop)] = value;
obj = prefixAll(obj);

var str = '';

for (var propPrefixed in obj) {
str += propPrefixed + ':' + obj[propPrefixed] + ';';
value = obj[propPrefixed];
propPrefixed = renderer.kebab(propPrefixed);

if (value instanceof Array) {
str += propPrefixed + ':' + value.join(';' + propPrefixed + ':') + ';';
} else {
str += propPrefixed + ':' + value + ';';
}
}

return str;
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ exports.create = function (config) {
client: typeof window === 'object',
assign: assign,
stringify: JSON.stringify,
toKebab: function (prop) {
kebab: function (prop) {
return prop.replace(KEBAB_REGEX, '-$&').toLowerCase();
},
decl: function (key, value) {
key = renderer.toKebab(key);
key = renderer.kebab(key);
return key + ':' + value + ';';
},
hash: function (obj) {
Expand Down

0 comments on commit 5197e66

Please sign in to comment.