Merge pull request #42 from twentyhq/sammy/t-79-i-can-see-checkboxes-ui
feature: add checkbox on people cells
This commit is contained in:
44
front/src/components/form/Checkbox.tsx
Normal file
44
front/src/components/form/Checkbox.tsx
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
|
type OwnProps = {
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const StyledContainer = styled.span`
|
||||||
|
input[type='checkbox'] {
|
||||||
|
accent-color: ${(props) => props.theme.blue};
|
||||||
|
margin: 8px;
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='checkbox']::before {
|
||||||
|
content: '';
|
||||||
|
border: 1px solid black;
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
border-radius: 2px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='checkbox']:checked::before {
|
||||||
|
border: 1px solid ${(props) => props.theme.blue};
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
function Checkbox({ name, id }: OwnProps) {
|
||||||
|
return (
|
||||||
|
<StyledContainer>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
data-testid="input-checkbox"
|
||||||
|
id={id}
|
||||||
|
name={name}
|
||||||
|
></input>
|
||||||
|
</StyledContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Checkbox;
|
||||||
20
front/src/components/form/__stories__/Checkbox.stories.tsx
Normal file
20
front/src/components/form/__stories__/Checkbox.stories.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
|
|
||||||
|
import Checkbox from '../Checkbox';
|
||||||
|
import { ThemeProvider } from '@emotion/react';
|
||||||
|
import { lightTheme } from '../../../layout/styles/themes';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Checkbox',
|
||||||
|
component: Checkbox,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RegularCheckbox = () => {
|
||||||
|
return (
|
||||||
|
<ThemeProvider theme={lightTheme}>
|
||||||
|
<MemoryRouter initialEntries={['/companies']}>
|
||||||
|
<Checkbox name="selected-company-1" id="selected-company--1" />
|
||||||
|
</MemoryRouter>
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
12
front/src/components/form/__tests__/Checkbox.test.tsx
Normal file
12
front/src/components/form/__tests__/Checkbox.test.tsx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { render } from '@testing-library/react';
|
||||||
|
|
||||||
|
import { RegularCheckbox } from '../__stories__/Checkbox.stories';
|
||||||
|
|
||||||
|
it('Checks the NavItem renders', () => {
|
||||||
|
const { getByTestId } = render(<RegularCheckbox />);
|
||||||
|
|
||||||
|
expect(getByTestId('input-checkbox')).toHaveAttribute(
|
||||||
|
'name',
|
||||||
|
'selected-company-1',
|
||||||
|
);
|
||||||
|
});
|
||||||
16
front/src/layout/containers/HorizontalyAlignedContainer.tsx
Normal file
16
front/src/layout/containers/HorizontalyAlignedContainer.tsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
|
type OwnProps = {
|
||||||
|
children: JSX.Element[];
|
||||||
|
};
|
||||||
|
|
||||||
|
const StyledContainer = styled.div`
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
`;
|
||||||
|
|
||||||
|
function HorizontalyAlignedContainer({ children: children }: OwnProps) {
|
||||||
|
return <StyledContainer>{children}</StyledContainer>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HorizontalyAlignedContainer;
|
||||||
@ -16,6 +16,8 @@ import CellLink from '../../components/table/CellLink';
|
|||||||
import ColumnHead from '../../components/table/ColumnHead';
|
import ColumnHead from '../../components/table/ColumnHead';
|
||||||
import personPlaceholder from './placeholder.png';
|
import personPlaceholder from './placeholder.png';
|
||||||
import { parsePhoneNumber, CountryCode } from 'libphonenumber-js';
|
import { parsePhoneNumber, CountryCode } from 'libphonenumber-js';
|
||||||
|
import Checkbox from '../../components/form/Checkbox';
|
||||||
|
import HorizontalyAlignedContainer from '../../layout/containers/HorizontalyAlignedContainer';
|
||||||
|
|
||||||
type Person = {
|
type Person = {
|
||||||
fullName: string;
|
fullName: string;
|
||||||
@ -105,11 +107,17 @@ const columns = [
|
|||||||
columnHelper.accessor('fullName', {
|
columnHelper.accessor('fullName', {
|
||||||
header: () => <ColumnHead viewName="People" viewIcon={faUser} />,
|
header: () => <ColumnHead viewName="People" viewIcon={faUser} />,
|
||||||
cell: (props) => (
|
cell: (props) => (
|
||||||
<CellLink
|
<HorizontalyAlignedContainer>
|
||||||
name={props.row.original.fullName}
|
<Checkbox
|
||||||
picture={props.row.original.picture}
|
id={`person-selected-${props.row.original.email}`}
|
||||||
href="#"
|
name={`person-selected${props.row.original.email}`}
|
||||||
/>
|
/>
|
||||||
|
<CellLink
|
||||||
|
name={props.row.original.fullName}
|
||||||
|
picture={props.row.original.picture}
|
||||||
|
href="#"
|
||||||
|
/>
|
||||||
|
</HorizontalyAlignedContainer>
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
columnHelper.accessor('email', {
|
columnHelper.accessor('email', {
|
||||||
|
|||||||
Reference in New Issue
Block a user