-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cards and section component. (#19168)
* Add filled section component. * Add card component. * Add mantine css for styleguide. * Update sawmill
- Loading branch information
Showing
9 changed files
with
202 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Most basic usage. | ||
```tsx | ||
<Card>The children</Card> | ||
``` | ||
|
||
With small padding. | ||
```tsx | ||
<Card padding="sm"> | ||
The children | ||
</Card> | ||
``` |
28 changes: 28 additions & 0 deletions
28
graylog2-web-interface/src/components/common/Card.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* 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 | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import React from 'react'; | ||
import { render, screen } from 'wrappedTestingLibrary'; | ||
|
||
import Card from './Card'; | ||
|
||
describe('Card', () => { | ||
it('should render children', async () => { | ||
render(<Card>The children</Card>); | ||
|
||
await screen.findByText(/the children/i); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* 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 | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
import { Card as MantineCard } from '@mantine/core'; | ||
|
||
const Container = styled(MantineCard)(({ theme }) => css` | ||
background-color: ${theme.colors.cards.background}; | ||
border-color: ${theme.colors.cards.border}; | ||
`); | ||
|
||
type Props = React.PropsWithChildren<{ | ||
className?: string, | ||
padding?: 'sm', | ||
}> | ||
|
||
/** | ||
* Simple card component. | ||
*/ | ||
const Card = ({ children, className, padding }: Props) => ( | ||
<Container className={className} shadow="sm" padding={padding} radius="md" withBorder> | ||
{children} | ||
</Container> | ||
); | ||
|
||
Card.defaultProps = { | ||
className: undefined, | ||
padding: undefined, | ||
}; | ||
|
||
export default Card; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Most basic usage. | ||
```tsx | ||
<Section title="The Title">The children</Section> | ||
``` | ||
|
||
With actions. | ||
```tsx | ||
import { Button } from 'components/bootstrap'; | ||
|
||
<Section title="The Title" actions={<Button>An Action</Button>}> | ||
The children | ||
</Section> | ||
``` |
41 changes: 41 additions & 0 deletions
41
graylog2-web-interface/src/components/common/Section.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* 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 | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import React from 'react'; | ||
import { render, screen } from 'wrappedTestingLibrary'; | ||
|
||
import Section from './Section'; | ||
|
||
describe('Section', () => { | ||
it('should render children', async () => { | ||
render(<Section title="The Title">The children</Section>); | ||
|
||
await screen.findByRole('heading', { name: /the title/i }); | ||
await screen.findByText(/the children/i); | ||
}); | ||
|
||
it('should render actions', async () => { | ||
render( | ||
<Section title="The Title" actions="The actions"> | ||
The children | ||
</Section>, | ||
); | ||
|
||
await screen.findByRole('heading', { name: /the title/i }); | ||
await screen.findByText(/the children/i); | ||
await screen.findByText(/the actions/i); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* 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 | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
|
||
const Container = styled.div(({ theme }) => css` | ||
background-color: ${theme.colors.section.filled.background}; | ||
border: 1px solid ${theme.colors.section.filled.border}; | ||
border-radius: 10px; | ||
padding: 15px; | ||
`); | ||
|
||
const Header = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: 10px; | ||
`; | ||
|
||
type Props = React.PropsWithChildren<{ | ||
title: React.ReactNode, | ||
actions?: React.ReactNode, | ||
}> | ||
|
||
/** | ||
* Simple section component. Currently only a "filled" version exists. | ||
*/ | ||
const Section = ({ title, actions, children }: Props) => ( | ||
<Container> | ||
<Header> | ||
<h2>{title}</h2> | ||
{actions && <div>{actions}</div>} | ||
</Header> | ||
{children} | ||
</Container> | ||
); | ||
|
||
Section.defaultProps = { | ||
actions: undefined, | ||
}; | ||
|
||
export default Section; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters