Skip to content

Commit

Permalink
fix(table): improve styles for color context (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroedin committed Jan 10, 2024
1 parent 78815d1 commit 42c167f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-oranges-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rhds/elements": patch
---

`<rh-table>`: improved color palette styles
37 changes: 1 addition & 36 deletions elements/rh-table/rh-table-lightdom.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
rh-table,
rh-table[color-palette="lightest"] {
rh-table {
--rh-table-row-border:
var(--rh-border-width-sm, 1px)
solid
Expand All @@ -22,40 +21,6 @@ rh-table[color-palette="lightest"] {
);
}

[color-palette="light"] > rh-table,
rh-table[color-palette="light"],
[color-palette="lighter"] > rh-table,
rh-table[color-palette="lighter"] {
--rh-table-row-background-color:
rgb(
var(
--_rh-color-white-rgb, /* making private as currently doesn't exist */
255 255 255
)
/ var(--rh-opacity-50, 50%)
);
}

[color-palette^="dark"] > rh-table,
rh-table[color-palette^="dark"] {
--rh-table-row-background-color:
rgb(
var(
--_rh-color-white-rgb, /* making private as currently doesn't exist */
255 255 255
)
/ var(--rh-opacity-10, 10%)
);
--rh-table-column-background-color:
rgb(
var(
--rh-color-blue-70-rgb,
0 51 102
)
/ var(--rh-opacity-30, 30%)
);
}

rh-table table {
min-width: 100%;
margin: 0 auto;
Expand Down
30 changes: 30 additions & 0 deletions elements/rh-table/rh-table.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@
display: block;
}

:is(.color-palette-light, .color-palette-lighter) {
--rh-table-row-background-color:
rgb(
var(
--_rh-color-white-rgb, /* making private as currently doesn't exist */
255 255 255
)
/ var(--rh-opacity-50, 50%)
);
}

.dark {
--rh-table-row-background-color:
rgb(
var(
--_rh-color-white-rgb, /* making private as currently doesn't exist */
255 255 255
)
/ var(--rh-opacity-10, 10%)
);
--rh-table-column-background-color:
rgb(
var(
--rh-color-blue-70-rgb,
0 51 102
)
/ var(--rh-opacity-30, 30%)
);
}

/* @todo: should I move these styles to light dom css file? */
::slotted([slot="summary"]) {
display: block;
Expand Down
20 changes: 15 additions & 5 deletions elements/rh-table/rh-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Logger } from '@patternfly/pfe-core/controllers/logger.js';

import { RequestSortEvent, RhSortButton } from './rh-sort-button.js';

import { colorContextProvider, type ColorPalette } from '@rhds/elements/lib/context/color/provider.js';
import { colorContextConsumer, type ColorTheme } from '../../lib/context/color/consumer.js';

import styles from './rh-table.css';
Expand All @@ -26,9 +25,6 @@ export class RhTable extends LitElement {

@colorContextConsumer() private on?: ColorTheme;

@colorContextProvider()
@property({ reflect: true, attribute: 'color-palette' }) colorPalette?: ColorPalette;

private static getNodeContentForSort(
columnIndexToSort: number,
node: Element,
Expand Down Expand Up @@ -68,17 +64,31 @@ export class RhTable extends LitElement {
return this.querySelector('[slot="summary"]') as HTMLElement | undefined;
}

#internalColorPalette?: string | null;

#logger = new Logger(this);

connectedCallback() {
super.connectedCallback();
this.#init();
}

protected willUpdate(): void {
/**
* TEMPORARY: this fixes the need to access the parents color-palette in order to get the `lightest`
* value. This fix will only update the component when switching between light and dark themes as
* thats when the consumer requests an update. Switching between lighter -> light for example will
* not trigger the component to update at this time.
**/
this.#internalColorPalette = this.closest('[color-palette]')?.getAttribute('color-palette');
}

render() {
const { on = '' } = this;
return html`
<div id="container" class="${classMap({ [on]: !!on })}" part="container">
<div id="container"
class="${classMap({ [on]: !!on, [`color-palette-${this.#internalColorPalette}`]: !!this.#internalColorPalette })}"
part="container">
<slot @pointerleave="${this.#onPointerleave}"
@pointerover="${this.#onPointerover}"
@request-sort="${this.#onRequestSort}"
Expand Down

0 comments on commit 42c167f

Please sign in to comment.