|
1 | | -import React from 'react'; |
| 1 | +import UnfoldLessIcon from '@mui/icons-material/UnfoldLess'; |
| 2 | +import UnfoldMoreIcon from '@mui/icons-material/UnfoldMore'; |
| 3 | +import React, { useState } from 'react'; |
2 | 4 | import { Grid, IconButton, Typography } from '../../base'; |
3 | | -import { iconSmall } from '../../constants/iconsSizes'; |
| 5 | +import { iconSmall, iconXSmall } from '../../constants/iconsSizes'; |
4 | 6 | import { CopyIcon } from '../../icons'; |
5 | 7 | import { useTheme } from '../../theme'; |
6 | 8 | import { CustomTooltip } from './../CustomTooltip'; |
@@ -29,7 +31,7 @@ import { |
29 | 31 | PrimaryDetailsProps, |
30 | 32 | SectionHeadingProps |
31 | 33 | } from './types'; |
32 | | -import { splitCamelCaseString } from './utils.js'; |
| 34 | +import { splitCamelCaseString } from './utils'; |
33 | 35 |
|
34 | 36 | export const PrimaryDetails: React.FC<PrimaryDetailsProps> = ({ title, value, hide = false }) => { |
35 | 37 | const titleFormatted = splitCamelCaseString(title); |
@@ -151,16 +153,39 @@ export const ActionIconButton: React.FC<ActionIconButtonProps> = ({ title, Icon, |
151 | 153 | ); |
152 | 154 | }; |
153 | 155 |
|
154 | | -export const KeyValueInRow: React.FC<KeyValueProps> = ({ Key, Value }) => { |
| 156 | +export const KeyValueInRow: React.FC<KeyValueProps> = ({ Key, Value, showFold = false }) => { |
| 157 | + const [isFolded, setIsFolded] = useState(true); |
| 158 | + |
155 | 159 | if (!Value || !Key) return null; |
| 160 | + |
| 161 | + const handleToggleFold = () => { |
| 162 | + setIsFolded(!isFolded); |
| 163 | + }; |
| 164 | + |
156 | 165 | return ( |
157 | 166 | <KeyValueGrid container> |
158 | 167 | <React.Fragment key={Key}> |
159 | | - <KeyValueGridCell item xs={3}> |
| 168 | + <KeyValueGridCell container xs={3} spacing={1}> |
160 | 169 | <KeyValueGridTitle>{Key}</KeyValueGridTitle> |
| 170 | + {showFold && ( |
| 171 | + <IconButton onClick={handleToggleFold}> |
| 172 | + {isFolded ? ( |
| 173 | + <UnfoldMoreIcon style={iconXSmall} /> |
| 174 | + ) : ( |
| 175 | + <UnfoldLessIcon style={iconXSmall} /> |
| 176 | + )} |
| 177 | + </IconButton> |
| 178 | + )} |
161 | 179 | </KeyValueGridCell> |
162 | 180 | <Grid item xs={9}> |
163 | | - <div>{React.isValidElement(Value) ? Value : String(Value)}</div> |
| 181 | + <div |
| 182 | + style={{ |
| 183 | + maxHeight: showFold && isFolded ? '200px' : 'none', |
| 184 | + overflow: showFold ? 'auto' : 'none' |
| 185 | + }} |
| 186 | + > |
| 187 | + {React.isValidElement(Value) ? Value : String(Value)} |
| 188 | + </div> |
164 | 189 | </Grid> |
165 | 190 | </React.Fragment> |
166 | 191 | </KeyValueGrid> |
|
0 commit comments