-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hightlighter to the tree control (#36480)
* Add tree-control expand/collapse on click the expander button or by a custom logic * Add stories * Upgrade WP components dependency to v19.8.5 to support indeterminate checkbox control * Add styles to fit the disign * Add type definitions * Add custom hook to manage highlight * Add hightlighter to the tree control * Add stories * Add changelog file * Fix rebase conflicts * Add comment suggestions
- Loading branch information
Showing
7 changed files
with
137 additions
and
3 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/js/components/changelog/add-35851-tree-control-highlight-item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: dev | ||
|
||
Add highlighter to the tree control |
31 changes: 31 additions & 0 deletions
31
packages/js/components/src/experimental-tree-control/hooks/use-highlighter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useMemo } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { CheckedStatus, TreeItemProps } from '../types'; | ||
|
||
export function useHighlighter( { | ||
item, | ||
multiple, | ||
checkedStatus, | ||
shouldItemBeHighlighted, | ||
}: Pick< TreeItemProps, 'item' | 'multiple' | 'shouldItemBeHighlighted' > & { | ||
checkedStatus: CheckedStatus; | ||
} ) { | ||
const isHighlighted = useMemo( () => { | ||
if ( typeof shouldItemBeHighlighted === 'function' ) { | ||
if ( multiple || item.children.length === 0 ) { | ||
return shouldItemBeHighlighted( item ); | ||
} | ||
} | ||
if ( ! multiple ) { | ||
return checkedStatus === 'checked'; | ||
} | ||
}, [ item, multiple, checkedStatus, shouldItemBeHighlighted ] ); | ||
|
||
return { isHighlighted }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters