@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,136 @@
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 from 'react'
26
+ import type {
27
+ AsElementType,
28
+ TextTheme,
29
+ OtherHTMLAttributes
30
+ } from '@instructure/shared-types'
31
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
32
+
33
+ type TextOwnProps = {
34
+ /**
35
+ * the element type to render as
36
+ */
37
+ as?: AsElementType
38
+ /**
39
+ * Color of the text
40
+ */
41
+ color?:
42
+ | 'primary'
43
+ | 'secondary'
44
+ | 'brand'
45
+ | 'success'
46
+ | 'danger'
47
+ | 'warning'
48
+ | 'primary-inverse'
49
+ | 'secondary-inverse'
50
+ | 'primary-on' // used on colored surfaces like warning, same color in dark and light themes
51
+ | 'secondary-on' // used on colored surfaces like warning, same color in dark and light themes
52
+ | 'ai-highlight'
53
+ /**
54
+ * Provides a reference to the underlying HTML element
55
+ */
56
+ elementRef?: (element: Element | null) => void
57
+ fontStyle?: 'italic' | 'normal'
58
+ letterSpacing?: 'normal' | 'condensed' | 'expanded'
59
+ /**
60
+ * Line height. Use `variant` if possible instead.
61
+ * `lineHeight100`, `lineHeight125`, `lineHeight150` are deprecated
62
+ */
63
+ lineHeight?:
64
+ | 'default'
65
+ | 'fit'
66
+ | 'condensed'
67
+ | 'double'
68
+ | 'lineHeight100'
69
+ | 'lineHeight125'
70
+ | 'lineHeight150'
71
+ /**
72
+ * Size of the text. Use `variant` if possible instead.
73
+ * `descriptionPage`, `descriptionSection`, `content`, `contentSmall`,
74
+ * `legend` are deprecated
75
+ */
76
+ size?:
77
+ | 'x-small'
78
+ | 'small'
79
+ | 'medium'
80
+ | 'large'
81
+ | 'x-large'
82
+ | 'xx-large'
83
+ | 'descriptionPage'
84
+ | 'descriptionSection'
85
+ | 'content'
86
+ | 'contentSmall'
87
+ | 'legend'
88
+ transform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase'
89
+ /**
90
+ * Sets multiple props at once. (size, fontStyle, lineHeight, weight)
91
+ * If set, these props are not allowed.
92
+ * NOTE: this is the recommended way of setting these values
93
+ */
94
+ variant?:
95
+ | 'descriptionPage'
96
+ | 'descriptionSection'
97
+ | 'content'
98
+ | 'contentImportant'
99
+ | 'contentQuote'
100
+ | 'contentSmall'
101
+ | 'legend'
102
+ /**
103
+ * Weight of the text. Use `variant` if possible instead.
104
+ * `weightRegular`, `weightImportant` are deprecated
105
+ */
106
+ weight?: 'normal' | 'light' | 'bold' | 'weightRegular' | 'weightImportant'
107
+ wrap?: 'normal' | 'break-word'
108
+ children?: React.ReactNode
109
+ }
110
+
111
+ type PropKeys = keyof TextOwnProps
112
+
113
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
114
+
115
+ type TextProps = TextOwnProps &
116
+ WithStyleProps<TextTheme, TextStyle> &
117
+ OtherHTMLAttributes<TextOwnProps>
118
+
119
+ type TextStyle = ComponentStyle<'text'>
120
+ const allowedProps: AllowedPropKeys = [
121
+ 'as',
122
+ 'children',
123
+ 'color',
124
+ 'elementRef',
125
+ 'fontStyle',
126
+ 'letterSpacing',
127
+ 'lineHeight',
128
+ 'size',
129
+ 'transform',
130
+ 'variant',
131
+ 'weight',
132
+ 'wrap'
133
+ ]
134
+
135
+ export type { TextProps, TextStyle }
136
+ export { allowedProps }
@@ -0,0 +1,260 @@
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 type { TextProps, TextStyle } from './props'
26
+ import type { NewComponentTypes } from '@instructure/ui-themes'
27
+ import type { TokenTypographyValueInst } from '@instructure/ui-themes'
28
+
29
+ type StyleParams = {
30
+ color: TextProps['color']
31
+ fontStyle: TextProps['fontStyle']
32
+ lineHeight: TextProps['lineHeight']
33
+ letterSpacing: TextProps['letterSpacing']
34
+ transform: TextProps['transform']
35
+ size: TextProps['size']
36
+ variant: TextProps['variant']
37
+ weight: TextProps['weight']
38
+ wrap: TextProps['wrap']
39
+ }
40
+
41
+ /**
42
+ * ---
43
+ * private: true
44
+ * ---
45
+ * Generates the style object from the theme and provided additional information
46
+ * @param componentTheme The theme variable object.
47
+ * @param params Additional parameters to customize the style.
48
+ * @return The final style object, which will be used in the component
49
+ */
50
+ const generateStyle = (
51
+ componentTheme: NewComponentTypes['Text'],
52
+ params: StyleParams
53
+ ): TextStyle => {
54
+ const {
55
+ color,
56
+ fontStyle,
57
+ lineHeight,
58
+ letterSpacing,
59
+ transform,
60
+ size,
61
+ variant,
62
+ weight,
63
+ wrap
64
+ } = params
65
+
66
+ const variants: Record<
67
+ NonNullable<TextProps['variant']>,
68
+ TokenTypographyValueInst
69
+ > = {
70
+ descriptionPage: {
71
+ fontFamily: componentTheme.descriptionPage.fontFamily,
72
+ fontWeight: componentTheme.descriptionPage.fontWeight,
73
+ fontSize: componentTheme.descriptionPage.fontSize,
74
+ lineHeight: componentTheme.descriptionPage.lineHeight
75
+ },
76
+ descriptionSection: {
77
+ fontFamily: componentTheme.descriptionSection.fontFamily,
78
+ fontWeight: componentTheme.descriptionSection.fontWeight,
79
+ fontSize: componentTheme.descriptionSection.fontSize,
80
+ lineHeight: componentTheme.descriptionSection.lineHeight
81
+ },
82
+ content: {
83
+ fontFamily: componentTheme.content.fontFamily,
84
+ fontWeight: componentTheme.content.fontWeight,
85
+ fontSize: componentTheme.content.fontSize,
86
+ lineHeight: componentTheme.content.lineHeight
87
+ },
88
+ contentImportant: {
89
+ fontFamily: componentTheme.contentImportant.fontFamily,
90
+ fontWeight: componentTheme.contentImportant.fontWeight,
91
+ fontSize: componentTheme.contentImportant.fontSize,
92
+ lineHeight: componentTheme.contentImportant.lineHeight
93
+ },
94
+ contentQuote: {
95
+ fontFamily: componentTheme.contentQuote.fontFamily,
96
+ fontWeight: componentTheme.contentQuote.fontWeight,
97
+ fontSize: componentTheme.contentQuote.fontSize,
98
+ lineHeight: componentTheme.contentQuote.lineHeight
99
+ },
100
+ contentSmall: {
101
+ fontFamily: componentTheme.contentSmall.fontFamily,
102
+ fontWeight: componentTheme.contentSmall.fontWeight,
103
+ fontSize: componentTheme.contentSmall.fontSize,
104
+ lineHeight: componentTheme.contentSmall.lineHeight
105
+ },
106
+ legend: {
107
+ fontFamily: componentTheme.legend.fontFamily,
108
+ fontWeight: componentTheme.legend.fontWeight,
109
+ fontSize: componentTheme.legend.fontSize,
110
+ lineHeight: componentTheme.legend.lineHeight
111
+ }
112
+ }
113
+
114
+ const colorVariants = {
115
+ primary: { color: componentTheme.baseColor },
116
+ secondary: { color: componentTheme.mutedColor },
117
+ 'primary-inverse': { color: componentTheme.inverseColor },
118
+ 'secondary-inverse': { color: componentTheme.inverseColor },
119
+ success: { color: componentTheme.successColor },
120
+ brand: { color: componentTheme.primaryColor },
121
+ danger: { color: componentTheme.errorColor },
122
+ warning: { color: componentTheme.warningColor },
123
+ 'primary-on': { color: componentTheme.baseOnColor },
124
+ 'secondary-on': { color: componentTheme.mutedOnColor },
125
+ 'ai-highlight': {
126
+ color: componentTheme.aiColor,
127
+ background: componentTheme.aiBackgroundColor
128
+ }
129
+ }
130
+
131
+ const wrapStyle = {
132
+ overflowWrap: 'break-word',
133
+ wordBreak: 'break-word',
134
+ hyphens: 'auto'
135
+ }
136
+
137
+ const weightStyle = {
138
+ normal: { fontWeight: componentTheme.fontWeightNormal },
139
+ light: { fontWeight: componentTheme.fontWeightLight },
140
+ bold: { fontWeight: componentTheme.fontWeightBold },
141
+ weightRegular: { fontWeight: componentTheme.fontWeightRegular },
142
+ weightImportant: { fontWeight: componentTheme.fontWeightImportant }
143
+ }
144
+
145
+ const fontSizeVariants = {
146
+ 'x-small': componentTheme.fontSizeXSmall,
147
+ small: componentTheme.fontSizeSmall,
148
+ medium: componentTheme.fontSizeMedium,
149
+ large: componentTheme.fontSizeLarge,
150
+ 'x-large': componentTheme.fontSizeXLarge,
151
+ 'xx-large': componentTheme.fontSizeXXLarge,
152
+ // these are deprecated
153
+ descriptionPage: componentTheme.descriptionPage.fontSize,
154
+ descriptionSection: componentTheme.descriptionSection.fontSize,
155
+ content: componentTheme.content.fontSize,
156
+ contentSmall: componentTheme.contentSmall.fontSize,
157
+ legend: componentTheme.legend.fontSize
158
+ }
159
+
160
+ const lineHeightVariants = {
161
+ default: { lineHeight: componentTheme.lineHeight },
162
+ fit: { lineHeight: componentTheme.lineHeightFit },
163
+ condensed: { lineHeight: componentTheme.lineHeightCondensed },
164
+ double: { lineHeight: componentTheme.lineHeightDouble },
165
+ lineHeight100: { lineHeight: componentTheme.lineHeight100 },
166
+ lineHeight125: { lineHeight: componentTheme.lineHeight125 },
167
+ lineHeight150: { lineHeight: componentTheme.lineHeight150 }
168
+ }
169
+
170
+ const letterSpacingVariants = {
171
+ normal: componentTheme.letterSpacingNormal,
172
+ condensed: componentTheme.letterSpacingCondensed,
173
+ expanded: componentTheme.letterSpacingExpanded
174
+ }
175
+
176
+ const calcTextStyles = () => {
177
+ if (variant) {
178
+ return variants[variant]
179
+ }
180
+ return {
181
+ ...(weight ? weightStyle[weight] : {}),
182
+ ...(fontStyle ? { fontStyle: fontStyle } : {}),
183
+ fontSize: fontSizeVariants[size!],
184
+ ...(lineHeight ? lineHeightVariants[lineHeight] : {})
185
+ }
186
+ }
187
+
188
+ const baseStyles = {
189
+ '&:focus': {
190
+ outline: 'none'
191
+ },
192
+ ...(color ? colorVariants[color] : { color: componentTheme.baseColor }),
193
+ ...(wrap === 'break-word' ? wrapStyle : {}),
194
+ letterSpacing: letterSpacingVariants[letterSpacing!],
195
+ ...(transform ? { textTransform: transform } : {}),
196
+ ...calcTextStyles()
197
+ }
198
+
199
+ const inputStyles = {
200
+ ...baseStyles,
201
+ outline: 0,
202
+ appearance: 'none',
203
+ boxSizing: 'border-box',
204
+ background: 'none',
205
+ border: 'none',
206
+ borderRadius: 0,
207
+ padding: 0,
208
+ margin: 0,
209
+ color: 'inherit',
210
+ height: 'auto',
211
+ width: '100%',
212
+ lineHeight: 'inherit',
213
+ textAlign: 'start',
214
+ boxShadow: 'none',
215
+ display: 'block'
216
+ }
217
+
218
+ return {
219
+ text: {
220
+ label: 'text',
221
+ fontFamily: componentTheme.fontFamily,
222
+ ...baseStyles,
223
+
224
+ // NOTE: needs separate groups for `:is()` and `:-webkit-any()` because
225
+ // of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
226
+ '&:is(input)[type]': inputStyles,
227
+ '&:-webkit-any(input)[type]': inputStyles,
228
+
229
+ 'sub, sup': {
230
+ fontSize: '75%',
231
+ lineHeight: 0,
232
+ position: 'relative',
233
+ verticalAlign: 'baseline'
234
+ },
235
+ sup: {
236
+ top: '-0.4em'
237
+ },
238
+ sub: {
239
+ bottom: '-0.4em'
240
+ },
241
+ 'pre, code': {
242
+ all: 'initial',
243
+ fontFamily: componentTheme.fontFamilyMonospace
244
+ },
245
+ 'i, em': {
246
+ fontStyle: 'italic'
247
+ },
248
+ 'b, strong': {
249
+ fontWeight: componentTheme.fontWeightBold
250
+ },
251
+ p: {
252
+ display: 'block',
253
+ padding: 0,
254
+ margin: componentTheme.paragraphMargin
255
+ }
256
+ }
257
+ }
258
+ }
259
+
260
+ export default generateStyle
@@ -0,0 +1,25 @@
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
+ export { Text } from '../Text/v1'
25
+ export type { TextProps } from '../Text/v1/props'
@@ -0,0 +1,25 @@
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
+ export { Text } from '../Text/v2'
25
+ export type { TextProps } from '../Text/v2/props'