Skip to content

Commit 9969c45

Browse files
authored
Re-add the Title component (#2734)
1 parent 70f3ab8 commit 9969c45

File tree

5 files changed

+108
-1
lines changed

5 files changed

+108
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright 2019, SumUp Ltd.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import { describe, expect, it } from 'vitest';
17+
import { createRef } from 'react';
18+
19+
import { axe, render } from '../../util/test-utils.js';
20+
21+
import { Title } from './Title.js';
22+
23+
describe('Title', () => {
24+
it('should merge a custom class name with the default ones', () => {
25+
const className = 'foo';
26+
const { container } = render(
27+
<Title as="h2" className={className}>
28+
Title
29+
</Title>,
30+
);
31+
const headline = container.querySelector('h2');
32+
expect(headline?.className).toContain(className);
33+
});
34+
35+
it('should forward a ref', () => {
36+
const ref = createRef<HTMLHeadingElement>();
37+
const { container } = render(
38+
<Title as="h2" ref={ref}>
39+
Title
40+
</Title>,
41+
);
42+
const headline = container.querySelector('h2');
43+
expect(ref.current).toBe(headline);
44+
});
45+
46+
it('should meet accessibility guidelines', async () => {
47+
const { container } = render(<Title as="h3">Subheading</Title>);
48+
const actual = await axe(container);
49+
expect(actual).toHaveNoViolations();
50+
});
51+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2019, SumUp Ltd.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
import { forwardRef } from 'react';
17+
18+
import { deprecate } from '../../util/logger.js';
19+
import { Display, type DisplayProps } from '../Display/Display.js';
20+
21+
export interface TitleProps extends DisplayProps {}
22+
23+
/**
24+
* @deprecated The Title component has been renamed to Display.
25+
*/
26+
export const Title = forwardRef<HTMLHeadingElement, TitleProps>(
27+
(props, ref) => {
28+
if (process.env.NODE_ENV !== 'production') {
29+
deprecate('Title', 'The Title component has been renamed to Display.');
30+
}
31+
32+
return <Display {...props} ref={ref} />;
33+
},
34+
);
35+
36+
Title.displayName = 'Title';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright 2019, SumUp Ltd.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
export { Title } from './Title.js';
17+
18+
export type { TitleProps } from './Title.js';

packages/circuit-ui/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export { Headline } from './components/Headline/index.js';
2323
export type { HeadlineProps } from './components/Headline/index.js';
2424
export { Display } from './components/Display/index.js';
2525
export type { DisplayProps } from './components/Display/index.js';
26+
export { Title } from './components/Title/index.js';
27+
export type { TitleProps } from './components/Title/index.js';
2628
export { SubHeadline } from './components/SubHeadline/index.js';
2729
export type { SubHeadlineProps } from './components/SubHeadline/index.js';
2830
export { Body } from './components/Body/index.js';

packages/eslint-plugin-circuit-ui/renamed-package-scope/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const mappings = [
4444
export const renamedPackageScope = createRule({
4545
name: 'renamed-organization-imports',
4646
meta: {
47-
type: 'suggestion',
47+
type: 'problem',
4848
schema: [],
4949
fixable: 'code',
5050
docs: {

0 commit comments

Comments
 (0)