Skip to content

Commit a342b8f

Browse files
committed
switch to CSS custom properties control and add intent property
1 parent 6ac22fa commit a342b8f

5 files changed

Lines changed: 94 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1818
- `searchListPredicate` property: Allows to filter the complete list of search options at once.
1919
- Following optional BlueprintJs properties are forwarded now to override default behaviour: `noResults`, `createNewItemRenderer` and `itemRenderer`
2020
- `isValidNewOption` property: Checks if an input string is or can be turned into a valid new option.
21+
- `<OverviewItem />`
22+
- `intent` property: visualize the state
2123

2224
### Fixed
2325

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from "react";
2+
import { render } from "@testing-library/react";
3+
4+
import "@testing-library/jest-dom";
5+
6+
import { IntentTypes } from "../../common/Intent";
7+
8+
import OverviewItem from "./OverviewItem";
9+
10+
describe("OverviewItem", () => {
11+
const findItem = (container: HTMLElement) => container.querySelector(".eccgui-overviewitem__item");
12+
13+
it("does not apply any intent class when `intent` is not set", () => {
14+
const { container } = render(<OverviewItem>content</OverviewItem>);
15+
const item = findItem(container);
16+
expect(item).not.toBeNull();
17+
expect(item!.className).not.toMatch(/eccgui-intent--/);
18+
});
19+
20+
it.each<IntentTypes>(["primary", "success", "warning", "danger", "neutral", "accent", "info"])(
21+
'applies the matching intent class for `intent="%s"`',
22+
(intent) => {
23+
const { container } = render(<OverviewItem intent={intent}>content</OverviewItem>);
24+
const item = findItem(container);
25+
expect(item).not.toBeNull();
26+
expect(item).toHaveClass(`eccgui-intent--${intent}`);
27+
},
28+
);
29+
30+
it("keeps the base class and additional className alongside the intent class", () => {
31+
const { container } = render(
32+
<OverviewItem intent="success" className="custom-class">
33+
content
34+
</OverviewItem>,
35+
);
36+
const item = findItem(container);
37+
expect(item).toHaveClass("eccgui-overviewitem__item");
38+
expect(item).toHaveClass("eccgui-intent--success");
39+
expect(item).toHaveClass("custom-class");
40+
});
41+
});

src/components/OverviewItem/OverviewItem.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import React from "react";
22

3+
import { intentClassName, IntentTypes } from "../../common/Intent";
34
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
45
import Card, { CardProps } from "../Card/Card";
56

67
export interface OverviewItemProps extends React.HTMLAttributes<HTMLDivElement> {
8+
/**
9+
* Visual intent state.
10+
*/
11+
intent?: IntentTypes;
712
/**
813
* Displays the element using reduced height and less white space inside.
914
*/
@@ -36,6 +41,7 @@ export const OverviewItem = ({
3641
hasSpacing = false,
3742
hasCardWrapper = false,
3843
cardProps,
44+
intent,
3945
...otherProps
4046
}: OverviewItemProps) => {
4147
const item = (
@@ -45,6 +51,7 @@ export const OverviewItem = ({
4551
`${eccgui}-overviewitem__item ` +
4652
(densityHigh ? `${eccgui}-overviewitem__item--highdensity ` : "") +
4753
(hasSpacing ? `${eccgui}-overviewitem__item--hasspacing ` : "") +
54+
(intent ? `${intentClassName(intent)} ` : "") +
4855
className
4956
}
5057
>

src/components/OverviewItem/overviewitem.scss

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ $eccgui-size-overviewitem-line-typo-large-lineheight: $eccgui-size-typo-subtitle
4444
}
4545

4646
.#{$eccgui}-overviewitem__item {
47+
--eccgui-overviewitem-color-background: transparent;
48+
--eccgui-overviewitem-color-text: inherit;
49+
4750
display: flex;
4851
flex-flow: row nowrap;
4952
place-content: stretch flex-start;
@@ -59,21 +62,54 @@ $eccgui-size-overviewitem-line-typo-large-lineheight: $eccgui-size-typo-subtitle
5962
// height: mini-units(6);
6063
min-height: mini-units(6);
6164
max-height: mini-units(6);
65+
color: var(--eccgui-overviewitem-color-text);
66+
background-color: var(--eccgui-overviewitem-color-background);
6267

6368
&[tabindex]:not([tabindex="-1"]) {
6469
cursor: pointer;
6570
}
6671

6772
.#{$ns}-menu > & {
6873
// TODO: discuss if this should be enabled via explicit element property
69-
// remove this because reason was not clear and it lead to wrong display
70-
// @extend .#{$ns}-menu-item;
7174

7275
&--active {
7376
color: $eccgui-color-accent-contrast;
7477
background-color: $eccgui-color-accent;
7578
}
7679
}
80+
81+
&.#{$eccgui}-intent--info {
82+
--eccgui-overviewitem-color-background: #{$eccgui-color-info-background};
83+
--eccgui-overviewitem-color-text: #{$eccgui-color-info-text};
84+
}
85+
&.#{$eccgui}-intent--success {
86+
--eccgui-overviewitem-color-background: #{$eccgui-color-success-background};
87+
--eccgui-overviewitem-color-text: #{$eccgui-color-success-text};
88+
}
89+
&.#{$eccgui}-intent--warning {
90+
--eccgui-overviewitem-color-background: #{$eccgui-color-warning-background};
91+
--eccgui-overviewitem-color-text: #{$eccgui-color-warning-text};
92+
}
93+
&.#{$eccgui}-intent--danger {
94+
--eccgui-overviewitem-color-background: #{$eccgui-color-danger-background};
95+
--eccgui-overviewitem-color-text: #{$eccgui-color-danger-text};
96+
}
97+
&.#{$eccgui}-intent--neutral {
98+
--eccgui-overviewitem-color-background: #{$eccgui-color-workspace-background};
99+
--eccgui-overviewitem-color-text: #{$eccgui-color-workspace-text};
100+
}
101+
&.#{$eccgui}-intent--neutral {
102+
--eccgui-overviewitem-color-background: #{$eccgui-color-workspace-background};
103+
--eccgui-overviewitem-color-text: #{$eccgui-color-workspace-text};
104+
}
105+
&.#{$eccgui}-intent--primary {
106+
--eccgui-overviewitem-color-background: #{eccgui-color-var("identity", "brand", "100")};
107+
--eccgui-overviewitem-color-text: #{eccgui-color-var("identity", "brand", "900")};
108+
}
109+
&.#{$eccgui}-intent--accent {
110+
--eccgui-overviewitem-color-background: #{eccgui-color-var("identity", "accent", "100")};
111+
--eccgui-overviewitem-color-text: #{eccgui-color-var("identity", "accent", "900")};
112+
}
77113
}
78114

79115
.#{$eccgui}-overviewitem__item--highdensity {

src/components/OverviewItem/stories/OverviewItem.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from "react";
22
import { OverlaysProvider } from "@blueprintjs/core";
33
import { Meta, StoryFn } from "@storybook/react";
44

5+
import { helpersArgTypes } from "../../../../.storybook/helpers";
6+
57
import {
68
Badge,
79
Card,
@@ -35,6 +37,10 @@ export default {
3537
control: false,
3638
description: "Elements used as depiction, text and interactive elements of an overview-item.",
3739
},
40+
intent: {
41+
...helpersArgTypes.exampleIntent,
42+
options: ["UNDEFINED", "none", "primary", "success", "warning", "danger", "neutral", "accent", "info"],
43+
},
3844
},
3945
} as Meta<typeof OverviewItem>;
4046

0 commit comments

Comments
 (0)