1
+ import {
2
+ type CSSObject ,
3
+ type Interpolation ,
4
+ type Theme ,
5
+ useTheme ,
6
+ } from "@emotion/react" ;
1
7
import Link from "@mui/material/Link" ;
2
- import { makeStyles } from "@mui/styles" ;
8
+ import { css } from "@emotion/react" ;
9
+ import { useState } from "react" ;
3
10
import { Expander } from "components/Expander/Expander" ;
4
11
import { Pill } from "components/Pill/Pill" ;
5
- import { useState } from "react" ;
6
12
import { colors } from "theme/colors" ;
7
13
8
14
export const Language = {
@@ -14,6 +20,13 @@ export const Language = {
14
20
moreDetails : "More" ,
15
21
} ;
16
22
23
+ const styles = {
24
+ leftContent : ( theme ) => ( {
25
+ marginRight : theme . spacing ( 1 ) ,
26
+ marginLeft : theme . spacing ( 1 ) ,
27
+ } ) ,
28
+ } satisfies Record < string , Interpolation < Theme > > ;
29
+
17
30
export interface LicenseBannerViewProps {
18
31
errors : string [ ] ;
19
32
warnings : string [ ] ;
@@ -23,17 +36,26 @@ export const LicenseBannerView: React.FC<LicenseBannerViewProps> = ({
23
36
errors,
24
37
warnings,
25
38
} ) => {
26
- const styles = useStyles ( ) ;
39
+ const theme = useTheme ( ) ;
27
40
const [ showDetails , setShowDetails ] = useState ( false ) ;
28
41
const isError = errors . length > 0 ;
29
42
const messages = [ ...errors , ...warnings ] ;
30
43
const type = isError ? "error" : "warning" ;
31
44
45
+ const containerStyles = css `
46
+ ${ theme . typography . body2 as CSSObject }
47
+
48
+ padding : ${ theme . spacing ( 1.5 ) } ;
49
+ background-color : ${ type === "error"
50
+ ? colors . red [ 12 ]
51
+ : theme . palette . warning . main } ;
52
+ ` ;
53
+
32
54
if ( messages . length === 1 ) {
33
55
return (
34
- < div className = { ` ${ styles . container } ${ type } ` } >
56
+ < div css = { containerStyles } >
35
57
< Pill text = { Language . licenseIssue } type = { type } lightBorder />
36
- < div className = { styles . leftContent } >
58
+ < div css = { styles . leftContent } >
37
59
< span > { messages [ 0 ] } </ span >
38
60
39
61
< Link color = "white" fontWeight = "medium" href = "mailto:sales@coder.com" >
@@ -42,65 +64,43 @@ export const LicenseBannerView: React.FC<LicenseBannerViewProps> = ({
42
64
</ div >
43
65
</ div >
44
66
) ;
45
- } else {
46
- return (
47
- < div className = { `${ styles . container } ${ type } ` } >
48
- < Pill
49
- text = { Language . licenseIssues ( messages . length ) }
50
- type = { type }
51
- lightBorder
52
- />
53
- < div className = { styles . leftContent } >
54
- < div >
55
- { Language . exceeded }
56
-
57
- < Link
58
- color = "white"
59
- fontWeight = "medium"
60
- href = "mailto:sales@coder.com"
61
- >
62
- { Language . upgrade }
63
- </ Link >
64
- </ div >
65
- < Expander expanded = { showDetails } setExpanded = { setShowDetails } >
66
- < ul className = { styles . list } >
67
- { messages . map ( ( message ) => (
68
- < li className = { styles . listItem } key = { message } >
69
- { message }
70
- </ li >
71
- ) ) }
72
- </ ul >
73
- </ Expander >
67
+ }
68
+
69
+ return (
70
+ < div css = { containerStyles } >
71
+ < Pill
72
+ text = { Language . licenseIssues ( messages . length ) }
73
+ type = { type }
74
+ lightBorder
75
+ />
76
+ < div css = { styles . leftContent } >
77
+ < div >
78
+ { Language . exceeded }
79
+
80
+ < Link color = "white" fontWeight = "medium" href = "mailto:sales@coder.com" >
81
+ { Language . upgrade }
82
+ </ Link >
74
83
</ div >
84
+ < Expander expanded = { showDetails } setExpanded = { setShowDetails } >
85
+ < ul
86
+ css = { {
87
+ padding : theme . spacing ( 1 ) ,
88
+ margin : 0 ,
89
+ } }
90
+ >
91
+ { messages . map ( ( message ) => (
92
+ < li
93
+ css = { {
94
+ margin : theme . spacing ( 0.5 ) ,
95
+ } }
96
+ key = { message }
97
+ >
98
+ { message }
99
+ </ li >
100
+ ) ) }
101
+ </ ul >
102
+ </ Expander >
75
103
</ div >
76
- ) ;
77
- }
104
+ </ div >
105
+ ) ;
78
106
} ;
79
-
80
- const useStyles = makeStyles ( ( theme ) => ( {
81
- container : {
82
- ...theme . typography . body2 ,
83
- padding : theme . spacing ( 1.5 ) ,
84
- backgroundColor : theme . palette . warning . main ,
85
- display : "flex" ,
86
- alignItems : "center" ,
87
-
88
- "&.error" : {
89
- backgroundColor : colors . red [ 12 ] ,
90
- } ,
91
- } ,
92
- flex : {
93
- display : "column" ,
94
- } ,
95
- leftContent : {
96
- marginRight : theme . spacing ( 1 ) ,
97
- marginLeft : theme . spacing ( 1 ) ,
98
- } ,
99
- list : {
100
- padding : theme . spacing ( 1 ) ,
101
- margin : 0 ,
102
- } ,
103
- listItem : {
104
- margin : theme . spacing ( 0.5 ) ,
105
- } ,
106
- } ) ) ;
0 commit comments