Skip to content

Commit

Permalink
Ignore CSS Custom properties in kebabifyStyleName
Browse files Browse the repository at this point in the history
Allow setting CSS Custom property values in various casing with StyleSheet.create/css by ignoring those keys in kebabifyStyleName utility
  • Loading branch information
dmiller9911 committed Aug 14, 2018
1 parent 62ee2f0 commit a864974
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const UPPERCASE_RE = /([A-Z])/g;
const UPPERCASE_RE_TO_KEBAB = (match /* : string */) /* : string */ => `-${match.toLowerCase()}`;

export const kebabifyStyleName = (string /* : string */) /* : string */ => {
if (string.substring(0, 2) === '--') {
return string;
}
const result = string.replace(UPPERCASE_RE, UPPERCASE_RE_TO_KEBAB);
if (result[0] === 'm' && result[1] === 's' && result[2] === '-') {
return `-${result}`;
Expand Down
3 changes: 3 additions & 0 deletions tests/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ describe('Utils', () => {
it('forces -ms-', () => {
assert.equal(kebabifyStyleName('msFooBarBaz'), '-ms-foo-bar-baz');
});
it('does not kebabify CSS Custom properties', () => {
assert.equal(kebabifyStyleName('--foo-Bar_Baz'), '--foo-Bar_Baz');
});
});
});

0 comments on commit a864974

Please sign in to comment.