Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAE-24927 update widgets schema & predefined theme #10185

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/protractor.excludes.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
"C282017": "https://hyland.atlassian.net/browse/ACS-7960",
"C282010": "https://hyland.atlassian.net/browse/ACS-7960",
"C261046": "https://hyland.atlassian.net/browse/ACS-7960",
"C286508": "https://hyland.atlassian.net/browse/ACS-8733"
"C286508": "https://hyland.atlassian.net/browse/ACS-8733",
"C286509": "https://hyland.atlassian.net/browse/ACS-8760"
}
1 change: 1 addition & 0 deletions lib/core/src/lib/form/components/widgets/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ export * from './form-field-utils';
export * from './form-field-variable-options';
export * from './widget-schema.model';
export * from './theme.model';
export * from './predefined-theme';
117 changes: 117 additions & 0 deletions lib/core/src/lib/form/components/widgets/core/predefined-theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { PredefinedThemeModel } from './theme.model';

export const predefinedTheme: PredefinedThemeModel = {
widgets: {
'readonly-text': {
normal: {
name: 'FORM.FIELD_STYLE.PREDEFINED.READONLY_TEXT.NORMAL',
styles: {
'--adf-readonly-text-font-size': '16px',
'--adf-readonly-text-font-weight': 'normal',
'--adf-readonly-text-color': 'inherit'
}
},
strong: {
name: 'FORM.FIELD_STYLE.PREDEFINED.READONLY_TEXT.STRONG',
styles: {
'--adf-readonly-text-font-size': '16px',
'--adf-readonly-text-font-weight': 'bold',
'--adf-readonly-text-color': 'inherit'
}
},
heading: {
name: 'FORM.FIELD_STYLE.PREDEFINED.READONLY_TEXT.HEADING',
styles: {
'--adf-readonly-text-font-size': '20px',
'--adf-readonly-text-font-weight': 'normal',
'--adf-readonly-text-color': 'inherit'
}
},
title: {
name: 'FORM.FIELD_STYLE.PREDEFINED.READONLY_TEXT.TITLE',
styles: {
'--adf-readonly-text-font-size': '24px',
'--adf-readonly-text-font-weight': 'normal',
'--adf-readonly-text-color': 'inherit'
}
},
annotation: {
name: 'FORM.FIELD_STYLE.PREDEFINED.READONLY_TEXT.ANNOTATION',
styles: {
'--adf-readonly-text-font-size': '12px',
'--adf-readonly-text-font-weight': 'normal',
'--adf-readonly-text-color': 'inherit'
}
}
},
group: {
normal: {
name: 'FORM.FIELD_STYLE.PREDEFINED.HEADER.NORMAL',
styles: {
'--adf-header-font-size': '16px',
'--adf-header-font-weight': 'normal',
'--adf-header-color': 'inherit'
}
},
heading: {
name: 'FORM.FIELD_STYLE.PREDEFINED.HEADER.HEADING',
styles: {
'--adf-header-font-size': '20px',
'--adf-header-font-weight': 'normal',
'--adf-header-color': 'inherit'
}
},
title: {
name: 'FORM.FIELD_STYLE.PREDEFINED.HEADER.TITLE',
styles: {
'--adf-header-font-size': '24px',
'--adf-header-font-weight': 'normal',
'--adf-header-color': 'inherit'
}
}
},
'radio-buttons': {
normal: {
name: 'FORM.FIELD_STYLE.PREDEFINED.RADIO_BUTTONS.NORMAL',
styles: {
'--adf-radio-buttons-font-size': '16px',
'--adf-radio-buttons-font-weight': 'normal',
'--adf-radio-buttons-color': 'inherit'
}
},
strong: {
name: 'FORM.FIELD_STYLE.PREDEFINED.RADIO_BUTTONS.STRONG',
styles: {
'--adf-radio-buttons-font-size': '16px',
'--adf-radio-buttons-font-weight': 'bold',
'--adf-radio-buttons-color': 'inherit'
}
},
heading: {
name: 'FORM.FIELD_STYLE.PREDEFINED.RADIO_BUTTONS.HEADING',
styles: {
'--adf-radio-buttons-font-size': '20px',
'--adf-radio-buttons-font-weight': 'normal',
'--adf-radio-buttons-color': 'inherit'
}
}
}
}
};
30 changes: 24 additions & 6 deletions lib/core/src/lib/form/components/widgets/core/theme.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,40 @@ export interface ThemeModel {
};
widgets?: {
['readonly-text']?: {
[styleName: string]: {
[variable in ReadonlyTextThemeVariable]?: string;
[styleKey: string]: {
name: string;
styles: { [variable in ReadonlyTextThemeVariable]?: string };
};
};
['group']?: {
[styleName: string]: {
[variable in HeaderThemeVariable]?: string;
[styleKey: string]: {
name: string;
styles: { [variable in HeaderThemeVariable]?: string };
};
};
['radio-buttons']?: {
[styleName: string]: {
[variable in RadioButtonsThemeVariable]?: string;
[styleKey: string]: {
name: string;
styles: { [variable in RadioButtonsThemeVariable]?: string };
};
};
};
defaults?: {
[widgetType in SupportedWidgetType]?: string;
};
}

export interface WidgetSchemaPredefinedStyle<TFieldVariable extends string> {
[styleKey: string]: {
name: string;
styles: { [key in TFieldVariable]?: string };
};
}

export interface PredefinedThemeModel {
widgets?: {
['readonly-text']?: WidgetSchemaPredefinedStyle<ReadonlyTextThemeVariable>;
['group']?: WidgetSchemaPredefinedStyle<HeaderThemeVariable>;
['radio-buttons']?: WidgetSchemaPredefinedStyle<RadioButtonsThemeVariable>;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { FormThemeVariable } from './theme.model';

export type WidgetStylePropertySelector = 'number' | 'options' | 'colorOptions';

export interface WidgetSchemaModel<TFieldVariable = string, TFormVariable = FormThemeVariable> {
export interface WidgetSchemaModel<TFieldVariable extends string, TFormVariable = FormThemeVariable> {
themeProperties: WidgetSchemaThemeProperty<TFieldVariable, TFormVariable>[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export const displayTextSchema: WidgetSchemaModel<ReadonlyTextThemeVariable> = {
type: 'options',
options: [
{
name: 'FORM.FIELD_STYLE.REGULAR',
name: 'FORM.FIELD_STYLE.FONT_WEIGHTS.REGULAR',
value: 'normal'
},
{
name: 'FORM.FIELD_STYLE.BOLD',
name: 'FORM.FIELD_STYLE.FONT_WEIGHTS.BOLD',
value: 'bold'
}
],
Expand All @@ -55,31 +55,31 @@ export const displayTextSchema: WidgetSchemaModel<ReadonlyTextThemeVariable> = {
type: 'colorOptions',
options: [
{
name: 'FORM.FIELD_STYLE.SYSTEM_COLOR',
name: 'FORM.FIELD_STYLE.COLORS.SYSTEM_COLOR',
value: 'inherit'
},
{
name: 'FORM.FIELD_STYLE.BLACK',
name: 'FORM.FIELD_STYLE.COLORS.BLACK',
value: '#000000'
},
{
name: 'FORM.FIELD_STYLE.GREY',
name: 'FORM.FIELD_STYLE.COLORS.GREY',
value: '#9CA3AF'
},
{
name: 'FORM.FIELD_STYLE.RED',
name: 'FORM.FIELD_STYLE.COLORS.RED',
value: '#DA1500'
},
{
name: 'FORM.FIELD_STYLE.GREEN',
name: 'FORM.FIELD_STYLE.COLORS.GREEN',
value: '#04A003'
},
{
name: 'FORM.FIELD_STYLE.BLUE',
name: 'FORM.FIELD_STYLE.COLORS.BLUE',
value: '#0A60CE'
},
{
name: 'FORM.FIELD_STYLE.YELLOW',
name: 'FORM.FIELD_STYLE.COLORS.YELLOW',
value: '#FACC15'
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export const headerSchema: WidgetSchemaModel<HeaderThemeVariable> = {
type: 'options',
options: [
{
name: 'FORM.FIELD_STYLE.REGULAR',
name: 'FORM.FIELD_STYLE.FONT_WEIGHTS.REGULAR',
value: 'normal'
},
{
name: 'FORM.FIELD_STYLE.BOLD',
name: 'FORM.FIELD_STYLE.FONT_WEIGHTS.BOLD',
value: 'bold'
}
],
Expand All @@ -55,31 +55,31 @@ export const headerSchema: WidgetSchemaModel<HeaderThemeVariable> = {
type: 'colorOptions',
options: [
{
name: 'FORM.FIELD_STYLE.SYSTEM_COLOR',
name: 'FORM.FIELD_STYLE.COLORS.SYSTEM_COLOR',
value: 'inherit'
},
{
name: 'FORM.FIELD_STYLE.BLACK',
name: 'FORM.FIELD_STYLE.COLORS.BLACK',
value: '#000000'
},
{
name: 'FORM.FIELD_STYLE.GREY',
name: 'FORM.FIELD_STYLE.COLORS.GREY',
value: '#9CA3AF'
},
{
name: 'FORM.FIELD_STYLE.RED',
name: 'FORM.FIELD_STYLE.COLORS.RED',
value: '#DA1500'
},
{
name: 'FORM.FIELD_STYLE.GREEN',
name: 'FORM.FIELD_STYLE.COLORS.GREEN',
value: '#04A003'
},
{
name: 'FORM.FIELD_STYLE.BLUE',
name: 'FORM.FIELD_STYLE.COLORS.BLUE',
value: '#0A60CE'
},
{
name: 'FORM.FIELD_STYLE.YELLOW',
name: 'FORM.FIELD_STYLE.COLORS.YELLOW',
value: '#FACC15'
}
],
Expand Down
30 changes: 20 additions & 10 deletions lib/core/src/lib/form/pipes/field-style.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,30 @@ const mockTheme: ThemeModel = {
widgets: {
'readonly-text': {
'my-custom-display-text': {
'--adf-readonly-text-font-size': '12px',
'--adf-readonly-text-font-weight': 'normal',
'--adf-readonly-text-color': '#000000'
name: 'My Custom Display Text',
styles: {
'--adf-readonly-text-font-size': '12px',
'--adf-readonly-text-font-weight': 'normal',
'--adf-readonly-text-color': '#000000'
}
},
'my-custom-display-text2': {
'--adf-readonly-text-font-size': '15px',
'--adf-readonly-text-color': 'green'
name: 'My Custom Display Text 2',
styles: {
'--adf-readonly-text-font-size': '15px',
'--adf-readonly-text-font-weight': 'normal',
'--adf-readonly-text-color': 'green'
}
}
},
'radio-buttons': {
'my-custom-radio-buttons2': {
'--adf-radio-buttons-font-size': '15px',
'--adf-radio-buttons-font-weight': 'normal',
'--adf-radio-buttons-color': 'green'
'my-custom-radio-buttons': {
name: 'My Custom Radio Buttons',
styles: {
'--adf-radio-buttons-font-size': '12px',
'--adf-radio-buttons-font-weight': 'normal',
'--adf-radio-buttons-color': '#000000'
}
}
}
}
Expand All @@ -59,7 +69,7 @@ describe('FieldStylePipe', () => {
};

const result = pipe.transform(field as FormFieldModel);
expect(result).toEqual('--adf-readonly-text-font-size: 12px;--adf-readonly-text-font-weight: normal;--adf-readonly-text-color: #000000');
expect(result).toEqual('--adf-readonly-text-font-size:12px;--adf-readonly-text-font-weight:normal;--adf-readonly-text-color:#000000;');
});

it('should return empty string when style name is not provided', () => {
Expand Down
16 changes: 11 additions & 5 deletions lib/core/src/lib/form/pipes/field-style.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,28 @@
import { Pipe, PipeTransform } from '@angular/core';
import { FormFieldModel } from '../components/widgets/core/form-field.model';
import { ContainerModel } from '../components/widgets/core/container.model';
import { predefinedTheme } from '../components/widgets/core/predefined-theme';

@Pipe({
name: 'adfFieldStyle',
standalone: true
})
export class FieldStylePipe implements PipeTransform {
transform(field: FormFieldModel | ContainerModel): string {
const theme = field.form?.theme?.widgets[field.type];
const style = field.style && theme?.[field.style];
if (!field.style) {
return '';
}

return style ? this.flattenStyles(style) : '';
const themeStyle = field.form?.theme?.widgets[field.type]?.[field.style];
const predefinedThemeStyle = predefinedTheme.widgets[field.type]?.[field.style];
const styles = (themeStyle || predefinedThemeStyle)?.styles;

return styles ? this.flattenStyles(styles) : '';
}

private flattenStyles(styles: { [key: string]: string }): string {
return Object.entries(styles)
.map(([key, value]) => `${key}: ${value}`)
.join(';');
.map(([key, value]) => `${key}:${value};`)
.join('');
}
}
Loading
Loading