Skip to content

Commit 9487b98

Browse files
committed
reintroduced spinner color and fixed notification intent behaviour, added intent to MultiSelect, fixed fieldItem and fieldSet, added changelog
1 parent b67db11 commit 9487b98

8 files changed

Lines changed: 50 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
4848
- `operation-format-list-bullet`
4949
- `operation-format-list-checked`
5050
- `operation-format-list-numbered`
51+
- `intent` property to `Button`, `FieldItem`, `FieldSet`, `Notification`, and `Spinner`
5152

5253
### Fixed
5354

src/components/Form/FieldItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ export const FieldItem = ({
117117
const notification =
118118
messageText &&
119119
(typeof messageText === "string" ? (
120-
<p className={`${eccgui}-fielditem__message` + intentClass || classIntent}>{messageText}</p>
120+
<p className={`${eccgui}-fielditem__message` + (intentClass || classIntent)}>{messageText}</p>
121121
) : (
122-
<div className={`${eccgui}-fielditem__message` + intentClass || classIntent}>{messageText}</div>
122+
<div className={`${eccgui}-fielditem__message` + (intentClass || classIntent)}>{messageText}</div>
123123
));
124124

125125
return (

src/components/Form/FieldSet.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ export const FieldSet = ({
107107
return (
108108
<fieldset
109109
className={
110-
`${eccgui}-fieldset` + (className ? " " + className : "") + intentClass ||
111-
classIntent + (boxed ? ` ${eccgui}-fieldset--boxed` : "")
110+
`${eccgui}-fieldset` +
111+
(className ? " " + className : "") +
112+
(intentClass || classIntent) +
113+
(boxed ? ` ${eccgui}-fieldset--boxed` : "")
112114
}
113115
{...otherProps}
114116
>

src/components/MultiSelect/MultiSelect.tsx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,28 @@ interface MultiSelectCommonProps<T>
7878
* Items that were newly created and not taken from the list will be post-fixed with this string.
7979
*/
8080
newItemPostfix?: string;
81+
/**
82+
* Intent state of the multi select.
83+
*/
84+
intent?: BlueprintIntent;
8185
/**
8286
* The input element is displayed with primary color scheme.
87+
* @deprecated (v25) use `intent="primary"` instead.
8388
*/
8489
hasStatePrimary?: boolean;
8590
/**
8691
* The input element is displayed with success (some type of green) color scheme.
92+
* @deprecated (v25) use `intent="success"` instead.
8793
*/
8894
hasStateSuccess?: boolean;
8995
/**
90-
* The input element is displayed with success (some type of orange) color scheme.
96+
* The input element is displayed with warning (some type of orange) color scheme.
97+
* @deprecated (v25) use `intent="warning"` instead.
9198
*/
9299
hasStateWarning?: boolean;
93100
/**
94-
* The input element is displayed with success (some type of red) color scheme.
101+
* The input element is displayed with danger (some type of red) color scheme.
102+
* @deprecated (v25) use `intent="danger"` instead.
95103
*/
96104
hasStateDanger?: boolean;
97105
/**
@@ -179,6 +187,7 @@ function MultiSelect<T>({
179187
wrapperProps,
180188
searchPredicate,
181189
limitHeightOpened,
190+
intent,
182191
...otherMultiSelectProps
183192
}: MultiSelectProps<T>) {
184193
// Options created by a user
@@ -203,19 +212,19 @@ function MultiSelect<T>({
203212
timeoutId?: number;
204213
}>({});
205214

206-
let intent;
215+
let stateIntent;
207216
switch (true) {
208217
case hasStatePrimary:
209-
intent = BlueprintIntent.PRIMARY;
218+
stateIntent = BlueprintIntent.PRIMARY;
210219
break;
211220
case hasStateSuccess:
212-
intent = BlueprintIntent.SUCCESS;
221+
stateIntent = BlueprintIntent.SUCCESS;
213222
break;
214223
case hasStateWarning:
215-
intent = BlueprintIntent.WARNING;
224+
stateIntent = BlueprintIntent.WARNING;
216225
break;
217226
case hasStateDanger:
218-
intent = BlueprintIntent.DANGER;
227+
stateIntent = BlueprintIntent.DANGER;
219228
break;
220229
default:
221230
break;
@@ -230,12 +239,11 @@ function MultiSelect<T>({
230239
}, [items.map((item) => itemId(item)).join("|")]);
231240

232241
React.useEffect(() => {
233-
onSelection &&
234-
onSelection({
235-
newlySelected: selectedItems.slice(-1)[0],
236-
createdItems: createdItems.current,
237-
selectedItems,
238-
});
242+
onSelection?.({
243+
newlySelected: selectedItems.slice(-1)[0],
244+
createdItems: createdItems.current,
245+
selectedItems,
246+
});
239247
}, [
240248
onSelection,
241249
selectedItems.map((item) => itemId(item)).join("|"),
@@ -430,7 +438,11 @@ function MultiSelect<T>({
430438
const handleOnKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {
431439
if (event.key === "Tab" && !!requestState.current.query) {
432440
event.preventDefault();
433-
focusedItem ? onItemSelect(focusedItem) : onItemSelect(createNewItem(requestState.current.query));
441+
if (focusedItem) {
442+
onItemSelect(focusedItem);
443+
} else {
444+
onItemSelect(createNewItem(requestState.current.query));
445+
}
434446
requestState.current.query = "";
435447
setTimeout(() => inputRef.current?.focus());
436448
}
@@ -511,7 +523,7 @@ function MultiSelect<T>({
511523
className: `${eccgui}-multiselect` + (className ? ` ${className}` : ""),
512524
fill: fullWidth,
513525
inputRef: inputRef,
514-
intent,
526+
intent: intent || stateIntent,
515527
addOnBlur: true,
516528
onKeyDown: handleOnKeyDown,
517529
onKeyUp: handleOnKeyUp,

src/components/MultiSuggestField/MultiSuggestField.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { OverlaysProvider } from "@blueprintjs/core";
44
import { Meta, StoryFn } from "@storybook/react";
55
import { fn } from "@storybook/test";
66

7+
import { helpersArgTypes } from "../../../.storybook/helpers";
8+
79
import { MultiSuggestField, MultiSuggestFieldSelectionProps, SimpleDialog } from "./../../../index";
810

911
const testLabels = loremIpsum({
@@ -29,6 +31,10 @@ export default {
2931
items: {
3032
control: "none",
3133
},
34+
intent: {
35+
...helpersArgTypes.exampleIntent,
36+
options: ["UNDEFINED", "primary", "success", "warning", "danger"],
37+
},
3238
},
3339
args: {
3440
onSelection: fn(),

src/components/Notification/Notification.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const Notification = ({
8989
wrapperProps,
9090
"data-test-id": dataTestId,
9191
"data-testid": dataTestid,
92-
intent = "info",
92+
intent,
9393
...otherProps
9494
}: NotificationProps) => {
9595
let intentLevel: string = IntentClassNames.INFO;
@@ -112,7 +112,7 @@ export const Notification = ({
112112
break;
113113
}
114114

115-
const intents: Array<NotificationProps["intent"]> = ["success", "warning", "danger"];
115+
const intents: Array<NotificationProps["intent"]> = ["info", "success", "warning", "danger"];
116116
const intentClass = intent ? " " + IntentClassNames[intent.toUpperCase()] : "";
117117
const intentIconSymbol = intents.includes(intent) ? `state-${intent}` : "state-info";
118118

src/components/Spinner/Spinner.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Intent = "inherit" | "primary" | "success" | "warning" | "danger";
1717
export interface SpinnerProps extends Omit<BlueprintSpinnerProps, "size" | "intent"> {
1818
/**
1919
* intent value or a valid css color definition
20-
* @deprecated (v25) use `intent` instead.
20+
* @deprecated (v25) it will allow in the future only a color value string and that for other states the intent property needs to be used
2121
*/
2222
color?: Intent | string;
2323
/**
@@ -98,9 +98,9 @@ export const Spinner = ({
9898
};
9999

100100
const spinnerElement = position === "inline" ? "span" : "div";
101-
const computedColor = intent || color;
102-
const spinnerColor = availableIntent.indexOf(computedColor) < 0 ? computedColor : null;
103-
const spinnerIntent = availableIntent.indexOf(computedColor) < 0 ? "usercolor" : computedColor;
101+
102+
const spinnerColor = !intent && availableIntent.indexOf(color) < 0 ? color : null;
103+
const spinnerIntent = !intent && availableIntent.indexOf(color) < 0 ? "usercolor" : intent || color;
104104

105105
let spinnerSize;
106106
let spinnerStroke;
@@ -138,7 +138,7 @@ export const Spinner = ({
138138
/>
139139
);
140140

141-
if (spinnerColor) {
141+
if (spinnerColor && spinnerIntent === "usercolor") {
142142
spinner = <span style={{ color: spinnerColor }}>{spinner}</span>;
143143
}
144144

src/components/Spinner/Stories/spinner.stories.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from "react";
22
import { Meta, StoryFn } from "@storybook/react";
33

4+
import { helpersArgTypes } from "../../../../.storybook/helpers";
45
import Spinner from "../Spinner";
56
export default {
67
title: "Components/Spinner",
78
component: Spinner,
89
argTypes: {
9-
color: { control: "radio", options: ["inherit", "primary", "success", "warning", "danger"] },
10-
intent: { control: "radio", options: ["inherit", "primary", "success", "warning", "danger"] },
10+
color: { control: "color" },
11+
intent: { ...helpersArgTypes.exampleIntent, options: ["UNDEFINED", "primary", "success", "warning", "danger"] },
1112
position: { control: "radio", options: ["local", "inline", "global"] },
1213
size: { control: "radio", options: ["tiny", "small", "medium", "large", "xlarge", "inherit"] },
1314
stroke: { control: "radio", options: ["thin", "medium", "bold"] },

0 commit comments

Comments
 (0)