add generic caption typography component (#9283)

This commit is contained in:
Kerry 2022-09-15 11:53:21 +02:00 committed by GitHub
parent 10bb10539b
commit 8d9e5237fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 118 additions and 0 deletions

View file

@ -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";

View file

@ -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;
}

View file

@ -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>;
};

View file

@ -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();
});
});

View file

@ -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>,
}
`;