@instructure/ui-text 11.6.0 → 11.6.1-snapshot-129

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +52 -287
  2. package/es/Text/{index.js → v1/index.js} +1 -1
  3. package/es/Text/v2/index.js +90 -0
  4. package/es/Text/v2/props.js +26 -0
  5. package/es/Text/v2/styles.js +272 -0
  6. package/es/{index.js → exports/a.js} +1 -1
  7. package/{src/index.ts → es/exports/b.js} +1 -2
  8. package/lib/Text/v1/index.js +97 -0
  9. package/lib/Text/{index.js → v2/index.js} +1 -2
  10. package/lib/Text/v2/props.js +31 -0
  11. package/lib/Text/v2/styles.js +278 -0
  12. package/lib/{index.js → exports/a.js} +2 -2
  13. package/lib/exports/b.js +12 -0
  14. package/package.json +38 -16
  15. package/src/Text/{index.tsx → v1/index.tsx} +1 -1
  16. package/src/Text/v2/README.md +200 -0
  17. package/src/Text/v2/index.tsx +106 -0
  18. package/src/Text/v2/props.ts +136 -0
  19. package/src/Text/v2/styles.ts +260 -0
  20. package/src/exports/a.ts +25 -0
  21. package/src/exports/b.ts +25 -0
  22. package/tsconfig.build.tsbuildinfo +1 -1
  23. package/types/Text/v1/index.d.ts.map +1 -0
  24. package/types/Text/v1/props.d.ts.map +1 -0
  25. package/types/Text/v1/styles.d.ts.map +1 -0
  26. package/types/Text/v1/theme.d.ts.map +1 -0
  27. package/types/Text/v2/index.d.ts +40 -0
  28. package/types/Text/v2/index.d.ts.map +1 -0
  29. package/types/Text/v2/props.d.ts +52 -0
  30. package/types/Text/v2/props.d.ts.map +1 -0
  31. package/types/Text/v2/styles.d.ts +25 -0
  32. package/types/Text/v2/styles.d.ts.map +1 -0
  33. package/types/exports/a.d.ts +3 -0
  34. package/types/exports/a.d.ts.map +1 -0
  35. package/types/exports/b.d.ts +3 -0
  36. package/types/exports/b.d.ts.map +1 -0
  37. package/types/Text/index.d.ts.map +0 -1
  38. package/types/Text/props.d.ts.map +0 -1
  39. package/types/Text/styles.d.ts.map +0 -1
  40. package/types/Text/theme.d.ts.map +0 -1
  41. package/types/index.d.ts +0 -3
  42. package/types/index.d.ts.map +0 -1
  43. /package/es/Text/{props.js → v1/props.js} +0 -0
  44. /package/es/Text/{styles.js → v1/styles.js} +0 -0
  45. /package/es/Text/{theme.js → v1/theme.js} +0 -0
  46. /package/lib/Text/{props.js → v1/props.js} +0 -0
  47. /package/lib/Text/{styles.js → v1/styles.js} +0 -0
  48. /package/lib/Text/{theme.js → v1/theme.js} +0 -0
  49. /package/src/Text/{README.md → v1/README.md} +0 -0
  50. /package/src/Text/{props.ts → v1/props.ts} +0 -0
  51. /package/src/Text/{styles.ts → v1/styles.ts} +0 -0
  52. /package/src/Text/{theme.ts → v1/theme.ts} +0 -0
  53. /package/types/Text/{index.d.ts → v1/index.d.ts} +0 -0
  54. /package/types/Text/{props.d.ts → v1/props.d.ts} +0 -0
  55. /package/types/Text/{styles.d.ts → v1/styles.d.ts} +0 -0
  56. /package/types/Text/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ /**
32
+ * ---
33
+ * private: true
34
+ * ---
35
+ * Generates the style object from the theme and provided additional information
36
+ * @param componentTheme The theme variable object.
37
+ * @param params Additional parameters to customize the style.
38
+ * @return The final style object, which will be used in the component
39
+ */
40
+ const generateStyle = (componentTheme, params) => {
41
+ const color = params.color,
42
+ fontStyle = params.fontStyle,
43
+ lineHeight = params.lineHeight,
44
+ letterSpacing = params.letterSpacing,
45
+ transform = params.transform,
46
+ size = params.size,
47
+ variant = params.variant,
48
+ weight = params.weight,
49
+ wrap = params.wrap;
50
+ const variants = {
51
+ descriptionPage: {
52
+ fontFamily: componentTheme.descriptionPage.fontFamily,
53
+ fontWeight: componentTheme.descriptionPage.fontWeight,
54
+ fontSize: componentTheme.descriptionPage.fontSize,
55
+ lineHeight: componentTheme.descriptionPage.lineHeight
56
+ },
57
+ descriptionSection: {
58
+ fontFamily: componentTheme.descriptionSection.fontFamily,
59
+ fontWeight: componentTheme.descriptionSection.fontWeight,
60
+ fontSize: componentTheme.descriptionSection.fontSize,
61
+ lineHeight: componentTheme.descriptionSection.lineHeight
62
+ },
63
+ content: {
64
+ fontFamily: componentTheme.content.fontFamily,
65
+ fontWeight: componentTheme.content.fontWeight,
66
+ fontSize: componentTheme.content.fontSize,
67
+ lineHeight: componentTheme.content.lineHeight
68
+ },
69
+ contentImportant: {
70
+ fontFamily: componentTheme.contentImportant.fontFamily,
71
+ fontWeight: componentTheme.contentImportant.fontWeight,
72
+ fontSize: componentTheme.contentImportant.fontSize,
73
+ lineHeight: componentTheme.contentImportant.lineHeight
74
+ },
75
+ contentQuote: {
76
+ fontFamily: componentTheme.contentQuote.fontFamily,
77
+ fontWeight: componentTheme.contentQuote.fontWeight,
78
+ fontSize: componentTheme.contentQuote.fontSize,
79
+ lineHeight: componentTheme.contentQuote.lineHeight
80
+ },
81
+ contentSmall: {
82
+ fontFamily: componentTheme.contentSmall.fontFamily,
83
+ fontWeight: componentTheme.contentSmall.fontWeight,
84
+ fontSize: componentTheme.contentSmall.fontSize,
85
+ lineHeight: componentTheme.contentSmall.lineHeight
86
+ },
87
+ legend: {
88
+ fontFamily: componentTheme.legend.fontFamily,
89
+ fontWeight: componentTheme.legend.fontWeight,
90
+ fontSize: componentTheme.legend.fontSize,
91
+ lineHeight: componentTheme.legend.lineHeight
92
+ }
93
+ };
94
+ const colorVariants = {
95
+ primary: {
96
+ color: componentTheme.baseColor
97
+ },
98
+ secondary: {
99
+ color: componentTheme.mutedColor
100
+ },
101
+ 'primary-inverse': {
102
+ color: componentTheme.inverseColor
103
+ },
104
+ 'secondary-inverse': {
105
+ color: componentTheme.inverseColor
106
+ },
107
+ success: {
108
+ color: componentTheme.successColor
109
+ },
110
+ brand: {
111
+ color: componentTheme.primaryColor
112
+ },
113
+ danger: {
114
+ color: componentTheme.errorColor
115
+ },
116
+ warning: {
117
+ color: componentTheme.warningColor
118
+ },
119
+ 'primary-on': {
120
+ color: componentTheme.baseOnColor
121
+ },
122
+ 'secondary-on': {
123
+ color: componentTheme.mutedOnColor
124
+ },
125
+ 'ai-highlight': {
126
+ color: componentTheme.aiColor,
127
+ background: componentTheme.aiBackgroundColor
128
+ }
129
+ };
130
+ const wrapStyle = {
131
+ overflowWrap: 'break-word',
132
+ wordBreak: 'break-word',
133
+ hyphens: 'auto'
134
+ };
135
+ const weightStyle = {
136
+ normal: {
137
+ fontWeight: componentTheme.fontWeightNormal
138
+ },
139
+ light: {
140
+ fontWeight: componentTheme.fontWeightLight
141
+ },
142
+ bold: {
143
+ fontWeight: componentTheme.fontWeightBold
144
+ },
145
+ weightRegular: {
146
+ fontWeight: componentTheme.fontWeightRegular
147
+ },
148
+ weightImportant: {
149
+ fontWeight: componentTheme.fontWeightImportant
150
+ }
151
+ };
152
+ const fontSizeVariants = {
153
+ 'x-small': componentTheme.fontSizeXSmall,
154
+ small: componentTheme.fontSizeSmall,
155
+ medium: componentTheme.fontSizeMedium,
156
+ large: componentTheme.fontSizeLarge,
157
+ 'x-large': componentTheme.fontSizeXLarge,
158
+ 'xx-large': componentTheme.fontSizeXXLarge,
159
+ // these are deprecated
160
+ descriptionPage: componentTheme.descriptionPage.fontSize,
161
+ descriptionSection: componentTheme.descriptionSection.fontSize,
162
+ content: componentTheme.content.fontSize,
163
+ contentSmall: componentTheme.contentSmall.fontSize,
164
+ legend: componentTheme.legend.fontSize
165
+ };
166
+ const lineHeightVariants = {
167
+ default: {
168
+ lineHeight: componentTheme.lineHeight
169
+ },
170
+ fit: {
171
+ lineHeight: componentTheme.lineHeightFit
172
+ },
173
+ condensed: {
174
+ lineHeight: componentTheme.lineHeightCondensed
175
+ },
176
+ double: {
177
+ lineHeight: componentTheme.lineHeightDouble
178
+ },
179
+ lineHeight100: {
180
+ lineHeight: componentTheme.lineHeight100
181
+ },
182
+ lineHeight125: {
183
+ lineHeight: componentTheme.lineHeight125
184
+ },
185
+ lineHeight150: {
186
+ lineHeight: componentTheme.lineHeight150
187
+ }
188
+ };
189
+ const letterSpacingVariants = {
190
+ normal: componentTheme.letterSpacingNormal,
191
+ condensed: componentTheme.letterSpacingCondensed,
192
+ expanded: componentTheme.letterSpacingExpanded
193
+ };
194
+ const calcTextStyles = () => {
195
+ if (variant) {
196
+ return variants[variant];
197
+ }
198
+ return {
199
+ ...(weight ? weightStyle[weight] : {}),
200
+ ...(fontStyle ? {
201
+ fontStyle: fontStyle
202
+ } : {}),
203
+ fontSize: fontSizeVariants[size],
204
+ ...(lineHeight ? lineHeightVariants[lineHeight] : {})
205
+ };
206
+ };
207
+ const baseStyles = {
208
+ '&:focus': {
209
+ outline: 'none'
210
+ },
211
+ ...(color ? colorVariants[color] : {
212
+ color: componentTheme.baseColor
213
+ }),
214
+ ...(wrap === 'break-word' ? wrapStyle : {}),
215
+ letterSpacing: letterSpacingVariants[letterSpacing],
216
+ ...(transform ? {
217
+ textTransform: transform
218
+ } : {}),
219
+ ...calcTextStyles()
220
+ };
221
+ const inputStyles = {
222
+ ...baseStyles,
223
+ outline: 0,
224
+ appearance: 'none',
225
+ boxSizing: 'border-box',
226
+ background: 'none',
227
+ border: 'none',
228
+ borderRadius: 0,
229
+ padding: 0,
230
+ margin: 0,
231
+ color: 'inherit',
232
+ height: 'auto',
233
+ width: '100%',
234
+ lineHeight: 'inherit',
235
+ textAlign: 'start',
236
+ boxShadow: 'none',
237
+ display: 'block'
238
+ };
239
+ return {
240
+ text: {
241
+ label: 'text',
242
+ fontFamily: componentTheme.fontFamily,
243
+ ...baseStyles,
244
+ // NOTE: needs separate groups for `:is()` and `:-webkit-any()` because
245
+ // of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
246
+ '&:is(input)[type]': inputStyles,
247
+ '&:-webkit-any(input)[type]': inputStyles,
248
+ 'sub, sup': {
249
+ fontSize: '75%',
250
+ lineHeight: 0,
251
+ position: 'relative',
252
+ verticalAlign: 'baseline'
253
+ },
254
+ sup: {
255
+ top: '-0.4em'
256
+ },
257
+ sub: {
258
+ bottom: '-0.4em'
259
+ },
260
+ 'pre, code': {
261
+ all: 'initial',
262
+ fontFamily: componentTheme.fontFamilyMonospace
263
+ },
264
+ 'i, em': {
265
+ fontStyle: 'italic'
266
+ },
267
+ 'b, strong': {
268
+ fontWeight: componentTheme.fontWeightBold
269
+ },
270
+ p: {
271
+ display: 'block',
272
+ padding: 0,
273
+ margin: componentTheme.paragraphMargin
274
+ }
275
+ }
276
+ };
277
+ };
278
+ var _default = exports.default = generateStyle;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "Text", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _Text.Text;
9
+ return _v.Text;
10
10
  }
11
11
  });
12
- var _Text = require("./Text");
12
+ var _v = require("../Text/v1");
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Text", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _v.Text;
10
+ }
11
+ });
12
+ var _v = require("../Text/v2");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-text",
3
- "version": "11.6.0",
3
+ "version": "11.6.1-snapshot-129",
4
4
  "description": "A component for styling textual content",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -15,18 +15,18 @@
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
17
  "@babel/runtime": "^7.27.6",
18
- "@instructure/console": "11.6.0",
19
- "@instructure/emotion": "11.6.0",
20
- "@instructure/shared-types": "11.6.0",
21
- "@instructure/ui-color-utils": "11.6.0",
22
- "@instructure/ui-react-utils": "11.6.0"
18
+ "@instructure/console": "11.6.1-snapshot-129",
19
+ "@instructure/emotion": "11.6.1-snapshot-129",
20
+ "@instructure/ui-react-utils": "11.6.1-snapshot-129",
21
+ "@instructure/ui-color-utils": "11.6.1-snapshot-129",
22
+ "@instructure/shared-types": "11.6.1-snapshot-129"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@testing-library/jest-dom": "^6.6.3",
26
26
  "@testing-library/react": "15.0.7",
27
- "@instructure/ui-axe-check": "11.6.0",
28
- "@instructure/ui-babel-preset": "11.6.0",
29
- "@instructure/ui-themes": "11.6.0"
27
+ "@instructure/ui-babel-preset": "11.6.1-snapshot-129",
28
+ "@instructure/ui-themes": "11.6.1-snapshot-129",
29
+ "@instructure/ui-axe-check": "11.6.1-snapshot-129"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": ">=18 <=19"
@@ -36,17 +36,39 @@
36
36
  },
37
37
  "sideEffects": false,
38
38
  "exports": {
39
- ".": {
40
- "types": "./types/index.d.ts",
41
- "import": "./es/index.js",
42
- "require": "./lib/index.js",
43
- "default": "./es/index.js"
44
- },
45
39
  "./lib/*": "./lib/*",
46
40
  "./es/*": "./es/*",
47
41
  "./types/*": "./types/*",
48
42
  "./package.json": "./package.json",
49
- "./src/*": "./src/*"
43
+ "./src/*": "./src/*",
44
+ ".": {
45
+ "src": "./src/exports/a.ts",
46
+ "types": "./types/exports/a.d.ts",
47
+ "import": "./es/exports/a.js",
48
+ "require": "./lib/exports/a.js",
49
+ "default": "./es/exports/a.js"
50
+ },
51
+ "./v11_6": {
52
+ "src": "./src/exports/a.ts",
53
+ "types": "./types/exports/a.d.ts",
54
+ "import": "./es/exports/a.js",
55
+ "require": "./lib/exports/a.js",
56
+ "default": "./es/exports/a.js"
57
+ },
58
+ "./v11_7": {
59
+ "src": "./src/exports/b.ts",
60
+ "types": "./types/exports/b.d.ts",
61
+ "import": "./es/exports/b.js",
62
+ "require": "./lib/exports/b.js",
63
+ "default": "./es/exports/b.js"
64
+ },
65
+ "./latest": {
66
+ "src": "./src/exports/b.ts",
67
+ "types": "./types/exports/b.d.ts",
68
+ "import": "./es/exports/b.js",
69
+ "require": "./lib/exports/b.js",
70
+ "default": "./es/exports/b.js"
71
+ }
50
72
  },
51
73
  "scripts": {
52
74
  "lint": "ui-scripts lint",
@@ -26,7 +26,7 @@ import { Component } from 'react'
26
26
 
27
27
  import { passthroughProps, getElementType } from '@instructure/ui-react-utils'
28
28
 
29
- import { withStyle } from '@instructure/emotion'
29
+ import { withStyleLegacy as withStyle } from '@instructure/emotion'
30
30
  import generateStyle from './styles'
31
31
  import generateComponentTheme from './theme'
32
32
  import type { TextProps } from './props'
@@ -0,0 +1,200 @@
1
+ ---
2
+ describes: Text
3
+ ---
4
+
5
+ A component for styling textual content
6
+
7
+ ## Variant
8
+
9
+ Variant takes care of - almost - all use-cases when it comes to texts on pages. Their name reflects the places they meant to be used. It sets `font family`, `size`, `weight` and `lineHeight`.
10
+
11
+ > We recommend using `variant` instead of setting values directly.
12
+
13
+ NOTE: when `variant` is set, `size`, `weight`, `fontStyle` and `lineHeight` props are ignored
14
+
15
+ ```js
16
+ ---
17
+ type: example
18
+ ---
19
+ <div>
20
+ <Text variant="descriptionPage"> descriptionPage </Text><br/>
21
+ <Text variant="descriptionSection"> descriptionSection </Text><br/>
22
+ <Text variant="content"> content </Text><br/>
23
+ <Text variant="contentImportant"> contentImportant </Text><br/>
24
+ <Text variant="contentQuote"> contentQuote </Text><br/>
25
+ <Text variant="contentSmall"> contentSmall </Text><br/>
26
+ <Text variant="legend"> legend </Text><br/>
27
+ </div>
28
+ ```
29
+
30
+ ### Text colors
31
+
32
+ ```js
33
+ ---
34
+ type: example
35
+ ---
36
+ <div>
37
+ <Text color="primary">I&#39;m primary text</Text><br/>
38
+ <Text color="secondary">I&#39;m secondary text</Text><br/>
39
+ <Text color="brand">I&#39;m brand text</Text><br />
40
+ <Text color="success">I&#39;m success text</Text><br/>
41
+ <Text color="warning">I&#39;m warning text</Text><br />
42
+ <Text color="danger">I&#39;m danger text</Text><br />
43
+ <Text color="ai-highlight">I&#39;m an ai-highlight text</Text><br />
44
+ <View background="primary-inverse">
45
+ <Text color="primary-inverse">I&#39;m primary-inverse text</Text><br />
46
+ <Text color="secondary-inverse">I&#39;m secondary-inverse text</Text><br />
47
+ </View>
48
+ <View background="success">
49
+ <Text color="primary-on">I&#39;m primary-on text</Text><br />
50
+ <Text color="secondary-on">I&#39;m secondary-on text</Text><br />
51
+ </View>
52
+ </div>
53
+ ```
54
+
55
+ ### Font sizes
56
+
57
+ ```js
58
+ ---
59
+ type: example
60
+ ---
61
+ <div>
62
+ <Text size='x-small'>x-small</Text><br/>
63
+ <Text size='small'>small</Text><br/>
64
+ <Text size='medium'>medium</Text><br/>
65
+ <Text size='large'>large</Text><br/>
66
+ <Text size='x-large'>x-large</Text><br/>
67
+ <Text size='xx-large'>xx-large</Text>
68
+ </div>
69
+ ```
70
+
71
+ ### Font weights
72
+
73
+ ```js
74
+ ---
75
+ type: example
76
+ ---
77
+ <div>
78
+ <Text weight="light">light text</Text><br/>
79
+ <Text weight="normal">normal text</Text><br/>
80
+ <Text weight="bold">bold text</Text>
81
+ </div>
82
+ ```
83
+
84
+ ### Font styles
85
+
86
+ ```js
87
+ ---
88
+ type: example
89
+ ---
90
+ <div>
91
+ <Text fontStyle="italic">I&#39;m italic text</Text><br/>
92
+ <Text>I&#39;m normal text</Text>
93
+ </div>
94
+ ```
95
+
96
+ ### Line heights
97
+
98
+ ```js
99
+ ---
100
+ type: example
101
+ ---
102
+ <div>
103
+ <Text lineHeight="default">
104
+ <p><b>default:</b> {lorem.paragraph()}</p>
105
+ </Text>
106
+ <Text lineHeight="fit">
107
+ <p><b>fit:</b> {lorem.paragraph()}</p>
108
+ </Text>
109
+ <Text lineHeight="condensed">
110
+ <p><b>condensed:</b> {lorem.paragraph()}</p>
111
+ </Text>
112
+ <Text lineHeight="double">
113
+ <p><b>double:</b> {lorem.paragraph()}</p>
114
+ </Text>
115
+ </div>
116
+ ```
117
+
118
+ ### Text transformations
119
+
120
+ ```js
121
+ ---
122
+ type: example
123
+ ---
124
+ <div>
125
+ <Text transform="capitalize">I&#39;m capitalized text</Text><br/>
126
+ <Text transform="uppercase">I&#39;m uppercase text</Text><br/>
127
+ <Text transform="lowercase">I&#39;M LOWERCASE TEXT</Text><br/>
128
+ </div>
129
+ ```
130
+
131
+ ### Letter-spacing
132
+
133
+ ```js
134
+ ---
135
+ type: example
136
+ ---
137
+ <div>
138
+ <Text letterSpacing="normal">I&#39;m normal text</Text><br/>
139
+ <Text letterSpacing="condensed">I&#39;m condensed text</Text><br/>
140
+ <Text letterSpacing="expanded" transform="uppercase">I&#39;m expanded uppercase text</Text><br/>
141
+ </div>
142
+ ```
143
+
144
+ ### Wrap
145
+
146
+ Use `wrap="break-word"` to force breaking in long strings that would otherwise
147
+ exceed the bounds of their containers.
148
+
149
+ ```js
150
+ ---
151
+ type: example
152
+ ---
153
+ <div>
154
+ <View as="div" maxWidth="300px" margin="none none small" debug>
155
+ <Text>
156
+ superlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstring
157
+ </Text>
158
+ </View>
159
+ <View as="div" maxWidth="300px" debug>
160
+ <Text wrap="break-word">
161
+ superlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstringsuperlongstring
162
+ </Text>
163
+ </View>
164
+ </div>
165
+ ```
166
+
167
+ ### Element styles
168
+
169
+ You can use simple HTML tags to style your text.
170
+
171
+ ```js
172
+ ---
173
+ type: example
174
+ ---
175
+ <Text>
176
+ <b>bold </b>
177
+ <strong>strong </strong>
178
+ <i>italic </i>
179
+ <em>emphasis </em>
180
+ <pre>preformatted </pre>
181
+ <code>code </code><br/>
182
+ This <sup>sup</sup> normal <sub>sub </sub> text.
183
+ </Text>
184
+ ```
185
+
186
+ ### DEPRECATED legacy values
187
+
188
+ Multiple values from `size`, `weight` and `lineHeight` are deprecated, but still supported for backward compatibility reasons. Please only use the above listed, semantic values.
189
+
190
+ Deprecated `size` values:
191
+
192
+ `descriptionPage`, `descriptionSection`, `content`, `contentSmall`, `legend`
193
+
194
+ Deprecated `weight` values:
195
+
196
+ `weightRegular`, `weightImportant`
197
+
198
+ Deprecated `lineHeight` values:
199
+
200
+ `lineHeight100`, `lineHeight125`, `lineHeight150`
@@ -0,0 +1,106 @@
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 { Component } from 'react'
26
+
27
+ import { passthroughProps, getElementType } from '@instructure/ui-react-utils'
28
+
29
+ import { withStyle } from '@instructure/emotion'
30
+ import generateStyle from './styles'
31
+ import type { TextProps } from './props'
32
+ import { allowedProps } from './props'
33
+
34
+ /**
35
+ ---
36
+ category: components
37
+ ---
38
+ **/
39
+ @withStyle(generateStyle)
40
+ class Text extends Component<TextProps> {
41
+ static readonly componentId = 'Text'
42
+
43
+ static allowedProps = allowedProps
44
+
45
+ static defaultProps = {
46
+ as: 'span',
47
+ wrap: 'normal',
48
+ size: 'medium',
49
+ letterSpacing: 'normal',
50
+ children: null
51
+ } as const
52
+
53
+ ref: Element | null = null
54
+
55
+ handleRef = (el: Element | null) => {
56
+ this.ref = el
57
+ const { elementRef } = this.props
58
+ if (typeof elementRef === 'function') {
59
+ elementRef(el)
60
+ }
61
+ }
62
+
63
+ checkProps() {
64
+ const { variant, lineHeight, weight, fontStyle } = this.props
65
+ if (variant) {
66
+ if (lineHeight) {
67
+ console.warn("[Text]: Don't use 'lineHeight' with 'variant' ")
68
+ }
69
+ if (weight) {
70
+ console.warn("[Text]: Don't use 'weight' with 'variant' ")
71
+ }
72
+ if (fontStyle) {
73
+ console.warn("[Text]: Don't use 'fontStyle' with 'variant' ")
74
+ }
75
+ }
76
+ }
77
+
78
+ componentDidMount() {
79
+ this.props.makeStyles?.()
80
+ this.checkProps()
81
+ }
82
+
83
+ componentDidUpdate() {
84
+ this.props.makeStyles?.()
85
+ this.checkProps()
86
+ }
87
+
88
+ render() {
89
+ const { children } = this.props
90
+
91
+ const ElementType = getElementType(Text, this.props)
92
+
93
+ return (
94
+ <ElementType
95
+ {...passthroughProps(this.props)}
96
+ css={this.props.styles?.text}
97
+ ref={this.handleRef}
98
+ >
99
+ {children}
100
+ </ElementType>
101
+ )
102
+ }
103
+ }
104
+
105
+ export default Text
106
+ export { Text }