Skip to content

Commit e633839

Browse files
committed
Support named theme palettes
REDMINE-20704
1 parent 9a82b79 commit e633839

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

entry_types/scrolled/package/spec/editor/models/ScrolledEntry-spec.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,6 +3114,57 @@ describe('ScrolledEntry', () => {
31143114
expect(values).toEqual(['brand-blue', 'brand-green']);
31153115
});
31163116

3117+
it('supports named palettes', () => {
3118+
const entry = factories.entry(
3119+
ScrolledEntry,
3120+
{},
3121+
{
3122+
entryTypeSeed: normalizeSeed({
3123+
themeOptions: {
3124+
properties: {
3125+
root: {
3126+
paletteColorBrandBlue: '#00f',
3127+
paletteColorBrandGreen: '#0f0',
3128+
paletteColorAccentColor: '#123)'
3129+
}
3130+
},
3131+
palettes: {
3132+
brandColors: ['brandBlue', 'brand_green']
3133+
}
3134+
}
3135+
})
3136+
}
3137+
);
3138+
3139+
const [values] = entry.getPaletteColors({name: 'brandColors'});
3140+
3141+
expect(values).toEqual(['brand-blue', 'brand-green']);
3142+
});
3143+
3144+
it('returns empty array if named palette is missing', () => {
3145+
const entry = factories.entry(
3146+
ScrolledEntry,
3147+
{},
3148+
{
3149+
entryTypeSeed: normalizeSeed({
3150+
themeOptions: {
3151+
properties: {
3152+
root: {
3153+
paletteColorBrandBlue: '#00f',
3154+
paletteColorBrandGreen: '#0f0',
3155+
paletteColorAccentColor: '#123)'
3156+
}
3157+
}
3158+
}
3159+
})
3160+
}
3161+
);
3162+
3163+
const [values] = entry.getPaletteColors({name: 'brandColors'});
3164+
3165+
expect(values).toEqual([]);
3166+
});
3167+
31173168
describe('with shared translations', () => {
31183169
const commonPrefix = 'pageflow_scrolled.editor.palette_colors'
31193170

entry_types/scrolled/package/src/editor/models/ScrolledEntry/index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,15 @@ export const ScrolledEntry = Entry.extend({
197197
return [values, texts]
198198
},
199199

200-
getPaletteColors() {
201-
const values = Object.keys(
202-
this.scrolledSeed.config.theme.options.properties?.root || {}
203-
).filter(
204-
key => key.indexOf('paletteColor') === 0
200+
getPaletteColors({name} = {}) {
201+
const themeOptions = this.scrolledSeed.config.theme.options
202+
203+
const values = (
204+
name ?
205+
(themeOptions.palettes?.[name] || []) :
206+
Object.keys(themeOptions.properties?.root || {}).filter(
207+
key => key.indexOf('paletteColor') === 0
208+
)
205209
).map(
206210
key => dasherize(key.replace('paletteColor', ''))
207211
);
@@ -229,7 +233,7 @@ export const ScrolledEntry = Entry.extend({
229233
function dasherize(text) {
230234
return (
231235
text[0] +
232-
text.slice(1).replace(/[A-Z]/g, match => `-${match}`)
236+
text.slice(1).replace('_', '-').replace(/[A-Z]/g, match => `-${match}`)
233237
).toLowerCase();
234238
}
235239

0 commit comments

Comments
 (0)