@instructure/ui-text 10.9.1-snapshot-4 → 10.9.1-snapshot-5
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +5 -2
- package/es/Text/__examples__/Text.examples.js +11 -5
- package/es/Text/index.js +20 -4
- package/es/Text/props.js +5 -4
- package/es/Text/styles.js +82 -9
- package/lib/Text/__examples__/Text.examples.js +11 -5
- package/lib/Text/index.js +20 -4
- package/lib/Text/props.js +5 -4
- package/lib/Text/styles.js +82 -9
- package/package.json +10 -10
- package/src/Text/README.md +59 -15
- package/src/Text/__examples__/Text.examples.ts +11 -15
- package/src/Text/index.tsx +20 -0
- package/src/Text/props.ts +66 -6
- package/src/Text/styles.ts +74 -9
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Text/__examples__/Text.examples.d.ts.map +1 -1
- package/types/Text/index.d.ts +9 -6
- package/types/Text/index.d.ts.map +1 -1
- package/types/Text/props.d.ts +9 -3
- package/types/Text/props.d.ts.map +1 -1
- package/types/Text/styles.d.ts.map +1 -1
package/src/Text/index.tsx
CHANGED
@@ -53,12 +53,32 @@ class Text extends Component<TextProps> {
|
|
53
53
|
children: null
|
54
54
|
} as const
|
55
55
|
|
56
|
+
checkProps() {
|
57
|
+
const { variant, size, lineHeight, weight, fontStyle } = this.props
|
58
|
+
if (variant) {
|
59
|
+
if (size) {
|
60
|
+
console.warn("[Text]: Don't use 'size' with 'variant' ")
|
61
|
+
}
|
62
|
+
if (lineHeight) {
|
63
|
+
console.warn("[Text]: Don't use 'lineHeight' with 'variant' ")
|
64
|
+
}
|
65
|
+
if (weight) {
|
66
|
+
console.warn("[Text]: Don't use 'weight' with 'variant' ")
|
67
|
+
}
|
68
|
+
if (fontStyle) {
|
69
|
+
console.warn("[Text]: Don't use 'fontStyle' with 'variant' ")
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
56
74
|
componentDidMount() {
|
57
75
|
this.props.makeStyles?.()
|
76
|
+
this.checkProps()
|
58
77
|
}
|
59
78
|
|
60
79
|
componentDidUpdate() {
|
61
80
|
this.props.makeStyles?.()
|
81
|
+
this.checkProps()
|
62
82
|
}
|
63
83
|
|
64
84
|
render() {
|
package/src/Text/props.ts
CHANGED
@@ -57,10 +57,41 @@ type TextOwnProps = {
|
|
57
57
|
elementRef?: (element: Element | null) => void
|
58
58
|
fontStyle?: 'italic' | 'normal'
|
59
59
|
letterSpacing?: 'normal' | 'condensed' | 'expanded'
|
60
|
-
lineHeight?:
|
61
|
-
|
60
|
+
lineHeight?:
|
61
|
+
| 'default'
|
62
|
+
| 'fit'
|
63
|
+
| 'condensed'
|
64
|
+
| 'double'
|
65
|
+
| 'lineHeight100'
|
66
|
+
| 'lineHeight125'
|
67
|
+
| 'lineHeight150'
|
68
|
+
size?:
|
69
|
+
| 'x-small'
|
70
|
+
| 'small'
|
71
|
+
| 'medium'
|
72
|
+
| 'large'
|
73
|
+
| 'x-large'
|
74
|
+
| 'xx-large'
|
75
|
+
| 'descriptionPage'
|
76
|
+
| 'descriptionSection'
|
77
|
+
| 'content'
|
78
|
+
| 'contentSmall'
|
79
|
+
| 'legend'
|
62
80
|
transform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase'
|
63
|
-
|
81
|
+
/**
|
82
|
+
* Sets multiple props at once. (size, fontStyle, lineHeight, weight)
|
83
|
+
* If set, these props are not allowed.
|
84
|
+
* NOTE: this is the recommended way of setting these values
|
85
|
+
*/
|
86
|
+
variant?:
|
87
|
+
| 'descriptionPage'
|
88
|
+
| 'descriptionSection'
|
89
|
+
| 'content'
|
90
|
+
| 'contentImportant'
|
91
|
+
| 'contentQuote'
|
92
|
+
| 'contentSmall'
|
93
|
+
| 'legend'
|
94
|
+
weight?: 'normal' | 'light' | 'bold' | 'weightRegular' | 'weightImportant'
|
64
95
|
wrap?: 'normal' | 'break-word'
|
65
96
|
children?: React.ReactNode
|
66
97
|
}
|
@@ -91,17 +122,45 @@ const propTypes: PropValidators<PropKeys> = {
|
|
91
122
|
elementRef: PropTypes.func,
|
92
123
|
fontStyle: PropTypes.oneOf(['italic', 'normal']),
|
93
124
|
letterSpacing: PropTypes.oneOf(['normal', 'condensed', 'expanded']),
|
94
|
-
lineHeight: PropTypes.oneOf([
|
125
|
+
lineHeight: PropTypes.oneOf([
|
126
|
+
'default',
|
127
|
+
'fit',
|
128
|
+
'condensed',
|
129
|
+
'double',
|
130
|
+
'lineHeight100',
|
131
|
+
'lineHeight125',
|
132
|
+
'lineHeight150'
|
133
|
+
]),
|
95
134
|
size: PropTypes.oneOf([
|
96
135
|
'x-small',
|
97
136
|
'small',
|
98
137
|
'medium',
|
99
138
|
'large',
|
100
139
|
'x-large',
|
101
|
-
'xx-large'
|
140
|
+
'xx-large',
|
141
|
+
'descriptionPage',
|
142
|
+
'descriptionSection',
|
143
|
+
'content',
|
144
|
+
'contentSmall',
|
145
|
+
'legend'
|
102
146
|
]),
|
103
147
|
transform: PropTypes.oneOf(['none', 'capitalize', 'uppercase', 'lowercase']),
|
104
|
-
|
148
|
+
variant: PropTypes.oneOf([
|
149
|
+
'descriptionPage',
|
150
|
+
'descriptionSection',
|
151
|
+
'content',
|
152
|
+
'contentImportant',
|
153
|
+
'contentQuote',
|
154
|
+
'contentSmall',
|
155
|
+
'legend'
|
156
|
+
]),
|
157
|
+
weight: PropTypes.oneOf([
|
158
|
+
'normal',
|
159
|
+
'light',
|
160
|
+
'bold',
|
161
|
+
'weightRegular',
|
162
|
+
'weightImportant'
|
163
|
+
]),
|
105
164
|
wrap: PropTypes.oneOf(['normal', 'break-word'])
|
106
165
|
}
|
107
166
|
|
@@ -115,6 +174,7 @@ const allowedProps: AllowedPropKeys = [
|
|
115
174
|
'lineHeight',
|
116
175
|
'size',
|
117
176
|
'transform',
|
177
|
+
'variant',
|
118
178
|
'weight',
|
119
179
|
'wrap'
|
120
180
|
]
|
package/src/Text/styles.ts
CHANGED
@@ -47,9 +47,55 @@ const generateStyle = (
|
|
47
47
|
transform,
|
48
48
|
lineHeight,
|
49
49
|
letterSpacing,
|
50
|
-
color
|
50
|
+
color,
|
51
|
+
variant
|
51
52
|
} = props
|
52
53
|
|
54
|
+
const variants: Record<NonNullable<TextProps['variant']>, object> = {
|
55
|
+
descriptionPage: {
|
56
|
+
fontStyle: 'normal',
|
57
|
+
fontWeight: componentTheme.weightRegular,
|
58
|
+
fontSize: componentTheme.descriptionPage,
|
59
|
+
lineHeight: componentTheme.lineHeight150
|
60
|
+
},
|
61
|
+
descriptionSection: {
|
62
|
+
fontStyle: 'normal',
|
63
|
+
fontWeight: componentTheme.weightRegular,
|
64
|
+
fontSize: componentTheme.descriptionSection,
|
65
|
+
lineHeight: componentTheme.lineHeight150
|
66
|
+
},
|
67
|
+
content: {
|
68
|
+
fontStyle: 'normal',
|
69
|
+
fontWeight: componentTheme.weightRegular,
|
70
|
+
fontSize: componentTheme.content,
|
71
|
+
lineHeight: componentTheme.lineHeight150
|
72
|
+
},
|
73
|
+
contentImportant: {
|
74
|
+
fontStyle: 'normal',
|
75
|
+
fontWeight: componentTheme.weightImportant,
|
76
|
+
fontSize: componentTheme.content,
|
77
|
+
lineHeight: componentTheme.lineHeight150
|
78
|
+
},
|
79
|
+
contentQuote: {
|
80
|
+
fontStyle: 'italic',
|
81
|
+
fontWeight: componentTheme.weightRegular,
|
82
|
+
fontSize: componentTheme.content,
|
83
|
+
lineHeight: componentTheme.lineHeight150
|
84
|
+
},
|
85
|
+
contentSmall: {
|
86
|
+
fontStyle: 'normal',
|
87
|
+
fontWeight: componentTheme.weightRegular,
|
88
|
+
fontSize: componentTheme.contentSmall,
|
89
|
+
lineHeight: componentTheme.lineHeight150
|
90
|
+
},
|
91
|
+
legend: {
|
92
|
+
fontStyle: 'normal',
|
93
|
+
fontWeight: componentTheme.weightRegular,
|
94
|
+
fontSize: componentTheme.legend,
|
95
|
+
lineHeight: componentTheme.lineHeight150
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
53
99
|
const colorVariants = {
|
54
100
|
primary: { color: componentTheme.primaryColor },
|
55
101
|
secondary: { color: componentTheme.secondaryColor },
|
@@ -70,7 +116,9 @@ const generateStyle = (
|
|
70
116
|
const weightStyle = {
|
71
117
|
normal: { fontWeight: componentTheme.fontWeightNormal },
|
72
118
|
light: { fontWeight: componentTheme.fontWeightLight },
|
73
|
-
bold: { fontWeight: componentTheme.fontWeightBold }
|
119
|
+
bold: { fontWeight: componentTheme.fontWeightBold },
|
120
|
+
weightRegular: { fontWeight: componentTheme.weightRegular },
|
121
|
+
weightImportant: { fontWeight: componentTheme.weightImportant }
|
74
122
|
}
|
75
123
|
|
76
124
|
const fontSizeVariants = {
|
@@ -79,14 +127,22 @@ const generateStyle = (
|
|
79
127
|
medium: componentTheme.fontSizeMedium,
|
80
128
|
large: componentTheme.fontSizeLarge,
|
81
129
|
'x-large': componentTheme.fontSizeXLarge,
|
82
|
-
'xx-large': componentTheme.fontSizeXXLarge
|
130
|
+
'xx-large': componentTheme.fontSizeXXLarge,
|
131
|
+
descriptionPage: componentTheme.descriptionPage,
|
132
|
+
descriptionSection: componentTheme.descriptionSection,
|
133
|
+
content: componentTheme.content,
|
134
|
+
contentSmall: componentTheme.contentSmall,
|
135
|
+
legend: componentTheme.legend
|
83
136
|
}
|
84
137
|
|
85
138
|
const lineHeightVariants = {
|
86
139
|
default: { lineHeight: componentTheme.lineHeight },
|
87
140
|
fit: { lineHeight: componentTheme.lineHeightFit },
|
88
141
|
condensed: { lineHeight: componentTheme.lineHeightCondensed },
|
89
|
-
double: { lineHeight: componentTheme.lineHeightDouble }
|
142
|
+
double: { lineHeight: componentTheme.lineHeightDouble },
|
143
|
+
lineHeight100: { lineHeight: componentTheme.lineHeight100 },
|
144
|
+
lineHeight125: { lineHeight: componentTheme.lineHeight125 },
|
145
|
+
lineHeight150: { lineHeight: componentTheme.lineHeight150 }
|
90
146
|
}
|
91
147
|
|
92
148
|
const letterSpacingVariants = {
|
@@ -95,18 +151,27 @@ const generateStyle = (
|
|
95
151
|
expanded: componentTheme.letterSpacingExpanded
|
96
152
|
}
|
97
153
|
|
154
|
+
const calcTextStyles = () => {
|
155
|
+
if (variant) {
|
156
|
+
return variants[variant]
|
157
|
+
}
|
158
|
+
return {
|
159
|
+
...(weight ? weightStyle[weight] : {}),
|
160
|
+
...(fontStyle ? { fontStyle: fontStyle } : {}),
|
161
|
+
fontSize: fontSizeVariants[size!],
|
162
|
+
...(lineHeight ? lineHeightVariants[lineHeight] : {})
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
98
166
|
const baseStyles = {
|
99
167
|
'&:focus': {
|
100
168
|
outline: 'none'
|
101
169
|
},
|
102
170
|
...(color ? colorVariants[color] : {}),
|
103
171
|
...(wrap === 'break-word' ? wrapStyle : {}),
|
104
|
-
...(weight ? weightStyle[weight] : {}),
|
105
|
-
...(fontStyle ? { fontStyle: fontStyle } : {}),
|
106
|
-
fontSize: fontSizeVariants[size!],
|
107
|
-
...(lineHeight ? lineHeightVariants[lineHeight] : {}),
|
108
172
|
letterSpacing: letterSpacingVariants[letterSpacing!],
|
109
|
-
...(transform ? { textTransform: transform } : {})
|
173
|
+
...(transform ? { textTransform: transform } : {}),
|
174
|
+
...calcTextStyles()
|
110
175
|
}
|
111
176
|
|
112
177
|
const inputStyles = {
|