Skip to content

Commit

Permalink
Added background styling to Table widget editors.
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslonov committed Mar 9, 2024
1 parent a58dfcc commit 60ecd17
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/table-cell/ko/tableCellEditor.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<alignment-editor params="{ container: container, onUpdate: onContainerUpdate }"></alignment-editor>

<details open>
<summary>
Background
</summary>
<background params="{ background: $component.background, onUpdate: onBackgroundUpdate }"></background>
</details>

<details open>
<summary>
Box
</summary>
<box params="{ features: 'border,padding', box: box, onUpdate: onBoxUpdate }"></box>
</details>
</details>
12 changes: 11 additions & 1 deletion src/table-cell/ko/tableCellEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ko from "knockout";
import template from "./tableCellEditor.html";
import { Component, OnMounted, Param, Event } from "@paperbits/common/ko/decorators";
import { TableCellModel } from "../tableCellModel";
import { ContainerStylePluginConfig, BoxStylePluginConfig, BorderStylePluginConfig } from "@paperbits/styles/plugins";
import { ContainerStylePluginConfig, BoxStylePluginConfig, BorderStylePluginConfig, BackgroundStylePluginConfig } from "@paperbits/styles/plugins";
import { StyleHelper } from "@paperbits/styles";
import { TableCellStylePluginConfig } from "@paperbits/styles/plugins/table/tableCellStylePluginConfig";
import { PaddingStylePluginConfig } from "@paperbits/styles/plugins/padding";
Expand All @@ -15,10 +15,12 @@ import { PaddingStylePluginConfig } from "@paperbits/styles/plugins/padding";
export class TableCellEditor {
public readonly container: ko.Observable<ContainerStylePluginConfig>;
public readonly box: ko.Observable<BoxStylePluginConfig>;
public readonly background: ko.Observable<BackgroundStylePluginConfig>;

constructor() {
this.container = ko.observable<ContainerStylePluginConfig>();
this.box = ko.observable<BoxStylePluginConfig>();
this.background = ko.observable<BackgroundStylePluginConfig>();
}

@Param()
Expand Down Expand Up @@ -56,6 +58,9 @@ export class TableCellEditor {
.getConfig<BorderStylePluginConfig>();

this.box({ padding: paddingConfig, border: borderConfig });

const backgroundStyles = <BackgroundStylePluginConfig>StyleHelper.getPluginConfigForLocalStyles(this.model.styles, "background");
this.background(backgroundStyles);
}

public onContainerUpdate(containerConfig: ContainerStylePluginConfig): void {
Expand All @@ -80,4 +85,9 @@ export class TableCellEditor {

this.onChange(this.model);
}

public onBackgroundUpdate(backgroundStyles: BackgroundStylePluginConfig): void {
StyleHelper.setPluginConfigForLocalStyles(this.model.styles, "background", backgroundStyles);
this.onChange(this.model);
}
}
10 changes: 9 additions & 1 deletion src/table/ko/tableColumnEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
data-bind="textInput: width" />
</div>
</div>

<details open>
<summary>
Container box
Background (applied once)
</summary>
<background params="{ background: $component.background, onUpdate: onBackgroundUpdate }"></background>
</details>

<details open>
<summary>
Container box (applied once)
</summary>
<box params="{ features: 'border,padding', onUpdate: onBoxUpdate }"></box>
</details>
7 changes: 6 additions & 1 deletion src/table/ko/tableColumnEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SizeUnits, Size } from "@paperbits/styles/size";
import { Component, OnMounted, Param, Event } from "@paperbits/common/ko/decorators";
import { TableModel } from "../tableModel";
import { ChangeRateLimit } from "@paperbits/common/ko/consts";
import { BoxStylePluginConfig } from "@paperbits/styles/plugins";
import { BackgroundStylePluginConfig, BoxStylePluginConfig } from "@paperbits/styles/plugins";
import { StylePluginConfig } from "@paperbits/common/styles";


Expand Down Expand Up @@ -69,6 +69,11 @@ export class TableColumnEditor {
this.onChange(this.model);
}

public onBackgroundUpdate(backgroundStyles: BackgroundStylePluginConfig): void {
this.applyColumnStyles("background", backgroundStyles);
this.onChange(this.model);
}

private applyChanges(): void {
if (!this.columnIndex) {
this.columnIndex = 0;
Expand Down
10 changes: 9 additions & 1 deletion src/table/ko/tableRowEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
data-bind="textInput: height" />
</div>
</div>

<details open>
<summary>
Container box
Background (applied once)
</summary>
<background params="{ background: $component.background, onUpdate: onBackgroundUpdate }"></background>
</details>

<details open>
<summary>
Container box (applied once)
</summary>
<box params="{ features: 'border,padding', onUpdate: onBoxUpdate }"></box>
</details>
6 changes: 5 additions & 1 deletion src/table/ko/tableRowEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Component, OnMounted, Param, Event } from "@paperbits/common/ko/decorat
import { TableModel } from "../tableModel";
import { ChangeRateLimit } from "@paperbits/common/ko/consts";
import { StylePluginConfig } from "@paperbits/common/styles";
import { BoxStylePluginConfig } from "@paperbits/styles/plugins";
import { BackgroundStylePluginConfig, BoxStylePluginConfig } from "@paperbits/styles/plugins";


@Component({
Expand Down Expand Up @@ -70,6 +70,10 @@ export class TableRowEditor {
this.onChange(this.model);
}

public onBackgroundUpdate(backgroundStyles: BackgroundStylePluginConfig): void {
this.applyRowStyles("background", backgroundStyles);
this.onChange(this.model);
}

private applyChanges(): void {
if (!this.rowIndex) {
Expand Down

0 comments on commit 60ecd17

Please sign in to comment.