Skip to content

Commit c2869d5

Browse files
authored
Setting CSS variables using styles modifier (#219)
* Add a test that CSS variables work * Allow CSS variables in the TypeScript definition
1 parent ed9627e commit c2869d5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

addon/modifiers/style.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import type * as CSS from 'csstype';
88
// interface does _not_ included dashed CSS property names. It only includes the
99
// camelCase version of a CSS property.
1010
// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1672
11-
type CSSStyles = Partial<CSS.Properties> | Partial<CSS.PropertiesHyphen>;
11+
type CSSStyles =
12+
| Partial<CSS.Properties>
13+
| Partial<CSS.PropertiesHyphen>
14+
| { readonly [key: `--${string}`]: string };
1215

1316
function isObject(o: unknown): boolean {
1417
return typeof o === 'object' && Boolean(o);

tests/integration/modifiers/style-test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ module('Integration | Modifiers | style', function (hooks) {
5252
.hasStyle({ fontStyle: 'italic' });
5353
});
5454

55+
test('it supports CSS variables', async function (assert) {
56+
await render(
57+
hbs`<p {{style --some-property="6px" font-size="var(--some-property)"}}></p>`,
58+
);
59+
60+
assert.dom('p').hasStyle({ fontSize: '6px' });
61+
});
62+
5563
{
5664
interface Context extends TestContext {
5765
// eslint-disable-next-line @typescript-eslint/ban-types

0 commit comments

Comments
 (0)