refactor: create company chip
This commit is contained in:
44
front/src/components/chips/CompanyChip.tsx
Normal file
44
front/src/components/chips/CompanyChip.tsx
Normal file
@ -0,0 +1,44 @@
|
||||
import * as React from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
type OwnProps = {
|
||||
name: string;
|
||||
picture?: string;
|
||||
};
|
||||
|
||||
const StyledContainer = styled.span`
|
||||
background-color: ${(props) => props.theme.tertiaryBackground};
|
||||
border-radius: ${(props) => props.theme.spacing(1)};
|
||||
color: ${(props) => props.theme.text80};
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: ${(props) => props.theme.spacing(1)};
|
||||
gap: ${(props) => props.theme.spacing(1)};
|
||||
|
||||
:hover {
|
||||
filter: brightness(95%);
|
||||
}
|
||||
|
||||
img {
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
object-fit: cover;
|
||||
}
|
||||
`;
|
||||
|
||||
function CompanyChip({ name, picture }: OwnProps) {
|
||||
return (
|
||||
<StyledContainer data-testid="company-chip">
|
||||
{picture && (
|
||||
<img
|
||||
data-testid="company-chip-image"
|
||||
src={picture?.toString()}
|
||||
alt=""
|
||||
/>
|
||||
)}
|
||||
{name}
|
||||
</StyledContainer>
|
||||
);
|
||||
}
|
||||
|
||||
export default CompanyChip;
|
||||
30
front/src/components/chips/__stories__/CompanyChip.tsx
Normal file
30
front/src/components/chips/__stories__/CompanyChip.tsx
Normal file
@ -0,0 +1,30 @@
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
|
||||
import CompanyChip from '../CompanyChip';
|
||||
import { ThemeProvider } from '@emotion/react';
|
||||
import { lightTheme } from '../../../layout/styles/themes';
|
||||
|
||||
export default {
|
||||
title: 'CompanyChip',
|
||||
component: CompanyChip,
|
||||
};
|
||||
|
||||
export const RegularCompanyChip = () => {
|
||||
return (
|
||||
<ThemeProvider theme={lightTheme}>
|
||||
<MemoryRouter initialEntries={['/companies']}>
|
||||
<CompanyChip name="selected-company-1" />
|
||||
</MemoryRouter>
|
||||
</ThemeProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export const RegularCompanyChipWithImage = () => {
|
||||
return (
|
||||
<ThemeProvider theme={lightTheme}>
|
||||
<MemoryRouter initialEntries={['/companies']}>
|
||||
<CompanyChip name="selected-company-1" picture="coucou.fr" />
|
||||
</MemoryRouter>
|
||||
</ThemeProvider>
|
||||
);
|
||||
};
|
||||
18
front/src/components/chips/__tests__/CompanyChip.test.tsx
Normal file
18
front/src/components/chips/__tests__/CompanyChip.test.tsx
Normal file
@ -0,0 +1,18 @@
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import {
|
||||
RegularCompanyChip,
|
||||
RegularCompanyChipWithImage,
|
||||
} from '../__stories__/CompanyChip';
|
||||
|
||||
it('Checks the NavItem renders', () => {
|
||||
const { getByText } = render(<RegularCompanyChip />);
|
||||
|
||||
expect(getByText('selected-company-1')).toBeDefined();
|
||||
});
|
||||
|
||||
it('Checks the img renders', () => {
|
||||
const { getByTestId } = render(<RegularCompanyChipWithImage />);
|
||||
|
||||
expect(getByTestId('company-chip-image')).toHaveAttribute('src', 'coucou.fr');
|
||||
});
|
||||
@ -1,6 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { Link } from 'react-router-dom';
|
||||
import CompanyChip from '../chips/CompanyChip';
|
||||
|
||||
type OwnProps = {
|
||||
name: string;
|
||||
@ -8,33 +8,10 @@ type OwnProps = {
|
||||
href: string;
|
||||
};
|
||||
|
||||
const StyledContainer = styled.span`
|
||||
background-color: ${(props) => props.theme.tertiaryBackground};
|
||||
border-radius: ${(props) => props.theme.spacing(1)};
|
||||
color: ${(props) => props.theme.text80};
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: ${(props) => props.theme.spacing(1)};
|
||||
gap: ${(props) => props.theme.spacing(1)};
|
||||
|
||||
:hover {
|
||||
filter: brightness(95%);
|
||||
}
|
||||
|
||||
img {
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
object-fit: cover;
|
||||
}
|
||||
`;
|
||||
|
||||
function CellLink({ name, picture, href }: OwnProps) {
|
||||
return (
|
||||
<Link to={href}>
|
||||
<StyledContainer>
|
||||
{picture && <img src={picture?.toString()} alt="" />}
|
||||
{name}
|
||||
</StyledContainer>
|
||||
<CompanyChip name={name} picture={picture} />
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user