Skip to content

Commit 7d1f1ee

Browse files
committed
added intent property to replace deprecated ones (hasState, color, or others)
1 parent ce1830b commit 7d1f1ee

10 files changed

Lines changed: 89 additions & 19 deletions

File tree

src/components/Button/Button.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export default {
1818
onClick: {
1919
action: "clicked",
2020
},
21+
intent: {
22+
...helpersArgTypes.exampleIntent,
23+
},
2124
},
2225
} as Meta<typeof Button>;
2326

src/components/Button/Button.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ButtonProps as BlueprintButtonProps,
77
Intent as BlueprintIntent,
88
} from "@blueprintjs/core";
9+
import { IntentTypes } from "common/Intent";
910

1011
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
1112
import { ValidIconName } from "../Icon/canonicalIconNames";
@@ -15,6 +16,10 @@ import Badge, { BadgeProps } from "./../Badge/Badge";
1516
import Tooltip, { TooltipProps } from "./../Tooltip/Tooltip";
1617

1718
interface AdditionalButtonProps {
19+
/**
20+
* Intent state of the button.
21+
*/
22+
intent?: IntentTypes;
1823
/**
1924
* Always use this when the button triggers an affirmative action, e.g. confirm a process.
2025
* The button is displayed with primary color scheme.
@@ -23,27 +28,33 @@ interface AdditionalButtonProps {
2328
/**
2429
* Always use this when the button triggers an disruptive action, e.g. delete or remove.
2530
* The button is displayed with primary color scheme.
31+
* @deprecated use `intent` instead.
2632
*/
2733
disruptive?: boolean;
2834
/**
2935
* Use this when a button is important enough to highlight it in a set of other buttons.
3036
* The button is displayed with primary color scheme.
37+
* @deprecated use `intent` instead.
3138
*/
3239
elevated?: boolean;
3340
/**
3441
* The button is displayed with primary color scheme.
42+
* @deprecated use `intent` instead.
3543
*/
3644
hasStatePrimary?: boolean;
3745
/**
3846
* The button is displayed with success (some type of green) color scheme.
47+
* @deprecated use `intent` instead.
3948
*/
4049
hasStateSuccess?: boolean;
4150
/**
4251
* The button is displayed with warning (some type of orange) color scheme.
52+
* @deprecated use `intent` instead.
4353
*/
4454
hasStateWarning?: boolean;
4555
/**
4656
* The button is displayed with danger (some type of red) color scheme.
57+
* @deprecated use `intent` instead.
4758
*/
4859
hasStateDanger?: boolean;
4960
/**
@@ -73,10 +84,12 @@ interface AdditionalButtonProps {
7384
//target?: string;
7485
}
7586

76-
interface ExtendedButtonProps extends AdditionalButtonProps, Omit<BlueprintButtonProps, "icon" | "rightIcon"> {}
87+
interface ExtendedButtonProps
88+
extends AdditionalButtonProps,
89+
Omit<BlueprintButtonProps, "icon" | "rightIcon" | "intent"> {}
7790
interface ExtendedAnchorButtonProps
7891
extends AdditionalButtonProps,
79-
Omit<BlueprintAnchorButtonProps, "icon" | "rightIcon"> {}
92+
Omit<BlueprintAnchorButtonProps, "icon" | "rightIcon" | "intent"> {}
8093

8194
export type ButtonProps = ExtendedButtonProps & ExtendedAnchorButtonProps;
8295

@@ -100,6 +113,7 @@ export const Button = ({
100113
tooltipProps,
101114
badge,
102115
badgeProps = { size: "small", position: "top-right", maxLength: 2 },
116+
intent,
103117
...restProps
104118
}: ButtonProps) => {
105119
let intention;
@@ -120,13 +134,13 @@ export const Button = ({
120134
break;
121135
}
122136

123-
const ButtonType: any = restProps.href ? BlueprintAnchorButton : BlueprintButton;
137+
const ButtonType = restProps.href ? BlueprintAnchorButton : BlueprintButton;
124138

125139
const button = (
126140
<ButtonType
127141
{...restProps}
128142
className={`${eccgui}-button ` + className}
129-
intent={intention}
143+
intent={(intent || intention) as BlueprintIntent}
130144
icon={typeof icon === "string" ? <Icon name={icon} /> : icon}
131145
rightIcon={typeof rightIcon === "string" ? <Icon name={rightIcon} /> : rightIcon}
132146
>

src/components/Form/FieldItem.tsx

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

3-
import { ClassNames as IntentClassNames } from "../../common/Intent";
3+
import { ClassNames as IntentClassNames, IntentTypes } from "../../common/Intent";
44
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
55
import { TestableComponent } from "../interfaces";
66
import Label, { LabelProps } from "../Label/Label";
@@ -18,23 +18,31 @@ export interface FieldItemProps extends React.HTMLAttributes<HTMLDivElement>, Te
1818
/**
1919
* Set primary state.
2020
* This is not routed through automatically.
21+
* @deprecated use `intent` instead.
2122
*/
2223
hasStatePrimary?: boolean;
2324
/**
2425
* Set success state.
2526
* This is not routed through automatically.
27+
* @deprecated use `intent` instead.
2628
*/
2729
hasStateSuccess?: boolean;
2830
/**
2931
* Set warning state.
3032
* This is not routed through automatically.
33+
* @deprecated use `intent` instead.
3134
*/
3235
hasStateWarning?: boolean;
3336
/**
3437
* Set danger state.
3538
* This is not routed through automatically.
39+
* @deprecated use `intent` instead.
3640
*/
3741
hasStateDanger?: boolean;
42+
/**
43+
* Intent state of the field item.
44+
*/
45+
intent?: IntentTypes;
3846
/**
3947
* Is disabled.
4048
* The included inout element nedd to set disabled directly itself.
@@ -71,6 +79,7 @@ export const FieldItem = ({
7179
labelProps,
7280
helperText,
7381
messageText,
82+
intent,
7483
...otherProps
7584
}: FieldItemProps) => {
7685
let classIntent = "";
@@ -91,6 +100,8 @@ export const FieldItem = ({
91100
break;
92101
}
93102

103+
const intentClass = intent ? " " + IntentClassNames[intent.toUpperCase()] : "";
104+
94105
const label = <Label {...labelProps} disabled={disabled} />;
95106

96107
const userhelp =
@@ -106,9 +117,9 @@ export const FieldItem = ({
106117
const notification =
107118
messageText &&
108119
(typeof messageText === "string" ? (
109-
<p className={`${eccgui}-fielditem__message` + classIntent}>{messageText}</p>
120+
<p className={`${eccgui}-fielditem__message` + intentClass || classIntent}>{messageText}</p>
110121
) : (
111-
<div className={`${eccgui}-fielditem__message` + classIntent}>{messageText}</div>
122+
<div className={`${eccgui}-fielditem__message` + intentClass || classIntent}>{messageText}</div>
112123
));
113124

114125
return (

src/components/Form/FieldSet.tsx

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

3-
import { ClassNames as IntentClassNames } from "../../common/Intent";
3+
import { ClassNames as IntentClassNames, IntentTypes } from "../../common/Intent";
44
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
55

66
export interface FieldSetProps extends Omit<React.FieldsetHTMLAttributes<HTMLFieldSetElement>, "title"> {
@@ -11,20 +11,28 @@ export interface FieldSetProps extends Omit<React.FieldsetHTMLAttributes<HTMLFie
1111
boxed?: boolean;
1212
/**
1313
* The fieldsetsection is displayed with primary color scheme.
14+
* @deprecated use `intent` instead.
1415
*/
1516
hasStatePrimary?: boolean;
1617
/**
1718
* The fieldset section is displayed with success (some type of green) color scheme.
19+
* @deprecated use `intent` instead.
1820
*/
1921
hasStateSuccess?: boolean;
2022
/**
2123
* The fieldset section is displayed with warning (some type of orange) color scheme.
24+
* @deprecated use `intent` instead.
2225
*/
2326
hasStateWarning?: boolean;
2427
/**
2528
* The fieldsetsection is displayed with danger (some type of red) color scheme.
29+
* @deprecated use `intent` instead.
2630
*/
2731
hasStateDanger?: boolean;
32+
/**
33+
* Intent state of the field item.
34+
*/
35+
intent?: IntentTypes;
2836
/**
2937
* Optional helper text. If given then it is displayed after the title.
3038
*/
@@ -52,6 +60,7 @@ export const FieldSet = ({
5260
hasStateSuccess = false,
5361
hasStateWarning = false,
5462
hasStateDanger = false,
63+
intent,
5564
helperText,
5665
messageText,
5766
title,
@@ -75,6 +84,8 @@ export const FieldSet = ({
7584
break;
7685
}
7786

87+
const intentClass = intent ? " " + IntentClassNames[intent.toUpperCase()] : "";
88+
7889
const userhelp =
7990
helperText &&
8091
(typeof helperText === "string" ? (
@@ -96,10 +107,8 @@ export const FieldSet = ({
96107
return (
97108
<fieldset
98109
className={
99-
`${eccgui}-fieldset` +
100-
(className ? " " + className : "") +
101-
classIntent +
102-
(boxed ? ` ${eccgui}-fieldset--boxed` : "")
110+
`${eccgui}-fieldset` + (className ? " " + className : "") + intentClass ||
111+
classIntent + (boxed ? ` ${eccgui}-fieldset--boxed` : "")
103112
}
104113
{...otherProps}
105114
>

src/components/Form/Stories/FieldItem.stories.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import { LoremIpsum } from "react-lorem-ipsum";
33
import { Meta, StoryFn } from "@storybook/react";
44

5+
import { helpersArgTypes } from "../../../../.storybook/helpers";
56
import { FieldItem, TextField } from "../../../../index";
67

78
export default {
@@ -11,6 +12,9 @@ export default {
1112
children: {
1213
control: "none",
1314
},
15+
intent: {
16+
...helpersArgTypes.exampleIntent,
17+
},
1418
},
1519
} as Meta<typeof FieldItem>;
1620

src/components/Form/Stories/FieldSet.stories.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import { LoremIpsum } from "react-lorem-ipsum";
33
import { Meta, StoryFn } from "@storybook/react";
44

5+
import { helpersArgTypes } from "../../../../.storybook/helpers";
56
import { FieldItem, FieldItemRow, FieldSet, TitleSubsection } from "../../../../index";
67

78
import { Default as SimpleFieldItemExample } from "./FieldItem.stories";
@@ -14,6 +15,9 @@ export default {
1415
children: {
1516
control: "none",
1617
},
18+
intent: {
19+
...helpersArgTypes.exampleIntent,
20+
},
1721
},
1822
} as Meta<typeof FieldSet>;
1923

src/components/Notification/Notification.stories.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export default {
1515
icon: {
1616
...helpersArgTypes.exampleIcon,
1717
},
18+
intent: {
19+
...helpersArgTypes.exampleIntent,
20+
options: ["UNDEFINED", "success", "warning", "danger", "neutral"],
21+
},
1822
},
1923
} as Meta<typeof Notification>;
2024

src/components/Notification/Notification.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ToastProps as BlueprintToastProps,
66
} from "@blueprintjs/core";
77

8-
import { ClassNames as IntentClassNames } from "../../common/Intent";
8+
import { ClassNames as IntentClassNames, IntentTypes } from "../../common/Intent";
99
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
1010
import { TestableComponent } from "../interfaces";
1111

@@ -25,23 +25,30 @@ export interface NotificationProps
2525
* Notification message that can be used as alternative to children elements.
2626
*/
2727
message?: JSX.Element | string;
28+
/**
29+
* Intent state of the notification.
30+
*/
31+
intent?: Extract<IntentTypes, "neutral" | "success" | "warning" | "danger">;
2832
/**
2933
* Notification has a neutral color scheme.
3034
*/
3135
neutral?: boolean;
3236
/**
3337
* Notification is a success info.
3438
* This defines the colorization and the icon symbol.
39+
* @deprecated use `intent` instead.
3540
*/
3641
success?: boolean;
3742
/**
3843
* Notification is a warning alert.
3944
* This defines the colorization and the icon symbol.
45+
* @deprecated use `intent` instead.
4046
*/
4147
warning?: boolean;
4248
/**
4349
* Notification is a danger alert.
4450
* This defines the colorization and the icon symbol.
51+
* @deprecated use `intent` instead.
4552
*/
4653
danger?: boolean;
4754
/**
@@ -81,6 +88,7 @@ export const Notification = ({
8188
wrapperProps,
8289
"data-test-id": dataTestId,
8390
"data-testid": dataTestid,
91+
intent,
8492
...otherProps
8593
}: NotificationProps) => {
8694
let intentLevel: string = IntentClassNames.INFO;
@@ -103,9 +111,13 @@ export const Notification = ({
103111
break;
104112
}
105113

114+
const intents: Array<NotificationProps["intent"]> = ["success", "warning", "danger"];
115+
const intentClass = intent ? " " + IntentClassNames[intent.toUpperCase()] : "";
116+
const intentIconSymbol = intents.includes(intent) ? `state-${intent}` : "";
117+
106118
let notificationIcon = icon !== false ? icon : undefined;
107-
if (icon !== false && !notificationIcon && !!iconSymbol) {
108-
notificationIcon = <Icon name={iconSymbol as ValidIconName} />;
119+
if (icon !== false && !notificationIcon && (!!iconSymbol || !!intentIconSymbol)) {
120+
notificationIcon = <Icon name={(intentIconSymbol || iconSymbol) as ValidIconName} />;
109121
}
110122

111123
const content = actions ? (
@@ -123,7 +135,7 @@ export const Notification = ({
123135
<BlueprintToast
124136
className={
125137
`${eccgui}-notification ` +
126-
intentLevel +
138+
(intentClass || intentLevel) +
127139
(className ? ` ${className}` : "") +
128140
(flexWidth ? ` ${eccgui}-notification--flexwidth` : "") +
129141
(otherProps.onDismiss ? "" : ` ${eccgui}-notification--static`)

0 commit comments

Comments
 (0)