Skip to content

Commit

Permalink
add generic caption typography component (#9283)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry committed Sep 15, 2022
1 parent 10bb105 commit 8d9e523
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
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>,
}
`;

0 comments on commit 8d9e523

Please sign in to comment.