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

Generic typography component - Caption #9283

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/css/_components.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@import "./components/views/settings/devices/_SelectableDeviceTile.pcss";
@import "./components/views/settings/shared/_SettingsSubsection.pcss";
@import "./components/views/spaces/_QuickThemeSwitcher.pcss";
@import "./components/views/typography/_Caption.pcss";
@import "./structures/_AutoHideScrollbar.pcss";
@import "./structures/_BackdropPanel.pcss";
@import "./structures/_CompatibilityPage.pcss";
Expand Down
20 changes: 20 additions & 0 deletions res/css/components/views/typography/_Caption.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_Caption {
font-size: $font-12px;
color: $secondary-content;
}
27 changes: 27 additions & 0 deletions src/components/views/typography/Caption.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React, { HTMLAttributes } from 'react';

interface Props extends Omit<HTMLAttributes<HTMLSpanElement>, 'className'> {
children: React.ReactNode;
}

export const Caption: React.FC<Props> = ({ children, ...rest }) => {
return <span className='mx_Caption' {...rest}>
{ children }
</span>;
};
40 changes: 40 additions & 0 deletions test/components/views/typography/Caption-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import { render } from '@testing-library/react';

import { Caption } from '../../../../src/components/views/typography/Caption';

describe('<Caption />', () => {
const defaultProps = {
'children': 'test',
'data-testid': 'test test id',
};
const getComponent = (props = {}) =>
(<Caption {...defaultProps} {...props} />);

it('renders plain text children', () => {
const { container } = render(getComponent());
expect({ container }).toMatchSnapshot();
});

it('renders react children', () => {
const children = <>Test <b>test but bold</b></>;
const { container } = render(getComponent({ children }));
expect({ container }).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Caption /> renders plain text children 1`] = `
Object {
"container": <div>
<span
class="mx_Caption"
data-testid="test test id"
>
test
</span>
</div>,
}
`;

exports[`<Caption /> renders react children 1`] = `
Object {
"container": <div>
<span
class="mx_Caption"
data-testid="test test id"
>
Test
<b>
test but bold
</b>
</span>
</div>,
}
`;