@instructure/ui-heading 10.9.1-snapshot-4 → 10.10.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 +5 -2
- package/es/Heading/__examples__/Heading.examples.js +4 -2
- package/es/Heading/index.js +45 -15
- package/es/Heading/props.js +3 -2
- package/es/Heading/styles.js +65 -2
- package/es/Heading/theme.js +1 -0
- package/lib/Heading/__examples__/Heading.examples.js +4 -2
- package/lib/Heading/index.js +45 -15
- package/lib/Heading/props.js +3 -2
- package/lib/Heading/styles.js +65 -2
- package/lib/Heading/theme.js +1 -0
- package/package.json +12 -12
- package/src/Heading/README.md +26 -5
- package/src/Heading/__examples__/Heading.examples.ts +5 -2
- package/src/Heading/index.tsx +37 -1
- package/src/Heading/props.ts +30 -2
- package/src/Heading/styles.ts +65 -2
- package/src/Heading/theme.ts +2 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Heading/__examples__/Heading.examples.d.ts.map +1 -1
- package/types/Heading/index.d.ts +3 -0
- package/types/Heading/index.d.ts.map +1 -1
- package/types/Heading/props.d.ts +5 -0
- package/types/Heading/props.d.ts.map +1 -1
- package/types/Heading/styles.d.ts.map +1 -1
- package/types/Heading/theme.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
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
|
-
|
|
6
|
+
# [10.10.0](https://github.com/instructure/instructure-ui/compare/v10.9.0...v10.10.0) (2024-12-18)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **many:** add new Typography tokens and update text and heading ([a09fa0f](https://github.com/instructure/instructure-ui/commit/a09fa0f9ee3b92e8b20415e1d57f5f465526936c))
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
|
@@ -23,9 +23,11 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
export default {
|
|
26
|
-
sectionProp: '
|
|
26
|
+
sectionProp: 'variant',
|
|
27
27
|
propValues: {
|
|
28
|
-
color: ['primary', 'secondary', 'primary-inverse', 'secondary-inverse', 'inherit']
|
|
28
|
+
color: ['primary', 'secondary', 'primary-inverse', 'secondary-inverse', 'inherit'],
|
|
29
|
+
level: [void 0],
|
|
30
|
+
as: [void 0]
|
|
29
31
|
},
|
|
30
32
|
getComponentProps: () => {
|
|
31
33
|
return {
|
package/es/Heading/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
-
const _excluded = ["border", "children", "color", "level", "margin", "elementRef", "makeStyles"];
|
|
2
|
+
const _excluded = ["border", "children", "color", "level", "margin", "elementRef", "makeStyles", "variant"];
|
|
3
3
|
var _dec, _dec2, _class, _Heading;
|
|
4
4
|
/*
|
|
5
5
|
* The MIT License (MIT)
|
|
@@ -33,6 +33,19 @@ import { withStyle, jsx } from '@instructure/emotion';
|
|
|
33
33
|
import generateStyle from './styles';
|
|
34
34
|
import generateComponentTheme from './theme';
|
|
35
35
|
import { propTypes, allowedProps } from './props';
|
|
36
|
+
const variantLevels = {
|
|
37
|
+
titlePageDesktop: 'h1',
|
|
38
|
+
titlePageMobile: 'h1',
|
|
39
|
+
titleSection: 'h2',
|
|
40
|
+
titleCardSection: 'h2',
|
|
41
|
+
titleModule: 'h3',
|
|
42
|
+
titleCardLarge: 'h4',
|
|
43
|
+
titleCardRegular: 'h4',
|
|
44
|
+
titleCardMini: 'h4',
|
|
45
|
+
label: 'h5',
|
|
46
|
+
labelInline: 'h5'
|
|
47
|
+
};
|
|
48
|
+
|
|
36
49
|
/**
|
|
37
50
|
---
|
|
38
51
|
category: components
|
|
@@ -50,26 +63,43 @@ let Heading = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 =
|
|
|
50
63
|
}
|
|
51
64
|
};
|
|
52
65
|
}
|
|
66
|
+
checkProps() {
|
|
67
|
+
const _this$props = this.props,
|
|
68
|
+
variant = _this$props.variant,
|
|
69
|
+
level = _this$props.level,
|
|
70
|
+
as = _this$props.as;
|
|
71
|
+
if (variant) {
|
|
72
|
+
if (level) {}
|
|
73
|
+
if (as) {}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
53
76
|
componentDidMount() {
|
|
54
|
-
var _this$props$makeStyle, _this$
|
|
55
|
-
(_this$props$makeStyle = (_this$
|
|
77
|
+
var _this$props$makeStyle, _this$props2;
|
|
78
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
79
|
+
this.checkProps();
|
|
56
80
|
}
|
|
57
81
|
componentDidUpdate() {
|
|
58
|
-
var _this$props$makeStyle2, _this$
|
|
59
|
-
(_this$props$makeStyle2 = (_this$
|
|
82
|
+
var _this$props$makeStyle2, _this$props3;
|
|
83
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
84
|
+
this.checkProps();
|
|
60
85
|
}
|
|
61
86
|
render() {
|
|
62
87
|
var _this$props$styles;
|
|
63
|
-
const _this$
|
|
64
|
-
border = _this$
|
|
65
|
-
children = _this$
|
|
66
|
-
color = _this$
|
|
67
|
-
level = _this$
|
|
68
|
-
margin = _this$
|
|
69
|
-
elementRef = _this$
|
|
70
|
-
makeStyles = _this$
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
const _this$props4 = this.props,
|
|
89
|
+
border = _this$props4.border,
|
|
90
|
+
children = _this$props4.children,
|
|
91
|
+
color = _this$props4.color,
|
|
92
|
+
level = _this$props4.level,
|
|
93
|
+
margin = _this$props4.margin,
|
|
94
|
+
elementRef = _this$props4.elementRef,
|
|
95
|
+
makeStyles = _this$props4.makeStyles,
|
|
96
|
+
variant = _this$props4.variant,
|
|
97
|
+
props = _objectWithoutProperties(_this$props4, _excluded);
|
|
98
|
+
const propsForGetElementType = variant ? {} : this.props;
|
|
99
|
+
const ElementType = getElementType(Heading, propsForGetElementType, () => {
|
|
100
|
+
if (variant) {
|
|
101
|
+
return variantLevels[variant];
|
|
102
|
+
}
|
|
73
103
|
if (level === 'reset') {
|
|
74
104
|
return 'span';
|
|
75
105
|
} else {
|
package/es/Heading/props.js
CHANGED
|
@@ -32,7 +32,8 @@ const propTypes = {
|
|
|
32
32
|
level: PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'reset']),
|
|
33
33
|
as: PropTypes.elementType,
|
|
34
34
|
margin: ThemeablePropTypes.spacing,
|
|
35
|
-
elementRef: PropTypes.func
|
|
35
|
+
elementRef: PropTypes.func,
|
|
36
|
+
variant: PropTypes.oneOf(['titlePageDesktop', 'titlePageMobile', 'titleSection', 'titleCardSection', 'titleModule', 'titleCardLarge', 'titleCardRegular', 'titleCardMini', 'label', 'labelInline'])
|
|
36
37
|
};
|
|
37
|
-
const allowedProps = ['border', 'children', 'color', 'level', 'as', 'margin', 'elementRef'];
|
|
38
|
+
const allowedProps = ['border', 'children', 'color', 'level', 'as', 'margin', 'elementRef', 'variant'];
|
|
38
39
|
export { propTypes, allowedProps };
|
package/es/Heading/styles.js
CHANGED
|
@@ -35,7 +35,70 @@
|
|
|
35
35
|
const generateStyle = (componentTheme, props) => {
|
|
36
36
|
const level = props.level,
|
|
37
37
|
color = props.color,
|
|
38
|
-
border = props.border
|
|
38
|
+
border = props.border,
|
|
39
|
+
variant = props.variant;
|
|
40
|
+
const variants = {
|
|
41
|
+
titlePageDesktop: {
|
|
42
|
+
fontStyle: 'normal',
|
|
43
|
+
fontWeight: componentTheme.weightImportant,
|
|
44
|
+
fontSize: componentTheme.titlePageDesktop,
|
|
45
|
+
lineHeight: componentTheme.lineHeight125
|
|
46
|
+
},
|
|
47
|
+
titlePageMobile: {
|
|
48
|
+
fontStyle: 'normal',
|
|
49
|
+
fontWeight: componentTheme.weightImportant,
|
|
50
|
+
fontSize: componentTheme.titlePageMobile,
|
|
51
|
+
lineHeight: componentTheme.lineHeight125
|
|
52
|
+
},
|
|
53
|
+
titleSection: {
|
|
54
|
+
fontStyle: 'normal',
|
|
55
|
+
fontWeight: componentTheme.weightImportant,
|
|
56
|
+
fontSize: componentTheme.titleSection,
|
|
57
|
+
lineHeight: componentTheme.lineHeight125
|
|
58
|
+
},
|
|
59
|
+
titleCardSection: {
|
|
60
|
+
fontStyle: 'normal',
|
|
61
|
+
fontWeight: componentTheme.weightImportant,
|
|
62
|
+
fontSize: componentTheme.titleSection,
|
|
63
|
+
lineHeight: componentTheme.lineHeight125
|
|
64
|
+
},
|
|
65
|
+
titleModule: {
|
|
66
|
+
fontStyle: 'normal',
|
|
67
|
+
fontWeight: componentTheme.weightImportant,
|
|
68
|
+
fontSize: componentTheme.titleModule,
|
|
69
|
+
lineHeight: componentTheme.lineHeight125
|
|
70
|
+
},
|
|
71
|
+
titleCardLarge: {
|
|
72
|
+
fontStyle: 'normal',
|
|
73
|
+
fontWeight: componentTheme.weightImportant,
|
|
74
|
+
fontSize: componentTheme.titleCardLarge,
|
|
75
|
+
lineHeight: componentTheme.lineHeight125
|
|
76
|
+
},
|
|
77
|
+
titleCardRegular: {
|
|
78
|
+
fontStyle: 'normal',
|
|
79
|
+
fontWeight: componentTheme.weightImportant,
|
|
80
|
+
fontSize: componentTheme.titleCardRegular,
|
|
81
|
+
lineHeight: componentTheme.lineHeight125
|
|
82
|
+
},
|
|
83
|
+
titleCardMini: {
|
|
84
|
+
fontStyle: 'normal',
|
|
85
|
+
fontWeight: componentTheme.weightImportant,
|
|
86
|
+
fontSize: componentTheme.titleCardMini,
|
|
87
|
+
lineHeight: componentTheme.lineHeight125
|
|
88
|
+
},
|
|
89
|
+
label: {
|
|
90
|
+
fontStyle: 'normal',
|
|
91
|
+
fontWeight: componentTheme.weightImportant,
|
|
92
|
+
fontSize: componentTheme.label,
|
|
93
|
+
lineHeight: componentTheme.lineHeight125
|
|
94
|
+
},
|
|
95
|
+
labelInline: {
|
|
96
|
+
fontStyle: 'normal',
|
|
97
|
+
fontWeight: componentTheme.weightImportant,
|
|
98
|
+
fontSize: componentTheme.label,
|
|
99
|
+
lineHeight: componentTheme.lineHeight150
|
|
100
|
+
}
|
|
101
|
+
};
|
|
39
102
|
const levelStyles = {
|
|
40
103
|
h1: {
|
|
41
104
|
fontFamily: componentTheme.h1FontFamily,
|
|
@@ -126,7 +189,7 @@ const generateStyle = (componentTheme, props) => {
|
|
|
126
189
|
// NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
|
|
127
190
|
'&:is(input)[type]': inputStyles,
|
|
128
191
|
'&:-webkit-any(input)[type]': inputStyles,
|
|
129
|
-
...levelStyles[level],
|
|
192
|
+
...(variant ? variants[variant] : levelStyles[level]),
|
|
130
193
|
...colorStyles[color],
|
|
131
194
|
...borderStyles[border]
|
|
132
195
|
}
|
package/es/Heading/theme.js
CHANGED
|
@@ -50,6 +50,7 @@ const generateComponentTheme = theme => {
|
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
const componentVariables = {
|
|
53
|
+
...typography,
|
|
53
54
|
lineHeight: typography === null || typography === void 0 ? void 0 : typography.lineHeightCondensed,
|
|
54
55
|
h1FontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeXXLarge,
|
|
55
56
|
h1FontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightBold,
|
|
@@ -28,9 +28,11 @@ exports.default = void 0;
|
|
|
28
28
|
* SOFTWARE.
|
|
29
29
|
*/
|
|
30
30
|
var _default = exports.default = {
|
|
31
|
-
sectionProp: '
|
|
31
|
+
sectionProp: 'variant',
|
|
32
32
|
propValues: {
|
|
33
|
-
color: ['primary', 'secondary', 'primary-inverse', 'secondary-inverse', 'inherit']
|
|
33
|
+
color: ['primary', 'secondary', 'primary-inverse', 'secondary-inverse', 'inherit'],
|
|
34
|
+
level: [void 0],
|
|
35
|
+
as: [void 0]
|
|
34
36
|
},
|
|
35
37
|
getComponentProps: () => {
|
|
36
38
|
return {
|
package/lib/Heading/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var _emotion = require("@instructure/emotion");
|
|
|
15
15
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
16
16
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
17
17
|
var _props = require("./props");
|
|
18
|
-
const _excluded = ["border", "children", "color", "level", "margin", "elementRef", "makeStyles"];
|
|
18
|
+
const _excluded = ["border", "children", "color", "level", "margin", "elementRef", "makeStyles", "variant"];
|
|
19
19
|
var _dec, _dec2, _class, _Heading;
|
|
20
20
|
/*
|
|
21
21
|
* The MIT License (MIT)
|
|
@@ -41,6 +41,19 @@ var _dec, _dec2, _class, _Heading;
|
|
|
41
41
|
* SOFTWARE.
|
|
42
42
|
*/
|
|
43
43
|
/** @jsx jsx */
|
|
44
|
+
const variantLevels = {
|
|
45
|
+
titlePageDesktop: 'h1',
|
|
46
|
+
titlePageMobile: 'h1',
|
|
47
|
+
titleSection: 'h2',
|
|
48
|
+
titleCardSection: 'h2',
|
|
49
|
+
titleModule: 'h3',
|
|
50
|
+
titleCardLarge: 'h4',
|
|
51
|
+
titleCardRegular: 'h4',
|
|
52
|
+
titleCardMini: 'h4',
|
|
53
|
+
label: 'h5',
|
|
54
|
+
labelInline: 'h5'
|
|
55
|
+
};
|
|
56
|
+
|
|
44
57
|
/**
|
|
45
58
|
---
|
|
46
59
|
category: components
|
|
@@ -58,26 +71,43 @@ let Heading = exports.Heading = (_dec = (0, _emotion.withStyle)(_styles.default,
|
|
|
58
71
|
}
|
|
59
72
|
};
|
|
60
73
|
}
|
|
74
|
+
checkProps() {
|
|
75
|
+
const _this$props = this.props,
|
|
76
|
+
variant = _this$props.variant,
|
|
77
|
+
level = _this$props.level,
|
|
78
|
+
as = _this$props.as;
|
|
79
|
+
if (variant) {
|
|
80
|
+
if (level) {}
|
|
81
|
+
if (as) {}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
61
84
|
componentDidMount() {
|
|
62
|
-
var _this$props$makeStyle, _this$
|
|
63
|
-
(_this$props$makeStyle = (_this$
|
|
85
|
+
var _this$props$makeStyle, _this$props2;
|
|
86
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
87
|
+
this.checkProps();
|
|
64
88
|
}
|
|
65
89
|
componentDidUpdate() {
|
|
66
|
-
var _this$props$makeStyle2, _this$
|
|
67
|
-
(_this$props$makeStyle2 = (_this$
|
|
90
|
+
var _this$props$makeStyle2, _this$props3;
|
|
91
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
92
|
+
this.checkProps();
|
|
68
93
|
}
|
|
69
94
|
render() {
|
|
70
95
|
var _this$props$styles;
|
|
71
|
-
const _this$
|
|
72
|
-
border = _this$
|
|
73
|
-
children = _this$
|
|
74
|
-
color = _this$
|
|
75
|
-
level = _this$
|
|
76
|
-
margin = _this$
|
|
77
|
-
elementRef = _this$
|
|
78
|
-
makeStyles = _this$
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
const _this$props4 = this.props,
|
|
97
|
+
border = _this$props4.border,
|
|
98
|
+
children = _this$props4.children,
|
|
99
|
+
color = _this$props4.color,
|
|
100
|
+
level = _this$props4.level,
|
|
101
|
+
margin = _this$props4.margin,
|
|
102
|
+
elementRef = _this$props4.elementRef,
|
|
103
|
+
makeStyles = _this$props4.makeStyles,
|
|
104
|
+
variant = _this$props4.variant,
|
|
105
|
+
props = (0, _objectWithoutProperties2.default)(_this$props4, _excluded);
|
|
106
|
+
const propsForGetElementType = variant ? {} : this.props;
|
|
107
|
+
const ElementType = (0, _getElementType.getElementType)(Heading, propsForGetElementType, () => {
|
|
108
|
+
if (variant) {
|
|
109
|
+
return variantLevels[variant];
|
|
110
|
+
}
|
|
81
111
|
if (level === 'reset') {
|
|
82
112
|
return 'span';
|
|
83
113
|
} else {
|
package/lib/Heading/props.js
CHANGED
|
@@ -39,6 +39,7 @@ const propTypes = exports.propTypes = {
|
|
|
39
39
|
level: _propTypes.default.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'reset']),
|
|
40
40
|
as: _propTypes.default.elementType,
|
|
41
41
|
margin: _emotion.ThemeablePropTypes.spacing,
|
|
42
|
-
elementRef: _propTypes.default.func
|
|
42
|
+
elementRef: _propTypes.default.func,
|
|
43
|
+
variant: _propTypes.default.oneOf(['titlePageDesktop', 'titlePageMobile', 'titleSection', 'titleCardSection', 'titleModule', 'titleCardLarge', 'titleCardRegular', 'titleCardMini', 'label', 'labelInline'])
|
|
43
44
|
};
|
|
44
|
-
const allowedProps = exports.allowedProps = ['border', 'children', 'color', 'level', 'as', 'margin', 'elementRef'];
|
|
45
|
+
const allowedProps = exports.allowedProps = ['border', 'children', 'color', 'level', 'as', 'margin', 'elementRef', 'variant'];
|
package/lib/Heading/styles.js
CHANGED
|
@@ -41,7 +41,70 @@ exports.default = void 0;
|
|
|
41
41
|
const generateStyle = (componentTheme, props) => {
|
|
42
42
|
const level = props.level,
|
|
43
43
|
color = props.color,
|
|
44
|
-
border = props.border
|
|
44
|
+
border = props.border,
|
|
45
|
+
variant = props.variant;
|
|
46
|
+
const variants = {
|
|
47
|
+
titlePageDesktop: {
|
|
48
|
+
fontStyle: 'normal',
|
|
49
|
+
fontWeight: componentTheme.weightImportant,
|
|
50
|
+
fontSize: componentTheme.titlePageDesktop,
|
|
51
|
+
lineHeight: componentTheme.lineHeight125
|
|
52
|
+
},
|
|
53
|
+
titlePageMobile: {
|
|
54
|
+
fontStyle: 'normal',
|
|
55
|
+
fontWeight: componentTheme.weightImportant,
|
|
56
|
+
fontSize: componentTheme.titlePageMobile,
|
|
57
|
+
lineHeight: componentTheme.lineHeight125
|
|
58
|
+
},
|
|
59
|
+
titleSection: {
|
|
60
|
+
fontStyle: 'normal',
|
|
61
|
+
fontWeight: componentTheme.weightImportant,
|
|
62
|
+
fontSize: componentTheme.titleSection,
|
|
63
|
+
lineHeight: componentTheme.lineHeight125
|
|
64
|
+
},
|
|
65
|
+
titleCardSection: {
|
|
66
|
+
fontStyle: 'normal',
|
|
67
|
+
fontWeight: componentTheme.weightImportant,
|
|
68
|
+
fontSize: componentTheme.titleSection,
|
|
69
|
+
lineHeight: componentTheme.lineHeight125
|
|
70
|
+
},
|
|
71
|
+
titleModule: {
|
|
72
|
+
fontStyle: 'normal',
|
|
73
|
+
fontWeight: componentTheme.weightImportant,
|
|
74
|
+
fontSize: componentTheme.titleModule,
|
|
75
|
+
lineHeight: componentTheme.lineHeight125
|
|
76
|
+
},
|
|
77
|
+
titleCardLarge: {
|
|
78
|
+
fontStyle: 'normal',
|
|
79
|
+
fontWeight: componentTheme.weightImportant,
|
|
80
|
+
fontSize: componentTheme.titleCardLarge,
|
|
81
|
+
lineHeight: componentTheme.lineHeight125
|
|
82
|
+
},
|
|
83
|
+
titleCardRegular: {
|
|
84
|
+
fontStyle: 'normal',
|
|
85
|
+
fontWeight: componentTheme.weightImportant,
|
|
86
|
+
fontSize: componentTheme.titleCardRegular,
|
|
87
|
+
lineHeight: componentTheme.lineHeight125
|
|
88
|
+
},
|
|
89
|
+
titleCardMini: {
|
|
90
|
+
fontStyle: 'normal',
|
|
91
|
+
fontWeight: componentTheme.weightImportant,
|
|
92
|
+
fontSize: componentTheme.titleCardMini,
|
|
93
|
+
lineHeight: componentTheme.lineHeight125
|
|
94
|
+
},
|
|
95
|
+
label: {
|
|
96
|
+
fontStyle: 'normal',
|
|
97
|
+
fontWeight: componentTheme.weightImportant,
|
|
98
|
+
fontSize: componentTheme.label,
|
|
99
|
+
lineHeight: componentTheme.lineHeight125
|
|
100
|
+
},
|
|
101
|
+
labelInline: {
|
|
102
|
+
fontStyle: 'normal',
|
|
103
|
+
fontWeight: componentTheme.weightImportant,
|
|
104
|
+
fontSize: componentTheme.label,
|
|
105
|
+
lineHeight: componentTheme.lineHeight150
|
|
106
|
+
}
|
|
107
|
+
};
|
|
45
108
|
const levelStyles = {
|
|
46
109
|
h1: {
|
|
47
110
|
fontFamily: componentTheme.h1FontFamily,
|
|
@@ -132,7 +195,7 @@ const generateStyle = (componentTheme, props) => {
|
|
|
132
195
|
// NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
|
|
133
196
|
'&:is(input)[type]': inputStyles,
|
|
134
197
|
'&:-webkit-any(input)[type]': inputStyles,
|
|
135
|
-
...levelStyles[level],
|
|
198
|
+
...(variant ? variants[variant] : levelStyles[level]),
|
|
136
199
|
...colorStyles[color],
|
|
137
200
|
...borderStyles[border]
|
|
138
201
|
}
|
package/lib/Heading/theme.js
CHANGED
|
@@ -56,6 +56,7 @@ const generateComponentTheme = theme => {
|
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
const componentVariables = {
|
|
59
|
+
...typography,
|
|
59
60
|
lineHeight: typography === null || typography === void 0 ? void 0 : typography.lineHeightCondensed,
|
|
60
61
|
h1FontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeXXLarge,
|
|
61
62
|
h1FontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightBold,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-heading",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.10.0",
|
|
4
4
|
"description": "A component for creating typographic headings",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,20 +24,20 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.26.0",
|
|
27
|
-
"@instructure/console": "10.
|
|
28
|
-
"@instructure/emotion": "10.
|
|
29
|
-
"@instructure/shared-types": "10.
|
|
30
|
-
"@instructure/ui-prop-types": "10.
|
|
31
|
-
"@instructure/ui-react-utils": "10.
|
|
32
|
-
"@instructure/ui-testable": "10.
|
|
33
|
-
"@instructure/ui-view": "10.
|
|
27
|
+
"@instructure/console": "10.10.0",
|
|
28
|
+
"@instructure/emotion": "10.10.0",
|
|
29
|
+
"@instructure/shared-types": "10.10.0",
|
|
30
|
+
"@instructure/ui-prop-types": "10.10.0",
|
|
31
|
+
"@instructure/ui-react-utils": "10.10.0",
|
|
32
|
+
"@instructure/ui-testable": "10.10.0",
|
|
33
|
+
"@instructure/ui-view": "10.10.0",
|
|
34
34
|
"prop-types": "^15.8.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@instructure/ui-axe-check": "10.
|
|
38
|
-
"@instructure/ui-babel-preset": "10.
|
|
39
|
-
"@instructure/ui-test-utils": "10.
|
|
40
|
-
"@instructure/ui-themes": "10.
|
|
37
|
+
"@instructure/ui-axe-check": "10.10.0",
|
|
38
|
+
"@instructure/ui-babel-preset": "10.10.0",
|
|
39
|
+
"@instructure/ui-test-utils": "10.10.0",
|
|
40
|
+
"@instructure/ui-themes": "10.10.0",
|
|
41
41
|
"@testing-library/jest-dom": "^6.6.3",
|
|
42
42
|
"@testing-library/react": "^16.0.1",
|
|
43
43
|
"vitest": "^2.1.8"
|
package/src/Heading/README.md
CHANGED
|
@@ -4,6 +4,31 @@ describes: Heading
|
|
|
4
4
|
|
|
5
5
|
Heading is a component for creating typographic headings.
|
|
6
6
|
|
|
7
|
+
## Variant
|
|
8
|
+
|
|
9
|
+
Variant takes care of - almost - all use-cases when it comes hedings on pages. Their name reflects the places they meant to be used. It sets the `level` prop and takes care of the style of the heading
|
|
10
|
+
We recommend using `variants` instead of the `level` (and `as`) props.
|
|
11
|
+
|
|
12
|
+
NOTE: when `variant` is set, `level` and `as` props are ignored
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
---
|
|
16
|
+
type: example
|
|
17
|
+
---
|
|
18
|
+
<div>
|
|
19
|
+
<Heading variant="titlePageDesktop"> titlePageDesktop </Heading><br/>
|
|
20
|
+
<Heading variant="titlePageMobile"> titlePageMobile </Heading><br/>
|
|
21
|
+
<Heading variant="titleSection"> titleSection </Heading><br/>
|
|
22
|
+
<Heading variant="titleCardSection"> titleCardSection </Heading><br/>
|
|
23
|
+
<Heading variant="titleModule"> titleModule </Heading><br/>
|
|
24
|
+
<Heading variant="titleCardLarge"> titleCardLarge </Heading><br/>
|
|
25
|
+
<Heading variant="titleCardRegular"> titleCardRegular </Heading><br/>
|
|
26
|
+
<Heading variant="titleCardMini"> titleCardMini </Heading><br/>
|
|
27
|
+
<Heading variant="label"> label </Heading><br/>
|
|
28
|
+
<Heading variant="labelInline"> labelInline </Heading><br/>
|
|
29
|
+
</div>
|
|
30
|
+
```
|
|
31
|
+
|
|
7
32
|
```js
|
|
8
33
|
---
|
|
9
34
|
type: example
|
|
@@ -24,11 +49,7 @@ type: example
|
|
|
24
49
|
---
|
|
25
50
|
<div>
|
|
26
51
|
<Heading level="h1" as="h2" margin="0 0 x-small">Heading level One</Heading>
|
|
27
|
-
|
|
28
|
-
<Heading level="h3" margin="0 0 x-small">Heading level Three</Heading>
|
|
29
|
-
<Heading level="h4" margin="0 0 x-small">Heading level Four</Heading>
|
|
30
|
-
<Heading level="h5" margin="0 0 x-small">Heading level Five</Heading>
|
|
31
|
-
<Heading level="reset" as="h2">Heading level reset as a Two</Heading>
|
|
52
|
+
|
|
32
53
|
</div>
|
|
33
54
|
```
|
|
34
55
|
|
|
@@ -26,7 +26,7 @@ import type { StoryConfig } from '@instructure/ui-test-utils'
|
|
|
26
26
|
import type { HeadingProps } from '../props'
|
|
27
27
|
|
|
28
28
|
export default {
|
|
29
|
-
sectionProp: '
|
|
29
|
+
sectionProp: 'variant',
|
|
30
30
|
propValues: {
|
|
31
31
|
color: [
|
|
32
32
|
'primary',
|
|
@@ -34,7 +34,10 @@ export default {
|
|
|
34
34
|
'primary-inverse',
|
|
35
35
|
'secondary-inverse',
|
|
36
36
|
'inherit'
|
|
37
|
-
]
|
|
37
|
+
],
|
|
38
|
+
|
|
39
|
+
level: [undefined],
|
|
40
|
+
as: [undefined]
|
|
38
41
|
},
|
|
39
42
|
getComponentProps: () => {
|
|
40
43
|
return {
|
package/src/Heading/index.tsx
CHANGED
|
@@ -36,6 +36,22 @@ import generateComponentTheme from './theme'
|
|
|
36
36
|
import { propTypes, allowedProps } from './props'
|
|
37
37
|
import type { HeadingProps } from './props'
|
|
38
38
|
|
|
39
|
+
const variantLevels: Record<
|
|
40
|
+
NonNullable<HeadingProps['variant']>,
|
|
41
|
+
'h1' | 'h2' | 'h3' | 'h4' | 'h5'
|
|
42
|
+
> = {
|
|
43
|
+
titlePageDesktop: 'h1',
|
|
44
|
+
titlePageMobile: 'h1',
|
|
45
|
+
titleSection: 'h2',
|
|
46
|
+
titleCardSection: 'h2',
|
|
47
|
+
titleModule: 'h3',
|
|
48
|
+
titleCardLarge: 'h4',
|
|
49
|
+
titleCardRegular: 'h4',
|
|
50
|
+
titleCardMini: 'h4',
|
|
51
|
+
label: 'h5',
|
|
52
|
+
labelInline: 'h5'
|
|
53
|
+
}
|
|
54
|
+
|
|
39
55
|
/**
|
|
40
56
|
---
|
|
41
57
|
category: components
|
|
@@ -67,12 +83,26 @@ class Heading extends Component<HeadingProps> {
|
|
|
67
83
|
}
|
|
68
84
|
}
|
|
69
85
|
|
|
86
|
+
checkProps() {
|
|
87
|
+
const { variant, level, as } = this.props
|
|
88
|
+
if (variant) {
|
|
89
|
+
if (level) {
|
|
90
|
+
console.warn("[Heading]: Don't use 'level' with 'variant' ")
|
|
91
|
+
}
|
|
92
|
+
if (as) {
|
|
93
|
+
console.warn("[Heading]: Don't use 'as' with 'variant' ")
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
70
98
|
componentDidMount() {
|
|
71
99
|
this.props.makeStyles?.()
|
|
100
|
+
this.checkProps()
|
|
72
101
|
}
|
|
73
102
|
|
|
74
103
|
componentDidUpdate() {
|
|
75
104
|
this.props.makeStyles?.()
|
|
105
|
+
this.checkProps()
|
|
76
106
|
}
|
|
77
107
|
|
|
78
108
|
render() {
|
|
@@ -84,10 +114,16 @@ class Heading extends Component<HeadingProps> {
|
|
|
84
114
|
margin,
|
|
85
115
|
elementRef,
|
|
86
116
|
makeStyles,
|
|
117
|
+
variant,
|
|
87
118
|
...props
|
|
88
119
|
} = this.props
|
|
89
120
|
|
|
90
|
-
const
|
|
121
|
+
const propsForGetElementType = variant ? {} : this.props
|
|
122
|
+
|
|
123
|
+
const ElementType = getElementType(Heading, propsForGetElementType, () => {
|
|
124
|
+
if (variant) {
|
|
125
|
+
return variantLevels[variant]
|
|
126
|
+
}
|
|
91
127
|
if (level === 'reset') {
|
|
92
128
|
return 'span'
|
|
93
129
|
} else {
|
package/src/Heading/props.ts
CHANGED
|
@@ -78,6 +78,21 @@ type HeadingOwnProps = {
|
|
|
78
78
|
* Provides a ref to the underlying HTML element
|
|
79
79
|
*/
|
|
80
80
|
elementRef?: (element: Element | null) => void
|
|
81
|
+
/**
|
|
82
|
+
* Sets style and level at once. The as property will be the same as the level.
|
|
83
|
+
* NOTE: this is the recommended way of setting the appearance, instead of level
|
|
84
|
+
*/
|
|
85
|
+
variant?:
|
|
86
|
+
| 'titlePageDesktop'
|
|
87
|
+
| 'titlePageMobile'
|
|
88
|
+
| 'titleSection'
|
|
89
|
+
| 'titleCardSection'
|
|
90
|
+
| 'titleModule'
|
|
91
|
+
| 'titleCardLarge'
|
|
92
|
+
| 'titleCardRegular'
|
|
93
|
+
| 'titleCardMini'
|
|
94
|
+
| 'label'
|
|
95
|
+
| 'labelInline'
|
|
81
96
|
}
|
|
82
97
|
|
|
83
98
|
type PropKeys = keyof HeadingOwnProps
|
|
@@ -103,7 +118,19 @@ const propTypes: PropValidators<PropKeys> = {
|
|
|
103
118
|
level: PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'reset']),
|
|
104
119
|
as: PropTypes.elementType,
|
|
105
120
|
margin: ThemeablePropTypes.spacing,
|
|
106
|
-
elementRef: PropTypes.func
|
|
121
|
+
elementRef: PropTypes.func,
|
|
122
|
+
variant: PropTypes.oneOf([
|
|
123
|
+
'titlePageDesktop',
|
|
124
|
+
'titlePageMobile',
|
|
125
|
+
'titleSection',
|
|
126
|
+
'titleCardSection',
|
|
127
|
+
'titleModule',
|
|
128
|
+
'titleCardLarge',
|
|
129
|
+
'titleCardRegular',
|
|
130
|
+
'titleCardMini',
|
|
131
|
+
'label',
|
|
132
|
+
'labelInline'
|
|
133
|
+
])
|
|
107
134
|
}
|
|
108
135
|
|
|
109
136
|
const allowedProps: AllowedPropKeys = [
|
|
@@ -113,7 +140,8 @@ const allowedProps: AllowedPropKeys = [
|
|
|
113
140
|
'level',
|
|
114
141
|
'as',
|
|
115
142
|
'margin',
|
|
116
|
-
'elementRef'
|
|
143
|
+
'elementRef',
|
|
144
|
+
'variant'
|
|
117
145
|
]
|
|
118
146
|
|
|
119
147
|
export type { HeadingProps, HeadingStyle }
|