Skip to content

Commit

Permalink
Support named theme palettes
Browse files Browse the repository at this point in the history
REDMINE-20704
  • Loading branch information
tf committed May 7, 2024
1 parent 9a82b79 commit e633839
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,57 @@ describe('ScrolledEntry', () => {
expect(values).toEqual(['brand-blue', 'brand-green']);
});

it('supports named palettes', () => {
const entry = factories.entry(
ScrolledEntry,
{},
{
entryTypeSeed: normalizeSeed({
themeOptions: {
properties: {
root: {
paletteColorBrandBlue: '#00f',
paletteColorBrandGreen: '#0f0',
paletteColorAccentColor: '#123)'
}
},
palettes: {
brandColors: ['brandBlue', 'brand_green']
}
}
})
}
);

const [values] = entry.getPaletteColors({name: 'brandColors'});

expect(values).toEqual(['brand-blue', 'brand-green']);
});

it('returns empty array if named palette is missing', () => {
const entry = factories.entry(
ScrolledEntry,
{},
{
entryTypeSeed: normalizeSeed({
themeOptions: {
properties: {
root: {
paletteColorBrandBlue: '#00f',
paletteColorBrandGreen: '#0f0',
paletteColorAccentColor: '#123)'
}
}
}
})
}
);

const [values] = entry.getPaletteColors({name: 'brandColors'});

expect(values).toEqual([]);
});

describe('with shared translations', () => {
const commonPrefix = 'pageflow_scrolled.editor.palette_colors'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,15 @@ export const ScrolledEntry = Entry.extend({
return [values, texts]
},

getPaletteColors() {
const values = Object.keys(
this.scrolledSeed.config.theme.options.properties?.root || {}
).filter(
key => key.indexOf('paletteColor') === 0
getPaletteColors({name} = {}) {
const themeOptions = this.scrolledSeed.config.theme.options

const values = (
name ?
(themeOptions.palettes?.[name] || []) :
Object.keys(themeOptions.properties?.root || {}).filter(
key => key.indexOf('paletteColor') === 0
)
).map(
key => dasherize(key.replace('paletteColor', ''))
);
Expand Down Expand Up @@ -229,7 +233,7 @@ export const ScrolledEntry = Entry.extend({
function dasherize(text) {
return (
text[0] +
text.slice(1).replace(/[A-Z]/g, match => `-${match}`)
text.slice(1).replace('_', '-').replace(/[A-Z]/g, match => `-${match}`)
).toLowerCase();
}

Expand Down

0 comments on commit e633839

Please sign in to comment.