@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.
- package/dist/index.cjs.mjs +1 -0
- package/dist/index.d.ts +69 -30
- package/dist/index.esm.js +422 -303
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +422 -302
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/components/menu/__workshop__/selectedItem.tsx +7 -2
- package/src/core/components/menu/menuButton.tsx +12 -1
- package/src/core/constants.ts +18 -0
- package/src/core/middleware/origin.ts +47 -0
- package/src/core/primitives/popover/popover.tsx +67 -13
- package/src/core/primitives/popover/popoverCard.tsx +26 -15
- package/src/core/primitives/tooltip/tooltip.tsx +46 -56
- package/src/core/primitives/tooltip/tooltipCard.tsx +104 -0
- package/src/core/{primitives/tooltip → utils/conditionalWrapper}/conditionalWrapper.tsx +3 -0
- package/src/core/utils/conditionalWrapper/index.ts +1 -0
- package/src/core/utils/index.ts +1 -0
|
@@ -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'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './conditionalWrapper'
|