Skip to content

Commit e365115

Browse files
authored
feat(web_core): expose theme from ComponentContext (#1027)
1 parent 94c1c9b commit e365115

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

renderers/web_core/src/v0_9/rendering/component-context.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,20 @@ describe('ComponentContext', () => {
6161
const context = new ComponentContext(mockSurface, componentId, '/foo/bar');
6262
assert.strictEqual(context.dataContext.path, '/foo/bar');
6363
});
64+
65+
it('exposes theme from surface', () => {
66+
const theme = {primaryColor: '#FF5733'};
67+
const themedSurface = new SurfaceModel('themed', {} as any, theme);
68+
const comp = new ComponentModel('c1', 'Text', {});
69+
themedSurface.componentsModel.addComponent(comp);
70+
71+
const context = new ComponentContext(themedSurface, 'c1');
72+
assert.deepStrictEqual(context.theme, theme);
73+
assert.strictEqual(context.theme.primaryColor, '#FF5733');
74+
});
75+
76+
it('exposes empty theme when none provided', () => {
77+
const context = new ComponentContext(mockSurface, componentId);
78+
assert.deepStrictEqual(context.theme, {});
79+
});
6480
});

renderers/web_core/src/v0_9/rendering/component-context.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export class ComponentContext {
3434
readonly dataContext: DataContext;
3535
/** The collection of all component models for the current surface, allowing lookups by ID. */
3636
readonly surfaceComponents: SurfaceComponentsModel;
37+
/** The theme configuration for the surface this component belongs to. */
38+
readonly theme: any;
3739

3840
/**
3941
* Creates a new component context.
@@ -53,6 +55,7 @@ export class ComponentContext {
5355
}
5456
this.componentModel = model;
5557
this.surfaceComponents = surface.componentsModel;
58+
this.theme = surface.theme;
5659

5760
this.dataContext = new DataContext(surface, dataModelBasePath);
5861
this._actionDispatcher = action =>

0 commit comments

Comments
 (0)