Skip to content

Commit d01ba0b

Browse files
committed
feat(StructuredYson): add configurable collapse indicators
1 parent e66f983 commit d01ba0b

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/ReactUnipika/ReactUnipika.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ReactUnipikaProps {
2121
customLayout?: (args: {toolbar: React.ReactNode; content: React.ReactNode}) => React.ReactNode;
2222
toolbarStickyTop?: number;
2323
renderToolbar?: (props: ToolbarProps) => React.ReactNode;
24+
useIconsForCollapse?: boolean;
2425
}
2526

2627
const defaultUnipikaSettings = {
@@ -43,6 +44,7 @@ export function ReactUnipika({
4344
customLayout,
4445
toolbarStickyTop = 0,
4546
renderToolbar,
47+
useIconsForCollapse = false, // Default to false for backward compatibility with tests
4648
}: ReactUnipikaProps) {
4749
const convertedValue = React.useMemo(() => {
4850
// TODO: fix me later
@@ -95,6 +97,7 @@ export function ReactUnipika({
9597
customLayout={customLayout}
9698
toolbarStickyTop={toolbarStickyTop}
9799
renderToolbar={renderToolbar}
100+
useIconsForCollapse={useIconsForCollapse}
98101
/>
99102
) : (
100103
<pre

src/StructuredYson/Cell.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface CellProps {
2828
filter?: string;
2929
index: number;
3030
showFullText: (index: number) => void;
31+
useIconsForCollapse?: boolean;
3132
}
3233

3334
export const JSON_VALUE_KEY = {
@@ -69,6 +70,7 @@ export function Cell(props: CellProps) {
6970
filter,
7071
showFullText,
7172
index,
73+
useIconsForCollapse,
7274
} = props;
7375

7476
const handleToggleCollapse = React.useCallback(() => {
@@ -90,6 +92,8 @@ export function Cell(props: CellProps) {
9092
collapsed={collapsed}
9193
path={path}
9294
onToggle={handleToggleCollapse}
95+
settings={settings}
96+
useIconsForCollapse={useIconsForCollapse}
9397
/>
9498
)}
9599
<Key
@@ -287,14 +291,21 @@ interface ToggleCollapseProps {
287291
collapsed?: boolean;
288292
path?: UnipikaFlattenTreeItem['path'];
289293
onToggle: () => void;
294+
settings?: UnipikaSettings;
295+
useIconsForCollapse?: boolean;
290296
}
291297

292298
function ToggleCollapseButton(props: ToggleCollapseProps) {
293-
const {collapsed, onToggle, path} = props;
299+
const {collapsed, onToggle, path, useIconsForCollapse = false} = props;
300+
294301
return (
295302
<span title={path} className={block('collapse')}>
296303
<Button onClick={onToggle} view="flat-secondary" size={'s'}>
297-
<Icon className={'unipika'} data={collapsed ? ChevronRight : ChevronUp} />
304+
{useIconsForCollapse ? (
305+
<Icon className={'unipika'} data={collapsed ? ChevronRight : ChevronUp} />
306+
) : (
307+
<span className={'unipika'}>{collapsed ? '[+]' : '[-]'}</span>
308+
)}
298309
</Button>
299310
</span>
300311
);

src/StructuredYson/StructuredYson.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface Props {
4040
customLayout?: (args: {toolbar: React.ReactNode; content: React.ReactNode}) => React.ReactNode;
4141
toolbarStickyTop?: number;
4242
renderToolbar?: (props: ToolbarProps) => React.ReactNode;
43+
useIconsForCollapse?: boolean;
4344
}
4445

4546
interface State {
@@ -156,6 +157,7 @@ export class StructuredYson extends React.PureComponent<Props, State> {
156157
settings,
157158
filter,
158159
} = this.state;
160+
const {useIconsForCollapse} = this.props;
159161

160162
return (
161163
<Table
@@ -167,6 +169,7 @@ export class StructuredYson extends React.PureComponent<Props, State> {
167169
onToggleCollapse={this.onTogglePathCollapse}
168170
onShowFullText={this.onShowFullText}
169171
scrollToRef={this.tableRef}
172+
useIconsForCollapse={useIconsForCollapse}
170173
/>
171174
);
172175
}

src/StructuredYson/Table.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface TableProps {
1919
onToggleCollapse: (path: string) => void;
2020
onShowFullText: (index: number) => void;
2121
scrollToRef: React.RefObject<null | {scrollToIndex(index: number): void}>;
22+
useIconsForCollapse?: boolean;
2223
}
2324

2425
export const Table: React.FC<TableProps> = ({
@@ -30,6 +31,7 @@ export const Table: React.FC<TableProps> = ({
3031
onToggleCollapse,
3132
onShowFullText,
3233
scrollToRef,
34+
useIconsForCollapse,
3335
}) => {
3436
const renderCell: ColumnDef<UnipikaFlattenTreeItem>['cell'] = ({row}) => {
3537
const {original, index} = row;
@@ -43,6 +45,7 @@ export const Table: React.FC<TableProps> = ({
4345
filter={filter}
4446
showFullText={onShowFullText}
4547
index={index}
48+
useIconsForCollapse={useIconsForCollapse}
4649
/>
4750
);
4851
};

0 commit comments

Comments
 (0)