@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.
@@ -1,138 +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 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'
33
-
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 bidirectional decorator.
37
- // see https://github.com/microsoft/TypeScript/issues/4881
38
- export type BidirectionalProps = PropsWithChildren<{
39
- dir?: 'ltr' | 'rtl'
40
- }>
41
-
42
- type BidirectionalInternalProps = {
43
- forwardedRef: ForwardedRef<any>
44
- }
45
-
46
- type BidirectionalType = {
47
- // TODO likely this can be typed better.
48
- (): (ComposedComponent: any) => any
49
- DIRECTION: typeof DIRECTION
50
- }
51
- /**
52
- * ---
53
- * category: utilities/i18n
54
- * ---
55
- *
56
- * #### DEPRECATED: This has been renamed to `textDirectionContextConsumer`, its functionality remains similar.
57
- *
58
- * A decorator or higher order component that makes a component `bidirectional`.
59
- *
60
- * As a HOC:
61
- *
62
- * ```js-code
63
- * import { bidirectional } from '@instructure/ui-i18n'
64
- *
65
- * class Example extends React.Component {
66
- * render () {
67
- * return this.props.dir === bidirectional.DIRECTION.rtl ? <div>rtl</div> : <div>ltr</div>
68
- * }
69
- * }
70
- *
71
- * export default bidirectional()(Example)
72
- * ```
73
- *
74
- * When used as a child of [InstUISettingsProvider](#InstUISettingsProvider), bidirectional components use
75
- * the direction provided in `TextDirectionContext`. When used without [InstUISettingsProvider](#InstUISettingsProvider),
76
- * the direction can be supplied explicitly via the `dir` prop. If no `dir` prop is provided,
77
- * bidirectional components query the documentElement for the `dir` attribute, defaulting to `ltr`
78
- * if it is not present.
79
- *
80
- * @module bidirectional
81
- * @return The decorator that composes the bidirectional component.
82
- */
83
- const bidirectional: BidirectionalType = decorator((ComposedComponent) => {
84
- class BidirectionalComponent extends React.Component<BidirectionalInternalProps> {
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 @bidirectional 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 <ComposedComponent ref={forwardedRef} dir={dir} {...rest} />
103
- }}
104
- </TextDirectionContext.Consumer>
105
- )
106
- }
107
- }
108
-
109
- const BidirectionalForwardingRef: ForwardRefExoticComponent<
110
- PropsWithoutRef<Record<string, unknown>> & RefAttributes<any>
111
- > & {
112
- originalType?: React.ComponentClass
113
- } = forwardRef<any, BidirectionalProps>((props, ref) => (
114
- <BidirectionalComponent {...props} forwardedRef={ref} />
115
- ))
116
- if (process.env.NODE_ENV !== 'production') {
117
- const displayName = ComposedComponent.displayName || ComposedComponent.name
118
- BidirectionalForwardingRef.displayName = `BidirectionalForwardingRef(${displayName})`
119
- }
120
- hoistNonReactStatics(BidirectionalForwardingRef, ComposedComponent)
121
- BidirectionalForwardingRef.defaultProps = ComposedComponent.defaultProps
122
- // eslint-disable-next-line react/forbid-foreign-prop-types
123
- BidirectionalForwardingRef.propTypes = ComposedComponent.propTypes
124
- // @ts-expect-error These static fields exist on InstUI components
125
- BidirectionalForwardingRef.allowedProps = ComposedComponent.allowedProps
126
-
127
- // added so it can be tested with ReactTestUtils
128
- // more info: https://github.com/facebook/react/issues/13455
129
- BidirectionalForwardingRef.originalType =
130
- (ComposedComponent as any).originalType || ComposedComponent
131
-
132
- return BidirectionalForwardingRef
133
- }) as BidirectionalType
134
-
135
- bidirectional.DIRECTION = DIRECTION
136
-
137
- export default bidirectional
138
- export { bidirectional }
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
- import { ApplyTextDirectionProps } from './props';
3
- /**
4
- ---
5
- category: components/utilities
6
- ---
7
- DEPRECATED. Please use TextDirectionContext instead.
8
- **/
9
- declare const ApplyTextDirection: {
10
- (props: ApplyTextDirectionProps): React.JSX.Element;
11
- defaultProps: {
12
- readonly dir: undefined;
13
- readonly as: "span";
14
- readonly children: null;
15
- };
16
- };
17
- export { ApplyTextDirection };
18
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ApplyTextDirection/index.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAIzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjD;;;;;GAKG;AACH,QAAA,MAAM,kBAAkB;YAAW,uBAAuB;;;;;;CAezD,CAAA;AAQD,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { AsElementType } from '@instructure/shared-types';
3
- type DirValues = 'ltr' | 'rtl' | 'auto';
4
- export type ApplyTextDirectionProps = {
5
- /**
6
- * The direction value to use. For values and their effects see
7
- * https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir
8
- */
9
- dir?: DirValues;
10
- /**
11
- * The children of this component. Either a React node or a function
12
- * that receives 2 parameters (text direction, is rtl direction?) and
13
- * returns a React node
14
- */
15
- children?: React.ReactNode | ((dir: DirValues, isRtl: boolean) => React.ReactNode);
16
- as?: AsElementType;
17
- };
18
- export {};
19
- //# sourceMappingURL=props.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/ApplyTextDirection/props.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAEzD,KAAK,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAA;AAEvC,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,GAAG,CAAC,EAAE,SAAS,CAAA;IACf;;;;OAIG;IACH,QAAQ,CAAC,EACL,KAAK,CAAC,SAAS,GACf,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,SAAS,CAAC,CAAA;IACzD,EAAE,CAAC,EAAE,aAAa,CAAA;CACnB,CAAA"}
@@ -1,45 +0,0 @@
1
- import { PropsWithChildren } from 'react';
2
- import { DIRECTION } from './TextDirectionContext';
3
- export type BidirectionalProps = PropsWithChildren<{
4
- dir?: 'ltr' | 'rtl';
5
- }>;
6
- type BidirectionalType = {
7
- (): (ComposedComponent: any) => any;
8
- DIRECTION: typeof DIRECTION;
9
- };
10
- /**
11
- * ---
12
- * category: utilities/i18n
13
- * ---
14
- *
15
- * #### DEPRECATED: This has been renamed to `textDirectionContextConsumer`, its functionality remains similar.
16
- *
17
- * A decorator or higher order component that makes a component `bidirectional`.
18
- *
19
- * As a HOC:
20
- *
21
- * ```js-code
22
- * import { bidirectional } from '@instructure/ui-i18n'
23
- *
24
- * class Example extends React.Component {
25
- * render () {
26
- * return this.props.dir === bidirectional.DIRECTION.rtl ? <div>rtl</div> : <div>ltr</div>
27
- * }
28
- * }
29
- *
30
- * export default bidirectional()(Example)
31
- * ```
32
- *
33
- * When used as a child of [InstUISettingsProvider](#InstUISettingsProvider), bidirectional components use
34
- * the direction provided in `TextDirectionContext`. When used without [InstUISettingsProvider](#InstUISettingsProvider),
35
- * the direction can be supplied explicitly via the `dir` prop. If no `dir` prop is provided,
36
- * bidirectional components query the documentElement for the `dir` attribute, defaulting to `ltr`
37
- * if it is not present.
38
- *
39
- * @module bidirectional
40
- * @return The decorator that composes the bidirectional component.
41
- */
42
- declare const bidirectional: BidirectionalType;
43
- export default bidirectional;
44
- export { bidirectional };
45
- //# sourceMappingURL=bidirectional.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bidirectional.d.ts","sourceRoot":"","sources":["../src/bidirectional.tsx"],"names":[],"mappings":"AAuBA,OAAc,EAA4B,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAO1E,OAAO,EAAE,SAAS,EAAwB,MAAM,wBAAwB,CAAA;AAOxE,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;IACjD,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;CACpB,CAAC,CAAA;AAMF,KAAK,iBAAiB,GAAG;IAEvB,IAAI,CAAC,iBAAiB,EAAE,GAAG,KAAK,GAAG,CAAA;IACnC,SAAS,EAAE,OAAO,SAAS,CAAA;CAC5B,CAAA;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,QAAA,MAAM,aAAa,EAAE,iBAkDE,CAAA;AAIvB,eAAe,aAAa,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,CAAA"}