Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 46b0865

Browse files
author
Kerry
authored
Add Heading components (#7362)
* add Heading components Signed-off-by: Kerry Archibald <[email protected]> * remove margins Signed-off-by: Kerry Archibald <[email protected]> * snapshots Signed-off-by: Kerry Archibald <[email protected]> * unset block and inline margins Signed-off-by: Kerry Archibald <[email protected]> * copyright Signed-off-by: Kerry Archibald <[email protected]> * fix werid quoting on heading test Signed-off-by: Kerry Archibald <[email protected]>
1 parent 9436f3b commit 46b0865

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

res/css/_components.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
@import "./views/toasts/_AnalyticsToast.scss";
299299
@import "./views/toasts/_IncomingCallToast.scss";
300300
@import "./views/toasts/_NonUrgentEchoFailureToast.scss";
301+
@import "./views/typography/_Heading.scss";
301302
@import "./views/verification/_VerificationShowSas.scss";
302303
@import "./views/voip/CallView/_CallViewButtons.scss";
303304
@import "./views/voip/_CallContainer.scss";
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright 2021 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_Heading_h1 {
18+
font-size: $font-32px;
19+
font-weight: $font-semi-bold;
20+
line-height: $font-39px;
21+
margin-inline: unset;
22+
margin-block: unset;
23+
}
24+
25+
.mx_Heading_h2 {
26+
font-size: $font-24px;
27+
font-weight: $font-semi-bold;
28+
line-height: $font-29px;
29+
margin-inline: unset;
30+
margin-block: unset;
31+
}
32+
33+
.mx_Heading_h3 {
34+
font-size: $font-18px;
35+
font-weight: $font-semi-bold;
36+
line-height: $font-22px;
37+
margin-inline: unset;
38+
margin-block: unset;
39+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2021 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React, { HTMLAttributes } from 'react';
18+
import classNames from 'classnames';
19+
20+
type Size = 'h1' | 'h2' | 'h3';
21+
interface HeadingProps extends HTMLAttributes<HTMLHeadingElement> {
22+
size: Size;
23+
}
24+
25+
const Heading: React.FC<HeadingProps> = ({ size, className, children, ...rest }) => React.createElement(size || 'h1', {
26+
...rest,
27+
className: classNames(`mx_Heading_${size}`, className),
28+
children,
29+
});
30+
31+
export default Heading;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { renderIntoDocument } from 'react-dom/test-utils';
3+
4+
import Heading from "../../../../src/components/views/typography/Heading";
5+
describe('<Heading />', () => {
6+
const defaultProps = {
7+
size: 'h1',
8+
children: <div>test</div>,
9+
['data-test-id']: 'test',
10+
className: 'test',
11+
} as any;
12+
const getComponent = (props = {}) => {
13+
const wrapper = renderIntoDocument<HTMLDivElement>(
14+
<div><Heading {...defaultProps} {...props} /></div>,
15+
) as HTMLDivElement;
16+
return wrapper.children[0];
17+
};
18+
19+
it('renders h1 with correct attributes', () => {
20+
expect(getComponent({ size: 'h1' })).toMatchSnapshot();
21+
});
22+
it('renders h2 with correct attributes', () => {
23+
expect(getComponent({ size: 'h2' })).toMatchSnapshot();
24+
});
25+
it('renders h3 with correct attributes', () => {
26+
expect(getComponent({ size: 'h3' })).toMatchSnapshot();
27+
});
28+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<Heading /> renders h1 with correct attributes 1`] = `
4+
<h1
5+
class="mx_Heading_h1 test"
6+
data-test-id="test"
7+
>
8+
<div>
9+
test
10+
</div>
11+
</h1>
12+
`;
13+
14+
exports[`<Heading /> renders h2 with correct attributes 1`] = `
15+
<h2
16+
class="mx_Heading_h2 test"
17+
data-test-id="test"
18+
>
19+
<div>
20+
test
21+
</div>
22+
</h2>
23+
`;
24+
25+
exports[`<Heading /> renders h3 with correct attributes 1`] = `
26+
<h3
27+
class="mx_Heading_h3 test"
28+
data-test-id="test"
29+
>
30+
<div>
31+
test
32+
</div>
33+
</h3>
34+
`;

0 commit comments

Comments
 (0)