@instructure/ui-react-utils 10.26.1 → 11.0.1-snapshot-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/src/deprecated.ts DELETED
@@ -1,237 +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
- import { decorator } from '@instructure/ui-decorator'
25
- import { logWarnDeprecated as warnDeprecated } from '@instructure/console'
26
- import { ComponentClass } from 'react'
27
- import PropTypes from 'prop-types'
28
-
29
- export interface DeprecatedDecorator {
30
- (version: string, oldProps?: Record<string, any> | null, message?: string): (
31
- ComposedComponent: any
32
- ) => any
33
- deprecatePropValues: (...args: any[]) => PropTypes.Validator<unknown>
34
- warnDeprecatedProps: (...args: any[]) => void
35
- warnDeprecatedComponent: (...args: any[]) => void
36
- changedPackageWarning: (...args: any[]) => string
37
- }
38
-
39
- /**
40
- * ---
41
- * category: utilities/react
42
- * ---
43
- * Deprecate React component props. Warnings will display in the console when deprecated
44
- * props are used. Include the version number when the deprecated component will be removed.
45
- *
46
- * ```js-code
47
- * class Example extends Component {
48
- * static propTypes = {
49
- * currentProp: PropTypes.func
50
- * }
51
- * }
52
- * export default deprecated('7.0.0', {
53
- * deprecatedProp: 'currentProp',
54
- * nowNonExistentProp: true
55
- * })(Example)
56
- * ```
57
- *
58
- * @param {string} version
59
- * @param {object} oldProps (if this argument is null or undefined, the entire component is deprecated)
60
- * @param {string} message
61
- * @return {function} React component with deprecated props behavior
62
- * @module deprecated
63
- */
64
- const deprecated = (() => {
65
- if (process.env.NODE_ENV === 'production') {
66
- const deprecated: DeprecatedDecorator = function () {
67
- return (ComposedComponent: ComponentClass) => ComposedComponent
68
- }
69
- deprecated.deprecatePropValues = () => () => null
70
- deprecated.warnDeprecatedProps = () => {}
71
- deprecated.warnDeprecatedComponent = () => {}
72
- deprecated.changedPackageWarning = () => ''
73
- return deprecated
74
- }
75
- const deprecated = decorator(
76
- (
77
- ComposedComponent,
78
- version: string,
79
- oldProps?: Record<string, any>,
80
- message = ''
81
- ) => {
82
- class DeprecatedComponent extends ComposedComponent {}
83
-
84
- DeprecatedComponent.prototype.componentDidMount = function () {
85
- if (oldProps) {
86
- warnDeprecatedProps(
87
- ComposedComponent.name,
88
- version,
89
- this.props,
90
- oldProps,
91
- message
92
- )
93
- } else {
94
- warnDeprecatedComponent(version, ComposedComponent.name, message)
95
- }
96
-
97
- if (ComposedComponent.prototype.componentDidMount) {
98
- ComposedComponent.prototype.componentDidMount.call(this)
99
- }
100
- }
101
-
102
- DeprecatedComponent.prototype.componentDidUpdate = function (
103
- prevProps,
104
- prevState,
105
- prevContext
106
- ) {
107
- if (oldProps) {
108
- warnDeprecatedProps(
109
- ComposedComponent.name,
110
- version,
111
- this.props,
112
- oldProps,
113
- message
114
- )
115
- } else {
116
- warnDeprecatedComponent(version, ComposedComponent.name, message)
117
- }
118
-
119
- if (ComposedComponent.prototype.componentDidUpdate) {
120
- ComposedComponent.prototype.componentDidUpdate.call(
121
- this,
122
- prevProps,
123
- prevState,
124
- prevContext
125
- )
126
- }
127
- }
128
- return DeprecatedComponent
129
- }
130
- )
131
- /**
132
- * ---
133
- * category: utilities
134
- * ---
135
- * Trigger a console warning if the specified prop variant is deprecated
136
- *
137
- * @param {function} propType - validates the prop type. Returns null if valid, error otherwise
138
- * @param {array} deprecated - an array of the deprecated variant names
139
- * @param {string|function} message - a string with additional information (like the version the prop will be removed) or a function returning a string
140
- */
141
- ;(deprecated as DeprecatedDecorator).deprecatePropValues = (
142
- propType: PropTypes.Validator<unknown>,
143
- deprecated: string[] = [],
144
- message:
145
- | string
146
- | ((arg: { props: any; propName: string; propValue: any }) => string)
147
- ) => {
148
- return (
149
- props: Record<string, any>,
150
- propName: string,
151
- componentName: string,
152
- ...rest
153
- ) => {
154
- const isDeprecatedValue = deprecated.includes(props[propName])
155
-
156
- const warningMessage =
157
- message && typeof message === 'function'
158
- ? message({ props, propName, propValue: props[propName] })
159
- : `The '${
160
- props[propName]
161
- }' value for the \`${propName}\` prop is deprecated. ${
162
- message || ''
163
- }`
164
- warnDeprecated(!isDeprecatedValue, `[${componentName}] ${warningMessage}`)
165
-
166
- return isDeprecatedValue
167
- ? null
168
- : propType(props, propName, componentName, ...rest)
169
- }
170
- }
171
-
172
- function warnDeprecatedProps(
173
- componentName: string,
174
- version: string,
175
- props: Record<string, any>,
176
- oldProps: Record<string, any>,
177
- message = ''
178
- ) {
179
- Object.keys(oldProps).forEach((oldProp) => {
180
- if (typeof props[oldProp] !== 'undefined') {
181
- const newProp =
182
- typeof oldProps[oldProp] === 'string' ? oldProps[oldProp] : null
183
-
184
- const newPropMessage = newProp ? `. Use \`${newProp}\` instead` : ''
185
-
186
- warnDeprecated(
187
- false,
188
- `[${componentName}] \`${oldProp}\` is deprecated and will be removed in version ${version}${newPropMessage}. ${message}`
189
- )
190
- }
191
- })
192
- }
193
- ;(deprecated as DeprecatedDecorator).warnDeprecatedProps = warnDeprecatedProps
194
-
195
- function warnDeprecatedComponent(
196
- version: string,
197
- componentName: string,
198
- message: string
199
- ) {
200
- warnDeprecated(
201
- false,
202
- `[${componentName}] is deprecated and will be removed in version ${version}. ${
203
- message || ''
204
- }`
205
- )
206
- }
207
- /**
208
- * ---
209
- * category: utilities
210
- * ---
211
- * @param {String} version the version of the package in which the component or function was deprecated
212
- * @param {String} componentName the name of the component or Function.name of the utility function
213
- * @param {String} message a message to display as a console error in DEV env when condition is false
214
- */
215
- ;(deprecated as DeprecatedDecorator).warnDeprecatedComponent =
216
- warnDeprecatedComponent
217
-
218
- /**
219
- * ---
220
- * category: utilities
221
- * ---
222
- * @param {String} prevPackage the previous name of the package
223
- * @param {String} newPackage the new version of the package
224
- * @return {String} the formatted warning string
225
- */
226
- ;(deprecated as DeprecatedDecorator).changedPackageWarning = (
227
- prevPackage: string,
228
- newPackage: string
229
- ) => {
230
- return `It has been moved from @instructure/${prevPackage} to @instructure/${newPackage}.`
231
- }
232
-
233
- return deprecated as DeprecatedDecorator
234
- })()
235
-
236
- export default deprecated
237
- export { deprecated }
@@ -1,127 +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
- import { decorator } from '@instructure/ui-decorator'
25
- import { logWarn as warn } from '@instructure/console'
26
- import { ComponentClass } from 'react'
27
-
28
- /**
29
- * ---
30
- * category: utilities/react
31
- * ---
32
- * Flag React component and component props as experimental.
33
- * Warnings will display in the console when experimental components/props
34
- * props are used.
35
- *
36
- * ```js-code
37
- * class Example extends Component {
38
- * static propTypes = {
39
- * currentProp: PropTypes.func
40
- * }
41
- * }
42
- * export default experimental(['experimentalProp'])(Example)
43
- * ```
44
- *
45
- * @module experimental
46
- * @param {array} experimentalProps (if this argument is null or undefined, the entire component is flagged)
47
- * @param {string} message
48
- * @return {function} React component flagged as experimental
49
- */
50
- const experimental =
51
- process.env.NODE_ENV == 'production'
52
- ? () => (ReactComponent: ComponentClass<any>) => ReactComponent
53
- : decorator(
54
- (ComposedComponent, experimentalProps: string[], message: string) => {
55
- return class ExperimentalComponent<
56
- P extends Readonly<any>,
57
- S extends Readonly<any>,
58
- SS
59
- > extends ComposedComponent {
60
- componentDidMount() {
61
- if (
62
- !(this.props as any).__dangerouslyIgnoreExperimentalWarnings
63
- ) {
64
- if (experimentalProps) {
65
- warnExperimentalProps(
66
- ComposedComponent.name,
67
- this.props,
68
- experimentalProps,
69
- message
70
- )
71
- } else {
72
- warnExperimentalComponent(ComposedComponent.name, message)
73
- }
74
- }
75
-
76
- if (super.componentDidMount) {
77
- super.componentDidMount()
78
- }
79
- }
80
-
81
- componentDidUpdate(prevProps: P, prevState: S, prevContext: SS) {
82
- if (
83
- !(this.props as any).__dangerouslyIgnoreExperimentalWarnings
84
- ) {
85
- if (experimentalProps) {
86
- warnExperimentalProps(
87
- ComposedComponent.name,
88
- this.props,
89
- experimentalProps,
90
- message
91
- )
92
- } else {
93
- warnExperimentalComponent(ComposedComponent.name, message)
94
- }
95
- }
96
-
97
- if (super.componentDidUpdate) {
98
- super.componentDidUpdate(prevProps, prevState, prevContext)
99
- }
100
- }
101
- }
102
- }
103
- )
104
-
105
- function warnExperimentalProps(
106
- name: string,
107
- props: Record<string, any>,
108
- experimentalProps: string[],
109
- message = ''
110
- ) {
111
- experimentalProps.forEach((experimentalProp) => {
112
- warn(
113
- typeof props[experimentalProp] === 'undefined',
114
- `[${name}] The \`${experimentalProp}\` prop is experimental and its API could change significantly in a future release. ${message}`
115
- )
116
- })
117
- }
118
-
119
- function warnExperimentalComponent(name: string, message = '') {
120
- warn(
121
- false,
122
- `[${name}] is experimental and its API could change significantly in a future release. ${message}`
123
- )
124
- }
125
-
126
- export default experimental
127
- export { experimental }
package/src/hack.ts DELETED
@@ -1,128 +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
- import { decorator } from '@instructure/ui-decorator'
25
-
26
- import { logWarn as warn } from '@instructure/console'
27
-
28
- /**
29
- * ---
30
- * category: utilities/react
31
- * ---
32
- * Flag React component props as hack props.
33
- * Warnings will display in the console when hack props are used.
34
- *
35
- * ```js-code
36
- * class Example extends Component {
37
- * static propTypes = {
38
- * currentProp: PropTypes.func
39
- * }
40
- * }
41
- * export default hack(['hackProp'])(Example)
42
- * ```
43
- *
44
- * @module hack
45
- * @param {array} hackProps
46
- * @param {string} message
47
- * @return {function} React component flagged as having hack props
48
- */
49
- const hack =
50
- process.env.NODE_ENV == 'production'
51
- ? () => (Component: React.ComponentClass<any>) => Component
52
- : decorator((ComposedComponent, hackProps: string[], message: string) => {
53
- return class HackComponent<
54
- P extends Readonly<any>,
55
- S extends Readonly<any>,
56
- SS
57
- > extends ComposedComponent {
58
- componentDidMount() {
59
- if (hackProps) {
60
- warnHackProps(
61
- ComposedComponent.name,
62
- this.props,
63
- hackProps,
64
- message
65
- )
66
- }
67
-
68
- if (super.componentDidMount) {
69
- super.componentDidMount()
70
- }
71
- }
72
-
73
- componentDidUpdate(prevProps: P, prevState: S, prevContext: SS) {
74
- if (hackProps) {
75
- warnHackProps(
76
- ComposedComponent.name,
77
- this.props,
78
- hackProps,
79
- message
80
- )
81
- }
82
-
83
- if (super.componentDidUpdate) {
84
- super.componentDidUpdate(prevProps, prevState, prevContext)
85
- }
86
- }
87
- }
88
- })
89
-
90
- function warnHackProps(
91
- name: string,
92
- props: Record<string, unknown>,
93
- hackProps: string[],
94
- message = ''
95
- ) {
96
- hackProps.forEach((hackProp) => {
97
- warn(
98
- typeof props[hackProp] === 'undefined',
99
- `[${name}] The \`${hackProp}\` prop is a temporary hack and will be removed in a future release. ${message}`
100
- )
101
- })
102
- }
103
-
104
- export default hack
105
- export {
106
- /**
107
- * ---
108
- * category: utilities/react
109
- * ---
110
- * Flag React component props as hack props.
111
- * Warnings will display in the console when hack props are used.
112
- *
113
- * ```js
114
- * class Example extends Component {
115
- * static propTypes = {
116
- * currentProp: PropTypes.func
117
- * }
118
- * }
119
- * export default hack(['hackProp'])(Example)
120
- * ```
121
- *
122
- * @module hack
123
- * @param {array} hackProps
124
- * @param {string} message
125
- * @return {function} React component flagged as having hack props
126
- */
127
- hack
128
- }
@@ -1,37 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- export interface DeprecatedDecorator {
3
- (version: string, oldProps?: Record<string, any> | null, message?: string): (ComposedComponent: any) => any;
4
- deprecatePropValues: (...args: any[]) => PropTypes.Validator<unknown>;
5
- warnDeprecatedProps: (...args: any[]) => void;
6
- warnDeprecatedComponent: (...args: any[]) => void;
7
- changedPackageWarning: (...args: any[]) => string;
8
- }
9
- /**
10
- * ---
11
- * category: utilities/react
12
- * ---
13
- * Deprecate React component props. Warnings will display in the console when deprecated
14
- * props are used. Include the version number when the deprecated component will be removed.
15
- *
16
- * ```js-code
17
- * class Example extends Component {
18
- * static propTypes = {
19
- * currentProp: PropTypes.func
20
- * }
21
- * }
22
- * export default deprecated('7.0.0', {
23
- * deprecatedProp: 'currentProp',
24
- * nowNonExistentProp: true
25
- * })(Example)
26
- * ```
27
- *
28
- * @param {string} version
29
- * @param {object} oldProps (if this argument is null or undefined, the entire component is deprecated)
30
- * @param {string} message
31
- * @return {function} React component with deprecated props behavior
32
- * @module deprecated
33
- */
34
- declare const deprecated: DeprecatedDecorator;
35
- export default deprecated;
36
- export { deprecated };
37
- //# sourceMappingURL=deprecated.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deprecated.d.ts","sourceRoot":"","sources":["../src/deprecated.ts"],"names":[],"mappings":"AA0BA,OAAO,SAAS,MAAM,YAAY,CAAA;AAElC,MAAM,WAAW,mBAAmB;IAClC,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAC1E,iBAAiB,EAAE,GAAG,KACnB,GAAG,CAAA;IACR,mBAAmB,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IACrE,mBAAmB,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC7C,uBAAuB,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IACjD,qBAAqB,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAA;CAClD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,QAAA,MAAM,UAAU,qBA0KZ,CAAA;AAEJ,eAAe,UAAU,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,CAAA"}
@@ -1,27 +0,0 @@
1
- import { ComponentClass } from 'react';
2
- /**
3
- * ---
4
- * category: utilities/react
5
- * ---
6
- * Flag React component and component props as experimental.
7
- * Warnings will display in the console when experimental components/props
8
- * props are used.
9
- *
10
- * ```js-code
11
- * class Example extends Component {
12
- * static propTypes = {
13
- * currentProp: PropTypes.func
14
- * }
15
- * }
16
- * export default experimental(['experimentalProp'])(Example)
17
- * ```
18
- *
19
- * @module experimental
20
- * @param {array} experimentalProps (if this argument is null or undefined, the entire component is flagged)
21
- * @param {string} message
22
- * @return {function} React component flagged as experimental
23
- */
24
- declare const experimental: (...args: unknown[]) => (ComposedComponent: ComponentClass<any>) => any;
25
- export default experimental;
26
- export { experimental };
27
- //# sourceMappingURL=experimental.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"experimental.d.ts","sourceRoot":"","sources":["../src/experimental.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAEtC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,QAAA,MAAM,YAAY,yEAqDX,CAAA;AAuBP,eAAe,YAAY,CAAA;AAC3B,OAAO,EAAE,YAAY,EAAE,CAAA"}
package/types/hack.d.ts DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- * ---
3
- * category: utilities/react
4
- * ---
5
- * Flag React component props as hack props.
6
- * Warnings will display in the console when hack props are used.
7
- *
8
- * ```js-code
9
- * class Example extends Component {
10
- * static propTypes = {
11
- * currentProp: PropTypes.func
12
- * }
13
- * }
14
- * export default hack(['hackProp'])(Example)
15
- * ```
16
- *
17
- * @module hack
18
- * @param {array} hackProps
19
- * @param {string} message
20
- * @return {function} React component flagged as having hack props
21
- */
22
- declare const hack: (...args: unknown[]) => (ComposedComponent: import("react").ComponentClass<any>) => any;
23
- export default hack;
24
- export {
25
- /**
26
- * ---
27
- * category: utilities/react
28
- * ---
29
- * Flag React component props as hack props.
30
- * Warnings will display in the console when hack props are used.
31
- *
32
- * ```js
33
- * class Example extends Component {
34
- * static propTypes = {
35
- * currentProp: PropTypes.func
36
- * }
37
- * }
38
- * export default hack(['hackProp'])(Example)
39
- * ```
40
- *
41
- * @module hack
42
- * @param {array} hackProps
43
- * @param {string} message
44
- * @return {function} React component flagged as having hack props
45
- */
46
- hack };
47
- //# sourceMappingURL=hack.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hack.d.ts","sourceRoot":"","sources":["../src/hack.ts"],"names":[],"mappings":"AA2BA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAA,MAAM,IAAI,yFAuCF,CAAA;AAgBR,eAAe,IAAI,CAAA;AACnB,OAAO;AACL;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,IAAI,EACL,CAAA"}