Skip to content

Commit

Permalink
[CP-3145] place refactored to placement
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarski committed Oct 2, 2024
1 parent 39c9290 commit a8b326e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions libs/device/models/src/lib/feature/extra-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import { z } from "zod"

const TooltipPlaceEnum = z.enum(["bottom-right", "bottom-left"]);
const TooltipPlacementEnum = z.enum(["bottom-right", "bottom-left"]);

export type TooltipPlace = z.infer<typeof TooltipPlaceEnum>;
export type TooltipPlacement = z.infer<typeof TooltipPlacementEnum>;

const tooltipSchema = z.object({
contentText: z.string().optional(),
contentList: z.array(z.string()).optional(),
place: TooltipPlaceEnum.optional(),
placement: TooltipPlacementEnum.optional(),
})

export const extraConfigSchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion libs/generic-view/feature/src/lib/setup-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const setupComponent = <P extends object>(
)

return extra?.tooltip ? (
<Tooltip place={extra.tooltip.place}>
<Tooltip placement={extra.tooltip.placement}>
<Tooltip.Anchor>{componentElement}</Tooltip.Anchor>
<Tooltip.Content $defaultStyles>
<Paragraph5>{extra.tooltip.contentText}</Paragraph5>
Expand Down
12 changes: 6 additions & 6 deletions libs/generic-view/ui/src/lib/interactive/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import React, {
} from "react"
import styled, { css } from "styled-components"
import { BaseGenericComponent } from "generic-view/utils"
import { TooltipPlace } from "device/models"
import { TooltipPlacement } from "device/models"

export const Tooltip: BaseGenericComponent<
undefined,
undefined,
{ place?: TooltipPlace }
{ placement?: TooltipPlacement }
> & {
Anchor: typeof TooltipAnchor
Content: typeof TooltipContent
} = ({ children, place = "bottom-right" }) => {
} = ({ children, placement = "bottom-right" }) => {
const [anchorPosition, setAnchorPosition] = useState<{
top?: number
left?: number
Expand All @@ -40,19 +40,19 @@ export const Tooltip: BaseGenericComponent<
return
}

if (place === "bottom-right") {
if (placement === "bottom-right") {
const top = anchorRect.top + anchorRect.height
const left = anchorRect.left

setAnchorPosition({ left, top })
} else if (place === "bottom-left") {
} else if (placement === "bottom-left") {
const top = anchorRect.top + anchorRect.height
const left = anchorRect.left - contentReact.width + anchorRect.width

setAnchorPosition({ left, top })
}
},
[place]
[placement]
)

const anchor = useMemo(() => {
Expand Down

0 comments on commit a8b326e

Please sign in to comment.