Skip to content

Commit 765e6d7

Browse files
committed
frontend: use Message component for Status
to improve consistency & aesthetics, we'd like to use our revamped Message component for our Status component. Please note that our Banner component uses Status. Therefore, with this change, Banner will also use Message component.
1 parent 0c82d7b commit 765e6d7

File tree

6 files changed

+50
-93
lines changed

6 files changed

+50
-93
lines changed

frontends/web/src/api/banners.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616

1717
import { apiGet } from '@/utils/request';
18-
import { statusType } from '@/components/status/status';
1918
import { subscribeEndpoint, TUnsubscribe } from './subscribe';
19+
import { TMessageTypes } from '@/utils/types';
2020

2121
export type TBannerInfo = {
2222
id: string;
@@ -26,7 +26,7 @@ export type TBannerInfo = {
2626
text?: string;
2727
};
2828
dismissible?: boolean;
29-
type?: statusType;
29+
type?: TMessageTypes;
3030
}
3131

3232
export const getBanner = (msgKey: string): Promise<TBannerInfo> => {

frontends/web/src/components/message/message.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
.content {
1616
padding-top: 2px;
17+
width: 100%;
1718
}
1819

1920
.message .title {

frontends/web/src/components/message/message.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import { ReactNode } from 'react';
1919
import { StatusInfo, StatusSuccess, StatusWarning, StatusError } from '@/components/icon';
2020
import styles from './message.module.css';
21+
import { TMessageTypes } from '@/utils/types';
2122

22-
type TMessageTypes = 'success' | 'info' | 'warning' | 'error';
2323
type TMessageIconProps = { type: TMessageTypes };
2424

2525
const MessageIcon = ({ type }: TMessageIconProps) => {
Lines changed: 15 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,27 @@
1+
.content {
2+
margin-right: var(--space-half);
3+
}
4+
15
.container {
2-
margin: 0 auto;
3-
position: relative;
4-
padding: calc(var(--space-default) * 1.5);
6+
align-items: flex-start;
7+
display: flex;
58
width: 100%;
69
}
710
.container.withCloseBtn {
811
padding-right: 60px;
912
}
1013

11-
:global(.padded) .container {
12-
max-width: var(--content-width);
13-
}
14-
15-
.status {
16-
font-size: var(--size-subheader);
17-
max-width: 800px;
18-
text-align: left;
19-
}
20-
21-
.success {
22-
background-color: var(--color-success);
23-
}
24-
25-
.warning {
26-
background-color: var(--color-warning);
27-
}
28-
29-
.info {
30-
background-color: var(--color-info);
31-
}
32-
33-
.success,
34-
.warning,
35-
.info,
36-
.success label, /* also force label elements to use color white */
37-
.warning label,
38-
.info label {
39-
color: var(--color-alt);
40-
}
41-
42-
.close-success {
43-
background: var(--color-darkgreen);
44-
}
45-
46-
.close-warning {
47-
background: var(--color-swissred);
48-
}
49-
50-
.close-info {
51-
background: var(--color-darkblue);
52-
}
53-
54-
.close {
14+
.closeButton {
15+
background-color: transparent;
5516
border: none;
56-
line-height: .5;
57-
padding: var(--space-half);
58-
position: absolute;
59-
top: 0;
60-
right: 0;
17+
margin-left: auto;
6118
}
6219

63-
.close svg {
64-
width: 18px;
65-
height: 18px;
20+
.closeButton img {
21+
width: 16px;
22+
height: 16px;
6623
}
6724

68-
.withCloseBtn .status::before {
69-
content: "";
70-
float: right;
71-
height: 18px;
72-
padding-bottom: 2px;
73-
padding-left: var(--space-default);
74-
width: 18px;
75-
}
76-
77-
@media (max-width: 1199px) {
78-
.container {
79-
padding: calc(var(--space-half) * 1.5);
80-
}
81-
}
25+
.messageWrapper {
26+
margin-bottom: calc(var(--spacing-default) * -1);
27+
}

frontends/web/src/components/status/status.tsx

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,35 @@
1717

1818
import { ReactNode, useCallback, useEffect, useState } from 'react';
1919
import { getConfig, setConfig } from '@/utils/config';
20-
import { CloseXWhite } from '@/components/icon';
20+
import { CloseXDark, CloseXWhite } from '@/components/icon';
21+
import { useDarkmode } from '@/hooks/darkmode';
22+
import { Message } from '@/components/message/message';
2123
import style from './status.module.css';
24+
import { TMessageTypes } from '@/utils/types';
2225

23-
export type statusType = 'success' | 'warning' | 'info';
2426

2527
type TPRops = {
26-
hidden?: boolean;
27-
type?: statusType;
28-
// used as keyName in the config if dismissing the status should be persisted, so it is not
29-
// shown again. Use an empty string if it should be dismissible without storing it in the
30-
// config, so the status will be shown again the next time.
31-
dismissible?: string;
32-
className?: string;
33-
children: ReactNode;
28+
hidden?: boolean;
29+
type?: TMessageTypes;
30+
// used as keyName in the config if dismissing the status should be persisted, so it is not
31+
// shown again. Use an empty string if it should be dismissible without storing it in the
32+
// config, so the status will be shown again the next time.
33+
dismissible?: string;
34+
className?: string;
35+
children: ReactNode;
3436
}
3537

3638
export const Status = ({
3739
hidden,
3840
type = 'warning',
3941
dismissible,
40-
className,
42+
className = '',
4143
children,
4244
}: TPRops) => {
4345
const [show, setShow] = useState(dismissible ? false : true);
4446

47+
const { isDarkMode } = useDarkmode();
48+
4549
const checkConfig = useCallback(async () => {
4650
if (dismissible) {
4751
const config = await getConfig();
@@ -70,16 +74,21 @@ export const Status = ({
7074
}
7175

7276
return (
73-
<div className={[style.container, style[type], className ? className : '', dismissible ? style.withCloseBtn : ''].join(' ')}>
74-
<div className={style.status}>
75-
{children}
76-
<button
77-
hidden={!dismissible}
78-
className={`${style.close} ${style[`close-${type}`]}`}
79-
onClick={dismiss}>
80-
<CloseXWhite />
81-
</button>
82-
</div>
77+
<div className={`${style.messageWrapper} ${className}`}>
78+
<Message type={type}>
79+
<div className={style.container}>
80+
<div className={style.content}>
81+
{children}
82+
</div>
83+
<button
84+
hidden={!dismissible}
85+
className={style.closeButton}
86+
onClick={dismiss}
87+
>
88+
{isDarkMode ? <CloseXWhite /> : <CloseXDark />}
89+
</button>
90+
</div>
91+
</Message>
8392
</div>
8493
);
8594
};

frontends/web/src/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ export type KeysOf<T> = Array<keyof T>;
2828
export type ObjectButNotFunction = object & { prototype?: never; };
2929

3030
export type TDeviceNameError = undefined | 'tooShort' | 'tooLong' | 'invalidChars'
31+
export type TMessageTypes = 'success' | 'info' | 'warning' | 'error';

0 commit comments

Comments
 (0)