Skip to content

Commit

Permalink
Added help center handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslonov committed Feb 1, 2025
1 parent 1228bea commit 41a673a
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 8 deletions.
19 changes: 19 additions & 0 deletions src/grid/ko/gridEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ export class GridEditor {
binding: binding,
half: half,
providers: providers,
openHelpCenter: (articleKey: string) => {
const view: View = {
heading: "Help center",
component: {
name: "help-center",
params: {
articleKey: articleKey,
}
},
resizing: {
directions: "vertically horizontally",
initialWidth: 500,
initialHeight: 700
},
scrolling: false
};

this.viewManager.openViewAsPopup(view);
},
openWidgetEditor: () => {
this.viewManager.openWidgetEditor(binding);
},
Expand Down
5 changes: 3 additions & 2 deletions src/ko/bindingHandlers/bindingHandlers.helpCenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export class HelpCenterBindingHandler {
directions: "vertically horizontally",
initialWidth: 500,
initialHeight: 700
}
},
scrolling: false
};

this.viewManager.openViewAsPopup(view);
};

ko.applyBindingsToNode(element, { click: openHelpCenter }, null);
ko.applyBindingsToNode(element, { activate: openHelpCenter }, null);
}
};
}
Expand Down
23 changes: 21 additions & 2 deletions src/ko/bindingHandlers/bindingHandlers.tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ import { BalloonHandle, BalloonActivationMethod } from "@paperbits/common/ui/bal
const defaultTooltipDelayMs = 700;

interface TooltipOptions {
/**
* Tooltip heading.
*/
heading?: string;

/**
* Tooltip message.
*/
message: string;

/**
* Tooltip help article.
*/
articleKey?: string;

/**
* Preferred tooltip position, e.g. `top`.
*/
Expand All @@ -31,6 +41,11 @@ interface TooltipOptions {
isDisabled: ko.Observable<boolean>;
}

interface TooltipParams {
heading: string;
observableText: ko.Observable<string>;
articleKey: string;
}

ko.bindingHandlers["tooltip"] = {
init: (triggerElement: HTMLElement, valueAccessor: () => TooltipOptions) => {
Expand Down Expand Up @@ -63,7 +78,11 @@ ko.bindingHandlers["tooltip"] = {
let hasText: boolean = false;
const isDisabled: () => boolean = () => !!options.isDisabled ? options.isDisabled() : false;

const textParams: any = {};
const textParams: TooltipParams = {
heading: options.heading,
observableText: null,
articleKey: options.articleKey
};
let closeTimeout = 0;

if (ko.isObservable(tooltipMessage)) {
Expand All @@ -80,7 +99,7 @@ ko.bindingHandlers["tooltip"] = {
}
else {
hasText = !!tooltipMessage;
textParams.text = tooltipMessage;
textParams.observableText = tooltipMessage;
}

ko.applyBindingsToNode(triggerElement, {
Expand Down
12 changes: 11 additions & 1 deletion src/ko/ui/tooltip.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
<div class="tooltip" data-bind="html: observableText, scrollable: true"></div>
<div class="tooltip">
<!-- ko if: heading -->
<h1 data-bind="text: heading"></h1>
<!-- /ko-->
<div data-bind="html: observableText, scrollable: true"></div>

<!-- ko if: articleKey -->
<a href="#" class="btn btn-link" data-bind="helpCenter: articleKey">Learn more ></a>
<!-- /ko-->
</div>

<span class="text-hide" aria-live="polite" data-bind="text: announcementText"></span>
8 changes: 8 additions & 0 deletions src/ko/ui/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@ export class Tooltip {
public readonly announcementText: ko.Observable<string>;

constructor() {
this.heading = ko.observable();
this.observableText = ko.observable();
this.announcementText = ko.observable();
this.articleKey = ko.observable();
}

@Param()
public text: any;

@Param()
public heading: any;

@Param()
public observableText: any;

@Param()
public articleKey: any;

@OnMounted()
public init(): void {
if (!this.text) {
Expand Down
3 changes: 2 additions & 1 deletion src/workshops/navigation/ko/navigationToolButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ToolButton, ViewManager, View } from "@paperbits/common/ui";

const helpText = "<h1>Navigation</h1><p>Add or edit navigation menus.</p>";
const helpText = "<p>Add or edit navigation menus.</p>";

export class NavigationToolButton implements ToolButton {
public readonly iconClass: string = "paperbits-icon paperbits-menu-34";
Expand All @@ -15,6 +15,7 @@ export class NavigationToolButton implements ToolButton {
const view: View = {
heading: this.title,
helpText: helpText,
helpArticle: "/navigation",
component: { name: "navigation" }
};

Expand Down
4 changes: 3 additions & 1 deletion src/workshops/page/ko/pagesToolButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ToolButton, ViewManager, View } from "@paperbits/common/ui";

const helpText = "<h1>Pages</h1><p>Add or edit pages of your website. Each page has a unique URL, which also automatically defines the layout it is part of.</p>";
const helpText = "<p>Add or edit pages of your website. Each page has a unique URL, which also automatically defines the layout it is part of.</p>";

export class PagesToolButton implements ToolButton {
public readonly iconClass: string = "paperbits-icon paperbits-menu-4";
Expand All @@ -14,7 +14,9 @@ export class PagesToolButton implements ToolButton {

const view: View = {
heading: this.title,
helpHeading: this.title,
helpText: helpText,
helpArticle: "/pages",
component: { name: "pages" }
};

Expand Down
2 changes: 1 addition & 1 deletion src/workshops/workshops.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1>
<span data-bind="text: heading"></span>
<!-- ko if: $data.helpText -->
<button class="btn-help" role="tooltip" aria-label="Help"
data-bind="tooltip: { message: $data.helpText, position: 'right', activateOn: 'clickOrKeyDown' }">
data-bind="tooltip: { heading: $data.helpHeading, message: $data.helpText, articleKey: $data.helpArticle, position: 'right', activateOn: 'clickOrKeyDown' }">
<i aria-hidden="true" class="paperbits-icon paperbits-c-question"></i>
</button>
<!--/ko -->
Expand Down

0 comments on commit 41a673a

Please sign in to comment.