2
2
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com>
3
3
//
4
4
// SPDX-License-Identifier: Apache-2.0
5
+ import NotesIcon from '@mui/icons-material/Notes' ;
6
+ import { Badge , ToggleButton } from '@mui/material' ;
5
7
import MuiBox from '@mui/material/Box' ;
6
8
import { sortBy } from 'lodash' ;
7
- import { useMemo } from 'react' ;
9
+ import { useMemo , useState } from 'react' ;
8
10
9
11
import { PackageInfo } from '../../../../shared/shared-types' ;
10
12
import { text } from '../../../../shared/text' ;
@@ -46,6 +48,7 @@ export function LicenseSubPanel({
46
48
hidden,
47
49
config,
48
50
} : LicenseSubPanelProps ) {
51
+ const [ showLicenseText , setShowLicenseText ] = useState ( false ) ;
49
52
const dispatch = useAppDispatch ( ) ;
50
53
const frequentLicenseTexts = useAppSelector ( getFrequentLicensesTexts ) ;
51
54
const frequentLicensesNames = useAppSelector ( getFrequentLicensesNameOrder ) ;
@@ -71,47 +74,69 @@ export function LicenseSubPanel({
71
74
72
75
return hidden ? null : (
73
76
< MuiBox >
74
- < PackageAutocomplete
75
- attribute = { 'licenseName' }
76
- title = { text . attributionColumn . licenseName }
77
- packageInfo = { packageInfo }
78
- readOnly = { ! onEdit }
79
- showHighlight = { showHighlight }
80
- onEdit = { onEdit }
81
- endAdornment = { config ?. licenseName ?. endIcon }
82
- defaults = { defaultLicenses }
83
- color = { config ?. licenseName ?. color }
84
- focused = { config ?. licenseName ?. focused }
85
- />
86
- < TextBox
87
- readOnly = { ! onEdit }
88
- placeholder = { defaultLicenseText }
89
- sx = { classes . licenseText }
90
- maxRows = { 8 }
91
- minRows = { 3 }
92
- color = { config ?. licenseText ?. color }
93
- focused = { config ?. licenseText ?. focused }
94
- multiline
95
- expanded = { expanded }
96
- title = {
97
- defaultLicenseText
98
- ? text . attributionColumn . licenseTextDefault
99
- : text . attributionColumn . licenseText
100
- }
101
- text = { packageInfo . licenseText }
102
- handleChange = { ( { target : { value } } ) =>
103
- onEdit ?.( ( ) =>
104
- dispatch (
105
- setTemporaryDisplayPackageInfo ( {
106
- ...packageInfo ,
107
- licenseText : value ,
108
- wasPreferred : undefined ,
109
- } ) ,
110
- ) ,
111
- )
112
- }
113
- endIcon = { config ?. licenseText ?. endIcon }
114
- />
77
+ < MuiBox display = { 'flex' } alignItems = { 'center' } gap = { '8px' } >
78
+ < PackageAutocomplete
79
+ attribute = { 'licenseName' }
80
+ title = { text . attributionColumn . licenseName }
81
+ packageInfo = { packageInfo }
82
+ readOnly = { ! onEdit }
83
+ showHighlight = { showHighlight }
84
+ onEdit = { onEdit }
85
+ endAdornment = { config ?. licenseName ?. endIcon }
86
+ defaults = { defaultLicenses }
87
+ color = { config ?. licenseName ?. color }
88
+ focused = { config ?. licenseName ?. focused }
89
+ />
90
+ { ! expanded && (
91
+ < ToggleButton
92
+ value = { 'license-text' }
93
+ selected = { showLicenseText }
94
+ onChange = { ( ) => setShowLicenseText ( ( prev ) => ! prev ) }
95
+ size = { 'small' }
96
+ aria-label = "license-text-toggle-button"
97
+ >
98
+ < Badge
99
+ anchorOrigin = { { vertical : 'bottom' , horizontal : 'right' } }
100
+ color = { 'info' }
101
+ variant = { 'dot' }
102
+ invisible = { ! packageInfo . licenseText }
103
+ >
104
+ < NotesIcon />
105
+ </ Badge >
106
+ </ ToggleButton >
107
+ ) }
108
+ </ MuiBox >
109
+ { ( showLicenseText || expanded ) && (
110
+ < TextBox
111
+ readOnly = { ! onEdit }
112
+ placeholder = { defaultLicenseText }
113
+ sx = { classes . licenseText }
114
+ maxRows = { 8 }
115
+ minRows = { 3 }
116
+ color = { config ?. licenseText ?. color }
117
+ focused = { config ?. licenseText ?. focused }
118
+ multiline
119
+ expanded = { expanded }
120
+ title = {
121
+ defaultLicenseText
122
+ ? text . attributionColumn . licenseTextDefault
123
+ : text . attributionColumn . licenseText
124
+ }
125
+ text = { packageInfo . licenseText }
126
+ handleChange = { ( { target : { value } } ) =>
127
+ onEdit ?.( ( ) =>
128
+ dispatch (
129
+ setTemporaryDisplayPackageInfo ( {
130
+ ...packageInfo ,
131
+ licenseText : value ,
132
+ wasPreferred : undefined ,
133
+ } ) ,
134
+ ) ,
135
+ )
136
+ }
137
+ endIcon = { config ?. licenseText ?. endIcon }
138
+ />
139
+ ) }
115
140
</ MuiBox >
116
141
) ;
117
142
}
0 commit comments