Skip to content

MP-305 - use popper & portals -> dev #847

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

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"@datadog/browser-logs": "^4.21.2",
"@heroicons/react": "^1.0.6",
"@popperjs/core": "^2.11.8",
"@sprig-technologies/sprig-browser": "^2.20.1",
"@storybook/addon-actions": "^7.0.5",
"@storybook/react": "^7.0.5",
Expand Down Expand Up @@ -83,6 +84,7 @@
"react-helmet": "^6.1.0",
"react-html-parser": "^2.0.2",
"react-markdown": "8.0.6",
"react-popper": "^2.3.0",
"react-redux": "^8.0.4",
"react-redux-toastr": "^7.6.10",
"react-responsive": "^9.0.0-beta.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,3 @@
}
}
}

.langModal {
@include gtemd {
overflow: visible !important;
}
}

.langModalBody {
overflow: visible !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,3 @@
margin-bottom: $sp-4;
}
}

.localModal {
@include gtemd {
overflow: visible !important;
}
}

.localModalBody {
overflow: visible !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@

.skillsModalBody {
overflow: visible !important;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
align-items: center;
margin-left: $sp-15;

@include ltemd {
margin-left: $sp-4;
}

:global(button) {
padding: $sp-2;
color: $turq-160;
Expand Down Expand Up @@ -83,4 +87,4 @@
display: flex;
justify-content: space-between;
width: 100%;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@import '@libs/ui/styles/includes';

.container {
:global(#react-date-portal) {
position: relative;
z-index: 10001;
:global(.react-datepicker__header) {
background-color: $tc-white;
border-bottom: none;
Expand Down Expand Up @@ -30,34 +32,36 @@
color: $tc-white;
border-radius: 50%;
}
}

.headerWrap {
display: flex;
justify-content: space-between;
padding: $sp-2 0;
border-bottom: 2px solid $black-5;
.headerWrap {
display: flex;
justify-content: space-between;
padding: $sp-2 0;
border-bottom: 2px solid $black-5;

button {
svg {
width: 27px;
height: 27px;
}
button {
svg {
width: 27px;
height: 27px;
}
}

select {
border: none;
background-color: transparent;
margin: auto;
-webkit-appearance: menulist;
appearance: menulist;
select {
border: none;
background-color: transparent;
margin: auto;
-webkit-appearance: menulist;
appearance: menulist;

option:hover {
background-color: $turq-160;
color: $tc-white;
}
option:hover {
background-color: $turq-160;
color: $tc-white;
}
}
}

.container {
input {
border: none;
pointer-events: none;
Expand All @@ -74,4 +78,4 @@
text-transform: none;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ const InputDatePicker: FC<InputDatePickerProps> = (props: InputDatePickerProps)
maxTime={props.maxTime}
showYearPicker={props.showYearPicker}
dateFormat={props.dateFormat}
popperPlacement='bottom'
portalId='react-date-portal'
/>
</InputWrapper>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
left: 0;
width: 100%;
&:not(:empty) {
z-index: 9;
z-index: 1001;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import {
useRef,
useState,
} from 'react'
import { usePopper } from 'react-popper'
import classNames from 'classnames'

import { beforeWrite } from '@popperjs/core/lib'
import { useClickOutside } from '~/libs/shared/lib/hooks'

import { IconOutline } from '../../../../svgs'
import { InputWrapper } from '../input-wrapper'
import { Portal } from '../../../../portal'

import styles from './InputSelect.module.scss'

Expand All @@ -40,12 +43,33 @@ interface InputSelectProps {
readonly value?: string
}

const sameWidthModifier = {
effect: ({ state }: any) => {
state.elements.popper.style.width = `${state.elements.reference.offsetWidth}px`
},
enabled: true,
fn: ({ state }: any) => {
state.styles.popper.width = `${state.rects.reference.width}px`
return state
},
name: 'sameWidth',
phase: beforeWrite,
requires: ['computeStyles'],
}
const modifiers = [sameWidthModifier]

const InputSelect: FC<InputSelectProps> = (props: InputSelectProps) => {
const triggerRef: MutableRefObject<any> = useRef(undefined)
const popperRef: MutableRefObject<any> = useRef(undefined)
const buttonRef: MutableRefObject<HTMLButtonElement | null> = useRef(null)
const [menuIsVisible, setMenuIsVisible]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)
const [isFocus, setIsFocus]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)

const popper = usePopper(triggerRef.current?.firstChild, popperRef.current, {
modifiers,
strategy: 'absolute',
})

const selectedOption: InputSelectOption | undefined = props.options.find(option => option.value === props.value)

const label: (option: InputSelectOption) => ReactNode = (option?: InputSelectOption) => (
Expand Down Expand Up @@ -125,27 +149,34 @@ const InputSelect: FC<InputSelectProps> = (props: InputSelectProps) => {
</span>
</button>

<div className={styles['menu-wrap']}>
{menuIsVisible && (
<div className={styles['select-menu']}>
{props.options.map(option => (
<div
className={
classNames(
styles['select-option'],
'body-main',
selectedOption === option && 'selected',
)
}
onClick={select(option)}
key={option.value}
>
{label(option)}
</div>
))}
</div>
)}
</div>
<Portal>
<div
className={styles['menu-wrap']}
ref={popperRef}
style={popper.styles.popper}
{...popper.attributes.popper}
>
{menuIsVisible && (
<div className={styles['select-menu']}>
{props.options.map(option => (
<div
className={
classNames(
styles['select-option'],
'body-main',
selectedOption === option && 'selected',
)
}
onClick={select(option)}
key={option.value}
>
{label(option)}
</div>
))}
</div>
)}
</div>
</Portal>

</InputWrapper>
)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2721,7 +2721,7 @@
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.21.tgz#5de5a2385a35309427f6011992b544514d559aa1"
integrity sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==

"@popperjs/core@^2.9.2":
"@popperjs/core@^2.11.8", "@popperjs/core@^2.9.2":
version "2.11.8"
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f"
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==
Expand Down