@instructure/ui-tooltip 8.14.1-snapshot.6 → 8.14.1-snapshot.63
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/es/Tooltip/TooltipLocator.js +4 -2
- package/es/Tooltip/index.js +33 -36
- package/es/Tooltip/props.js +0 -69
- package/lib/Tooltip/TooltipLocator.js +3 -1
- package/lib/Tooltip/index.js +33 -36
- package/lib/Tooltip/props.js +0 -69
- package/package.json +16 -16
- package/src/Tooltip/index.tsx +21 -20
- package/src/Tooltip/props.ts +103 -52
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Tooltip/TooltipLocator.d.ts +4 -4
- package/types/Tooltip/index.d.ts +24 -25
- package/types/Tooltip/index.d.ts.map +1 -1
- package/types/Tooltip/props.d.ts +72 -9
- package/types/Tooltip/props.d.ts.map +1 -1
package/src/Tooltip/props.ts
CHANGED
|
@@ -31,7 +31,8 @@ import { element } from '@instructure/ui-prop-types'
|
|
|
31
31
|
import type {
|
|
32
32
|
PropValidators,
|
|
33
33
|
AsElementType,
|
|
34
|
-
TooltipTheme
|
|
34
|
+
TooltipTheme,
|
|
35
|
+
OtherHTMLAttributes
|
|
35
36
|
} from '@instructure/shared-types'
|
|
36
37
|
import type {
|
|
37
38
|
PlacementPropValues,
|
|
@@ -39,12 +40,13 @@ import type {
|
|
|
39
40
|
PositionMountNode
|
|
40
41
|
} from '@instructure/ui-position'
|
|
41
42
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
43
|
+
import type { PopoverOwnProps } from '@instructure/ui-popover'
|
|
42
44
|
|
|
43
45
|
type TooltipRenderChildrenArgs = {
|
|
44
46
|
focused: boolean
|
|
45
|
-
getTriggerProps: <
|
|
46
|
-
props:
|
|
47
|
-
) => { 'aria-describedby': string } &
|
|
47
|
+
getTriggerProps: <TriggerProps extends Record<string, any>>(
|
|
48
|
+
props: TriggerProps
|
|
49
|
+
) => { 'aria-describedby': string } & TriggerProps
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
type TooltipRenderChildren = (
|
|
@@ -52,106 +54,154 @@ type TooltipRenderChildren = (
|
|
|
52
54
|
) => React.ReactNode
|
|
53
55
|
|
|
54
56
|
type TooltipOwnProps = {
|
|
55
|
-
renderTip: React.ReactNode | ((...args: any[]) => any)
|
|
56
|
-
children: React.ReactNode | TooltipRenderChildren
|
|
57
|
-
isShowingContent?: boolean
|
|
58
|
-
defaultIsShowingContent?: boolean
|
|
59
|
-
as?: AsElementType
|
|
60
|
-
on?: ('click' | 'hover' | 'focus') | ('click' | 'hover' | 'focus')[]
|
|
61
|
-
color?: 'primary' | 'primary-inverse'
|
|
62
|
-
placement?: PlacementPropValues
|
|
63
|
-
mountNode?: PositionMountNode
|
|
64
|
-
constrain?: PositionConstraint
|
|
65
|
-
positionTarget?: PositionMountNode
|
|
66
|
-
offsetX?: string | number
|
|
67
|
-
offsetY?: string | number
|
|
68
|
-
onShowContent?: (...args: any[]) => any
|
|
69
|
-
onHideContent?: (...args: any[]) => any
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
type PropKeys = keyof TooltipOwnProps
|
|
73
|
-
|
|
74
|
-
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
75
|
-
|
|
76
|
-
// For now it doesn't need the OtherHTMLAttributes, because the extra props
|
|
77
|
-
// get passed to Popover and it doesn't handle them
|
|
78
|
-
type TooltipProps = TooltipOwnProps & WithStyleProps<TooltipTheme, TooltipStyle>
|
|
79
|
-
|
|
80
|
-
type TooltipStyle = ComponentStyle<'tooltip'>
|
|
81
|
-
|
|
82
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
83
57
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* @param {
|
|
58
|
+
* A ReactNode or a function that returns a ReactNode with the following params:
|
|
59
|
+
*
|
|
60
|
+
* @param {Boolean} focused - Is the Tooltip trigger focused?
|
|
61
|
+
* @param {Function} getTriggerProps - Props to be spread onto the trigger element
|
|
87
62
|
*/
|
|
88
|
-
children:
|
|
63
|
+
children: React.ReactNode | TooltipRenderChildren
|
|
64
|
+
|
|
89
65
|
/**
|
|
90
66
|
* The content to render in the tooltip
|
|
91
67
|
*/
|
|
92
|
-
renderTip:
|
|
68
|
+
renderTip: React.ReactNode | (() => React.ReactNode)
|
|
69
|
+
|
|
93
70
|
/**
|
|
94
71
|
* Whether or not the tooltip content is shown, when controlled
|
|
95
72
|
*/
|
|
96
|
-
isShowingContent
|
|
73
|
+
isShowingContent?: boolean
|
|
74
|
+
|
|
97
75
|
/**
|
|
98
76
|
* Whether or not to show the content by default, when uncontrolled
|
|
99
77
|
*/
|
|
100
|
-
defaultIsShowingContent
|
|
78
|
+
defaultIsShowingContent?: boolean
|
|
79
|
+
|
|
101
80
|
/**
|
|
102
81
|
* the element type to render as (assumes a single child if 'as' is undefined)
|
|
103
82
|
*/
|
|
104
|
-
as
|
|
83
|
+
as?: AsElementType
|
|
84
|
+
|
|
105
85
|
/**
|
|
106
86
|
* The action that causes the Content to display (`click`, `hover`, `focus`)
|
|
107
87
|
*/
|
|
108
|
-
on
|
|
109
|
-
|
|
110
|
-
PropTypes.arrayOf(PropTypes.oneOf(['click', 'hover', 'focus']))
|
|
111
|
-
]),
|
|
88
|
+
on?: ('click' | 'hover' | 'focus') | ('click' | 'hover' | 'focus')[]
|
|
89
|
+
|
|
112
90
|
/**
|
|
113
91
|
* The color of the tooltip content
|
|
114
92
|
*/
|
|
115
|
-
color
|
|
93
|
+
color?: 'primary' | 'primary-inverse'
|
|
94
|
+
|
|
116
95
|
/**
|
|
117
96
|
* Specifies where the Tooltip will be placed in relation to the target element.
|
|
118
97
|
* Ex. placement="bottom" will render the Tooltip below the triggering element
|
|
119
98
|
* (Note: if there is not room, it will position opposite. Ex. "top" will
|
|
120
99
|
* automatically switch to "bottom")
|
|
121
100
|
*/
|
|
122
|
-
placement
|
|
101
|
+
placement?: PlacementPropValues
|
|
102
|
+
|
|
123
103
|
/**
|
|
124
104
|
* An element or a function returning an element to use as the mount node
|
|
125
105
|
* for the `<Tooltip />` (defaults to `document.body`)
|
|
126
106
|
*/
|
|
127
|
-
mountNode
|
|
107
|
+
mountNode?: PositionMountNode
|
|
108
|
+
|
|
128
109
|
/**
|
|
129
110
|
* The parent in which to constrain the tooltip.
|
|
130
111
|
* One of: 'window', 'scroll-parent', 'parent', 'none', an element,
|
|
131
112
|
* or a function returning an element
|
|
132
113
|
*/
|
|
133
|
-
constrain
|
|
114
|
+
constrain?: PositionConstraint
|
|
115
|
+
|
|
134
116
|
/**
|
|
135
117
|
* The horizontal offset for the positioned content
|
|
136
118
|
*/
|
|
137
|
-
offsetX
|
|
119
|
+
offsetX?: string | number
|
|
120
|
+
|
|
138
121
|
/**
|
|
139
122
|
* The vertical offset for the positioned content
|
|
140
123
|
*/
|
|
141
|
-
offsetY
|
|
124
|
+
offsetY?: string | number
|
|
125
|
+
|
|
142
126
|
/**
|
|
143
127
|
* Target element for positioning the Tooltip (if it differs from children/trigger)
|
|
144
128
|
*/
|
|
145
|
-
positionTarget
|
|
129
|
+
positionTarget?: PositionMountNode
|
|
130
|
+
|
|
146
131
|
/**
|
|
147
132
|
* Callback fired when content is shown. When controlled, this callback is
|
|
148
133
|
* fired when the tooltip expects to be shown
|
|
149
134
|
*/
|
|
150
|
-
onShowContent:
|
|
135
|
+
onShowContent?: (event: React.UIEvent | React.FocusEvent) => void
|
|
136
|
+
|
|
151
137
|
/**
|
|
152
138
|
* Callback fired when content is hidden. When controlled, this callback is
|
|
153
139
|
* fired when the tooltip expects to be hidden
|
|
154
140
|
*/
|
|
141
|
+
onHideContent?: (
|
|
142
|
+
event: React.UIEvent | React.FocusEvent,
|
|
143
|
+
args: { documentClick: boolean }
|
|
144
|
+
) => void
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
type PropKeys = keyof TooltipOwnProps
|
|
148
|
+
|
|
149
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
150
|
+
|
|
151
|
+
// passes through props for Popover, except the ones set manually
|
|
152
|
+
type PropsPassableToPopover = Omit<
|
|
153
|
+
PopoverOwnProps,
|
|
154
|
+
| 'isShowingContent'
|
|
155
|
+
| 'defaultIsShowingContent'
|
|
156
|
+
| 'on'
|
|
157
|
+
| 'shouldRenderOffscreen'
|
|
158
|
+
| 'shouldReturnFocus'
|
|
159
|
+
| 'placement'
|
|
160
|
+
| 'color'
|
|
161
|
+
| 'mountNode'
|
|
162
|
+
| 'constrain'
|
|
163
|
+
| 'shadow'
|
|
164
|
+
| 'offsetX'
|
|
165
|
+
| 'offsetY'
|
|
166
|
+
| 'positionTarget'
|
|
167
|
+
| 'renderTrigger'
|
|
168
|
+
| 'onShowContent'
|
|
169
|
+
| 'onHideContent'
|
|
170
|
+
| 'onFocus'
|
|
171
|
+
| 'onBlur'
|
|
172
|
+
| 'elementRef'
|
|
173
|
+
>
|
|
174
|
+
|
|
175
|
+
type TooltipProps = PropsPassableToPopover &
|
|
176
|
+
TooltipOwnProps &
|
|
177
|
+
WithStyleProps<TooltipTheme, TooltipStyle> &
|
|
178
|
+
// the OtherHTMLAttributes might be passed to the trigger or Popover
|
|
179
|
+
OtherHTMLAttributes<TooltipOwnProps>
|
|
180
|
+
|
|
181
|
+
type TooltipStyle = ComponentStyle<'tooltip'>
|
|
182
|
+
|
|
183
|
+
type TooltipState = {
|
|
184
|
+
hasFocus: boolean
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
188
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
|
|
189
|
+
renderTip: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
|
|
190
|
+
isShowingContent: PropTypes.bool,
|
|
191
|
+
defaultIsShowingContent: PropTypes.bool,
|
|
192
|
+
as: PropTypes.elementType, // eslint-disable-line react/require-default-props
|
|
193
|
+
on: PropTypes.oneOfType([
|
|
194
|
+
PropTypes.oneOf(['click', 'hover', 'focus']),
|
|
195
|
+
PropTypes.arrayOf(PropTypes.oneOf(['click', 'hover', 'focus']))
|
|
196
|
+
]),
|
|
197
|
+
color: PropTypes.oneOf(['primary', 'primary-inverse']),
|
|
198
|
+
placement: PositionPropTypes.placement,
|
|
199
|
+
mountNode: PositionPropTypes.mountNode,
|
|
200
|
+
constrain: PositionPropTypes.constrain,
|
|
201
|
+
offsetX: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
202
|
+
offsetY: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
203
|
+
positionTarget: PropTypes.oneOfType([element, PropTypes.func]),
|
|
204
|
+
onShowContent: PropTypes.func,
|
|
155
205
|
onHideContent: PropTypes.func
|
|
156
206
|
}
|
|
157
207
|
|
|
@@ -175,6 +225,7 @@ const allowedProps: AllowedPropKeys = [
|
|
|
175
225
|
|
|
176
226
|
export type {
|
|
177
227
|
TooltipProps,
|
|
228
|
+
TooltipState,
|
|
178
229
|
TooltipStyle,
|
|
179
230
|
TooltipRenderChildren,
|
|
180
231
|
TooltipRenderChildrenArgs
|