docs: handle step tooltip bug in safari (#10954)
This commit is contained in:
1 parent
fa5d1b65fd
commit
cf62a0a43c
4 files changed
+51
-9
No files matched your search
@@ -7,6 +7,7 @@ import React, { useEffect, useMemo, useRef, useState } from "react"
|
|||||||
import { WorkflowStepUi } from "types"
|
import { WorkflowStepUi } from "types"
|
||||||
import { InlineCode, MarkdownContent, Tooltip } from "../../.."
|
import { InlineCode, MarkdownContent, Tooltip } from "../../.."
|
||||||
import { Bolt, InformationCircle } from "@medusajs/icons"
|
import { Bolt, InformationCircle } from "@medusajs/icons"
|
||||||
|
import { getBrowser } from "../../../../utils"
|
||||||
|
|
||||||
export type WorkflowDiagramNodeProps = {
|
export type WorkflowDiagramNodeProps = {
|
||||||
step: WorkflowStepUi
|
step: WorkflowStepUi
|
||||||
@@ -34,12 +35,22 @@ export const WorkflowDiagramStepNode = ({ step }: WorkflowDiagramNodeProps) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const firstChild = nodeParent.firstChild as HTMLElement
|
||||||
|
|
||||||
const nodeBoundingRect = nodeParent.getBoundingClientRect()
|
const nodeBoundingRect = nodeParent.getBoundingClientRect()
|
||||||
const diagramBoundingRect = diagramParent.getBoundingClientRect()
|
const diagramBoundingRect = diagramParent.getBoundingClientRect()
|
||||||
|
const browser = getBrowser()
|
||||||
|
|
||||||
|
if (browser === "Safari") {
|
||||||
|
// React Tooltip has a bug in Safari where the offset is not calculated correctly
|
||||||
|
// when place is set.
|
||||||
|
const firstChildBoundingRect = firstChild.getBoundingClientRect()
|
||||||
|
setOffset(diagramBoundingRect.width - firstChildBoundingRect.width + 20)
|
||||||
|
} else {
|
||||||
setOffset(
|
setOffset(
|
||||||
Math.max(diagramBoundingRect.width - nodeBoundingRect.width + 10, 10)
|
Math.max(diagramBoundingRect.width - nodeBoundingRect.width + 10, 10)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}, [ref.current])
|
}, [ref.current])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
export function getOsShortcut() {
|
|
||||||
const isMacOs =
|
|
||||||
typeof navigator !== "undefined"
|
|
||||||
? navigator.userAgent.toLowerCase().indexOf("mac") !== 0
|
|
||||||
: true
|
|
||||||
|
|
||||||
return isMacOs ? "⌘" : "Ctrl"
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ export * from "./decode-str"
|
|||||||
export * from "./dom-utils"
|
export * from "./dom-utils"
|
||||||
export * from "./get-link-with-base-path"
|
export * from "./get-link-with-base-path"
|
||||||
export * from "./get-navbar-items"
|
export * from "./get-navbar-items"
|
||||||
export * from "./get-os-shortcut"
|
export * from "./os-browser-utils"
|
||||||
export * from "./get-scrolled-top"
|
export * from "./get-scrolled-top"
|
||||||
export * from "./is-elm-window"
|
export * from "./is-elm-window"
|
||||||
export * from "./is-in-view"
|
export * from "./is-in-view"
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
export function getBrowser():
|
||||||
|
| "Chrome"
|
||||||
|
| "Safari"
|
||||||
|
| "Firefox"
|
||||||
|
| "Internet Explorer"
|
||||||
|
| "Edge"
|
||||||
|
| "unknown" {
|
||||||
|
if (typeof navigator === "undefined") {
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
const userAgent = navigator.userAgent.toLowerCase()
|
||||||
|
|
||||||
|
if (userAgent.indexOf("chrome") > -1) {
|
||||||
|
return "Chrome"
|
||||||
|
} else if (userAgent.indexOf("safari") > -1) {
|
||||||
|
return "Safari"
|
||||||
|
} else if (userAgent.indexOf("firefox") > -1) {
|
||||||
|
return "Firefox"
|
||||||
|
} else if (
|
||||||
|
userAgent.indexOf("msie") > -1 ||
|
||||||
|
userAgent.indexOf("trident") > -1
|
||||||
|
) {
|
||||||
|
return "Internet Explorer"
|
||||||
|
} else if (userAgent.indexOf("edge") > -1) {
|
||||||
|
return "Edge"
|
||||||
|
} else {
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getOsShortcut() {
|
||||||
|
const isMacOs =
|
||||||
|
typeof navigator !== "undefined"
|
||||||
|
? navigator.userAgent.toLowerCase().indexOf("mac") !== 0
|
||||||
|
: true
|
||||||
|
|
||||||
|
return isMacOs ? "⌘" : "Ctrl"
|
||||||
|
}
|
||||||
Reference in new issue
Block a user