@instructure/ui-tooltip 8.8.1-snapshot.8 → 8.9.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.
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.allowedProps = exports.propTypes = void 0;
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _PositionPropTypes = require("@instructure/ui-position/lib/PositionPropTypes.js");
13
+
14
+ var _element = require("@instructure/ui-prop-types/lib/element.js");
15
+
16
+ /*
17
+ * The MIT License (MIT)
18
+ *
19
+ * Copyright (c) 2015 - present Instructure, Inc.
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
22
+ * of this software and associated documentation files (the "Software"), to deal
23
+ * in the Software without restriction, including without limitation the rights
24
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
+ * copies of the Software, and to permit persons to whom the Software is
26
+ * furnished to do so, subject to the following conditions:
27
+ *
28
+ * The above copyright notice and this permission notice shall be included in all
29
+ * copies or substantial portions of the Software.
30
+ *
31
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
+ * SOFTWARE.
38
+ */
39
+ const propTypes = {
40
+ /**
41
+ * @param {Object} renderProps
42
+ * @param {Boolean} renderProps.focused - Is the Tooltip trigger focused?
43
+ * @param {Function} renderProps.getTriggerProps - Props to be spread onto the trigger element
44
+ */
45
+ children: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]).isRequired,
46
+
47
+ /**
48
+ * The content to render in the tooltip
49
+ */
50
+ renderTip: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]).isRequired,
51
+
52
+ /**
53
+ * Whether or not the tooltip content is shown, when controlled
54
+ */
55
+ isShowingContent: _propTypes.default.bool,
56
+
57
+ /**
58
+ * Whether or not to show the content by default, when uncontrolled
59
+ */
60
+ defaultIsShowingContent: _propTypes.default.bool,
61
+
62
+ /**
63
+ * the element type to render as (assumes a single child if 'as' is undefined)
64
+ */
65
+ as: _propTypes.default.elementType,
66
+ // eslint-disable-line react/require-default-props
67
+
68
+ /**
69
+ * The action that causes the Content to display (`click`, `hover`, `focus`)
70
+ */
71
+ on: _propTypes.default.oneOfType([_propTypes.default.oneOf(['click', 'hover', 'focus']), _propTypes.default.arrayOf(_propTypes.default.oneOf(['click', 'hover', 'focus']))]),
72
+
73
+ /**
74
+ * The color of the tooltip content
75
+ */
76
+ color: _propTypes.default.oneOf(['primary', 'primary-inverse']),
77
+
78
+ /**
79
+ * Specifies where the Tooltip will be placed in relation to the target element.
80
+ * Ex. placement="bottom" will render the Tooltip below the triggering element
81
+ * (Note: if there is not room, it will position opposite. Ex. "top" will
82
+ * automatically switch to "bottom")
83
+ */
84
+ placement: _PositionPropTypes.PositionPropTypes.placement,
85
+
86
+ /**
87
+ * An element or a function returning an element to use as the mount node
88
+ * for the `<Tooltip />` (defaults to `document.body`)
89
+ */
90
+ mountNode: _PositionPropTypes.PositionPropTypes.mountNode,
91
+
92
+ /**
93
+ * The parent in which to constrain the tooltip.
94
+ * One of: 'window', 'scroll-parent', 'parent', 'none', an element,
95
+ * or a function returning an element
96
+ */
97
+ constrain: _PositionPropTypes.PositionPropTypes.constrain,
98
+
99
+ /**
100
+ * The horizontal offset for the positioned content
101
+ */
102
+ offsetX: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
103
+
104
+ /**
105
+ * The vertical offset for the positioned content
106
+ */
107
+ offsetY: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
108
+
109
+ /**
110
+ * Target element for positioning the Tooltip (if it differs from children/trigger)
111
+ */
112
+ positionTarget: _propTypes.default.oneOfType([_element.element, _propTypes.default.func]),
113
+
114
+ /**
115
+ * Callback fired when content is shown. When controlled, this callback is
116
+ * fired when the tooltip expects to be shown
117
+ */
118
+ onShowContent: _propTypes.default.func,
119
+
120
+ /**
121
+ * Callback fired when content is hidden. When controlled, this callback is
122
+ * fired when the tooltip expects to be hidden
123
+ */
124
+ onHideContent: _propTypes.default.func
125
+ };
126
+ exports.propTypes = propTypes;
127
+ const allowedProps = ['children', 'renderTip', 'isShowingContent', 'defaultIsShowingContent', 'as', 'on', 'color', 'placement', 'mountNode', 'constrain', 'offsetX', 'offsetY', 'positionTarget', 'onShowContent', 'onHideContent'];
128
+ exports.allowedProps = allowedProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-tooltip",
3
- "version": "8.8.1-snapshot.8+7b83164f4",
3
+ "version": "8.9.0",
4
4
  "description": "A component for showing small text-only overlays on hover/focus.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "type": "commonjs",
@@ -25,23 +25,23 @@
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
27
  "@babel/runtime": "^7.13.10",
28
- "@instructure/emotion": "8.8.1-snapshot.8+7b83164f4",
29
- "@instructure/shared-types": "8.8.1-snapshot.8+7b83164f4",
30
- "@instructure/ui-popover": "8.8.1-snapshot.8+7b83164f4",
31
- "@instructure/ui-position": "8.8.1-snapshot.8+7b83164f4",
32
- "@instructure/ui-prop-types": "8.8.1-snapshot.8+7b83164f4",
33
- "@instructure/ui-react-utils": "8.8.1-snapshot.8+7b83164f4",
34
- "@instructure/ui-testable": "8.8.1-snapshot.8+7b83164f4",
35
- "@instructure/uid": "8.8.1-snapshot.8+7b83164f4",
28
+ "@instructure/emotion": "8.9.0",
29
+ "@instructure/shared-types": "8.9.0",
30
+ "@instructure/ui-popover": "8.9.0",
31
+ "@instructure/ui-position": "8.9.0",
32
+ "@instructure/ui-prop-types": "8.9.0",
33
+ "@instructure/ui-react-utils": "8.9.0",
34
+ "@instructure/ui-testable": "8.9.0",
35
+ "@instructure/uid": "8.9.0",
36
36
  "prop-types": "^15"
37
37
  },
38
38
  "devDependencies": {
39
- "@instructure/ui-babel-preset": "8.8.1-snapshot.8+7b83164f4",
40
- "@instructure/ui-color-utils": "8.8.1-snapshot.8+7b83164f4",
41
- "@instructure/ui-test-locator": "8.8.1-snapshot.8+7b83164f4",
42
- "@instructure/ui-test-queries": "8.8.1-snapshot.8+7b83164f4",
43
- "@instructure/ui-test-utils": "8.8.1-snapshot.8+7b83164f4",
44
- "@instructure/ui-themes": "8.8.1-snapshot.8+7b83164f4"
39
+ "@instructure/ui-babel-preset": "8.9.0",
40
+ "@instructure/ui-color-utils": "8.9.0",
41
+ "@instructure/ui-test-locator": "8.9.0",
42
+ "@instructure/ui-test-queries": "8.9.0",
43
+ "@instructure/ui-test-utils": "8.9.0",
44
+ "@instructure/ui-themes": "8.9.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": ">=16.8 <=17"
@@ -49,6 +49,5 @@
49
49
  "publishConfig": {
50
50
  "access": "public"
51
51
  },
52
- "sideEffects": false,
53
- "gitHead": "7b83164f4c5872f3a217e010563f59bf584ae4fc"
52
+ "sideEffects": false
54
53
  }
@@ -24,7 +24,6 @@
24
24
 
25
25
  /** @jsx jsx */
26
26
  import { Component } from 'react'
27
- import PropTypes from 'prop-types'
28
27
 
29
28
  import {
30
29
  getElementType,
@@ -33,16 +32,15 @@ import {
33
32
  passthroughProps,
34
33
  callRenderProp
35
34
  } from '@instructure/ui-react-utils'
36
- import { PositionPropTypes } from '@instructure/ui-position'
37
35
  import { uid } from '@instructure/uid'
38
36
  import { testable } from '@instructure/ui-testable'
39
37
  import { Popover } from '@instructure/ui-popover'
40
- import { element } from '@instructure/ui-prop-types'
41
38
  import { withStyle, jsx } from '@instructure/emotion'
42
39
 
43
40
  import generateStyle from './styles'
44
41
  import generateComponentTheme from './theme'
45
- import { TooltipProps } from './types'
42
+ import type { TooltipProps } from './props'
43
+ import { allowedProps, propTypes } from './props'
46
44
 
47
45
  /**
48
46
  ---
@@ -54,97 +52,17 @@ category: components
54
52
  class Tooltip extends Component<TooltipProps> {
55
53
  static readonly componentId = 'Tooltip'
56
54
 
57
- static propTypes = {
58
- // eslint-disable-next-line react/require-default-props
59
- makeStyles: PropTypes.func,
60
- // eslint-disable-next-line react/require-default-props
61
- styles: PropTypes.object,
62
- /**
63
- * @param {Object} renderProps
64
- * @param {Boolean} renderProps.focused - Is the Tooltip trigger focused?
65
- * @param {Function} renderProps.getTriggerProps - Props to be spread onto the trigger element
66
- */
67
- children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
68
- /**
69
- * The content to render in the tooltip
70
- */
71
- renderTip: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
72
- /**
73
- * Whether or not the tooltip content is shown, when controlled
74
- */
75
- isShowingContent: PropTypes.bool,
76
- /**
77
- * Whether or not to show the content by default, when uncontrolled
78
- */
79
- defaultIsShowingContent: PropTypes.bool,
80
- /**
81
- * the element type to render as (assumes a single child if 'as' is undefined)
82
- */
83
- as: PropTypes.elementType, // eslint-disable-line react/require-default-props
84
- /**
85
- * The action that causes the Content to display (`click`, `hover`, `focus`)
86
- */
87
- on: PropTypes.oneOfType([
88
- PropTypes.oneOf(['click', 'hover', 'focus']),
89
- PropTypes.arrayOf(PropTypes.oneOf(['click', 'hover', 'focus']))
90
- ]),
91
- /**
92
- * The color of the tooltip content
93
- */
94
- color: PropTypes.oneOf(['primary', 'primary-inverse']),
95
- /**
96
- * Specifies where the Tooltip will be placed in relation to the target element.
97
- * Ex. placement="bottom" will render the Tooltip below the triggering element
98
- * (Note: if there is not room, it will position opposite. Ex. "top" will
99
- * automatically switch to "bottom")
100
- */
101
- placement: PositionPropTypes.placement,
102
- /**
103
- * An element or a function returning an element to use as the mount node
104
- * for the `<Tooltip />` (defaults to `document.body`)
105
- */
106
- mountNode: PositionPropTypes.mountNode,
107
- /**
108
- * The parent in which to constrain the tooltip.
109
- * One of: 'window', 'scroll-parent', 'parent', 'none', an element,
110
- * or a function returning an element
111
- */
112
- constrain: PositionPropTypes.constrain,
113
- /**
114
- * The horizontal offset for the positioned content
115
- */
116
- offsetX: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
117
- /**
118
- * The vertical offset for the positioned content
119
- */
120
- offsetY: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
121
- /**
122
- * Target element for positioning the Tooltip (if it differs from children/trigger)
123
- */
124
- positionTarget: PropTypes.oneOfType([element, PropTypes.func]),
125
- /**
126
- * Callback fired when content is shown. When controlled, this callback is
127
- * fired when the tooltip expects to be shown
128
- */
129
- onShowContent: PropTypes.func,
130
- /**
131
- * Callback fired when content is hidden. When controlled, this callback is
132
- * fired when the tooltip expects to be hidden
133
- */
134
- onHideContent: PropTypes.func
135
- } as const
55
+ static allowedProps = allowedProps
56
+ static propTypes = propTypes
136
57
 
137
58
  static defaultProps = {
138
- isShowingContent: undefined,
139
59
  defaultIsShowingContent: false,
140
- on: undefined,
141
60
  color: 'primary',
142
61
  placement: 'top',
143
62
  mountNode: null,
144
63
  constrain: 'window',
145
64
  offsetX: 0,
146
65
  offsetY: 0,
147
- positionTarget: undefined,
148
66
  // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
149
67
  onShowContent: (event) => {},
150
68
  // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
@@ -155,14 +73,12 @@ class Tooltip extends Component<TooltipProps> {
155
73
  state = { hasFocus: false }
156
74
 
157
75
  componentDidMount() {
158
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
159
- this.props.makeStyles()
76
+ this.props.makeStyles?.()
160
77
  }
161
78
 
162
79
  // @ts-expect-error ts-migrate(6133) FIXME: 'prevProps' is declared but its value is never rea... Remove this comment to see the full error message
163
80
  componentDidUpdate(prevProps, prevState, snapshot) {
164
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
165
- this.props.makeStyles()
81
+ this.props.makeStyles?.()
166
82
  }
167
83
 
168
84
  // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
@@ -191,6 +107,7 @@ class Tooltip extends Component<TooltipProps> {
191
107
  </Trigger>
192
108
  )
193
109
  } else if (typeof children === 'function') {
110
+ // @ts-expect-error FIXME: React children types are badly calculated
194
111
  return children({
195
112
  focused: hasFocus,
196
113
  // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'props' implicitly has an 'any' type.
@@ -247,7 +164,7 @@ class Tooltip extends Component<TooltipProps> {
247
164
  onFocus={this.handleFocus}
248
165
  onBlur={this.handleBlur}
249
166
  >
250
- <span id={this._id} css={styles.tooltip} role="tooltip">
167
+ <span id={this._id} css={styles?.tooltip} role="tooltip">
251
168
  {callRenderProp(renderTip)}
252
169
  </span>
253
170
  </Popover>
@@ -0,0 +1,156 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import PropTypes from 'prop-types'
25
+ import { PositionPropTypes } from '@instructure/ui-position'
26
+ import { element } from '@instructure/ui-prop-types'
27
+
28
+ import type { PropValidators, AsElementType } from '@instructure/shared-types'
29
+ import type {
30
+ PlacementPropValues,
31
+ PositionConstraint,
32
+ PositionMountNode
33
+ } from '@instructure/ui-position'
34
+ import React from 'react'
35
+ import type { WithStyleProps } from '@instructure/emotion'
36
+
37
+ type TooltipOwnProps = {
38
+ renderTip: React.ReactNode | ((...args: any[]) => any)
39
+ children: React.ReactNode | ((...args: any[]) => React.ReactNode)
40
+ isShowingContent?: boolean
41
+ defaultIsShowingContent?: boolean
42
+ as?: AsElementType
43
+ on?: ('click' | 'hover' | 'focus') | ('click' | 'hover' | 'focus')[]
44
+ color?: 'primary' | 'primary-inverse'
45
+ placement?: PlacementPropValues
46
+ mountNode?: PositionMountNode
47
+ constrain?: PositionConstraint
48
+ positionTarget?: PositionMountNode
49
+ offsetX?: string | number
50
+ offsetY?: string | number
51
+ onShowContent?: (...args: any[]) => any
52
+ onHideContent?: (...args: any[]) => any
53
+ }
54
+
55
+ type PropKeys = keyof TooltipOwnProps
56
+
57
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
58
+
59
+ type TooltipProps = TooltipOwnProps & WithStyleProps
60
+
61
+ const propTypes: PropValidators<PropKeys> = {
62
+ /**
63
+ * @param {Object} renderProps
64
+ * @param {Boolean} renderProps.focused - Is the Tooltip trigger focused?
65
+ * @param {Function} renderProps.getTriggerProps - Props to be spread onto the trigger element
66
+ */
67
+ children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
68
+ /**
69
+ * The content to render in the tooltip
70
+ */
71
+ renderTip: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
72
+ /**
73
+ * Whether or not the tooltip content is shown, when controlled
74
+ */
75
+ isShowingContent: PropTypes.bool,
76
+ /**
77
+ * Whether or not to show the content by default, when uncontrolled
78
+ */
79
+ defaultIsShowingContent: PropTypes.bool,
80
+ /**
81
+ * the element type to render as (assumes a single child if 'as' is undefined)
82
+ */
83
+ as: PropTypes.elementType, // eslint-disable-line react/require-default-props
84
+ /**
85
+ * The action that causes the Content to display (`click`, `hover`, `focus`)
86
+ */
87
+ on: PropTypes.oneOfType([
88
+ PropTypes.oneOf(['click', 'hover', 'focus']),
89
+ PropTypes.arrayOf(PropTypes.oneOf(['click', 'hover', 'focus']))
90
+ ]),
91
+ /**
92
+ * The color of the tooltip content
93
+ */
94
+ color: PropTypes.oneOf(['primary', 'primary-inverse']),
95
+ /**
96
+ * Specifies where the Tooltip will be placed in relation to the target element.
97
+ * Ex. placement="bottom" will render the Tooltip below the triggering element
98
+ * (Note: if there is not room, it will position opposite. Ex. "top" will
99
+ * automatically switch to "bottom")
100
+ */
101
+ placement: PositionPropTypes.placement,
102
+ /**
103
+ * An element or a function returning an element to use as the mount node
104
+ * for the `<Tooltip />` (defaults to `document.body`)
105
+ */
106
+ mountNode: PositionPropTypes.mountNode,
107
+ /**
108
+ * The parent in which to constrain the tooltip.
109
+ * One of: 'window', 'scroll-parent', 'parent', 'none', an element,
110
+ * or a function returning an element
111
+ */
112
+ constrain: PositionPropTypes.constrain,
113
+ /**
114
+ * The horizontal offset for the positioned content
115
+ */
116
+ offsetX: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
117
+ /**
118
+ * The vertical offset for the positioned content
119
+ */
120
+ offsetY: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
121
+ /**
122
+ * Target element for positioning the Tooltip (if it differs from children/trigger)
123
+ */
124
+ positionTarget: PropTypes.oneOfType([element, PropTypes.func]),
125
+ /**
126
+ * Callback fired when content is shown. When controlled, this callback is
127
+ * fired when the tooltip expects to be shown
128
+ */
129
+ onShowContent: PropTypes.func,
130
+ /**
131
+ * Callback fired when content is hidden. When controlled, this callback is
132
+ * fired when the tooltip expects to be hidden
133
+ */
134
+ onHideContent: PropTypes.func
135
+ }
136
+
137
+ const allowedProps: AllowedPropKeys = [
138
+ 'children',
139
+ 'renderTip',
140
+ 'isShowingContent',
141
+ 'defaultIsShowingContent',
142
+ 'as',
143
+ 'on',
144
+ 'color',
145
+ 'placement',
146
+ 'mountNode',
147
+ 'constrain',
148
+ 'offsetX',
149
+ 'offsetY',
150
+ 'positionTarget',
151
+ 'onShowContent',
152
+ 'onHideContent'
153
+ ]
154
+
155
+ export type { TooltipProps }
156
+ export { propTypes, allowedProps }