Skip to content

Commit 455002c

Browse files
feat(@clayui/core): Add expanderIcons API to change icons throughout the structure
1 parent 3e3b8c8 commit 455002c

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

packages/clay-core/src/tree-view/TreeView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React from 'react';
99
import {ChildrenFunction, Collection, ICollectionProps} from './Collection';
1010
import {TreeViewGroup} from './TreeViewGroup';
1111
import {TreeViewItem, TreeViewItemStack} from './TreeViewItem';
12-
import {TreeViewContext} from './context';
12+
import {Icons, TreeViewContext} from './context';
1313
import {IExpandable, IMultipleSelection, useTree} from './useTree';
1414

1515
interface ITreeViewProps<T>
@@ -18,6 +18,7 @@ interface ITreeViewProps<T>
1818
IExpandable,
1919
ICollectionProps<T> {
2020
displayType?: 'light' | 'dark';
21+
expanderIcons?: Icons;
2122
nestedKey?: string;
2223
showExpanderOnHover?: boolean;
2324
}
@@ -35,6 +36,7 @@ export function TreeView<T>({
3536
className,
3637
displayType = 'light',
3738
expandedKeys,
39+
expanderIcons,
3840
items,
3941
nestedKey,
4042
onExpandedChange,
@@ -51,6 +53,7 @@ export function TreeView<T>({
5153
typeof children === 'function'
5254
? (children as ChildrenFunction<Object>)
5355
: undefined,
56+
expanderIcons,
5457
nestedKey,
5558
showExpanderOnHover,
5659
...state,

packages/clay-core/src/tree-view/TreeViewItem.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,21 @@ export function TreeViewItemStack({
110110
onClick={() => toggle!(item.key)}
111111
>
112112
<span className="c-inner" tabIndex={-2}>
113-
<Icon symbol="angle-down" />
114-
<Icon
115-
className="component-expanded-d-none"
116-
symbol="angle-right"
117-
/>
113+
{expanderIcons?.close ? (
114+
expanderIcons.close
115+
) : (
116+
<Icon symbol="angle-down" />
117+
)}
118+
{expanderIcons?.open ? (
119+
React.cloneElement(expanderIcons.open, {
120+
className: 'component-expanded-d-none',
121+
})
122+
) : (
123+
<Icon
124+
className="component-expanded-d-none"
125+
symbol="angle-right"
126+
/>
127+
)}
118128
</span>
119129
</Button>
120130
</Layout.ContentCol>

packages/clay-core/src/tree-view/context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
import React, {Key, useContext} from 'react';
77

8+
export type Icons = {
9+
open: React.ReactElement;
10+
close: React.ReactElement;
11+
};
12+
813
export interface ITreeViewContext {
914
childrenRoot?: (item: Object) => React.ReactElement;
1015
expandedKeys?: Set<Key>;

0 commit comments

Comments
 (0)