From c3151a0dc6efb5f78e0e211f62e62eaf574c2c56 Mon Sep 17 00:00:00 2001 From: Revanshu Paliwal Date: Thu, 13 Apr 2023 12:00:18 +0200 Subject: [PATCH] SONAR-19024 Adding generic card component for project overview page --- .../design-system/src/components/Card.tsx | 42 +++++++++++++++++++ .../src/components/__tests__/Card-test.tsx | 38 +++++++++++++++++ .../design-system/src/components/index.ts | 1 + 3 files changed, 81 insertions(+) create mode 100644 server/sonar-web/design-system/src/components/Card.tsx create mode 100644 server/sonar-web/design-system/src/components/__tests__/Card-test.tsx diff --git a/server/sonar-web/design-system/src/components/Card.tsx b/server/sonar-web/design-system/src/components/Card.tsx new file mode 100644 index 00000000000..f45cfe02bd4 --- /dev/null +++ b/server/sonar-web/design-system/src/components/Card.tsx @@ -0,0 +1,42 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import styled from '@emotion/styled'; +import * as React from 'react'; +import tw from 'twin.macro'; +import { themeBorder, themeColor } from '../helpers/theme'; + +interface CardProps { + children: React.ReactNode; + className?: string; +} + +export function Card(props: CardProps) { + const { className, children } = props; + + return {children}; +} + +const CardStyled = styled.div` + background-color: ${themeColor('backgroundSecondary')}; + border: ${themeBorder('default', 'projectCardBorder')}; + + ${tw`sw-p-6`}; + ${tw`sw-rounded-1`}; +`; diff --git a/server/sonar-web/design-system/src/components/__tests__/Card-test.tsx b/server/sonar-web/design-system/src/components/__tests__/Card-test.tsx new file mode 100644 index 00000000000..04b58a7dcba --- /dev/null +++ b/server/sonar-web/design-system/src/components/__tests__/Card-test.tsx @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import { screen } from '@testing-library/react'; +import { render } from '../../helpers/testUtils'; +import { Card } from '../Card'; + +it('renders card correctly', () => { + render(Hello); + const cardContent = screen.getByText('Hello'); + expect(cardContent).toHaveStyle({ + border: '1px solid rgb(225,230,243)', + 'background-color': 'rgb(255,255,255)', + }); +}); + +it('renders card correctly with classNames', () => { + render(Hello); + const cardContent = screen.getByText('Hello'); + expect(cardContent).toHaveClass('sw-bg-black sw-border-8'); +}); diff --git a/server/sonar-web/design-system/src/components/index.ts b/server/sonar-web/design-system/src/components/index.ts index 741a4c04f3b..31a1c322c40 100644 --- a/server/sonar-web/design-system/src/components/index.ts +++ b/server/sonar-web/design-system/src/components/index.ts @@ -21,6 +21,7 @@ export * from './Accordion'; export * from './Avatar'; export { Badge } from './Badge'; +export * from './Card'; export { DeferredSpinner } from './DeferredSpinner'; export { Dropdown } from './Dropdown'; export * from './DropdownMenu'; -- 2.39.5