Skip to content

Commit 5a7fd83

Browse files
authored
Informer: add type option and styles for info type
1 parent 5801d57 commit 5a7fd83

File tree

11 files changed

+156
-40
lines changed

11 files changed

+156
-40
lines changed

apps/react-storybook/stories/informer/Informer.stories.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { wrapDxWithReact } from '../utils';
77
const Informer = wrapDxWithReact(dxInformer);
88

99
const textOptions = {
10-
error: 'error',
11-
biggerError: 'bigger error',
12-
bigError: 'really really big and huge error that takes really much space',
13-
superBigError: 'error that will never be able to fit into one line because it is so big and even if it tried to fit it would still not be able to be displayed properly due to its excessive length',
10+
error: 'message',
11+
biggerError: 'bigger message',
12+
bigError: 'really really big and huge message that takes really much space',
13+
superBigError: 'message that will never be able to fit into one line because it is so big and even if it tried to fit it would still not be able to be displayed properly due to its excessive length',
1414
};
1515

1616
const meta: Meta<typeof Informer> = {
@@ -32,6 +32,7 @@ export const DefaultInformer: Story = {
3232
contentAlignment: 'center',
3333
icon: 'errorcircle',
3434
text: 'error',
35+
type: 'error',
3536
visible: true,
3637
rtlEnabled: false,
3738
disabled: false,
@@ -57,6 +58,10 @@ export const DefaultInformer: Story = {
5758
mapping: textOptions,
5859
control: { type: 'select' }
5960
},
61+
type: {
62+
options: ['error', 'info'],
63+
control: { type: 'select' }
64+
},
6065
visible: {
6166
control: 'boolean'
6267
},
@@ -73,6 +78,7 @@ export const DefaultInformer: Story = {
7378
contentAlignment,
7479
icon,
7580
text,
81+
type,
7682
visible,
7783
rtlEnabled,
7884
disabled,
@@ -85,6 +91,7 @@ export const DefaultInformer: Story = {
8591
rtlEnabled={rtlEnabled}
8692
visible={visible}
8793
text={text}
94+
type={type}
8895
icon={icon}
8996
showBackground={showBackground}
9097
contentAlignment={contentAlignment}

packages/devextreme-scss/scss/widgets/base/informer/_mixins.scss

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
@use "../icons" as *;
22

33
@mixin informer(
4-
$color,
5-
$background-color,
4+
$error-color,
5+
$error-background-color,
6+
$info-color,
7+
$info-background-color,
68
$border-radius,
79
$icon-size,
810
$padding-inline,
911
$padding-block,
1012
$column-gap,
1113
) {
1214
.dx-informer {
13-
color: $color;
1415
padding-inline: $padding-inline;
1516
padding-block: $padding-block;
1617
column-gap: $column-gap;
1718
}
1819

1920
.dx-informer-bg {
20-
background-color: $background-color;
2121
border-radius: $border-radius;
2222
}
2323

24+
.dx-informer-error {
25+
color: $error-color;
26+
27+
&.dx-informer-bg {
28+
background-color: $error-background-color;
29+
}
30+
}
31+
32+
.dx-informer-info {
33+
color: $info-color;
34+
35+
&.dx-informer-bg {
36+
background-color: $info-background-color;
37+
}
38+
}
39+
2440
.dx-informer-icon {
2541
& * {
2642
@include dx-icon-sizing($icon-size);

packages/devextreme-scss/scss/widgets/fluent/informer/_colors.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33

44
// adduse
55

6-
$informer-color: $base-invalid-color !default;
7-
$informer-background-color: null !default;
6+
$informer-error-color: $base-invalid-color !default;
7+
$informer-error-background-color: null !default;
8+
$informer-info-color: $base-text-color !default;
9+
$informer-info-background-color: null !default;
810

911
@if $mode == "light" {
10-
$informer-background-color: lighten(saturate(adjust-hue($base-danger, -358), 0.58), 46.67);
12+
$informer-error-background-color: lighten(saturate(adjust-hue($base-danger, -358), 0.58), 46.67);
13+
$informer-info-background-color: lighten($base-text-color, 74.90);
1114
}
1215

1316
@if $mode == "dark" {
14-
$informer-background-color: darken(desaturate($base-danger, 5.06), 53.53);
17+
$informer-error-background-color: darken(desaturate($base-danger, 5.06), 53.53);
18+
$informer-info-background-color: darken($base-text-color, 76.08);
1519
}

packages/devextreme-scss/scss/widgets/fluent/informer/_index.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// adduse
77

88
@include informer(
9-
$informer-color,
10-
$informer-background-color,
9+
$informer-error-color,
10+
$informer-error-background-color,
11+
$informer-info-color,
12+
$informer-info-background-color,
1113
$informer-border-radius,
1214
$informer-icon-size,
1315
$informer-padding-inline,

packages/devextreme-scss/scss/widgets/generic/informer/_colors.scss

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,63 @@
33

44
// adduse
55

6-
$informer-color: $base-invalid-color !default;
7-
$informer-background-color: null !default;
6+
$informer-error-color: null !default;
7+
$informer-error-background-color: null !default;
8+
$informer-info-color: null !default;
9+
$informer-info-background-color: null !default;
810

911
@if $color == "carmine" {
10-
$informer-color: darken(desaturate(adjust-hue($base-danger, -351), 26.91), 5.49);
11-
$informer-background-color: lighten(desaturate(adjust-hue($base-danger, -347), 26.69), 33.14);
12+
$informer-error-color: darken(desaturate(adjust-hue($base-danger, -351), 26.91), 5.49);
13+
$informer-error-background-color: lighten(desaturate(adjust-hue($base-danger, -347), 26.69), 33.14);
14+
$informer-info-color: $base-text-color;
15+
$informer-info-background-color: lighten($base-text-color, 72.16);
1216
}
1317

1418
@if $color == "contrast" {
15-
$informer-color: darken(desaturate(adjust-hue($base-danger, 2), 16.93), 6.08);
16-
$informer-background-color: rgba(212, 63, 58, 0.1);
19+
$informer-error-color: darken(desaturate(adjust-hue($base-danger, 2), 16.93), 6.08);
20+
$informer-error-background-color: rgba(212, 63, 58, 0.1);
21+
$informer-info-color: darken($base-text-color, 12.94);
22+
$informer-info-background-color: darken($base-text-color, 68.63);;
1723
}
1824

1925
@if $color == "dark" {
20-
$informer-color: $base-danger;
21-
$informer-background-color: rgba(212, 63, 58, 0.1);
26+
$informer-error-color: $base-danger;
27+
$informer-error-background-color: rgba(212, 63, 58, 0.1);
28+
$informer-info-color: $base-text-color;
29+
$informer-info-background-color: darken($base-text-color, 55.69)
2230
}
2331

2432
@if $color == "darkmoon" {
25-
$informer-color: darken(desaturate(adjust-hue($base-danger, -342), 28.85), 6.67);
26-
$informer-background-color: rgba(212, 63, 58, 0.1);
33+
$informer-error-color: darken(desaturate(adjust-hue($base-danger, -342), 28.85), 6.67);
34+
$informer-error-background-color: rgba(212, 63, 58, 0.1);
35+
$informer-info-color: darken($base-text-color, 12.94);
36+
$informer-info-background-color: darken($base-text-color, 68.63);
2737
}
2838

2939
@if $color == "darkviolet" {
30-
$informer-color: $base-danger;
31-
$informer-background-color: rgba(212, 63, 58, 0.1);
40+
$informer-error-color: $base-danger;
41+
$informer-error-background-color: rgba(212, 63, 58, 0.1);
42+
$informer-info-color: darken(desaturate(adjust-hue($base-text-color, -210), 11.11), 9.41);
43+
$informer-info-background-color: darken(desaturate(adjust-hue($base-text-color, -210), 11.11), 65.10);
3244
}
3345

3446
@if $color == "greenmist" {
35-
$informer-color: darken(desaturate(adjust-hue($base-danger, -351), 27.05), 4.90);
36-
$informer-background-color: lighten(desaturate(adjust-hue($base-danger, -348), 26.83), 33.73);
47+
$informer-error-color: darken(desaturate(adjust-hue($base-danger, -351), 27.05), 4.90);
48+
$informer-error-background-color: lighten(desaturate(adjust-hue($base-danger, -348), 26.83), 33.73);
49+
$informer-info-color: darken(desaturate(adjust-hue($base-text-color, -191), 32.77), 3.33);
50+
$informer-info-background-color: lighten(desaturate(adjust-hue($base-text-color, -191), 32.77), 68.82)
3751
}
3852

3953
@if $color == "light" {
40-
$informer-color: $base-danger;
41-
$informer-background-color: lighten(saturate(adjust-hue($base-danger, 4), 0.22), 38.63);
54+
$informer-error-color: $base-danger;
55+
$informer-error-background-color: lighten(saturate(adjust-hue($base-danger, 4), 0.22), 38.63);
56+
$informer-info-color: $base-text-color;
57+
$informer-info-background-color: lighten($base-text-color, 72.16);
4258
}
4359

4460
@if $color == "softblue" {
45-
$informer-color: $base-danger;
46-
$informer-background-color: lighten(saturate(adjust-hue($base-danger, 4), 0.22), 38.63);
61+
$informer-error-color: $base-danger;
62+
$informer-error-background-color: lighten(saturate(adjust-hue($base-danger, 4), 0.22), 38.63);
63+
$informer-info-color: $base-text-color;
64+
$informer-info-background-color: lighten($base-text-color, 72.16);
4765
}

packages/devextreme-scss/scss/widgets/generic/informer/_index.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// adduse
77

88
@include informer(
9-
$informer-color,
10-
$informer-background-color,
9+
$informer-error-color,
10+
$informer-error-background-color,
11+
$informer-info-color,
12+
$informer-info-background-color,
1113
$informer-border-radius,
1214
$informer-icon-size,
1315
$informer-padding-inline,

packages/devextreme-scss/scss/widgets/material/informer/_colors.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33

44
// adduse
55

6-
$informer-color: $base-danger !default;
7-
$informer-background-color: null !default;
6+
$informer-error-color: $base-danger !default;
7+
$informer-error-background-color: null !default;
8+
$informer-info-color: $base-text-color !default;
9+
$informer-info-background-color: null !default;
810

911
@if $mode == "light" {
10-
$informer-background-color: lighten(desaturate(adjust-hue($base-danger, 1), 24.92), 38.24);
12+
$informer-error-background-color: lighten(desaturate(adjust-hue($base-danger, 1), 24.92), 38.24);
13+
$informer-info-background-color: lighten(desaturate(adjust-hue($base-text-color, -240), 100.00), 48.63);
1114
}
1215

1316
@if $mode == "dark" {
14-
$informer-background-color: darken(desaturate(adjust-hue($base-danger, 1), 41.80), 53.92);
17+
$informer-error-background-color: darken(desaturate(adjust-hue($base-danger, 1), 41.80), 53.92);
18+
$informer-info-background-color: darken(saturate(adjust-hue($base-text-color, 240), 6.04), 70.78);
1519
}

packages/devextreme-scss/scss/widgets/material/informer/_index.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// adduse
77

88
@include informer(
9-
$informer-color,
10-
$informer-background-color,
9+
$informer-error-color,
10+
$informer-error-background-color,
11+
$informer-info-color,
12+
$informer-info-background-color,
1113
$informer-border-radius,
1214
$informer-icon-size,
1315
$informer-padding-inline,

packages/devextreme/js/__internal/ui/informer/informer.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import type { OptionChanged } from '@ts/core/widget/types';
77
import Widget from '@ts/core/widget/widget';
88

99
export const INFORMER_CLASS = 'dx-informer';
10+
const INFORMER_ERROR_CLASS = 'dx-informer-error';
11+
const INFORMER_INFO_CLASS = 'dx-informer-info';
1012
const INFORMER_ALIGNMENT_START_CLASS = 'dx-informer-alignment-start';
1113
const INFORMER_ALIGNMENT_CENTER_CLASS = 'dx-informer-alignment-center';
1214
const INFORMER_ALIGNMENT_END_CLASS = 'dx-informer-alignment-end';
@@ -19,6 +21,7 @@ export interface Properties extends WidgetOptions<Informer> {
1921
icon?: string;
2022
showBackground?: boolean;
2123
text?: string;
24+
type?: 'error' | 'info';
2225
}
2326

2427
class Informer extends Widget<Properties> {
@@ -33,6 +36,7 @@ class Informer extends Widget<Properties> {
3336
icon: '',
3437
showBackground: true,
3538
text: '',
39+
type: 'error',
3640
};
3741
}
3842

@@ -42,6 +46,7 @@ class Informer extends Widget<Properties> {
4246
this.$element().addClass(INFORMER_CLASS);
4347
this.$element().toggleClass(INFORMER_BG_CLASS, showBackground);
4448
this._setAlignmentClass();
49+
this._setTypeClass();
4550

4651
super._initMarkup();
4752

@@ -71,6 +76,24 @@ class Informer extends Widget<Properties> {
7176
}
7277
}
7378

79+
_setTypeClass(): void {
80+
this.$element()
81+
.removeClass(INFORMER_ERROR_CLASS)
82+
.removeClass(INFORMER_INFO_CLASS);
83+
84+
const { type } = this.option();
85+
86+
switch (type) {
87+
case 'info':
88+
this.$element().addClass(INFORMER_INFO_CLASS);
89+
break;
90+
case 'error':
91+
default:
92+
this.$element().addClass(INFORMER_ERROR_CLASS);
93+
break;
94+
}
95+
}
96+
7497
_renderIcon(): void {
7598
this._$icon?.remove();
7699

@@ -119,6 +142,9 @@ class Informer extends Widget<Properties> {
119142
case 'text':
120143
this._updateText();
121144
break;
145+
case 'type':
146+
this._setTypeClass();
147+
break;
122148
default:
123149
super._optionChanged(args);
124150
}

packages/devextreme/testing/tests/DevExpress.ui.widgets/informer.markup.tests.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import $ from 'jquery';
33
import Informer from 'ui/informer';
44

55
const INFORMER_CLASS = 'dx-informer';
6+
const INFORMER_ERROR_CLASS = 'dx-informer-error';
7+
const INFORMER_INFO_CLASS = 'dx-informer-info';
68
const INFORMER_ALIGNMENT_START_CLASS = 'dx-informer-alignment-start';
79
const INFORMER_ALIGNMENT_CENTER_CLASS = 'dx-informer-alignment-center';
810
const INFORMER_ALIGNMENT_END_CLASS = 'dx-informer-alignment-end';
@@ -96,5 +98,37 @@ QUnit.module('Informer', moduleConfig, () => {
9698
assert.strictEqual(this.$element.hasClass(INFORMER_ALIGNMENT_START_CLASS), false, 'previous alignment class is removed');
9799
assert.strictEqual(this.$element.hasClass(INFORMER_ALIGNMENT_END_CLASS), true, 'new alignment class is added');
98100
});
101+
102+
QUnit.test(`should have ${INFORMER_ERROR_CLASS} class by default`, function(assert) {
103+
assert.strictEqual(this.$element.hasClass(INFORMER_ALIGNMENT_CENTER_CLASS), true);
104+
});
105+
106+
[
107+
{
108+
type: 'error',
109+
className: INFORMER_ERROR_CLASS,
110+
},
111+
{
112+
type: 'info',
113+
className: INFORMER_INFO_CLASS,
114+
},
115+
].forEach(({ type, className }) => {
116+
QUnit.test(`should have ${className} class when type=${type}`, function(assert) {
117+
this.reinit({ type });
118+
119+
assert.strictEqual(this.$element.hasClass(className), true);
120+
});
121+
});
122+
123+
QUnit.test('should add actual type class and remove the old one on type option runtime change', function(assert) {
124+
this.reinit({ type: 'info' });
125+
126+
assert.strictEqual(this.$element.hasClass(INFORMER_INFO_CLASS), true, 'info type class is added on init');
127+
128+
this.instance.option('type', 'error');
129+
130+
assert.strictEqual(this.$element.hasClass(INFORMER_INFO_CLASS), false, 'previous type info class is removed');
131+
assert.strictEqual(this.$element.hasClass(INFORMER_ERROR_CLASS), true, 'new type error class is added');
132+
});
99133
});
100134
});

0 commit comments

Comments
 (0)