Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

feat: add support for styling widgets #107

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions projects/assets-library/assets/styles/_color-palette.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ $color-text-emphasis: $blue-5;

// Elements
$color-border: $gray-2;

// Background colors for widgets
$widget-background-gray: linear-gradient(283.16deg, $gray-1 0%, rgba(244, 245, 245, 0.62) 100%);
$widget-background-white: white;
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class AutoContainerLayoutModel extends ContainerLayout {
columns: `repeat(${gridDimension[1]}, minmax(${this.minColumnWidth}px, 1fr))`,
gap: `${this.gridGap}`,
enableStyle: this.enableStyle,
widgetTheme: this.widgetTheme,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm super hesitant to add theme to our existing model considering it's already built in (but not fleshed out). @arjunlalb I'm guessing you were unaware of it, so do you mind looking into that first and seeing if we could accomplish the same thing with that system?

Some pointers:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah. You're right. I wasn't aware of it. Will take a look.

Is that a theme system for the whole app or usable for just isolated usecases?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use it isolated but it's meant to integrate with the broader app. Specifically two aspects to watch out for:

  • Themes are inherited. If you theme a container, then any of its children will inherit that theme by default. They're also merged.
  • Using a theme is opt in for the renderer. Because different widgets will apply styles differently, they need to explicitly apply theme values.

children: children.map(child => ({ model: child, areaSpan: '' }))
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'color-palette';

:host {
width: 100%;
height: 100%;
Expand All @@ -9,3 +11,13 @@
box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.14), 0px 2px 2px rgba(0, 0, 0, 0.12), 0px 1px 3px rgba(0, 0, 0, 0.2);
padding: 0 16px;
}

.gray {
background: $widget-background-gray;
border: 1px solid $gray-1;
box-shadow: inset 2px 2px 12px rgba(225, 228, 229, 0.24);
}

.white {
background-color: $widget-background-white;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const CONTAINER_LAYOUT = new InjectionToken<ContainerLayoutData>('CONTAIN
<div
*ngFor="let child of layout.children; let index = index"
[gdArea]="child.areaSpan"
[ngClass]="{ 'container-child': layout.enableStyle }"
[ngClass]="[layout.enableStyle ? 'container-child' : '', layout.widgetTheme]"
>
<ng-container [hdaDashboardModel]="child.model"> </ng-container>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ComponentFactoryResolver, Injector, Type, ViewContainerRef } from '@angular/core';
import { BOOLEAN_PROPERTY, ModelProperty, STRING_PROPERTY } from '@hypertrace/hyperdash';
import { EnumPropertyTypeInstance, ENUM_TYPE } from '../../../properties/enums/enum-property-type';
import { ContainerLayoutComponent, CONTAINER_LAYOUT } from './container-layout.component';
import { WidgetTheme } from './widget-theme';

// Make abstract so it exists at runtime and can be used by the dashboard system
export abstract class ContainerLayout {
Expand All @@ -20,6 +22,17 @@ export abstract class ContainerLayout {
})
public gridGap: string = '16px';

@ModelProperty({
key: 'widget-theme',
// tslint:disable-next-line: no-object-literal-type-assertion
type: {
key: ENUM_TYPE.type,
values: [WidgetTheme.Gray, WidgetTheme.White]
} as EnumPropertyTypeInstance,
required: false
})
public widgetTheme: WidgetTheme = WidgetTheme.White;

public abstract getContainerLayoutData(children: object[]): ContainerLayoutData;

public draw(containerRef: ViewContainerRef, children: object[]): void {
Expand Down Expand Up @@ -59,5 +72,6 @@ export interface ContainerLayoutData {
rows?: string;
columns: string;
enableStyle: boolean;
widgetTheme: WidgetTheme;
children: ContainerLayoutChildData[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class CustomContainerLayoutModel extends ContainerLayout {
columns: this.getColumnStyles(),
gap: `${this.gridGap}`,
enableStyle: this.enableStyle,
widgetTheme: this.widgetTheme,
children: this.getChildLayoutData(children)
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum WidgetTheme {
Gray = 'gray',
White = 'white'
}