diff options
author | Revanshu Paliwal <revanshu.paliwal@sonarsource.com> | 2023-04-13 12:00:18 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-04-13 20:03:05 +0000 |
commit | c3151a0dc6efb5f78e0e211f62e62eaf574c2c56 (patch) | |
tree | dad6dcaff8ec99256e6e80b5b835e33e47710ef0 /server | |
parent | c1da61ac1f763bef50112eaf0ae88c086940f5a4 (diff) | |
download | sonarqube-c3151a0dc6efb5f78e0e211f62e62eaf574c2c56.tar.gz sonarqube-c3151a0dc6efb5f78e0e211f62e62eaf574c2c56.zip |
SONAR-19024 Adding generic card component for project overview page
Diffstat (limited to 'server')
3 files changed, 81 insertions, 0 deletions
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 <CardStyled className={className}>{children}</CardStyled>; +} + +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(<Card>Hello</Card>); + 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(<Card className="sw-bg-black sw-border-8">Hello</Card>); + 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'; |