-
Notifications
You must be signed in to change notification settings - Fork 0
добавлен vanilla popper, удален react-popper из проекта #29
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
Open
grigoriy-grisha
wants to merge
10
commits into
master
Choose a base branch
from
native_popper
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7a1088b
реализация попера с нативным попером
6f90d43
рефакторинг Popper, Manager,Reference компонентов, добавлен хук useVa…
9b735e4
замена react-popper внури popup-manager на на обыкновенный поппер
51207ea
удален react-popper из проекта
932171c
удалены стили
be4b38f
исправления путей
84ab4af
удален попрос
0540e77
Обновлен пакет @worksolutions/react-utils,удален хук useVanillaPopper…
b8cf53a
типизация компонента popper, правки
60780e6
реализация определения маунта в компоненте Manager через хук
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ | |
| box-sizing: border-box; | ||
| line-height: 0; | ||
| } | ||
|
|
||
This file contains hidden or 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,20 @@ | ||
| import React from "react"; | ||
| import { useMountedState } from "react-use"; | ||
|
|
||
| export const ManagerReferenceNodeContext = React.createContext<HTMLElement>(null!); | ||
| export const ManagerReferenceNodeSetterContext = React.createContext<(elem: HTMLElement) => void>(null!); | ||
|
|
||
| export function Manager({ children }: React.PropsWithChildren<{}>) { | ||
| const [referenceNode, setReferenceNode] = React.useState<HTMLElement>(null!); | ||
| const isMounted = useMountedState(); | ||
|
|
||
| const handleSetReferenceNode = React.useCallback((node) => isMounted() && setReferenceNode(node), [isMounted]); | ||
|
|
||
| return ( | ||
| <ManagerReferenceNodeContext.Provider value={referenceNode}> | ||
| <ManagerReferenceNodeSetterContext.Provider value={handleSetReferenceNode}> | ||
| {children} | ||
| </ManagerReferenceNodeSetterContext.Provider> | ||
| </ManagerReferenceNodeContext.Provider> | ||
| ); | ||
| } |
This file contains hidden or 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,99 @@ | ||
| import React, { Ref } from "react"; | ||
| import { provideRef, useVanillaPopper } from "@worksolutions/react-utils"; | ||
| import { Modifier, Options, Placement, PositioningStrategy, State } from "@popperjs/core/lib"; | ||
|
|
||
| import { ManagerReferenceNodeContext } from "../Manager"; | ||
|
|
||
| import { getFirstIfArray } from "../utils"; | ||
|
|
||
| type ReferenceElement = HTMLElement; | ||
|
|
||
| export interface PopperArrowProps { | ||
| ref: React.Ref<any>; | ||
| style?: Partial<CSSStyleDeclaration | null>; | ||
| } | ||
|
|
||
| export type PopperChildrenProps = { | ||
| ref: Ref<any>; | ||
| style?: Partial<CSSStyleDeclaration | undefined>; | ||
| placement: Placement; | ||
| isReferenceHidden?: boolean | null; | ||
| hasPopperEscaped?: boolean | null; | ||
| update: (() => Promise<Partial<State>>) | null; | ||
| forceUpdate: () => void; | ||
| arrowProps: PopperArrowProps; | ||
| }; | ||
|
|
||
| type Modifiers = Array<Partial<Modifier<any, any>>>; | ||
| export type PopperChildren = (popperChildrenProps: PopperChildrenProps) => React.ReactNode; | ||
|
|
||
| export type PopperProps = { | ||
| children: PopperChildren; | ||
| innerRef?: Ref<any>; | ||
| modifiers?: Modifiers; | ||
| placement?: Placement; | ||
| strategy?: PositioningStrategy; | ||
| referenceElement?: ReferenceElement; | ||
| onFirstUpdate?: (arg0: Partial<State>) => void; | ||
| }; | ||
|
|
||
| const noop: any = () => {}; | ||
| const noopPromise: any = () => Promise.resolve(null); | ||
| const EMPTY_MODIFIERS: Modifiers = []; | ||
|
|
||
| export function Popper({ | ||
| placement = "bottom", | ||
| strategy = "absolute", | ||
| modifiers = EMPTY_MODIFIERS, | ||
| referenceElement, | ||
| onFirstUpdate, | ||
| innerRef, | ||
| children, | ||
| }: PopperProps) { | ||
| const referenceNode = React.useContext(ManagerReferenceNodeContext); | ||
|
|
||
| const [popperElement, setPopperElement] = React.useState(null); | ||
| const [arrowElement, setArrowElement] = React.useState(null); | ||
|
|
||
| React.useEffect(() => { | ||
| provideRef(innerRef)(popperElement!); | ||
| }, [innerRef, popperElement]); | ||
|
|
||
| const options: Options = React.useMemo( | ||
| () => ({ | ||
| placement, | ||
| strategy, | ||
| onFirstUpdate, | ||
| modifiers: [ | ||
| ...modifiers, | ||
| { | ||
| name: "arrow", | ||
| enabled: arrowElement != null, | ||
| options: { element: arrowElement }, | ||
| }, | ||
| ], | ||
| }), | ||
| [placement, strategy, onFirstUpdate, modifiers, arrowElement], | ||
| ); | ||
|
|
||
| const { state, forceUpdate, update } = useVanillaPopper(referenceElement || referenceNode, popperElement, options); | ||
|
|
||
| const childrenProps: PopperChildrenProps = React.useMemo( | ||
| () => ({ | ||
| ref: setPopperElement, | ||
| style: state?.styles?.popper, | ||
| placement: state ? state.placement : placement, | ||
| hasPopperEscaped: state && state.modifiersData.hide ? state.modifiersData.hide.hasPopperEscaped : null, | ||
| isReferenceHidden: state && state.modifiersData.hide ? state.modifiersData.hide.isReferenceHidden : null, | ||
| arrowProps: { | ||
| style: state?.styles?.arrow, | ||
| ref: setArrowElement, | ||
| }, | ||
| forceUpdate: forceUpdate || noop, | ||
| update: update || noopPromise, | ||
| }), | ||
| [setPopperElement, setArrowElement, placement, state, update, forceUpdate], | ||
| ); | ||
|
|
||
| return getFirstIfArray(children)(childrenProps); | ||
| } |
This file contains hidden or 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,32 @@ | ||
| import React, { Ref } from "react"; | ||
| import { provideRef } from "@worksolutions/react-utils"; | ||
|
|
||
| import { getFirstIfArray } from "../utils"; | ||
| import { ManagerReferenceNodeSetterContext } from "../Manager"; | ||
|
|
||
| export type ReferenceChildrenProps = { ref: Ref<any> }; | ||
| export type ReferenceProps = { | ||
| children: (ReferenceChildrenProps: ReferenceChildrenProps) => React.ReactNode; | ||
| innerRef?: Ref<any>; | ||
| }; | ||
|
|
||
| export function Reference({ children, innerRef }: ReferenceProps) { | ||
| const setReferenceNode = React.useContext(ManagerReferenceNodeSetterContext); | ||
|
|
||
| const refHandler = React.useCallback( | ||
| (node?: HTMLElement) => { | ||
| if (!node) return; | ||
| provideRef(innerRef)(node); | ||
| setReferenceNode(node); | ||
| }, | ||
| [innerRef, setReferenceNode], | ||
| ); | ||
|
|
||
| React.useEffect(() => () => provideRef(innerRef)(null!), []); | ||
|
|
||
| React.useEffect(() => { | ||
| console.warn("`Reference` should not be used outside of a `Manager` component."); | ||
| }, [setReferenceNode]); | ||
|
|
||
| return getFirstIfArray(children)({ ref: refHandler }); | ||
| } |
This file contains hidden or 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 @@ | ||
| export const getFirstIfArray = <T>(arg: T | T[]): T => (Array.isArray(arg) ? arg[0] : arg); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
мне не очень нравиться что попер так сильно связан с VisibilityManagerContextInterface. По факту, я хочу чтобы попер занимался только позиционированием моего элемента. А как и когда его показывать уже должен решать я. И желательно чтоб я это мог пропсами рулить
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.
поэтому PopupManagerForClick.tsx и тот же для hover вообще не должны знать что они poper отображают