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

feat(Description): add ability for control description to handle html #1333

Merged
merged 4 commits into from
Jul 28, 2022
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
310 changes: 200 additions & 110 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"prettier": "^2.2.1",
"prettier-plugin-organize-imports": "^1.1.1",
"pretty-quick": "^2.0.1",
"semantic-release": "^19.0.2",
"semantic-release": "^19.0.3",
"standard-version": "^9.1.0",
"stylelint": "~13.2.1",
"stylelint-config-prettier": "^8.0.1",
Expand Down
5 changes: 2 additions & 3 deletions projects/novo-elements/src/elements/form/Control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ export class NovoAutoSize implements AfterContentInit {
</span>
</span>
<!--Field Hint-->
<span class="description" *ngIf="form.controls[control.key].description">
{{ form.controls[control.key].description }}
</span>
<div class="description" *ngIf="form.controls[control.key].description" [innerHTML]="form.controls[control.key].description">
</div>
<span class="warning-text" *ngIf="form.controls[control.key].warning">{{ form.controls[control.key].warning }}</span>
</div>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ export class FieldInteractionApi {
}
}

setDescription(key: string, description: string, otherForm?: NovoFormGroup): void {
const control = this.getControl(key, otherForm);
if (control && !control.restrictFieldInteractions) {
control.description = description;
this.triggerEvent({ controlKey: key, prop: 'description', value: description }, otherForm);
}
}

highlight(key: string, isHighlighted: boolean, otherForm?: NovoFormGroup): void {
const control = this.getControl(key, otherForm);
if (control && !control.restrictFieldInteractions) {
Expand Down
3 changes: 3 additions & 0 deletions projects/novo-examples/src/examples.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6106,6 +6106,9 @@ export class May2022Page {
<h5>Add Tooltip</h5>
<p>You are able to dynamically change a field's tooltip.</p>
<p><code-example example="fi-tooltip"></code-example></p>
<h5>Modify Description</h5>
<p>You are able to dynamically change the description of a field, potentially adding in custom HTML.</p>
<p><code-example example="fi-description"></code-example></p>
<h5>Interacting with Nested Forms</h5>
<p>Field Interactions can navigate nested forms to interact with parent and child forms. This example uses the Form Group component which contains an array of nested forms that are kept in sync by field interactions.</p>
<p><code-example example="fi-nested"></code-example></p>
Expand Down
1 change: 1 addition & 0 deletions projects/novo-examples/src/form-controls/form/MockMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const MockMeta = {
label: 'Float',
required: true,
sortOrder: 50,
description: '<span><b>BOLD</b> description with a <a target="_blank" href="https://www.google.com">Google</a> Link</span>'
},
{
name: 'currency',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** No CSS for this example */
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<novo-form [form]="form" layout="vertical">
<div class="novo-form-row">
<novo-control [form]="form" [control]="controls.descriptionControl"></novo-control>
</div>
<div class="novo-form-row">
<novo-control [form]="form" [control]="controls.toggleControl"></novo-control>
</div>
</novo-form>
<div class="final-value">Form Value - {{ form.value | json }}</div>
<div class="final-value">Form Dirty - {{ form.dirty | json }}</div>
<div class="final-value">Is Form Valid? - {{ form.valid | json }}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Component } from '@angular/core';
// Vendor
import { CheckboxControl, FieldInteractionApi, FormUtils, TextBoxControl } from 'novo-elements';

/**
* @title Fi Required Example
*/
@Component({
selector: 'fi-required-example',
templateUrl: 'fi-description-example.html',
styleUrls: ['fi-description-example.css'],
})
export class FiDescriptionExample {
public form: any = {};
public controls: any = {};

constructor(formUtils: FormUtils) {
const standardDescription = 'Toggle the checkbox below to toggle between an HTML description and a plain text description!';
const htmlDescription = '<span><b>BOLD</b> description with a <a target="_blank" href="https://www.google.com">Google</a> Link</span>';

const descriptionFunction = (API: FieldInteractionApi) => {
console.log('[FieldInteractionDemo] - descriptionFunction'); // tslint:disable-line
const activeValue = API.getActiveValue();

if (activeValue) {
API.setDescription('description', htmlDescription);
} else {
API.setDescription('description', standardDescription);
}
};

// Required Field Interactions
this.controls.descriptionControl = new TextBoxControl({
type: 'text',
key: 'description',
label: 'Test',
description: standardDescription,
});
this.controls.toggleControl = new CheckboxControl({
key: 'toggle',
label: 'Description has HTML?',
interactions: [{ event: 'change', script: descriptionFunction }],
});
this.form = formUtils.toFormGroup([this.controls.descriptionControl, this.controls.toggleControl]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './fi-description-example';
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ You are able to dynamically change a field's tooltip.

<code-example example="fi-tooltip"></code-example>

##### Modify Description

You are able to dynamically change the description of a field, potentially adding in custom HTML.

<code-example example="fi-description"></code-example>

##### Interacting with Nested Forms

Field Interactions can navigate nested forms to interact with parent and child forms. This example uses the Form Group component which contains an array of nested forms that are kept in sync by field interactions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './fi-adding-removing';
export * from './fi-async';
export * from './fi-calculation';
export * from './fi-confirm';
export * from './fi-description';
export * from './fi-enable-disable';
export * from './fi-globals';
export * from './fi-hide-show';
Expand Down