Skip to content

Commit 4143d4c

Browse files
committed
feat: add fold unfold option for the lables and annotations
Signed-off-by: Amit Amrutiya <amitamrutiya2210@gmail.com>
1 parent d716685 commit 4143d4c

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

src/custom/ResourceDetailFormatters/Component.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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';
24
import { Grid, IconButton, Typography } from '../../base';
3-
import { iconSmall } from '../../constants/iconsSizes';
5+
import { iconSmall, iconXSmall } from '../../constants/iconsSizes';
46
import { CopyIcon } from '../../icons';
57
import { useTheme } from '../../theme';
68
import { CustomTooltip } from './../CustomTooltip';
@@ -29,7 +31,7 @@ import {
2931
PrimaryDetailsProps,
3032
SectionHeadingProps
3133
} from './types';
32-
import { splitCamelCaseString } from './utils.js';
34+
import { splitCamelCaseString } from './utils';
3335

3436
export const PrimaryDetails: React.FC<PrimaryDetailsProps> = ({ title, value, hide = false }) => {
3537
const titleFormatted = splitCamelCaseString(title);
@@ -151,16 +153,39 @@ export const ActionIconButton: React.FC<ActionIconButtonProps> = ({ title, Icon,
151153
);
152154
};
153155

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+
155159
if (!Value || !Key) return null;
160+
161+
const handleToggleFold = () => {
162+
setIsFolded(!isFolded);
163+
};
164+
156165
return (
157166
<KeyValueGrid container>
158167
<React.Fragment key={Key}>
159-
<KeyValueGridCell item xs={3}>
168+
<KeyValueGridCell container xs={3} spacing={1}>
160169
<KeyValueGridTitle>{Key}</KeyValueGridTitle>
170+
{showFold && (
171+
<IconButton onClick={handleToggleFold}>
172+
{isFolded ? (
173+
<UnfoldMoreIcon style={iconXSmall} />
174+
) : (
175+
<UnfoldLessIcon style={iconXSmall} />
176+
)}
177+
</IconButton>
178+
)}
161179
</KeyValueGridCell>
162180
<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>
164189
</Grid>
165190
</React.Fragment>
166191
</KeyValueGrid>

0 commit comments

Comments
 (0)