@sanity/ui 2.0.0-beta.3 → 2.0.0-beta.5

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.
@@ -0,0 +1,104 @@
1
+ import {ThemeColorSchemeKey} from '@sanity/ui/theme'
2
+ import {MotionProps, motion} from 'framer-motion'
3
+ import React, {CSSProperties, forwardRef, memo, useMemo} from 'react'
4
+ import styled from 'styled-components'
5
+ import {POPOVER_MOTION_PROPS} from '../../constants'
6
+ import {Placement, Radius} from '../../types'
7
+ import {Arrow} from '../../utils'
8
+ import {Card, CardProps} from '../card'
9
+ import {
10
+ DEFAULT_TOOLTIP_ARROW_HEIGHT,
11
+ DEFAULT_TOOLTIP_ARROW_RADIUS,
12
+ DEFAULT_TOOLTIP_ARROW_WIDTH,
13
+ } from './constants'
14
+
15
+ const MotionCard = styled(motion(Card))``
16
+
17
+ /**
18
+ * @internal
19
+ */
20
+ export const TooltipCard = memo(
21
+ forwardRef(function TooltipCard(
22
+ props: {
23
+ animate?: boolean
24
+ arrow: boolean
25
+ arrowRef: React.Ref<HTMLDivElement>
26
+ arrowX?: number
27
+ arrowY?: number
28
+ originX?: number
29
+ originY?: number
30
+ padding?: number | number[]
31
+ placement?: Placement
32
+ radius?: Radius | Radius[]
33
+ scheme?: ThemeColorSchemeKey
34
+ shadow?: number | number[]
35
+ } & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'height' | 'width'>,
36
+ ref: React.ForwardedRef<HTMLDivElement>,
37
+ ) {
38
+ const {
39
+ animate,
40
+ arrow,
41
+ arrowRef,
42
+ arrowX,
43
+ arrowY,
44
+ children,
45
+ originX,
46
+ originY,
47
+ padding,
48
+ placement,
49
+ radius,
50
+ scheme,
51
+ shadow,
52
+ style,
53
+ ...restProps
54
+ } = props
55
+
56
+ const rootStyle: CSSProperties = useMemo(
57
+ () => ({
58
+ originX,
59
+ originY,
60
+ ...style,
61
+ }),
62
+ [originX, originY, style],
63
+ )
64
+
65
+ const arrowStyle: CSSProperties = useMemo(
66
+ () => ({
67
+ left: arrowX !== null ? arrowX : undefined,
68
+ top: arrowY !== null ? arrowY : undefined,
69
+ right: undefined,
70
+ bottom: undefined,
71
+ }),
72
+ [arrowX, arrowY],
73
+ )
74
+
75
+ return (
76
+ <MotionCard
77
+ data-ui="Tooltip__card"
78
+ {...(restProps as CardProps & MotionProps)}
79
+ data-placement={placement}
80
+ padding={padding}
81
+ radius={radius}
82
+ ref={ref}
83
+ scheme={scheme}
84
+ shadow={shadow}
85
+ style={rootStyle}
86
+ {...(animate ? POPOVER_MOTION_PROPS : {})}
87
+ >
88
+ {children}
89
+
90
+ {arrow && (
91
+ <Arrow
92
+ ref={arrowRef}
93
+ style={arrowStyle}
94
+ width={DEFAULT_TOOLTIP_ARROW_WIDTH}
95
+ height={DEFAULT_TOOLTIP_ARROW_HEIGHT}
96
+ radius={DEFAULT_TOOLTIP_ARROW_RADIUS}
97
+ />
98
+ )}
99
+ </MotionCard>
100
+ )
101
+ }),
102
+ )
103
+
104
+ TooltipCard.displayName = 'TooltipCard'
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @internal
3
+ */
1
4
  export function ConditionalWrapper({
2
5
  children,
3
6
  condition,
@@ -0,0 +1 @@
1
+ export * from './conditionalWrapper'
@@ -1,5 +1,6 @@
1
1
  export * from './arrow'
2
2
  export * from './boundaryElement'
3
+ export * from './conditionalWrapper'
3
4
  export * from './elementQuery'
4
5
  export * from './errorBoundary'
5
6
  export * from './layer'