Skip to content

Commit 68387a0

Browse files
fix(KeyboardSearch): allow custom key styles inside a preset Keyboard (#484)
* fix(Keyboard): add nested Keyboard Search styles for number keys * fix(withThemeStyles): update tone/mode filtering for colors to return value * fix: roll back base theme changes * fix(KeyboardSearch): remove unused imports from story * fix: update withThemeStyles utils tests --------- Co-authored-by: David Richards, Jr <[email protected]>
1 parent ef67bc8 commit 68387a0

File tree

5 files changed

+103
-45
lines changed

5 files changed

+103
-45
lines changed

packages/@lightningjs/ui-components/src/components/Keyboard/Keyboard.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,24 @@ export default class Keyboard extends Base {
151151
};
152152

153153
if (typeof keyProps === 'object') {
154-
// keyId is used to account for localization
155-
const iconName = keyProps.keyId || keyProps.title;
156-
const keyIcon =
157-
this.style.keyProps?.[keyboard]?.[iconName] ||
158-
this.style.keyProps?.[iconName];
159-
160-
if (keyIcon && keyIcon.icon) {
161-
return {
162-
...key,
163-
...keyProps,
164-
...this.style.keyProps?.[iconName],
165-
style: {
166-
iconStyle: {
167-
...keyIcon.iconStyle
168-
}
169-
},
170-
size: keyIcon.size || keyProps.size
154+
// keyId is used to account for style overrides on individual keys,
155+
// icon updates, and localization
156+
const keyName = keyProps.keyId || keyProps.title;
157+
const keyOverrides =
158+
this.style.keyProps?.[keyboard]?.[keyName] ||
159+
this.style.keyProps?.[keyName] ||
160+
{};
161+
const keyPatch = { ...key, ...keyProps, ...keyOverrides };
162+
163+
if (keyOverrides?.icon) {
164+
keyPatch.style = {
165+
...keyOverrides.style,
166+
iconStyle: {
167+
...keyOverrides.iconStyle
168+
}
171169
};
172170
}
173-
return { ...key, ...keyProps };
171+
return keyPatch;
174172
}
175173
return { ...key, title: keyProps };
176174
});

packages/@lightningjs/ui-components/src/components/Keyboard/KeyboardSearch.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,22 @@ export default class KeyboardSearch extends Keyboard {
4040
['G', 'H', 'I', 'J', 'K', 'L'],
4141
['M', 'N', 'O', 'P', 'Q', 'R'],
4242
['S', 'T', 'U', 'V', 'W', 'X'],
43-
['Y', 'Z', '1', '2', '3', '4'],
44-
['5', '6', '7', '8', '9', '0'],
43+
[
44+
'Y',
45+
'Z',
46+
{ title: '1', keyId: 'number' },
47+
{ title: '2', keyId: 'number' },
48+
{ title: '3', keyId: 'number' },
49+
{ title: '4', keyId: 'number' }
50+
],
51+
[
52+
{ title: '5', keyId: 'number' },
53+
{ title: '6', keyId: 'number' },
54+
{ title: '7', keyId: 'number' },
55+
{ title: '8', keyId: 'number' },
56+
{ title: '9', keyId: 'number' },
57+
{ title: '0', keyId: 'number' }
58+
],
4559
[
4660
{
4761
title: 'Space',

packages/@lightningjs/ui-components/src/components/Keyboard/KeyboardSearch.stories.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
*/
1818

1919
import lng from '@lightningjs/core';
20-
import context from '../../globals/context/index';
21-
import utils from '../../utils';
2220
import { default as KeyboardSearchComponent } from './KeyboardSearch';
2321
import { Keyboard } from './Keyboard.stories';
2422

@@ -31,10 +29,8 @@ export const KeyboardSearch = () =>
3129
static _template() {
3230
return {
3331
Keyboard: {
34-
type: KeyboardSearchComponent,
35-
defaultFormat: 'uppercase'
36-
},
37-
w: utils.getWidthByUpCount(context.theme, 3)
32+
type: KeyboardSearchComponent
33+
}
3834
};
3935
}
4036
};

packages/@lightningjs/ui-components/src/mixins/withThemeStyles/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ export const colorParser = (targetObject, styleObj) => {
556556

557557
// Process style object and remove unnecessary properties
558558
const processedStyle = JSON.stringify(styleObj, (_, value) => {
559-
if (-1 < ['tone', 'mode'].indexOf(_)) return undefined; // Remove any tone/mode or mode/tone properties as they have already been processed
559+
if (-1 < ['tone', 'mode'].indexOf(_)) return value; // Remove any tone/mode or mode/tone properties as they have already been processed
560560
if ('string' === typeof value && value.startsWith('theme.')) {
561561
// Support theme strings example: theme.radius.md
562562
return getValFromObjPath(targetObject, value); // If no theme value exists, the property will be removed from the object

packages/@lightningjs/ui-components/src/mixins/withThemeStyles/utils.test.js

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -880,15 +880,40 @@ describe('generateComponentStyleSource', () => {
880880
});
881881

882882
expect(source).toStrictEqual({
883-
unfocused_neutral: { color: 'primary' },
884-
unfocused_inverse: { color: 'primary' },
885-
unfocused_brand: { color: 'primary' },
886-
focused_neutral: { color: 'primary' },
887-
focused_inverse: { color: 'primary' },
888-
focused_brand: { color: 'primary' },
889-
disabled_neutral: { color: 'primary' },
890-
disabled_inverse: { color: 'primary' },
891-
disabled_brand: { color: 'primary' }
883+
unfocused_neutral: {
884+
color: 'primary',
885+
mode: { unfocused: { color: 'primary' } }
886+
},
887+
unfocused_inverse: {
888+
color: 'primary',
889+
mode: { unfocused: { color: 'primary' } }
890+
},
891+
unfocused_brand: {
892+
color: 'primary',
893+
mode: { unfocused: { color: 'primary' } }
894+
},
895+
focused_neutral: {
896+
mode: { unfocused: { color: 'primary' } }
897+
},
898+
focused_inverse: {
899+
color: 'primary',
900+
mode: { unfocused: { color: 'primary' } }
901+
},
902+
focused_brand: {
903+
color: 'primary',
904+
mode: { unfocused: { color: 'primary' } }
905+
},
906+
disabled_neutral: {
907+
mode: { unfocused: { color: 'primary' } }
908+
},
909+
disabled_inverse: {
910+
color: 'primary',
911+
mode: { unfocused: { color: 'primary' } }
912+
},
913+
disabled_brand: {
914+
color: 'primary',
915+
mode: { unfocused: { color: 'primary' } }
916+
}
892917
});
893918
});
894919

@@ -908,15 +933,40 @@ describe('generateComponentStyleSource', () => {
908933
});
909934

910935
expect(source).toStrictEqual({
911-
unfocused_neutral: { color: 'primary' },
912-
unfocused_inverse: { color: 'primary' },
913-
unfocused_brand: { color: 'primary' },
914-
focused_neutral: { color: 'primary' },
915-
focused_inverse: { color: 'primary' },
916-
focused_brand: { color: 'primary' },
917-
disabled_neutral: { color: 'primary' },
918-
disabled_inverse: { color: 'primary' },
919-
disabled_brand: { color: 'primary' }
936+
unfocused_neutral: {
937+
color: 'primary',
938+
tone: { neutral: { color: 'primary' } }
939+
},
940+
unfocused_inverse: {
941+
tone: { neutral: { color: 'primary' } }
942+
},
943+
unfocused_brand: {
944+
tone: { neutral: { color: 'primary' } }
945+
},
946+
focused_neutral: {
947+
color: 'primary',
948+
tone: { neutral: { color: 'primary' } }
949+
},
950+
focused_inverse: {
951+
color: 'primary',
952+
tone: { neutral: { color: 'primary' } }
953+
},
954+
focused_brand: {
955+
color: 'primary',
956+
tone: { neutral: { color: 'primary' } }
957+
},
958+
disabled_neutral: {
959+
color: 'primary',
960+
tone: { neutral: { color: 'primary' } }
961+
},
962+
disabled_inverse: {
963+
color: 'primary',
964+
tone: { neutral: { color: 'primary' } }
965+
},
966+
disabled_brand: {
967+
color: 'primary',
968+
tone: { neutral: { color: 'primary' } }
969+
}
920970
});
921971
});
922972
});

0 commit comments

Comments
 (0)