From b9e4b78e6ab89a3cf10054db954a565131adc7bf Mon Sep 17 00:00:00 2001 From: Doug Miller Date: Tue, 14 Aug 2018 15:46:42 -0400 Subject: [PATCH] Ignore CSS Custom properties in kebabifyStyleName Allow setting CSS Custom property values in various casing with StyleSheet.create/css by ignoring those keys in kebabifyStyleName utility Fixes: #339 --- src/util.js | 3 +++ tests/util_test.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/util.js b/src/util.js index 72733db..18d507e 100644 --- a/src/util.js +++ b/src/util.js @@ -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}`; diff --git a/tests/util_test.js b/tests/util_test.js index 1b2d774..7c61fc6 100644 --- a/tests/util_test.js +++ b/tests/util_test.js @@ -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'); + }); }); });