@instructure/ui-react-utils 8.55.2-snapshot-0 → 9.0.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.
@@ -22,7 +22,7 @@ interface PropsObject {
22
22
  * @param {Function} getDefault an optional function that returns the default element type
23
23
  * @returns {String} the element type
24
24
  */
25
- declare function getElementType<T extends PropsObject>(Component: Omit<ComponentType<T>, 'propTypes'>, props: T, getDefault?: () => AsElementType<T>): "symbol" | "object" | import("react").ComponentClass<any, any> | import("react").FunctionComponent<any> | "map" | "filter" | "style" | "search" | "big" | "link" | "small" | "sub" | "sup" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "center" | "cite" | "code" | "col" | "colgroup" | "data" | "datalist" | "dd" | "del" | "details" | "dfn" | "dialog" | "div" | "dl" | "dt" | "em" | "embed" | "fieldset" | "figcaption" | "figure" | "footer" | "form" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "img" | "input" | "ins" | "kbd" | "keygen" | "label" | "legend" | "li" | "main" | "mark" | "menu" | "menuitem" | "meta" | "meter" | "nav" | "noindex" | "noscript" | "ol" | "optgroup" | "option" | "output" | "p" | "param" | "picture" | "pre" | "progress" | "q" | "rp" | "rt" | "ruby" | "s" | "samp" | "slot" | "script" | "section" | "select" | "source" | "span" | "strong" | "summary" | "table" | "template" | "tbody" | "td" | "textarea" | "tfoot" | "th" | "thead" | "time" | "title" | "tr" | "track" | "u" | "ul" | "var" | "video" | "wbr" | "webview" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | import("react").ComponentClass<T, any> | import("react").FunctionComponent<T> | NonNullable<T["as"]>;
25
+ declare function getElementType<T extends PropsObject>(Component: Omit<ComponentType<T>, 'propTypes'>, props: T, getDefault?: () => AsElementType<T>): "symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | "caption" | "center" | "cite" | "code" | "col" | "colgroup" | "data" | "datalist" | "dd" | "del" | "details" | "dfn" | "dialog" | "div" | "dl" | "dt" | "em" | "embed" | "fieldset" | "figcaption" | "figure" | "footer" | "form" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "img" | "input" | "ins" | "kbd" | "keygen" | "label" | "legend" | "li" | "link" | "main" | "map" | "mark" | "menu" | "menuitem" | "meta" | "meter" | "nav" | "noscript" | "ol" | "optgroup" | "option" | "output" | "p" | "param" | "picture" | "pre" | "progress" | "q" | "rp" | "rt" | "ruby" | "s" | "samp" | "search" | "slot" | "script" | "section" | "select" | "small" | "source" | "span" | "strong" | "style" | "sub" | "summary" | "sup" | "table" | "template" | "tbody" | "td" | "textarea" | "tfoot" | "th" | "thead" | "time" | "title" | "tr" | "track" | "u" | "ul" | "var" | "video" | "wbr" | "webview" | "animate" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "stop" | "svg" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | import("react").FunctionComponent<any> | import("react").ComponentClass<any, any> | "noindex" | "animateMotion" | "animateTransform" | "mpath" | import("react").ComponentClass<T, any> | import("react").FunctionComponent<T> | NonNullable<T["as"]>;
26
26
  export default getElementType;
27
27
  export { getElementType };
28
28
  //# sourceMappingURL=getElementType.d.ts.map
package/types/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { callRenderProp } from './callRenderProp';
2
- export { ComponentIdentifier } from './ComponentIdentifier';
3
2
  export { deprecated } from './deprecated';
4
3
  export { ensureSingleChild } from './ensureSingleChild';
5
4
  export { experimental } from './experimental';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EACL,sBAAsB,EACtB,0BAA0B,EAC1B,8BAA8B,EAC9B,mBAAmB,EACpB,MAAM,0BAA0B,CAAA;AACjC,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAC7D,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,YAAY,EACV,4BAA4B,EAC5B,wBAAwB,EACzB,MAAM,0BAA0B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EACL,sBAAsB,EACtB,0BAA0B,EAC1B,8BAA8B,EAC9B,mBAAmB,EACpB,MAAM,0BAA0B,CAAA;AACjC,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAC7D,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,YAAY,EACV,4BAA4B,EAC5B,wBAAwB,EACzB,MAAM,0BAA0B,CAAA"}
@@ -1,101 +0,0 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
- const _excluded = ["children"];
3
- var _dec, _class, _class2;
4
- /*
5
- * The MIT License (MIT)
6
- *
7
- * Copyright (c) 2015 - present Instructure, Inc.
8
- *
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy
10
- * of this software and associated documentation files (the "Software"), to deal
11
- * in the Software without restriction, including without limitation the rights
12
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- * copies of the Software, and to permit persons to whom the Software is
14
- * furnished to do so, subject to the following conditions:
15
- *
16
- * The above copyright notice and this permission notice shall be included in all
17
- * copies or substantial portions of the Software.
18
- *
19
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
- * SOFTWARE.
26
- */
27
-
28
- import React, { Component } from 'react';
29
- import PropTypes from 'prop-types';
30
- import { matchComponentTypes } from './matchComponentTypes';
31
- import { ensureSingleChild } from './ensureSingleChild';
32
- import deprecated from './deprecated';
33
-
34
- // TODO delete this class, its not used anywhere, see livegrep
35
- /**
36
- ---
37
- category: utilities/react
38
- ---
39
- Abstract component identifier. Helpful for picking out a specific child.
40
-
41
- ```js-code
42
- class App extends Component {
43
- render () {
44
- const title = pick(Title, this.props.children)
45
- const content = pick(Content, this.props.children)
46
-
47
- return (
48
- <div>
49
- {title}
50
- <ContextView>
51
- {content}
52
- </ContextView>
53
- </div>
54
- )
55
- }
56
- }
57
-
58
- class Title extends ComponentIdentifier { static displayName = 'Title' }
59
- class Content extends ComponentIdentifier { static displayName = 'Content' }
60
-
61
- ReactDOM.render(
62
- <App>
63
- <Title><h2>Hello World!</h2></Title>
64
- <Content><div>This text gets decorated within `App`.</div></Content>
65
- </App>,
66
- document.getElementById('container')
67
- )
68
- ```
69
- @module ComponentIdentifier
70
- **/
71
- let ComponentIdentifier = (_dec = deprecated('8.0.0', void 0, 'This component will be removed in InstUI 9.0 since its not used.'), _dec(_class = (_class2 = class ComponentIdentifier extends Component {
72
- render() {
73
- const _this$props = this.props,
74
- children = _this$props.children,
75
- props = _objectWithoutProperties(_this$props, _excluded);
76
- return ensureSingleChild(children, props);
77
- }
78
- }, _class2.displayName = "ComponentIdentifier", _class2.propTypes = {
79
- children: PropTypes.node
80
- }, _class2.defaultProps = {
81
- children: null
82
- }, _class2.pick = (component, children) => {
83
- let result;
84
- React.Children.forEach(children, child => {
85
- if (matchComponentTypes(child, [component])) {
86
- result = child;
87
- }
88
- });
89
- return result;
90
- }, _class2)) || _class);
91
- export default ComponentIdentifier;
92
- export {
93
- /**
94
- *
95
- * Pick a specific child component from a component's children
96
- *
97
- * @param {Component} component The component to look for
98
- * @param {Array} children The child components to look through
99
- * @return {Component} The matching component if found, otherwise undefined
100
- */
101
- ComponentIdentifier };
@@ -1,77 +0,0 @@
1
- var _h;
2
- /*
3
- * The MIT License (MIT)
4
- *
5
- * Copyright (c) 2015 - present Instructure, Inc.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in all
15
- * copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- */
25
-
26
- import React, { Component } from 'react';
27
- import PropTypes from 'prop-types';
28
- import { render } from '@testing-library/react';
29
- import '@testing-library/jest-dom';
30
- import { ComponentIdentifier } from '../ComponentIdentifier';
31
- describe('ComponentIdentifier', () => {
32
- var _App;
33
- beforeAll(() => {
34
- // Mocking console warnings to prevent test output pollution
35
- jest.spyOn(console, 'warn').mockImplementation(() => {});
36
- });
37
- afterAll(() => {
38
- jest.restoreAllMocks();
39
- });
40
- class Trigger extends ComponentIdentifier {}
41
- Trigger.displayName = 'Trigger';
42
- class App extends Component {
43
- render() {
44
- const trigger = ComponentIdentifier.pick(Trigger, this.props.children);
45
- return /*#__PURE__*/React.createElement("div", null, _h || (_h = /*#__PURE__*/React.createElement("h2", null, "Trigger")), trigger);
46
- }
47
- }
48
- App.displayName = "App";
49
- App.propTypes = {
50
- children: PropTypes.node
51
- };
52
- App.defaultProps = {
53
- children: null
54
- };
55
- it('should render only child', () => {
56
- let buttonRef;
57
- render( /*#__PURE__*/React.createElement(App, null, /*#__PURE__*/React.createElement(Trigger, null, /*#__PURE__*/React.createElement("button", {
58
- ref: el => buttonRef = el
59
- }, "Click Me"))));
60
- expect(buttonRef.textContent).toEqual('Click Me');
61
- });
62
- it('should not error when no children provided', () => {
63
- const renderApp = () => render(_App || (_App = /*#__PURE__*/React.createElement(App, null, /*#__PURE__*/React.createElement(Trigger, null))));
64
- expect(renderApp).not.toThrow();
65
- });
66
- it('should pass props', () => {
67
- let buttonRef;
68
- const onClick = jest.fn();
69
- render( /*#__PURE__*/React.createElement(App, null, /*#__PURE__*/React.createElement(Trigger, {
70
- onClick: onClick
71
- }, /*#__PURE__*/React.createElement("button", {
72
- ref: el => buttonRef = el
73
- }, "Click Me"))));
74
- buttonRef.click();
75
- expect(onClick).toHaveBeenCalled();
76
- });
77
- });
@@ -1,97 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = exports.ComponentIdentifier = void 0;
9
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
- var _react = _interopRequireWildcard(require("react"));
11
- var _propTypes = _interopRequireDefault(require("prop-types"));
12
- var _matchComponentTypes = require("./matchComponentTypes");
13
- var _ensureSingleChild = require("./ensureSingleChild");
14
- var _deprecated = _interopRequireDefault(require("./deprecated"));
15
- const _excluded = ["children"];
16
- var _dec, _class, _class2;
17
- /*
18
- * The MIT License (MIT)
19
- *
20
- * Copyright (c) 2015 - present Instructure, Inc.
21
- *
22
- * Permission is hereby granted, free of charge, to any person obtaining a copy
23
- * of this software and associated documentation files (the "Software"), to deal
24
- * in the Software without restriction, including without limitation the rights
25
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
- * copies of the Software, and to permit persons to whom the Software is
27
- * furnished to do so, subject to the following conditions:
28
- *
29
- * The above copyright notice and this permission notice shall be included in all
30
- * copies or substantial portions of the Software.
31
- *
32
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
- * SOFTWARE.
39
- */
40
- // TODO delete this class, its not used anywhere, see livegrep
41
- /**
42
- ---
43
- category: utilities/react
44
- ---
45
- Abstract component identifier. Helpful for picking out a specific child.
46
-
47
- ```js-code
48
- class App extends Component {
49
- render () {
50
- const title = pick(Title, this.props.children)
51
- const content = pick(Content, this.props.children)
52
-
53
- return (
54
- <div>
55
- {title}
56
- <ContextView>
57
- {content}
58
- </ContextView>
59
- </div>
60
- )
61
- }
62
- }
63
-
64
- class Title extends ComponentIdentifier { static displayName = 'Title' }
65
- class Content extends ComponentIdentifier { static displayName = 'Content' }
66
-
67
- ReactDOM.render(
68
- <App>
69
- <Title><h2>Hello World!</h2></Title>
70
- <Content><div>This text gets decorated within `App`.</div></Content>
71
- </App>,
72
- document.getElementById('container')
73
- )
74
- ```
75
- @module ComponentIdentifier
76
- **/
77
- let ComponentIdentifier = exports.ComponentIdentifier = (_dec = (0, _deprecated.default)('8.0.0', void 0, 'This component will be removed in InstUI 9.0 since its not used.'), _dec(_class = (_class2 = class ComponentIdentifier extends _react.Component {
78
- render() {
79
- const _this$props = this.props,
80
- children = _this$props.children,
81
- props = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
82
- return (0, _ensureSingleChild.ensureSingleChild)(children, props);
83
- }
84
- }, _class2.displayName = "ComponentIdentifier", _class2.propTypes = {
85
- children: _propTypes.default.node
86
- }, _class2.defaultProps = {
87
- children: null
88
- }, _class2.pick = (component, children) => {
89
- let result;
90
- _react.default.Children.forEach(children, child => {
91
- if ((0, _matchComponentTypes.matchComponentTypes)(child, [component])) {
92
- result = child;
93
- }
94
- });
95
- return result;
96
- }, _class2)) || _class);
97
- var _default = exports.default = ComponentIdentifier;
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- var _react = _interopRequireWildcard(require("react"));
6
- var _propTypes = _interopRequireDefault(require("prop-types"));
7
- var _react2 = require("@testing-library/react");
8
- require("@testing-library/jest-dom");
9
- var _ComponentIdentifier = require("../ComponentIdentifier");
10
- var _h;
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
- describe('ComponentIdentifier', () => {
35
- var _App;
36
- beforeAll(() => {
37
- // Mocking console warnings to prevent test output pollution
38
- jest.spyOn(console, 'warn').mockImplementation(() => {});
39
- });
40
- afterAll(() => {
41
- jest.restoreAllMocks();
42
- });
43
- class Trigger extends _ComponentIdentifier.ComponentIdentifier {}
44
- Trigger.displayName = 'Trigger';
45
- class App extends _react.Component {
46
- render() {
47
- const trigger = _ComponentIdentifier.ComponentIdentifier.pick(Trigger, this.props.children);
48
- return /*#__PURE__*/_react.default.createElement("div", null, _h || (_h = /*#__PURE__*/_react.default.createElement("h2", null, "Trigger")), trigger);
49
- }
50
- }
51
- App.displayName = "App";
52
- App.propTypes = {
53
- children: _propTypes.default.node
54
- };
55
- App.defaultProps = {
56
- children: null
57
- };
58
- it('should render only child', () => {
59
- let buttonRef;
60
- (0, _react2.render)( /*#__PURE__*/_react.default.createElement(App, null, /*#__PURE__*/_react.default.createElement(Trigger, null, /*#__PURE__*/_react.default.createElement("button", {
61
- ref: el => buttonRef = el
62
- }, "Click Me"))));
63
- expect(buttonRef.textContent).toEqual('Click Me');
64
- });
65
- it('should not error when no children provided', () => {
66
- const renderApp = () => (0, _react2.render)(_App || (_App = /*#__PURE__*/_react.default.createElement(App, null, /*#__PURE__*/_react.default.createElement(Trigger, null))));
67
- expect(renderApp).not.toThrow();
68
- });
69
- it('should pass props', () => {
70
- let buttonRef;
71
- const onClick = jest.fn();
72
- (0, _react2.render)( /*#__PURE__*/_react.default.createElement(App, null, /*#__PURE__*/_react.default.createElement(Trigger, {
73
- onClick: onClick
74
- }, /*#__PURE__*/_react.default.createElement("button", {
75
- ref: el => buttonRef = el
76
- }, "Click Me"))));
77
- buttonRef.click();
78
- expect(onClick).toHaveBeenCalled();
79
- });
80
- });
@@ -1,115 +0,0 @@
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
-
25
- import React, { Component, ComponentType, ReactNode } from 'react'
26
- import PropTypes from 'prop-types'
27
-
28
- import { matchComponentTypes } from './matchComponentTypes'
29
- import { ensureSingleChild } from './ensureSingleChild'
30
- import deprecated from './deprecated'
31
-
32
- // TODO delete this class, its not used anywhere, see livegrep
33
- /**
34
- ---
35
- category: utilities/react
36
- ---
37
- Abstract component identifier. Helpful for picking out a specific child.
38
-
39
- ```js-code
40
- class App extends Component {
41
- render () {
42
- const title = pick(Title, this.props.children)
43
- const content = pick(Content, this.props.children)
44
-
45
- return (
46
- <div>
47
- {title}
48
- <ContextView>
49
- {content}
50
- </ContextView>
51
- </div>
52
- )
53
- }
54
- }
55
-
56
- class Title extends ComponentIdentifier { static displayName = 'Title' }
57
- class Content extends ComponentIdentifier { static displayName = 'Content' }
58
-
59
- ReactDOM.render(
60
- <App>
61
- <Title><h2>Hello World!</h2></Title>
62
- <Content><div>This text gets decorated within `App`.</div></Content>
63
- </App>,
64
- document.getElementById('container')
65
- )
66
- ```
67
- @module ComponentIdentifier
68
- **/
69
- @deprecated(
70
- '8.0.0',
71
- undefined,
72
- 'This component will be removed in InstUI 9.0 since its not used.'
73
- )
74
- class ComponentIdentifier<
75
- P extends { children: ReactNode }
76
- > extends Component<P> {
77
- static propTypes = {
78
- children: PropTypes.node
79
- }
80
-
81
- static defaultProps = {
82
- children: null
83
- }
84
-
85
- static pick = (component: ComponentType, children: ReactNode) => {
86
- let result
87
-
88
- React.Children.forEach(children, (child) => {
89
- if (matchComponentTypes(child, [component])) {
90
- result = child
91
- }
92
- })
93
-
94
- return result
95
- }
96
-
97
- render() {
98
- const { children, ...props } = this.props
99
-
100
- return ensureSingleChild(children, props)
101
- }
102
- }
103
-
104
- export default ComponentIdentifier
105
- export {
106
- /**
107
- *
108
- * Pick a specific child component from a component's children
109
- *
110
- * @param {Component} component The component to look for
111
- * @param {Array} children The child components to look through
112
- * @return {Component} The matching component if found, otherwise undefined
113
- */
114
- ComponentIdentifier
115
- }
@@ -1,105 +0,0 @@
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
-
25
- import React, { Component, ReactNode } from 'react'
26
- import PropTypes from 'prop-types'
27
-
28
- import { render } from '@testing-library/react'
29
- import '@testing-library/jest-dom'
30
-
31
- import { ComponentIdentifier } from '../ComponentIdentifier'
32
-
33
- describe('ComponentIdentifier', () => {
34
- beforeAll(() => {
35
- // Mocking console warnings to prevent test output pollution
36
- jest.spyOn(console, 'warn').mockImplementation(() => {})
37
- })
38
- afterAll(() => {
39
- jest.restoreAllMocks()
40
- })
41
-
42
- class Trigger extends ComponentIdentifier<any> {
43
- static displayName = 'Trigger'
44
- }
45
-
46
- class App extends Component<{ children: ReactNode }> {
47
- static propTypes = {
48
- children: PropTypes.node
49
- }
50
-
51
- static defaultProps = {
52
- children: null
53
- }
54
-
55
- render() {
56
- const trigger = ComponentIdentifier.pick(Trigger, this.props.children)
57
-
58
- return (
59
- <div>
60
- <h2>Trigger</h2>
61
- {trigger}
62
- </div>
63
- )
64
- }
65
- }
66
-
67
- it('should render only child', () => {
68
- let buttonRef: HTMLButtonElement
69
- render(
70
- <App>
71
- <Trigger>
72
- <button ref={(el) => (buttonRef = el!)}>Click Me</button>
73
- </Trigger>
74
- </App>
75
- )
76
-
77
- expect(buttonRef!.textContent).toEqual('Click Me')
78
- })
79
-
80
- it('should not error when no children provided', () => {
81
- const renderApp = () =>
82
- render(
83
- <App>
84
- <Trigger />
85
- </App>
86
- )
87
-
88
- expect(renderApp).not.toThrow()
89
- })
90
-
91
- it('should pass props', () => {
92
- let buttonRef: HTMLButtonElement | null
93
- const onClick = jest.fn()
94
- render(
95
- <App>
96
- <Trigger onClick={onClick}>
97
- <button ref={(el) => (buttonRef = el)}>Click Me</button>
98
- </Trigger>
99
- </App>
100
- )
101
-
102
- buttonRef!.click()
103
- expect(onClick).toHaveBeenCalled()
104
- })
105
- })
@@ -1,62 +0,0 @@
1
- import React, { Component, ComponentType, ReactNode } from 'react';
2
- import PropTypes from 'prop-types';
3
- /**
4
- ---
5
- category: utilities/react
6
- ---
7
- Abstract component identifier. Helpful for picking out a specific child.
8
-
9
- ```js-code
10
- class App extends Component {
11
- render () {
12
- const title = pick(Title, this.props.children)
13
- const content = pick(Content, this.props.children)
14
-
15
- return (
16
- <div>
17
- {title}
18
- <ContextView>
19
- {content}
20
- </ContextView>
21
- </div>
22
- )
23
- }
24
- }
25
-
26
- class Title extends ComponentIdentifier { static displayName = 'Title' }
27
- class Content extends ComponentIdentifier { static displayName = 'Content' }
28
-
29
- ReactDOM.render(
30
- <App>
31
- <Title><h2>Hello World!</h2></Title>
32
- <Content><div>This text gets decorated within `App`.</div></Content>
33
- </App>,
34
- document.getElementById('container')
35
- )
36
- ```
37
- @module ComponentIdentifier
38
- **/
39
- declare class ComponentIdentifier<P extends {
40
- children: ReactNode;
41
- }> extends Component<P> {
42
- static propTypes: {
43
- children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
44
- };
45
- static defaultProps: {
46
- children: null;
47
- };
48
- static pick: (component: ComponentType, children: ReactNode) => undefined;
49
- render(): React.JSX.Element | null;
50
- }
51
- export default ComponentIdentifier;
52
- export {
53
- /**
54
- *
55
- * Pick a specific child component from a component's children
56
- *
57
- * @param {Component} component The component to look for
58
- * @param {Array} children The child components to look through
59
- * @return {Component} The matching component if found, otherwise undefined
60
- */
61
- ComponentIdentifier };
62
- //# sourceMappingURL=ComponentIdentifier.d.ts.map