@cloudflare/component-tooltip 4.4.0 → 4.5.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 04083908a0: Add componentRef prop to allow a ref to the element from the parent
8
+
9
+ ## 4.4.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [0d66b430a2]
14
+ - @cloudflare/elements@3.0.4
15
+
3
16
  ## 4.4.0
4
17
 
5
18
  ### Minor Changes
package/es/Tooltip.js CHANGED
@@ -113,7 +113,8 @@ class Tooltip extends React.PureComponent {
113
113
  isCapture,
114
114
  display,
115
115
  ariaLabel,
116
- Component = Button
116
+ Component = Button,
117
+ componentRef
117
118
  } = this.props;
118
119
  var id = this.props.id ? this.props.id : this.id;
119
120
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ReactTooltip, {
@@ -132,7 +133,15 @@ class Tooltip extends React.PureComponent {
132
133
  event: "click",
133
134
  role: "status"
134
135
  }), /*#__PURE__*/React.createElement(Component, _extends({
135
- innerRef: ref => this.tooltipElement = ref,
136
+ innerRef: ref => {
137
+ this.tooltipElement = ref;
138
+
139
+ if (componentRef !== null && componentRef !== void 0 && componentRef.hasOwnProperty('current')) {
140
+ componentRef.current = ref;
141
+ } else if (typeof componentRef === 'function') {
142
+ componentRef(ref);
143
+ }
144
+ },
136
145
  display: display ? display : 'flex',
137
146
  pointerEvents: "bounding-box",
138
147
  padding: 0,
@@ -176,7 +185,10 @@ Tooltip.propTypes = {
176
185
  onClick: PropTypes.func,
177
186
  display: PropTypes.string,
178
187
  ariaLabel: PropTypes.string,
179
- Component: PropTypes.func
188
+ Component: PropTypes.func,
189
+ // Allow the Component element to be referenced from a parent. innerRef
190
+ // is swallowed by createComponent.
191
+ componentRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
180
192
  };
181
193
  Tooltip.defaultProps = {
182
194
  disable: false,
package/index.d.ts CHANGED
@@ -19,6 +19,7 @@ interface TooltipProps extends React.CSSProperties, TfelaMProps {
19
19
  ariaLabel?: string;
20
20
  buttonProps?: React.ComponentProps<typeof Button>;
21
21
  Component?: React.ComponentType<any>;
22
+ componentRef?: React.Ref<HTMLElement>;
22
23
  }
23
24
 
24
25
  export const Tooltip: React.FC<TooltipProps>;
package/lib/Tooltip.js CHANGED
@@ -172,7 +172,8 @@ var Tooltip = /*#__PURE__*/function (_React$PureComponent) {
172
172
  display = _this$props.display,
173
173
  ariaLabel = _this$props.ariaLabel,
174
174
  _this$props$Component = _this$props.Component,
175
- Component = _this$props$Component === void 0 ? _elements.Button : _this$props$Component;
175
+ Component = _this$props$Component === void 0 ? _elements.Button : _this$props$Component,
176
+ componentRef = _this$props.componentRef;
176
177
  var id = this.props.id ? this.props.id : this.id;
177
178
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactTooltip.default, {
178
179
  id: id,
@@ -193,7 +194,13 @@ var Tooltip = /*#__PURE__*/function (_React$PureComponent) {
193
194
  role: "status"
194
195
  }), /*#__PURE__*/_react.default.createElement(Component, _extends({
195
196
  innerRef: function innerRef(ref) {
196
- return _this3.tooltipElement = ref;
197
+ _this3.tooltipElement = ref;
198
+
199
+ if (componentRef !== null && componentRef !== void 0 && componentRef.hasOwnProperty('current')) {
200
+ componentRef.current = ref;
201
+ } else if (typeof componentRef === 'function') {
202
+ componentRef(ref);
203
+ }
197
204
  },
198
205
  display: display ? display : 'flex',
199
206
  pointerEvents: "bounding-box",
@@ -248,7 +255,10 @@ Tooltip.propTypes = {
248
255
  onClick: _propTypes.default.func,
249
256
  display: _propTypes.default.string,
250
257
  ariaLabel: _propTypes.default.string,
251
- Component: _propTypes.default.func
258
+ Component: _propTypes.default.func,
259
+ // Allow the Component element to be referenced from a parent. innerRef
260
+ // is swallowed by createComponent.
261
+ componentRef: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object])
252
262
  };
253
263
  Tooltip.defaultProps = {
254
264
  disable: false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudflare/component-tooltip",
3
3
  "description": "Cloudflare Tooltip Component",
4
- "version": "4.4.0",
4
+ "version": "4.5.0",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
7
7
  "author": "James Kyle <jkyle@cloudflare.com>",
@@ -12,7 +12,7 @@
12
12
  "module": "es/index.js"
13
13
  },
14
14
  "dependencies": {
15
- "@cloudflare/elements": "^3.0.3",
15
+ "@cloudflare/elements": "^3.0.4",
16
16
  "lodash.uniqueid": "^4.0.1",
17
17
  "prop-types": "^15.6.0",
18
18
  "react-tooltip": "^3.11.6"