Skip to content

Commit

Permalink
fix: bug in generateStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
joshhowenstine committed Nov 6, 2023
1 parent acbcae3 commit 51cb832
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23681,7 +23681,7 @@ exports[`KeyboardInput renders 1`] = `
"visible": true,
"w": 1920,
"x": 0,
"y": 20,
"y": 110,
"zIndex": 0,
},
},
Expand All @@ -23690,7 +23690,7 @@ exports[`KeyboardInput renders 1`] = `
"enabled": true,
"flex": false,
"flexItem": false,
"h": 20,
"h": 110,
"isComponent": undefined,
"mount": 0,
"mountX": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export default class StyleManager extends lng.EventEmitter {
if (!style) {
// Style does not exist so will also need to be generated
style = generateStyle(this.component, styleSource);

this._addCache(`style_${mode}_${tone}`, style);
}
this._props = style.props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,21 +675,12 @@ export const generateStyle = (component, componentStyleSource = {}) => {
if (!isPlainObject(component)) return {};
const { mode = 'unfocused', tone = 'neutral' } = component;

const style =
return (
componentStyleSource[`${mode}_${tone}`] ||
componentStyleSource[`unfocused_${tone}`] ||
componentStyleSource['unfocused_neutral'] ||
{};

const componentStyle = component._componentLevelStyle;
if (componentStyle) {
return formatStyleObj(
clone(style, colorParser(component, componentStyle)),
component.constructor.aliasStyles
);
}

return formatStyleObj(style, component.constructor.aliasStyles);
{}
);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1352,36 +1352,6 @@ describe('generateStyle', () => {
expect(generatedStyle).toEqual(expectedStyle);
});

it('should handle componentStyle and aliasStyles', () => {
const component = {
mode: 'focused',
tone: 'brand',
_componentLevelStyle: {
fontSize: '24'
},
constructor: {
aliasStyles: [
{ prev: 'fontSize', curr: 'fs' } // Alias style
]
}
};

const componentStyleSource = {
focused_brand: {
color: 'red'
}
};

const generatedStyle = generateStyle(component, componentStyleSource);

const expectedStyle = {
fs: '24', // Alias style applied
color: 'red'
};

expect(generatedStyle).toEqual(expectedStyle);
});

it('should return an empty object for non-object component', () => {
const component = 'not an object';

Expand Down

0 comments on commit 51cb832

Please sign in to comment.