-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Frontend core components migration (#311)
- Loading branch information
1 parent
801eec7
commit d41c34a
Showing
36 changed files
with
2,972 additions
and
1,370 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
modulePaths: ['<rootDir>/src'], | ||
testEnvironment: 'jsdom', | ||
transform: { | ||
'.+\\.(ts|tsx)$': 'ts-jest' | ||
} | ||
} |
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
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,36 @@ | ||
import Button from '../../Button' | ||
import { NoteAdd as IconAdd } from '../../../icons' | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
|
||
export type Props = { | ||
label?: string | ||
name: string | ||
margin?: string | number | ||
padding?: string | number | ||
onClick?(): void | ||
} | ||
|
||
const ButtonStyled = styled(Button)` | ||
display: flex; | ||
flex: 1; | ||
align-items: center; | ||
justify-content: center; | ||
` | ||
|
||
const AddButton = (props: Props) => ( | ||
<ButtonStyled | ||
{...props} | ||
variant='dashed' | ||
color='primary' | ||
id={'add-' + props.name} | ||
name={'add-' + props.name} | ||
padding={props.padding} | ||
margin={props.margin || '12px 0 24px'} | ||
onClick={props.onClick}> | ||
<IconAdd /> | ||
{props.label} | ||
</ButtonStyled> | ||
) | ||
|
||
export default AddButton |
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,25 @@ | ||
import * as React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import Button from './Button' | ||
|
||
describe('Button', () => { | ||
const NAME = 'btnName' | ||
const LABEL = 'Click Me' | ||
it('should render', () => { | ||
render(<Button name={NAME} label={LABEL} />) | ||
|
||
const button = screen.getByText(LABEL) | ||
|
||
expect(button).toBeDefined() | ||
}) | ||
|
||
it('should call onClick', () => { | ||
const onClick = jest.fn() | ||
render(<Button name={NAME} label={LABEL} onClick={onClick} />) | ||
|
||
const button = screen.getByText(LABEL) | ||
button.click() | ||
|
||
expect(onClick).toHaveBeenCalled() | ||
}) | ||
}) |
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 @@ | ||
import React from 'react' | ||
import Button from './Button' | ||
|
||
export const button = () => { | ||
return <Button name='AddFoo' label='Add Foo' /> | ||
} | ||
|
||
export default { | ||
title: 'v2/Button', | ||
component: Button | ||
} |
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,3 @@ | ||
export { default } from './Button' | ||
|
||
// export more components, hooks or helpers below if needed |
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,112 @@ | ||
import { Close as IconClose, Edit as IconEdit } from '../../../icons' | ||
import React, { CSSProperties } from 'react' | ||
import Typography from '../../Typography' | ||
import styled from 'styled-components' | ||
import IconButton from '../../IconButton' | ||
import Paper from '../../Paper' | ||
import Line from '../../Line' | ||
import AddButton from '../../Button' | ||
|
||
export interface IProps { | ||
children: React.ReactNode | ||
label?: string | ||
nested?: boolean | ||
title?: string | ||
name: string | ||
id?: string | ||
editing?: boolean | ||
action?: JSX.Element | null | ||
onClickAdd?(): void | ||
onToggleEdit?(): void | ||
} | ||
|
||
export const Content = styled.div` | ||
flex: 1; | ||
justify-content: center; | ||
display: flex; | ||
flex-direction: column; | ||
padding: 12px; | ||
` | ||
|
||
const Header = styled.div` | ||
display: flex; | ||
` | ||
|
||
export const Title = styled(Typography)` | ||
flex: 1; | ||
` | ||
|
||
const EditButton = styled(IconButton)` | ||
&& { | ||
width: 36px; | ||
height: 36px; | ||
} | ||
` | ||
|
||
const NESTED_ELEVATION = 0 | ||
|
||
const paperStyle: CSSProperties = { | ||
flex: 1, | ||
display: 'flex', | ||
flexDirection: 'column' | ||
} | ||
|
||
const Card = (props: IProps) => { | ||
const { | ||
id, | ||
name, | ||
nested, | ||
title, | ||
action, | ||
onToggleEdit, | ||
editing, | ||
label, | ||
children, | ||
onClickAdd, | ||
...otherProps | ||
} = props | ||
|
||
return ( | ||
<Paper | ||
{...otherProps} | ||
name={name} | ||
id={id} | ||
style={paperStyle} | ||
className='showable' | ||
elevation={nested ? NESTED_ELEVATION : undefined} | ||
padding={nested ? '0' : '24px'}> | ||
{title && ( | ||
<> | ||
<Header> | ||
{title && ( | ||
<Title | ||
name={name + '-title'} | ||
variant='h6' | ||
color='primary'> | ||
{title} | ||
</Title> | ||
)} | ||
{action} | ||
{onToggleEdit && ( | ||
<EditButton | ||
className={editing ? '' : 'showable-target'} | ||
name={`${editing ? 'cancel' : 'edit'}-${name}`} | ||
margin='-10px' | ||
padding='0px' | ||
onClick={onToggleEdit}> | ||
{editing ? <IconClose /> : <IconEdit />} | ||
</EditButton> | ||
)} | ||
</Header> | ||
<div> | ||
<Line /> | ||
</div> | ||
</> | ||
)} | ||
{onClickAdd && <AddButton onClick={onClickAdd} />} | ||
<div>{children}</div> | ||
</Paper> | ||
) | ||
} | ||
|
||
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,16 @@ | ||
import React from 'react' | ||
import Card from './Card' | ||
import Typography from '../../Typography' | ||
|
||
export const card = () => { | ||
return ( | ||
<Card name='Card' title='Foo Bar'> | ||
<Typography>Dummy content</Typography> | ||
</Card> | ||
) | ||
} | ||
|
||
export default { | ||
title: 'experimental/Card', | ||
component: 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,3 @@ | ||
export { default } from './Card' | ||
|
||
// export more components, hooks or helpers below if needed |
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,45 @@ | ||
import React from 'react' | ||
import DialogV2 from './Dialog' | ||
|
||
export interface IProps { | ||
open: boolean | ||
title: string | ||
text: string | ||
disableBackdropClick?: boolean | ||
labels?: { | ||
cancel?: string | ||
confirm?: string | ||
} | ||
onCancel(): void | ||
onConfirm(): void | ||
} | ||
|
||
const ConfirmDialog = (props: IProps) => { | ||
const { | ||
open, | ||
title, | ||
text, | ||
labels, | ||
onCancel, | ||
onConfirm, | ||
disableBackdropClick, | ||
...otherProps | ||
} = props | ||
|
||
return ( | ||
<DialogV2 | ||
{...otherProps} | ||
open={open} | ||
title={title} | ||
text={text} | ||
primaryButtonAction={onConfirm} | ||
primaryButtonText={(labels && labels.confirm) || 'Sim'} | ||
secondaryButtonText={(labels && labels.cancel) || 'Voltar'} | ||
primaryButtonColor='primary' | ||
secondaryButtonAction={onCancel} | ||
onClose={disableBackdropClick ? undefined : onCancel} | ||
/> | ||
) | ||
} | ||
|
||
export default ConfirmDialog |
Oops, something went wrong.