Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

ako/ add method to get base ref of passed element #2520

Merged
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
7 changes: 7 additions & 0 deletions src/common/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,10 @@ export const slugify = (text) =>
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w-]+/g, '') // Remove all non-word chars
.replace(/--+/g, '-') // Replace multiple - with single -

export const getBaseRef = (ref) => {
// this is intended to solve a problem of preact that
// in some cases element api's are in the ref.current.base and
// in other cases they are in ref.current
return ref?.current?.base?.style ? ref?.current?.base : ref?.current
}
24 changes: 14 additions & 10 deletions src/components/layout/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getLanguage,
getDerivAppLocalizedURL,
redirectToTradingPlatform,
getBaseRef,
} from 'common/utility'
// Icons
import Logo from 'images/svg/layout/logo-deriv.svg'
Expand Down Expand Up @@ -213,18 +214,20 @@ const NavRight = styled.div`
}};
transform: translateX(
${(props) => {
const ref_base = getBaseRef(props.button_ref)

if (props.hide_signup_login) {
return 0
} else if (props.move && !props.hide_signup_login) {
if (props.button_ref.current && props.mounted) {
props.button_ref.current.style.opacity = 1
if (ref_base && props.mounted) {
ref_base.style.opacity = 1
}
return 0
} else {
if (props.button_ref.current && props.mounted) {
props.button_ref.current.style.opacity = 0
if (ref_base && props.mounted) {
ref_base.style.opacity = 0

const calculation = props.button_ref.current.offsetWidth + 2
const calculation = ref_base.offsetWidth + 2
return `${calculation}px`
}
return '300px'
Expand Down Expand Up @@ -843,16 +846,17 @@ const StyledNavRight = styled(NavRight)`
margin-left: auto;
transform: translateX(
${(props) => {
const ref_base = getBaseRef(props.button_ref)
if (props.move) {
if (props.button_ref.current && props.mounted) {
props.button_ref.current.style.opacity = 1
if (ref_base && props.mounted) {
ref_base.style.opacity = 1
}
return '50px'
} else {
if (props.button_ref.current && props.mounted) {
props.button_ref.current.style.opacity = 0
if (ref_base && props.mounted) {
ref_base.style.opacity = 0

const calculation = props.button_ref.current.offsetWidth + 50
const calculation = ref_base.offsetWidth + 50
return `${calculation}px`
}
return '225px'
Expand Down