Skip to content

Commit

Permalink
RAC-225: fix missing prettier on tsx files
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenVAIDIE committed Sep 11, 2020
1 parent 87aba67 commit a81a746
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 51 deletions.
2 changes: 1 addition & 1 deletion akeneo-design-system/package.json
Expand Up @@ -15,7 +15,7 @@
"test:visual:run": "jest --config ./jest.visual.config.js",
"test:unit:watch": "jest --watch",
"eslint": "eslint --config .eslintrc.json --quiet src/**/*.tsx",
"lint:fix": "prettier --config .prettierrc.json --parser typescript --write \"./src/**/*.ts\";",
"lint:fix": "prettier --config .prettierrc.json --parser typescript --write \"./src/**/*.{ts,tsx}\";",
"lint:check": "prettier --config .prettierrc.json --parser typescript --check \"./src/**/*.ts\" && eslint --config .eslintrc.json --quiet src/**/*.{ts,tsx}",
"storybook:start": "start-storybook -p 6006",
"storybook:ci": "start-storybook -p 6006 --ci",
Expand Down
58 changes: 28 additions & 30 deletions akeneo-design-system/src/components/Checkbox/Checkbox.tsx
Expand Up @@ -15,7 +15,7 @@ to {
`;

const Container = styled.div`
display: flex;
display: flex;
`;

const TickIcon = styled(CheckIcon)`
Expand All @@ -27,16 +27,17 @@ const TickIcon = styled(CheckIcon)`
transition: opacity 0.1s ease-out;
`;

const CheckboxContainer = styled.div <{ checked: boolean, readOnly: boolean }>`
const CheckboxContainer = styled.div<{checked: boolean; readOnly: boolean}>`
background-color: transparent;
height: 20px;
width: 20px;
border: 1px solid ${({theme}) => theme.palette.checkbox.borderColor};
border-radius: 3px;
outline: none;
${props =>
(props.checked) && css`
${(props) =>
props.checked &&
css`
background-color: ${({theme}) => theme.palette.checkbox.checked.backgroundColor};
${TickIcon} {
animation-delay: 0.2s;
Expand All @@ -45,59 +46,64 @@ const CheckboxContainer = styled.div <{ checked: boolean, readOnly: boolean }>`
opacity: 1;
transition-delay: 0s;
}
`}
`}
${props =>
props.checked && props.readOnly && css`
${(props) =>
props.checked &&
props.readOnly &&
css`
background-color: ${({theme}) => theme.palette.checkbox.checkedAndDisabled.backgroundColor};
border-color: ${({theme}) => theme.palette.checkbox.checkedAndDisabled.borderColor};
`}
`}
${props =>
!props.checked && props.readOnly && css`
${(props) =>
!props.checked &&
props.readOnly &&
css`
background-color: ${({theme}) => theme.palette.checkbox.disabled.backgroundColor};
border-color: ${({theme}) => theme.palette.checkbox.disabled.borderColor};
`}
`}
`;

const LabelContainer = styled.div <{ readOnly: boolean }>`
const LabelContainer = styled.div<{readOnly: boolean}>`
color: ${({theme}) => theme.palette.formLabel.color};
font-weight: 400;
font-size: 15px;
padding-left: 10px;
${props =>
props.readOnly && css`
${(props) =>
props.readOnly &&
css`
color: ${({theme}) => theme.palette.formLabel.disabled.color};
`}
`}
`;

type CheckboxProps = {
/**
* State of the Checkbox
*/
checked: boolean,
checked: boolean;

/**
* Displays the value of the input, but does not allow changes.s
*/
readOnly?: boolean,
readOnly?: boolean;

/**
* The undetermined state comes into play when the checkbox contains a sublist of selections,
* some of which are selected, and others aren't.
*/
undetermined?: boolean,
undetermined?: boolean;

/**
* Provide a description of the Checkbox, the label appears on the right of the checkboxes.
*/
label?: string,
label?: string;

/**
* The handler called when clicking on Checkbox
*/
onChange?: (value: boolean) => void,
onChange?: (value: boolean) => void;
};

/**
Expand All @@ -113,17 +119,9 @@ const Checkbox = ({label, checked, onChange, undetermined = false, readOnly = fa
return (
<Container onClick={handleChange}>
<CheckboxContainer checked={checked || undetermined} readOnly={readOnly}>
{undetermined ? (
<PartialCheckIcon height={20} width={20}/>
) :
<TickIcon height={20} width={20}/>
}
{undetermined ? <PartialCheckIcon height={20} width={20} /> : <TickIcon height={20} width={20} />}
</CheckboxContainer>
{label ? (
<LabelContainer readOnly={readOnly}>
{label}
</LabelContainer>
) : null}
{label ? <LabelContainer readOnly={readOnly}>{label}</LabelContainer> : null}
</Container>
);
};
Expand Down
10 changes: 3 additions & 7 deletions akeneo-design-system/src/components/Checkbox/Checkbox.unit.tsx
Expand Up @@ -4,9 +4,7 @@ import {Checkbox} from './Checkbox';

it('it calls onChange handler when user clicks on checkbox', () => {
const onChange = jest.fn();
const {getByText} = render(
<Checkbox checked={true} onChange={onChange} label="Checkbox"/>
);
const {getByText} = render(<Checkbox checked={true} onChange={onChange} label="Checkbox" />);

const checkbox = getByText('Checkbox');
fireEvent.click(checkbox);
Expand All @@ -16,9 +14,7 @@ it('it calls onChange handler when user clicks on checkbox', () => {

it('it does not call onChange handler when read-only', () => {
const onChange = jest.fn();
const {getByText} = render(
<Checkbox checked={true} readOnly={true} onChange={onChange} label="Checkbox"/>
);
const {getByText} = render(<Checkbox checked={true} readOnly={true} onChange={onChange} label="Checkbox" />);

const checkbox = getByText('Checkbox');
fireEvent.click(checkbox);
Expand All @@ -28,6 +24,6 @@ it('it does not call onChange handler when read-only', () => {

it('it cannot be instantiated without handler when not readonly', () => {
expect(() => {
render(<Checkbox checked={true} label="Checkbox"/>);
render(<Checkbox checked={true} label="Checkbox" />);
}).toThrow('A Checkbox element expect an onChange attribute if not readOnly');
});
2 changes: 1 addition & 1 deletion akeneo-design-system/src/components/Dummy/Dummy.tsx
@@ -1,7 +1,7 @@
import React, {ReactNode} from 'react';
import styled from 'styled-components';

const DummyContainer = styled.div<{size: number, type: Type}>`
const DummyContainer = styled.div<{size: number; type: Type}>`
font-size: ${({size}) => size}px;
line-height: ${({size}) => size + 5}px;
color: ${({type}) => (type === 'primary' ? 'blue' : 'green')};
Expand Down
2 changes: 1 addition & 1 deletion akeneo-design-system/src/icons/CheckIcon.tsx
@@ -1,6 +1,6 @@
import React from 'react';

const CheckIcon = ({width = 24, height = 24, className = ''}: {width: number, height: number, className?: string}) => (
const CheckIcon = ({width = 24, height = 24, className = ''}: {width: number; height: number; className?: string}) => (
<svg width={width} height={height} viewBox="0 0 24 24">
<path
className={className}
Expand Down
11 changes: 10 additions & 1 deletion akeneo-design-system/src/icons/PartialCheckIcon.tsx
@@ -1,8 +1,17 @@
import React from 'react';

const PartialCheckIcon = ({width = 24, height = 24}) => (
const PartialCheckIcon = ({
width = 24,
height = 24,
className = '',
}: {
width: number;
height: number;
className?: string;
}) => (
<svg width={width} height={height} viewBox="0 0 24 24">
<path
className={className}
d="M2 12.5h20"
stroke="#FFFFFF"
fill="none"
Expand Down
12 changes: 4 additions & 8 deletions akeneo-design-system/src/shared/test-util.tsx
@@ -1,18 +1,14 @@
import React, {ComponentType, ReactElement, ReactNode} from 'react';
import {render, RenderOptions} from '@testing-library/react';
import AkeneoPim from '../themes/akeneo-pim';
import { ThemeProvider } from 'styled-components';
import {ThemeProvider} from 'styled-components';

const AllTheProviders = ({children}: {children: ReactNode}) => {
return (
<ThemeProvider theme={AkeneoPim}>
{children}
</ThemeProvider>
);
return <ThemeProvider theme={AkeneoPim}>{children}</ThemeProvider>;
};

const customRender = (ui: ReactElement, options?: Omit<RenderOptions, 'queries'>) =>
render(ui, { wrapper: AllTheProviders as ComponentType, ...options });
render(ui, {wrapper: AllTheProviders as ComponentType, ...options});

export * from '@testing-library/react';
export { customRender as render };
export {customRender as render};
4 changes: 2 additions & 2 deletions akeneo-design-system/src/themes/akeneo-pim.tsx
Expand Up @@ -67,8 +67,8 @@ export default {
formLabel: {
color: colorRange.grey140,
disabled: {
color: colorRange.grey100
color: colorRange.grey100,
},
}
},
},
};

0 comments on commit a81a746

Please sign in to comment.