This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UIKIT-1592,TreeLikeList): Реализовано раскрытие списка и скролл …
…до первочально выбранных элементов (#1110)
- Loading branch information
Showing
12 changed files
with
224 additions
and
51 deletions.
There are no files selected for viewing
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
22 changes: 11 additions & 11 deletions
22
packages/components/src/TreeLikeList/TreeItem/useLogic/useLogic.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,48 @@ | ||
import { useMemo } from 'react'; | ||
import { useEffect, useMemo, useRef } from 'react'; | ||
|
||
import { useId } from '../../hooks/useId'; | ||
import { getFormatDisabledItems } from '../../Tree/utils'; | ||
import { type DisabledItemValue } from '../types'; | ||
import { type TreeLikeListProps } from '../TreeLikeList'; | ||
|
||
type UseLogicParams = { | ||
disabledItems?: Array<DisabledItemValue>; | ||
}; | ||
import { getChainsId } from './utils'; | ||
|
||
type UseLogicParams = TreeLikeListProps; | ||
|
||
export const useLogic = ({ data, value, disabledItems }: UseLogicParams) => { | ||
const prefixId = useId(); | ||
|
||
const listRef = useRef<HTMLUListElement>(null); | ||
|
||
useEffect(() => { | ||
if (listRef.current && value?.length) { | ||
// Выбираем первый элемент из списка value | ||
const targetItem = listRef.current.querySelector(` | ||
li[id="${prefixId}${value[0]}"]`); | ||
|
||
if (targetItem) { | ||
targetItem.scrollIntoView({ block: 'center' }); | ||
} | ||
} | ||
}, [listRef, prefixId]); | ||
|
||
export const useLogic = ({ disabledItems }: UseLogicParams) => { | ||
const formattedDisabledItems = useMemo( | ||
() => getFormatDisabledItems(disabledItems), | ||
[disabledItems], | ||
); | ||
|
||
return { formattedDisabledItems }; | ||
const chainsToSelectedItem = useMemo( | ||
() => getChainsId(data, value), | ||
[data, value], | ||
); | ||
|
||
return { | ||
listProps: { | ||
ref: listRef, | ||
}, | ||
itemProps: { | ||
chainsToSelectedItem, | ||
disabledItems: formattedDisabledItems, | ||
prefixId, | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.