-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(TreeSelect): added TreeSelect unstable component and new list hooks #1090
Conversation
Preview is ready. |
dae52f5
to
acbf76d
Compare
I see you're using the This library has a problem. In rtl, the list for an item when dragging sets the style To fix this you can manually set |
acbf76d
to
dde5216
Compare
The default virtualization solution is no longer assumed. |
dbbe45a
to
65e9bf6
Compare
41af609
to
df03760
Compare
df03760
to
3dcb75f
Compare
3dcb75f
to
4b6d553
Compare
border-radius: var(--g-list-item-border-radius-l, 8px); | ||
} | ||
&_radius_xl { | ||
border-radius: var(--g-list-item-border-radius-xl, 8px); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public var should be without any size, just --g-list-item-border-radius
src/components/useList/types.ts
Outdated
@@ -1,6 +1,6 @@ | |||
export type ListItemId = string; | |||
|
|||
export type ListSizeTypes = 's' | 'm' | 'l' | 'xl'; | |||
export type ListItemSizeType = 's' | 'm' | 'l' | 'xl'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ListItemSize
, "Type" suffix is redundant
src/unstable.ts
Outdated
useListState as unstable_useListState, | ||
useListFilter as unstable_useListFilter, | ||
useListKeydown as unstable_useListKeydown, | ||
} from './components/useList'; | ||
export * from './components/TreeSelect'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We keep TreeSelect stable?
height, | ||
expanded, | ||
style, | ||
role = 'listitem', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
role option
more suitable here, it supports aria-selected
attribute, while listitem
doesn't
/fixed |
|
||
interface UseListStateProps extends Partial<ListState> {} | ||
|
||
function useControlledState<T>(value: T, defaultValue: T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be more precise useControlledState<T>(value: T | undefined, defaultValue: T)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would even write like this
function useControlledState<T>(value: T | undefined, defaultValue: T) {
const [state, setState] = React.useState(value ?? defaultValue);
const isControlled = value === undefined;
return {value: value ?? state, setState, isControlled};
}
const [innerValue, setInnerValue] = React.useState(defaultValue || []); | ||
|
||
const value = valueProps || innerValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like useControlledState
from here.
const [innerValue, setInnerValue] = React.useState(defaultValue || []); | |
const value = valueProps || innerValue; | |
const [value, setInnerValue] = useControlledState(valueProps, defaultValue || []); |
useControlledState
is good hook for library not only for useList
area
const [open, setOpenState] = React.useState(props.defaultOpen || false); | ||
const {onOpenChange} = props; | ||
const {onOpenChange, onClose} = props; | ||
const isControlled = typeof props.open === 'boolean'; | ||
const openValue = isControlled ? (props.open as boolean) : open; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [open, setOpenState] = React.useState(props.defaultOpen || false); | |
const {onOpenChange} = props; | |
const {onOpenChange, onClose} = props; | |
const isControlled = typeof props.open === 'boolean'; | |
const openValue = isControlled ? (props.open as boolean) : open; | |
const { | |
value: open, | |
isControlled, | |
setState: setOpenState, | |
} = useControlledState(props.open, false); | |
const {onOpenChange, onClose} = props; |
if (externalItems !== prevItems) { | ||
setItems(filterItemsFn(filter, externalItems)); | ||
setPrevItems(externalItems); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prevItems
looks like extra:
React.useEffect(() => {
setItems(filterItemsFn(filter, externalItems));
}, [externalItems])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's new recommended way to not use useEffect
things in code - https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Why they do not use React.useRef
for prev state
|
||
return () => items; | ||
}, | ||
[filterItem, filterItems], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be wrap filterItem
and filterItems
in the React.useRef like this:
const filterItemsRef = React.useRef(filterItems);
filterItemsRef.current = filterItems;
const filterItemRef = React.useRef(filterItem);
filterItemRef.current = filterItem;
const filterItemsFn = React.useCallback(() => {
...
filterItemRef.current() or filterItemsRef.current()
....
}, []);
to remove them from dependency list - otherwise, if the user does not memorize them, then there is no point in debouncedFn
…oks (#1090) Co-authored-by: Alexandr Isaev <[email protected]>
…oks (#1090) Co-authored-by: Alexandr Isaev <[email protected]>
Completely rewritten to version with hooks.
Prev pr: #1039