@instructure/ui-i18n 8.56.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [9.0.0](https://github.com/instructure/instructure-ui/compare/v8.56.0...v9.0.0) (2024-05-09)
7
+
8
+ **Note:** Version bump only for package @instructure/ui-i18n
9
+
10
+
11
+
12
+
13
+
6
14
  # [8.56.0](https://github.com/instructure/instructure-ui/compare/v8.55.1...v8.56.0) (2024-05-06)
7
15
 
8
16
  **Note:** Version bump only for package @instructure/ui-i18n
package/README.md CHANGED
@@ -15,7 +15,6 @@ Helper components and utilities for internationalization.
15
15
  The `ui-i18n` package contains the following:
16
16
 
17
17
  - [ApplyLocale](#ApplyLocale)
18
- - [ApplyTextDirection](#ApplyTextDirection)
19
18
 
20
19
  ### Utilities
21
20
 
package/es/index.js CHANGED
@@ -24,11 +24,9 @@
24
24
 
25
25
  export { ApplyLocale } from './ApplyLocale';
26
26
  export { ApplyLocaleContext } from './ApplyLocale/ApplyLocaleContext';
27
- export { bidirectional } from './bidirectional';
28
27
  export { textDirectionContextConsumer } from './textDirectionContextConsumer';
29
28
  export { DateTime } from './DateTime';
30
29
  export { getTextDirection } from './getTextDirection';
31
30
  export { I18nPropTypes } from './I18nPropTypes';
32
31
  export { Locale } from './Locale';
33
- export { DIRECTION, TextDirectionContext } from './TextDirectionContext';
34
- export { ApplyTextDirection } from './ApplyTextDirection';
32
+ export { DIRECTION, TextDirectionContext } from './TextDirectionContext';
@@ -1,3 +1,5 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["forwardedRef"];
1
3
  /*
2
4
  * The MIT License (MIT)
3
5
  *
@@ -21,9 +23,15 @@
21
23
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
24
  * SOFTWARE.
23
25
  */
26
+ import React, { forwardRef } from 'react';
27
+ import { decorator } from '@instructure/ui-decorator';
28
+ import { DIRECTION, TextDirectionContext } from './TextDirectionContext';
29
+ import hoistNonReactStatics from 'hoist-non-react-statics';
24
30
 
25
- import { bidirectional } from './bidirectional';
26
-
31
+ // This is a workaround because TS cannot take type information from
32
+ // decorators into account. This type needs to be added to every component,
33
+ // that uses the TextDirectionContextConsumer decorator.
34
+ // see https://github.com/microsoft/TypeScript/issues/4881
27
35
  /**
28
36
  * ---
29
37
  * category: utilities/i18n
@@ -46,15 +54,57 @@ import { bidirectional } from './bidirectional';
46
54
  * export default textDirectionContextConsumer()(Example)
47
55
  * ```
48
56
  *
49
- * When used as a child of [InstUISettingsProvider](#InstUISettingsProvider), bidirectional components use
57
+ * When used as a child of [InstUISettingsProvider](#InstUISettingsProvider), textDirectionContextConsumer components use
50
58
  * the direction provided in `TextDirectionContext`. When used without [InstUISettingsProvider](#InstUISettingsProvider),
51
59
  * the direction can be supplied explicitly via the `dir` prop. If no `dir` prop is provided,
52
- * bidirectional components query the documentElement for the `dir` attribute, defaulting to `ltr`
60
+ * textDirectionContextConsumer components query the documentElement for the `dir` attribute, defaulting to `ltr`
53
61
  * if it is not present.
54
62
  *
55
63
  * @module textDirectionContextConsumer
56
- * @return The decorator that composes the bidirectional component.
64
+ * @return The decorator that composes the textDirectionContextConsumer component.
57
65
  */
58
- const textDirectionContextConsumer = bidirectional;
66
+ const textDirectionContextConsumer = decorator(ComposedComponent => {
67
+ class TextDirectionContextConsumerComponent extends React.Component {
68
+ render() {
69
+ const _this$props = this.props,
70
+ forwardedRef = _this$props.forwardedRef,
71
+ rest = _objectWithoutProperties(_this$props, _excluded);
72
+ // Quite complex code, this is the priority order of applying the `dir` prop:
73
+ // 1. The highest priority is adding it via a prop
74
+ // 2. If there is a <TextDirectionContext.Provider> (or <ApplyTextDirection>
75
+ // which uses it) above the @textDirectionContextConsumer in the DOM, use its value.
76
+ // 3. If TextDirectionContext.Provider was called without params
77
+ // TextDirectionContext calls getTextDirection() which returns
78
+ // the 'dir' prop of the HTML document element.
79
+ return /*#__PURE__*/React.createElement(TextDirectionContext.Consumer, null, dir => {
80
+ if (process.env.NODE_ENV !== 'production' && dir === 'auto') {}
81
+ return /*#__PURE__*/React.createElement(ComposedComponent, Object.assign({
82
+ ref: forwardedRef,
83
+ dir: dir
84
+ }, rest));
85
+ });
86
+ }
87
+ }
88
+ TextDirectionContextConsumerComponent.displayName = "TextDirectionContextConsumerComponent";
89
+ const TextDirectionContextConsumerForwardingRef = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/React.createElement(TextDirectionContextConsumerComponent, Object.assign({}, props, {
90
+ forwardedRef: ref
91
+ })));
92
+ if (process.env.NODE_ENV !== 'production') {
93
+ const displayName = ComposedComponent.displayName || ComposedComponent.name;
94
+ TextDirectionContextConsumerForwardingRef.displayName = `TextDirectionContextConsumerForwardingRef(${displayName})`;
95
+ }
96
+ hoistNonReactStatics(TextDirectionContextConsumerForwardingRef, ComposedComponent);
97
+ TextDirectionContextConsumerForwardingRef.defaultProps = ComposedComponent.defaultProps;
98
+ // eslint-disable-next-line react/forbid-foreign-prop-types
99
+ TextDirectionContextConsumerForwardingRef.propTypes = ComposedComponent.propTypes;
100
+ // @ts-expect-error These static fields exist on InstUI components
101
+ TextDirectionContextConsumerForwardingRef.allowedProps = ComposedComponent.allowedProps;
102
+
103
+ // added so it can be tested with ReactTestUtils
104
+ // more info: https://github.com/facebook/react/issues/13455
105
+ TextDirectionContextConsumerForwardingRef.originalType = ComposedComponent.originalType || ComposedComponent;
106
+ return TextDirectionContextConsumerForwardingRef;
107
+ });
108
+ textDirectionContextConsumer.DIRECTION = DIRECTION;
59
109
  export default textDirectionContextConsumer;
60
110
  export { textDirectionContextConsumer };
package/lib/index.js CHANGED
@@ -15,12 +15,6 @@ Object.defineProperty(exports, "ApplyLocaleContext", {
15
15
  return _ApplyLocaleContext.ApplyLocaleContext;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "ApplyTextDirection", {
19
- enumerable: true,
20
- get: function () {
21
- return _ApplyTextDirection.ApplyTextDirection;
22
- }
23
- });
24
18
  Object.defineProperty(exports, "DIRECTION", {
25
19
  enumerable: true,
26
20
  get: function () {
@@ -51,12 +45,6 @@ Object.defineProperty(exports, "TextDirectionContext", {
51
45
  return _TextDirectionContext.TextDirectionContext;
52
46
  }
53
47
  });
54
- Object.defineProperty(exports, "bidirectional", {
55
- enumerable: true,
56
- get: function () {
57
- return _bidirectional.bidirectional;
58
- }
59
- });
60
48
  Object.defineProperty(exports, "getTextDirection", {
61
49
  enumerable: true,
62
50
  get: function () {
@@ -71,11 +59,9 @@ Object.defineProperty(exports, "textDirectionContextConsumer", {
71
59
  });
72
60
  var _ApplyLocale = require("./ApplyLocale");
73
61
  var _ApplyLocaleContext = require("./ApplyLocale/ApplyLocaleContext");
74
- var _bidirectional = require("./bidirectional");
75
62
  var _textDirectionContextConsumer = require("./textDirectionContextConsumer");
76
63
  var _DateTime = require("./DateTime");
77
64
  var _getTextDirection = require("./getTextDirection");
78
65
  var _I18nPropTypes = require("./I18nPropTypes");
79
66
  var _Locale = require("./Locale");
80
- var _TextDirectionContext = require("./TextDirectionContext");
81
- var _ApplyTextDirection = require("./ApplyTextDirection");
67
+ var _TextDirectionContext = require("./TextDirectionContext");
@@ -1,10 +1,17 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.textDirectionContextConsumer = exports.default = void 0;
7
- var _bidirectional = require("./bidirectional");
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
12
+ var _TextDirectionContext = require("./TextDirectionContext");
13
+ var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
14
+ const _excluded = ["forwardedRef"];
8
15
  /*
9
16
  * The MIT License (MIT)
10
17
  *
@@ -28,7 +35,10 @@ var _bidirectional = require("./bidirectional");
28
35
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
36
  * SOFTWARE.
30
37
  */
31
-
38
+ // This is a workaround because TS cannot take type information from
39
+ // decorators into account. This type needs to be added to every component,
40
+ // that uses the TextDirectionContextConsumer decorator.
41
+ // see https://github.com/microsoft/TypeScript/issues/4881
32
42
  /**
33
43
  * ---
34
44
  * category: utilities/i18n
@@ -51,14 +61,56 @@ var _bidirectional = require("./bidirectional");
51
61
  * export default textDirectionContextConsumer()(Example)
52
62
  * ```
53
63
  *
54
- * When used as a child of [InstUISettingsProvider](#InstUISettingsProvider), bidirectional components use
64
+ * When used as a child of [InstUISettingsProvider](#InstUISettingsProvider), textDirectionContextConsumer components use
55
65
  * the direction provided in `TextDirectionContext`. When used without [InstUISettingsProvider](#InstUISettingsProvider),
56
66
  * the direction can be supplied explicitly via the `dir` prop. If no `dir` prop is provided,
57
- * bidirectional components query the documentElement for the `dir` attribute, defaulting to `ltr`
67
+ * textDirectionContextConsumer components query the documentElement for the `dir` attribute, defaulting to `ltr`
58
68
  * if it is not present.
59
69
  *
60
70
  * @module textDirectionContextConsumer
61
- * @return The decorator that composes the bidirectional component.
71
+ * @return The decorator that composes the textDirectionContextConsumer component.
62
72
  */
63
- const textDirectionContextConsumer = exports.textDirectionContextConsumer = _bidirectional.bidirectional;
73
+ const textDirectionContextConsumer = exports.textDirectionContextConsumer = (0, _decorator.decorator)(ComposedComponent => {
74
+ class TextDirectionContextConsumerComponent extends _react.default.Component {
75
+ render() {
76
+ const _this$props = this.props,
77
+ forwardedRef = _this$props.forwardedRef,
78
+ rest = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
79
+ // Quite complex code, this is the priority order of applying the `dir` prop:
80
+ // 1. The highest priority is adding it via a prop
81
+ // 2. If there is a <TextDirectionContext.Provider> (or <ApplyTextDirection>
82
+ // which uses it) above the @textDirectionContextConsumer in the DOM, use its value.
83
+ // 3. If TextDirectionContext.Provider was called without params
84
+ // TextDirectionContext calls getTextDirection() which returns
85
+ // the 'dir' prop of the HTML document element.
86
+ return /*#__PURE__*/_react.default.createElement(_TextDirectionContext.TextDirectionContext.Consumer, null, dir => {
87
+ if (process.env.NODE_ENV !== 'production' && dir === 'auto') {}
88
+ return /*#__PURE__*/_react.default.createElement(ComposedComponent, Object.assign({
89
+ ref: forwardedRef,
90
+ dir: dir
91
+ }, rest));
92
+ });
93
+ }
94
+ }
95
+ TextDirectionContextConsumerComponent.displayName = "TextDirectionContextConsumerComponent";
96
+ const TextDirectionContextConsumerForwardingRef = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => /*#__PURE__*/_react.default.createElement(TextDirectionContextConsumerComponent, Object.assign({}, props, {
97
+ forwardedRef: ref
98
+ })));
99
+ if (process.env.NODE_ENV !== 'production') {
100
+ const displayName = ComposedComponent.displayName || ComposedComponent.name;
101
+ TextDirectionContextConsumerForwardingRef.displayName = `TextDirectionContextConsumerForwardingRef(${displayName})`;
102
+ }
103
+ (0, _hoistNonReactStatics.default)(TextDirectionContextConsumerForwardingRef, ComposedComponent);
104
+ TextDirectionContextConsumerForwardingRef.defaultProps = ComposedComponent.defaultProps;
105
+ // eslint-disable-next-line react/forbid-foreign-prop-types
106
+ TextDirectionContextConsumerForwardingRef.propTypes = ComposedComponent.propTypes;
107
+ // @ts-expect-error These static fields exist on InstUI components
108
+ TextDirectionContextConsumerForwardingRef.allowedProps = ComposedComponent.allowedProps;
109
+
110
+ // added so it can be tested with ReactTestUtils
111
+ // more info: https://github.com/facebook/react/issues/13455
112
+ TextDirectionContextConsumerForwardingRef.originalType = ComposedComponent.originalType || ComposedComponent;
113
+ return TextDirectionContextConsumerForwardingRef;
114
+ });
115
+ textDirectionContextConsumer.DIRECTION = _TextDirectionContext.DIRECTION;
64
116
  var _default = exports.default = textDirectionContextConsumer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-i18n",
3
- "version": "8.56.0",
3
+ "version": "9.0.0",
4
4
  "description": "Helper components and utilities for internationalization.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,19 +23,19 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "8.56.0",
27
- "@instructure/ui-test-utils": "8.56.0",
26
+ "@instructure/ui-babel-preset": "9.0.0",
27
+ "@instructure/ui-test-utils": "9.0.0",
28
28
  "@types/hoist-non-react-statics": "^3.3.3",
29
29
  "react-dom": "^18.2.0"
30
30
  },
31
31
  "dependencies": {
32
32
  "@babel/runtime": "^7.23.2",
33
- "@instructure/shared-types": "8.56.0",
34
- "@instructure/ui-decorator": "8.56.0",
35
- "@instructure/ui-dom-utils": "8.56.0",
36
- "@instructure/ui-prop-types": "8.56.0",
37
- "@instructure/ui-react-utils": "8.56.0",
38
- "@instructure/ui-utils": "8.56.0",
33
+ "@instructure/shared-types": "9.0.0",
34
+ "@instructure/ui-decorator": "9.0.0",
35
+ "@instructure/ui-dom-utils": "9.0.0",
36
+ "@instructure/ui-prop-types": "9.0.0",
37
+ "@instructure/ui-react-utils": "9.0.0",
38
+ "@instructure/ui-utils": "9.0.0",
39
39
  "hoist-non-react-statics": "^3.3.2",
40
40
  "moment-timezone": "^0.5.43",
41
41
  "prop-types": "^15.8.1"
package/src/index.ts CHANGED
@@ -25,16 +25,13 @@
25
25
  export { ApplyLocale } from './ApplyLocale'
26
26
  export { ApplyLocaleContext } from './ApplyLocale/ApplyLocaleContext'
27
27
 
28
- export { bidirectional } from './bidirectional'
29
28
  export { textDirectionContextConsumer } from './textDirectionContextConsumer'
30
29
  export { DateTime } from './DateTime'
31
30
  export { getTextDirection } from './getTextDirection'
32
31
  export { I18nPropTypes } from './I18nPropTypes'
33
32
  export { Locale } from './Locale'
34
33
  export { DIRECTION, TextDirectionContext } from './TextDirectionContext'
35
- export { ApplyTextDirection } from './ApplyTextDirection'
36
34
 
37
35
  export type { Moment } from './DateTime'
38
- export type { BidirectionalProps } from './bidirectional'
36
+ export type { TextDirectionContextConsumerProps } from './textDirectionContextConsumer'
39
37
  export type { ApplyLocaleProps } from './ApplyLocale/props'
40
- export type { ApplyTextDirectionProps } from './ApplyTextDirection/props'
@@ -21,9 +21,33 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+ import React, { ForwardedRef, forwardRef, PropsWithChildren } from 'react'
25
+ import type {
26
+ ForwardRefExoticComponent,
27
+ PropsWithoutRef,
28
+ RefAttributes
29
+ } from 'react'
30
+ import { decorator } from '@instructure/ui-decorator'
31
+ import { DIRECTION, TextDirectionContext } from './TextDirectionContext'
32
+ import hoistNonReactStatics from 'hoist-non-react-statics'
24
33
 
25
- import { bidirectional } from './bidirectional'
34
+ // This is a workaround because TS cannot take type information from
35
+ // decorators into account. This type needs to be added to every component,
36
+ // that uses the TextDirectionContextConsumer decorator.
37
+ // see https://github.com/microsoft/TypeScript/issues/4881
38
+ export type TextDirectionContextConsumerProps = PropsWithChildren<{
39
+ dir?: 'ltr' | 'rtl'
40
+ }>
26
41
 
42
+ type TextDirectionContextConsumerInternalProps = {
43
+ forwardedRef: ForwardedRef<any>
44
+ }
45
+
46
+ type TextDirectionContextConsumerType = {
47
+ // TODO likely this can be typed better.
48
+ (): (ComposedComponent: any) => any
49
+ DIRECTION: typeof DIRECTION
50
+ }
27
51
  /**
28
52
  * ---
29
53
  * category: utilities/i18n
@@ -46,16 +70,76 @@ import { bidirectional } from './bidirectional'
46
70
  * export default textDirectionContextConsumer()(Example)
47
71
  * ```
48
72
  *
49
- * When used as a child of [InstUISettingsProvider](#InstUISettingsProvider), bidirectional components use
73
+ * When used as a child of [InstUISettingsProvider](#InstUISettingsProvider), textDirectionContextConsumer components use
50
74
  * the direction provided in `TextDirectionContext`. When used without [InstUISettingsProvider](#InstUISettingsProvider),
51
75
  * the direction can be supplied explicitly via the `dir` prop. If no `dir` prop is provided,
52
- * bidirectional components query the documentElement for the `dir` attribute, defaulting to `ltr`
76
+ * textDirectionContextConsumer components query the documentElement for the `dir` attribute, defaulting to `ltr`
53
77
  * if it is not present.
54
78
  *
55
79
  * @module textDirectionContextConsumer
56
- * @return The decorator that composes the bidirectional component.
80
+ * @return The decorator that composes the textDirectionContextConsumer component.
57
81
  */
58
- const textDirectionContextConsumer = bidirectional
82
+ const textDirectionContextConsumer: TextDirectionContextConsumerType =
83
+ decorator((ComposedComponent) => {
84
+ class TextDirectionContextConsumerComponent extends React.Component<TextDirectionContextConsumerInternalProps> {
85
+ render() {
86
+ const { forwardedRef, ...rest } = this.props
87
+ // Quite complex code, this is the priority order of applying the `dir` prop:
88
+ // 1. The highest priority is adding it via a prop
89
+ // 2. If there is a <TextDirectionContext.Provider> (or <ApplyTextDirection>
90
+ // which uses it) above the @textDirectionContextConsumer in the DOM, use its value.
91
+ // 3. If TextDirectionContext.Provider was called without params
92
+ // TextDirectionContext calls getTextDirection() which returns
93
+ // the 'dir' prop of the HTML document element.
94
+ return (
95
+ <TextDirectionContext.Consumer>
96
+ {(dir) => {
97
+ if (process.env.NODE_ENV !== 'production' && dir === 'auto') {
98
+ console.warn(
99
+ "'auto' is not an supported value for the 'dir' prop. Please pass 'ltr' or 'rtl'"
100
+ )
101
+ }
102
+ return (
103
+ <ComposedComponent ref={forwardedRef} dir={dir} {...rest} />
104
+ )
105
+ }}
106
+ </TextDirectionContext.Consumer>
107
+ )
108
+ }
109
+ }
110
+
111
+ const TextDirectionContextConsumerForwardingRef: ForwardRefExoticComponent<
112
+ PropsWithoutRef<Record<string, unknown>> & RefAttributes<any>
113
+ > & {
114
+ originalType?: React.ComponentClass
115
+ } = forwardRef<any, TextDirectionContextConsumerProps>((props, ref) => (
116
+ <TextDirectionContextConsumerComponent {...props} forwardedRef={ref} />
117
+ ))
118
+ if (process.env.NODE_ENV !== 'production') {
119
+ const displayName =
120
+ ComposedComponent.displayName || ComposedComponent.name
121
+ TextDirectionContextConsumerForwardingRef.displayName = `TextDirectionContextConsumerForwardingRef(${displayName})`
122
+ }
123
+ hoistNonReactStatics(
124
+ TextDirectionContextConsumerForwardingRef,
125
+ ComposedComponent
126
+ )
127
+ TextDirectionContextConsumerForwardingRef.defaultProps =
128
+ ComposedComponent.defaultProps
129
+ // eslint-disable-next-line react/forbid-foreign-prop-types
130
+ TextDirectionContextConsumerForwardingRef.propTypes = ComposedComponent.propTypes
131
+ // @ts-expect-error These static fields exist on InstUI components
132
+ TextDirectionContextConsumerForwardingRef.allowedProps = ComposedComponent.allowedProps
133
+
134
+ // added so it can be tested with ReactTestUtils
135
+ // more info: https://github.com/facebook/react/issues/13455
136
+ TextDirectionContextConsumerForwardingRef.originalType =
137
+ (ComposedComponent as any).originalType || ComposedComponent
138
+
139
+ return TextDirectionContextConsumerForwardingRef
140
+ }) as TextDirectionContextConsumerType
141
+
142
+ textDirectionContextConsumer.DIRECTION = DIRECTION
59
143
 
60
144
  export default textDirectionContextConsumer
61
145
  export { textDirectionContextConsumer }