diff --git a/res/css/_components.pcss b/res/css/_components.pcss index 640184c8ca..b6b98aee3e 100644 --- a/res/css/_components.pcss +++ b/res/css/_components.pcss @@ -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"; diff --git a/res/css/components/views/typography/_Caption.pcss b/res/css/components/views/typography/_Caption.pcss new file mode 100644 index 0000000000..3af270c4a5 --- /dev/null +++ b/res/css/components/views/typography/_Caption.pcss @@ -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; +} diff --git a/src/components/views/typography/Caption.tsx b/src/components/views/typography/Caption.tsx new file mode 100644 index 0000000000..98d928fd42 --- /dev/null +++ b/src/components/views/typography/Caption.tsx @@ -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, 'className'> { + children: React.ReactNode; +} + +export const Caption: React.FC = ({ children, ...rest }) => { + return + { children } + ; +}; diff --git a/test/components/views/typography/Caption-test.tsx b/test/components/views/typography/Caption-test.tsx new file mode 100644 index 0000000000..3257cd9b7e --- /dev/null +++ b/test/components/views/typography/Caption-test.tsx @@ -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('', () => { + const defaultProps = { + 'children': 'test', + 'data-testid': 'test test id', + }; + const getComponent = (props = {}) => + (); + + it('renders plain text children', () => { + const { container } = render(getComponent()); + expect({ container }).toMatchSnapshot(); + }); + + it('renders react children', () => { + const children = <>Test test but bold; + const { container } = render(getComponent({ children })); + expect({ container }).toMatchSnapshot(); + }); +}); diff --git a/test/components/views/typography/__snapshots__/Caption-test.tsx.snap b/test/components/views/typography/__snapshots__/Caption-test.tsx.snap new file mode 100644 index 0000000000..4ed7dc569f --- /dev/null +++ b/test/components/views/typography/__snapshots__/Caption-test.tsx.snap @@ -0,0 +1,30 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` renders plain text children 1`] = ` +Object { + "container":
+ + test + +
, +} +`; + +exports[` renders react children 1`] = ` +Object { + "container":
+ + Test + + test but bold + + +
, +} +`;