@skbkontur/react-ui 6.1.4-c0aae.0 → 6.1.4-e0cd1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -77,13 +77,12 @@ var PopupPin = /** @class */ (function (_super) {
|
|
|
77
77
|
_this.getPinCoordinates = function (popupElement) {
|
|
78
78
|
var popupRect = _this.getPopupElementRect(popupElement);
|
|
79
79
|
var _a = _this.positionObject, direction = _a.direction, align = _a.align;
|
|
80
|
-
var defaultPinCoordinates = {
|
|
81
|
-
top: popupRect.height,
|
|
82
|
-
left: _this.getPinLeftCoordinate(popupRect, align),
|
|
83
|
-
};
|
|
84
80
|
switch (direction) {
|
|
85
81
|
case 'top':
|
|
86
|
-
return
|
|
82
|
+
return {
|
|
83
|
+
top: popupRect.height,
|
|
84
|
+
left: _this.getPinLeftCoordinate(popupRect, align),
|
|
85
|
+
};
|
|
87
86
|
case 'bottom':
|
|
88
87
|
return {
|
|
89
88
|
top: -2 * _this.props.size,
|
|
@@ -101,7 +100,10 @@ var PopupPin = /** @class */ (function (_super) {
|
|
|
101
100
|
};
|
|
102
101
|
default:
|
|
103
102
|
warning(false, "Can't get coordinates: invalid direction '".concat(direction, "'. Must be one of - 'top', 'right', 'bottom', 'left'."));
|
|
104
|
-
return
|
|
103
|
+
return {
|
|
104
|
+
top: popupRect.height,
|
|
105
|
+
left: _this.getPinLeftCoordinate(popupRect, align),
|
|
106
|
+
};
|
|
105
107
|
}
|
|
106
108
|
};
|
|
107
109
|
_this.getPinTopCoordinate = function (popupRect, align) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopupPin.js","sourceRoot":"","sources":["PopupPin.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF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CAA8B,KAAK,CAAC,SAAS,GA4T5C;SA5TY,QAAQ","sourcesContent":["import type { Emotion } from '@emotion/css/create-instance';\nimport React from 'react';\nimport warning from 'warning';\n\nimport { responsiveLayout } from '../../components/ResponsiveLayout/decorator.js';\nimport { getDOMRect } from '../../lib/dom/getDOMRect.js';\nimport type { GlobalObject } from '../../lib/globalObject.js';\nimport * as LayoutEvents from '../../lib/LayoutEvents.js';\nimport { withRenderEnvironment } from '../../lib/renderEnvironment/index.js';\nimport type { Theme } from '../../lib/theming/Theme.js';\nimport { ThemeContext } from '../../lib/theming/ThemeContext.js';\nimport type { Nullable } from '../../typings/utility-types.js';\nimport { PopupDataTids } from './Popup.js';\nimport type { PositionObject, Rect } from './PopupHelper.js';\nimport { PopupHelper } from './PopupHelper.js';\nimport { getStyles } from './PopupPin.styles.js';\n\ninterface PopupPinProps {\n /** Цвет фона пина */\n backgroundColor: string;\n\n /** Смещение пина от края попапа. Край задаётся в пропе position вторым словом */\n offset: number;\n\n /** Ссылка на попап */\n popupElement?: Nullable<Element>;\n\n /** Позиция попапа, по которой будет вычислено положение пина */\n popupPosition: string;\n\n /**\n * Высота пина в px. Ширина основания = 2 × size для top/bottom, для left/right наоборот.\n */\n size: number;\n}\n\ninterface ClampedPinPosition {\n left: number;\n top: number;\n hidden: boolean;\n}\n\n@withRenderEnvironment\n@responsiveLayout\nexport class PopupPin extends React.Component<PopupPinProps> {\n public static __KONTUR_REACT_UI__ = 'PopupPin';\n public static displayName = 'PopupPin';\n\n private positionObject!: PositionObject;\n private theme!: Theme;\n private isMobileLayout!: boolean;\n\n private styles!: ReturnType<typeof getStyles>;\n private emotion!: Emotion;\n private cx!: Emotion['cx'];\n private globalObject!: GlobalObject;\n private layoutEventsToken: Nullable<ReturnType<typeof LayoutEvents.addListener>> = null;\n private layoutUpdateId: Nullable<number> = null;\n private cachedPopupElement: Nullable<Element> = null;\n\n public componentDidMount() {\n this.layoutEventsToken = LayoutEvents.addListener(this.handleLayoutEvent, this.globalObject);\n this.scheduleRemeasure();\n }\n\n public componentDidUpdate(prevProps: PopupPinProps) {\n if (\n prevProps.popupPosition !== this.props.popupPosition ||\n prevProps.offset !== this.props.offset ||\n prevProps.popupElement !== this.props.popupElement\n ) {\n this.scheduleRemeasure();\n }\n }\n\n public componentWillUnmount() {\n this.cancelScheduledRemeasure();\n this.layoutEventsToken?.remove();\n this.layoutEventsToken = null;\n }\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderPinContent();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderPinContent() {\n this.styles = getStyles(this.emotion);\n\n if (this.props.popupElement) {\n this.cachedPopupElement = this.props.popupElement;\n }\n\n const popupElement = this.props.popupElement || this.cachedPopupElement;\n\n if (!popupElement) {\n return null;\n }\n\n this.positionObject = PopupHelper.getPositionObject(this.props.popupPosition);\n\n const coords = this.getPinCoordinates(popupElement);\n if (!coords || typeof coords.left !== 'number' || typeof coords.top !== 'number') {\n return null;\n }\n\n const popupRect = this.getPopupElementRect(popupElement);\n const clampedPosition = this.applyEdgeClamp(coords, popupRect);\n const inlineStyle = this.getPinInlineStyle(clampedPosition.left, clampedPosition.top);\n const directionalStyle = this.getPinDirectionalStyle();\n if (!inlineStyle || !directionalStyle) {\n return null;\n }\n\n const pinEdgePadding = this.getPinEdgePadding();\n\n return (\n <div\n data-tid={PopupDataTids.popupPin}\n className={this.cx(\n this.styles.pin(),\n pinEdgePadding > 0 && this.styles.pinAnimated(),\n clampedPosition.hidden && this.styles.pinHidden(),\n directionalStyle,\n )}\n style={inlineStyle}\n ></div>\n );\n }\n\n private getPinEdgePadding(): number {\n return PopupHelper.getPopupViewportSidePadding(this.theme, this.isMobileLayout);\n }\n\n private handleLayoutEvent = () => {\n this.scheduleRemeasure();\n };\n\n private scheduleRemeasure() {\n this.cancelScheduledRemeasure();\n this.layoutUpdateId = this.globalObject.requestAnimationFrame?.(() => {\n this.layoutUpdateId = null;\n this.forceUpdate();\n });\n }\n\n private cancelScheduledRemeasure() {\n if (this.layoutUpdateId && this.layoutUpdateId !== null) {\n this.globalObject.cancelAnimationFrame?.(this.layoutUpdateId);\n this.layoutUpdateId = null;\n }\n }\n\n private getPopupOppositeDirection() {\n const popupDirection = PopupHelper.getPositionObject(this.props.popupPosition).direction;\n switch (popupDirection) {\n case 'top':\n return 'bottom';\n case 'bottom':\n return 'top';\n case 'left':\n return 'right';\n case 'right':\n return 'left';\n default:\n warning(\n false,\n `Can't get opposite direction: invalid direction ${popupDirection}. Must be one of - 'top', 'bottom', 'left', 'right'.`,\n );\n return 'bottom';\n }\n }\n\n private getPinInlineStyle = (left: number, top: number) => {\n const direction = this.getPopupOppositeDirection();\n if (!direction) {\n return;\n }\n\n // Добавляем запас в 1px, чтобы пофиксить случайные отделения пинов\n const correctedLeft = left - 1;\n const correctedTop = top - 1;\n const correctedSize = this.props.size + 1;\n\n const defaultPinInlineStyle = {\n [direction]: -this.props.size + 'px',\n left: correctedLeft + 'px',\n width: correctedSize * 2 + 'px',\n height: correctedSize + 'px',\n backgroundColor: this.props.backgroundColor,\n };\n\n switch (direction) {\n case 'top':\n case 'bottom':\n return defaultPinInlineStyle;\n case 'left':\n case 'right':\n return {\n [direction]: -this.props.size + 'px',\n top: correctedTop + 'px',\n height: correctedSize * 2 + 'px',\n width: correctedSize + 'px',\n backgroundColor: this.props.backgroundColor,\n };\n default:\n warning(\n false,\n `Can't get inline style: invalid direction '${direction}'. Must be one of - 'top', 'right', 'bottom', 'left'.`,\n );\n return defaultPinInlineStyle;\n }\n };\n\n private clampValue(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n }\n\n private applyEdgeClamp(coords: { left: number; top: number }, popupRect: Rect): ClampedPinPosition {\n const pinEdgePadding = this.getPinEdgePadding();\n\n if (pinEdgePadding <= 0) {\n return { left: coords.left, top: coords.top, hidden: false };\n }\n\n const { direction } = this.positionObject;\n const pinSpan = 2 * this.props.size;\n\n if (direction === 'top' || direction === 'bottom') {\n const minLeft = pinEdgePadding;\n const maxLeft = popupRect.width - pinSpan - pinEdgePadding;\n const clampedLeft = this.clampValue(coords.left, minLeft, maxLeft);\n const centerOffset = coords.left - clampedLeft;\n\n return {\n left: clampedLeft,\n top: coords.top,\n hidden: centerOffset !== 0,\n };\n }\n\n const minTop = pinEdgePadding;\n const maxTop = popupRect.height - pinSpan - pinEdgePadding;\n const clampedTop = this.clampValue(coords.top, minTop, maxTop);\n const centerOffset = coords.top - clampedTop;\n\n return {\n left: coords.left,\n top: clampedTop,\n hidden: centerOffset !== 0,\n };\n }\n\n private getPopupElementRect(popupElement: Element): Rect {\n const rect = getDOMRect(popupElement);\n\n return {\n top: 0,\n left: 0,\n width: rect.width,\n height: rect.height,\n };\n }\n\n private getPinCoordinates = (popupElement: Element) => {\n const popupRect = this.getPopupElementRect(popupElement);\n const { direction, align } = this.positionObject;\n\n const defaultPinCoordinates = {\n top: popupRect.height,\n left: this.getPinLeftCoordinate(popupRect, align),\n };\n\n switch (direction) {\n case 'top':\n return defaultPinCoordinates;\n case 'bottom':\n return {\n top: -2 * this.props.size,\n left: this.getPinLeftCoordinate(popupRect, align),\n };\n case 'left':\n return {\n top: this.getPinTopCoordinate(popupRect, align),\n left: popupRect.width,\n };\n case 'right':\n return {\n top: this.getPinTopCoordinate(popupRect, align),\n left: -2 * this.props.size,\n };\n default:\n warning(\n false,\n `Can't get coordinates: invalid direction '${direction}'. Must be one of - 'top', 'right', 'bottom', 'left'.`,\n );\n return defaultPinCoordinates;\n }\n };\n\n private getPinTopCoordinate = (popupRect: Rect, align: string) => {\n const defaultTopCoordinate = this.props.offset;\n switch (align) {\n case 'top':\n return defaultTopCoordinate;\n case 'middle':\n return popupRect.height / 2 - this.props.size;\n case 'bottom':\n return popupRect.height - this.props.offset - 2 * this.props.size;\n default:\n warning(\n false,\n `Can't get top coordinate: invalid align '${align}'. Must be one of - 'top', 'middle', 'bottom'.`,\n );\n return defaultTopCoordinate;\n }\n };\n\n private getPinLeftCoordinate = (popupRect: Rect, align: string) => {\n const defaultLetfCoordinate = popupRect.width / 2 - this.props.size;\n switch (align) {\n case 'left':\n return this.props.offset;\n case 'center':\n return defaultLetfCoordinate + this.props.offset;\n case 'right':\n return popupRect.width - this.props.offset - 2 * this.props.size;\n default:\n warning(\n false,\n `Can't get left coordinate: invalid align '${align}'. Must be one of - 'left', 'center', 'right'.`,\n );\n return defaultLetfCoordinate;\n }\n };\n\n private getPinDirectionalStyle = () => {\n switch (this.positionObject.direction) {\n case 'top':\n return this.styles.pinTop();\n case 'bottom':\n return this.styles.pinBottom();\n case 'left':\n return this.styles.pinLeft();\n case 'right':\n return this.styles.pinRight();\n default:\n warning(\n false,\n `Can't get directional style: invalid direction '${this.positionObject.direction}'. Must be one of - 'top', 'right', 'bottom', 'left'.`,\n );\n return this.styles.pinTop();\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PopupPin.js","sourceRoot":"","sources":["PopupPin.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,OAAO,KAAK,YAAY,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AA6BjD;IAA8B,4BAA8B;IAA5D;;QAYU,uBAAiB,GAA0D,IAAI,CAAC;QAChF,oBAAc,GAAqB,IAAI,CAAC;QACxC,wBAAkB,GAAsB,I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;QAED,IAAM,MAAM,GAAG,cAAc,CAAC;QAC9B,IAAM,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG,OAAO,GAAG,cAAc,CAAC;QAC3D,IAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/D,IAAM,YAAY,GAAG,MAAM,CAAC,GAAG,GAAG,UAAU,CAAC;QAE7C,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,GAAG,EAAE,UAAU;YACf,MAAM,EAAE,YAAY,KAAK,CAAC;SAC3B,CAAC;IACJ,CAAC;IAEO,sCAAmB,GAA3B,UAA4B,YAAqB;QAC/C,IAAM,IAAI,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;QAEtC,OAAO;YACL,GAAG,EAAE,CAAC;YACN,IAAI,EAAE,CAAC;YACP,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;IA/Na,4BAAmB,GAAG,UAAU,AAAb,CAAc;IACjC,oBAAW,GAAG,UAAU,AAAb,CAAc;IAF5B,QAAQ;QAFpB,qBAAqB;QACrB,gBAAgB;OACJ,QAAQ,CA6TpB;IAAD,eAAC;CAAA,AA7TD,CAA8B,KAAK,CAAC,SAAS,GA6T5C;SA7TY,QAAQ","sourcesContent":["import type { Emotion } from '@emotion/css/create-instance';\nimport React from 'react';\nimport warning from 'warning';\n\nimport { responsiveLayout } from '../../components/ResponsiveLayout/decorator.js';\nimport { getDOMRect } from '../../lib/dom/getDOMRect.js';\nimport type { GlobalObject } from '../../lib/globalObject.js';\nimport * as LayoutEvents from '../../lib/LayoutEvents.js';\nimport { withRenderEnvironment } from '../../lib/renderEnvironment/index.js';\nimport type { Theme } from '../../lib/theming/Theme.js';\nimport { ThemeContext } from '../../lib/theming/ThemeContext.js';\nimport type { Nullable } from '../../typings/utility-types.js';\nimport { PopupDataTids } from './Popup.js';\nimport type { PositionObject, Rect } from './PopupHelper.js';\nimport { PopupHelper } from './PopupHelper.js';\nimport { getStyles } from './PopupPin.styles.js';\n\ninterface PopupPinProps {\n /** Цвет фона пина */\n backgroundColor: string;\n\n /** Смещение пина от края попапа. Край задаётся в пропе position вторым словом */\n offset: number;\n\n /** Ссылка на попап */\n popupElement?: Nullable<Element>;\n\n /** Позиция попапа, по которой будет вычислено положение пина */\n popupPosition: string;\n\n /**\n * Высота пина в px. Ширина основания = 2 × size для top/bottom, для left/right наоборот.\n */\n size: number;\n}\n\ninterface ClampedPinPosition {\n left: number;\n top: number;\n hidden: boolean;\n}\n\n@withRenderEnvironment\n@responsiveLayout\nexport class PopupPin extends React.Component<PopupPinProps> {\n public static __KONTUR_REACT_UI__ = 'PopupPin';\n public static displayName = 'PopupPin';\n\n private positionObject!: PositionObject;\n private theme!: Theme;\n private isMobileLayout!: boolean;\n\n private styles!: ReturnType<typeof getStyles>;\n private emotion!: Emotion;\n private cx!: Emotion['cx'];\n private globalObject!: GlobalObject;\n private layoutEventsToken: Nullable<ReturnType<typeof LayoutEvents.addListener>> = null;\n private layoutUpdateId: Nullable<number> = null;\n private cachedPopupElement: Nullable<Element> = null;\n\n public componentDidMount() {\n this.layoutEventsToken = LayoutEvents.addListener(this.handleLayoutEvent, this.globalObject);\n this.scheduleRemeasure();\n }\n\n public componentDidUpdate(prevProps: PopupPinProps) {\n if (\n prevProps.popupPosition !== this.props.popupPosition ||\n prevProps.offset !== this.props.offset ||\n prevProps.popupElement !== this.props.popupElement\n ) {\n this.scheduleRemeasure();\n }\n }\n\n public componentWillUnmount() {\n this.cancelScheduledRemeasure();\n this.layoutEventsToken?.remove();\n this.layoutEventsToken = null;\n }\n\n public render() {\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return this.renderPinContent();\n }}\n </ThemeContext.Consumer>\n );\n }\n\n private renderPinContent() {\n this.styles = getStyles(this.emotion);\n\n if (this.props.popupElement) {\n this.cachedPopupElement = this.props.popupElement;\n }\n\n const popupElement = this.props.popupElement || this.cachedPopupElement;\n\n if (!popupElement) {\n return null;\n }\n\n this.positionObject = PopupHelper.getPositionObject(this.props.popupPosition);\n\n const coords = this.getPinCoordinates(popupElement);\n if (!coords || typeof coords.left !== 'number' || typeof coords.top !== 'number') {\n return null;\n }\n\n const popupRect = this.getPopupElementRect(popupElement);\n const clampedPosition = this.applyEdgeClamp(coords, popupRect);\n const inlineStyle = this.getPinInlineStyle(clampedPosition.left, clampedPosition.top);\n const directionalStyle = this.getPinDirectionalStyle();\n if (!inlineStyle || !directionalStyle) {\n return null;\n }\n\n const pinEdgePadding = this.getPinEdgePadding();\n\n return (\n <div\n data-tid={PopupDataTids.popupPin}\n className={this.cx(\n this.styles.pin(),\n pinEdgePadding > 0 && this.styles.pinAnimated(),\n clampedPosition.hidden && this.styles.pinHidden(),\n directionalStyle,\n )}\n style={inlineStyle}\n ></div>\n );\n }\n\n private getPinEdgePadding(): number {\n return PopupHelper.getPopupViewportSidePadding(this.theme, this.isMobileLayout);\n }\n\n private handleLayoutEvent = () => {\n this.scheduleRemeasure();\n };\n\n private scheduleRemeasure() {\n this.cancelScheduledRemeasure();\n this.layoutUpdateId = this.globalObject.requestAnimationFrame?.(() => {\n this.layoutUpdateId = null;\n this.forceUpdate();\n });\n }\n\n private cancelScheduledRemeasure() {\n if (this.layoutUpdateId && this.layoutUpdateId !== null) {\n this.globalObject.cancelAnimationFrame?.(this.layoutUpdateId);\n this.layoutUpdateId = null;\n }\n }\n\n private getPopupOppositeDirection() {\n const popupDirection = PopupHelper.getPositionObject(this.props.popupPosition).direction;\n switch (popupDirection) {\n case 'top':\n return 'bottom';\n case 'bottom':\n return 'top';\n case 'left':\n return 'right';\n case 'right':\n return 'left';\n default:\n warning(\n false,\n `Can't get opposite direction: invalid direction ${popupDirection}. Must be one of - 'top', 'bottom', 'left', 'right'.`,\n );\n return 'bottom';\n }\n }\n\n private getPinInlineStyle = (left: number, top: number) => {\n const direction = this.getPopupOppositeDirection();\n if (!direction) {\n return;\n }\n\n // Добавляем запас в 1px, чтобы пофиксить случайные отделения пинов\n const correctedLeft = left - 1;\n const correctedTop = top - 1;\n const correctedSize = this.props.size + 1;\n\n const defaultPinInlineStyle = {\n [direction]: -this.props.size + 'px',\n left: correctedLeft + 'px',\n width: correctedSize * 2 + 'px',\n height: correctedSize + 'px',\n backgroundColor: this.props.backgroundColor,\n };\n\n switch (direction) {\n case 'top':\n case 'bottom':\n return defaultPinInlineStyle;\n case 'left':\n case 'right':\n return {\n [direction]: -this.props.size + 'px',\n top: correctedTop + 'px',\n height: correctedSize * 2 + 'px',\n width: correctedSize + 'px',\n backgroundColor: this.props.backgroundColor,\n };\n default:\n warning(\n false,\n `Can't get inline style: invalid direction '${direction}'. Must be one of - 'top', 'right', 'bottom', 'left'.`,\n );\n return defaultPinInlineStyle;\n }\n };\n\n private clampValue(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n }\n\n private applyEdgeClamp(coords: { left: number; top: number }, popupRect: Rect): ClampedPinPosition {\n const pinEdgePadding = this.getPinEdgePadding();\n\n if (pinEdgePadding <= 0) {\n return { left: coords.left, top: coords.top, hidden: false };\n }\n\n const { direction } = this.positionObject;\n const pinSpan = 2 * this.props.size;\n\n if (direction === 'top' || direction === 'bottom') {\n const minLeft = pinEdgePadding;\n const maxLeft = popupRect.width - pinSpan - pinEdgePadding;\n const clampedLeft = this.clampValue(coords.left, minLeft, maxLeft);\n const centerOffset = coords.left - clampedLeft;\n\n return {\n left: clampedLeft,\n top: coords.top,\n hidden: centerOffset !== 0,\n };\n }\n\n const minTop = pinEdgePadding;\n const maxTop = popupRect.height - pinSpan - pinEdgePadding;\n const clampedTop = this.clampValue(coords.top, minTop, maxTop);\n const centerOffset = coords.top - clampedTop;\n\n return {\n left: coords.left,\n top: clampedTop,\n hidden: centerOffset !== 0,\n };\n }\n\n private getPopupElementRect(popupElement: Element): Rect {\n const rect = getDOMRect(popupElement);\n\n return {\n top: 0,\n left: 0,\n width: rect.width,\n height: rect.height,\n };\n }\n\n private getPinCoordinates = (popupElement: Element) => {\n const popupRect = this.getPopupElementRect(popupElement);\n const { direction, align } = this.positionObject;\n\n switch (direction) {\n case 'top':\n return {\n top: popupRect.height,\n left: this.getPinLeftCoordinate(popupRect, align),\n };\n case 'bottom':\n return {\n top: -2 * this.props.size,\n left: this.getPinLeftCoordinate(popupRect, align),\n };\n case 'left':\n return {\n top: this.getPinTopCoordinate(popupRect, align),\n left: popupRect.width,\n };\n case 'right':\n return {\n top: this.getPinTopCoordinate(popupRect, align),\n left: -2 * this.props.size,\n };\n default:\n warning(\n false,\n `Can't get coordinates: invalid direction '${direction}'. Must be one of - 'top', 'right', 'bottom', 'left'.`,\n );\n return {\n top: popupRect.height,\n left: this.getPinLeftCoordinate(popupRect, align),\n };\n }\n };\n\n private getPinTopCoordinate = (popupRect: Rect, align: string) => {\n const defaultTopCoordinate = this.props.offset;\n switch (align) {\n case 'top':\n return defaultTopCoordinate;\n case 'middle':\n return popupRect.height / 2 - this.props.size;\n case 'bottom':\n return popupRect.height - this.props.offset - 2 * this.props.size;\n default:\n warning(\n false,\n `Can't get top coordinate: invalid align '${align}'. Must be one of - 'top', 'middle', 'bottom'.`,\n );\n return defaultTopCoordinate;\n }\n };\n\n private getPinLeftCoordinate = (popupRect: Rect, align: string) => {\n const defaultLetfCoordinate = popupRect.width / 2 - this.props.size;\n switch (align) {\n case 'left':\n return this.props.offset;\n case 'center':\n return defaultLetfCoordinate + this.props.offset;\n case 'right':\n return popupRect.width - this.props.offset - 2 * this.props.size;\n default:\n warning(\n false,\n `Can't get left coordinate: invalid align '${align}'. Must be one of - 'left', 'center', 'right'.`,\n );\n return defaultLetfCoordinate;\n }\n };\n\n private getPinDirectionalStyle = () => {\n switch (this.positionObject.direction) {\n case 'top':\n return this.styles.pinTop();\n case 'bottom':\n return this.styles.pinBottom();\n case 'left':\n return this.styles.pinLeft();\n case 'right':\n return this.styles.pinRight();\n default:\n warning(\n false,\n `Can't get directional style: invalid direction '${this.positionObject.direction}'. Must be one of - 'top', 'right', 'bottom', 'left'.`,\n );\n return this.styles.pinTop();\n }\n };\n}\n"]}
|