Skip to content

Commit 0055dd7

Browse files
authored
refactor: checkbox component visible flag (#1780)
Signed-off-by: Adam Setch <[email protected]>
1 parent 2713100 commit 0055dd7

File tree

5 files changed

+407
-50
lines changed

5 files changed

+407
-50
lines changed

src/renderer/components/fields/Checkbox.test.tsx

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,25 @@ describe('renderer/components/fields/Checkbox.tsx', () => {
99
onChange: jest.fn(),
1010
};
1111

12-
it('should render', () => {
12+
it('should render - visible', () => {
1313
const tree = render(<Checkbox {...props} />);
1414
expect(tree).toMatchSnapshot();
1515
});
16+
17+
it('should render - not visible', () => {
18+
const tree = render(<Checkbox visible={false} {...props} />);
19+
expect(tree).toMatchSnapshot();
20+
});
21+
22+
it('should render - disabled', () => {
23+
const tree = render(<Checkbox disabled={true} {...props} />);
24+
expect(tree).toMatchSnapshot();
25+
});
26+
27+
it('should render - tooltip', () => {
28+
const tree = render(
29+
<Checkbox {...props} tooltip={<div>Hello world</div>} />,
30+
);
31+
expect(tree).toMatchSnapshot();
32+
});
1633
});

src/renderer/components/fields/Checkbox.tsx

+34-28
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,45 @@ export interface ICheckbox {
1111
tooltip?: ReactNode | string;
1212
checked: boolean;
1313
disabled?: boolean;
14+
visible?: boolean;
1415
onChange: (evt: React.ChangeEvent<HTMLInputElement>) => void;
1516
}
1617

17-
export const Checkbox: FC<ICheckbox> = (props: ICheckbox) => {
18+
export const Checkbox: FC<ICheckbox> = ({
19+
visible = true,
20+
...props
21+
}: ICheckbox) => {
1822
return (
19-
<Stack
20-
direction="horizontal"
21-
gap="condensed"
22-
align="center"
23-
className="text-sm"
24-
>
25-
<input
26-
type="checkbox"
27-
id={props.name}
28-
className="size-4 rounded-sm cursor-pointer"
29-
checked={props.checked}
30-
onChange={props.onChange}
31-
disabled={props.disabled}
32-
data-testid={`checkbox-${props.name}`}
33-
/>
23+
visible && (
24+
<Stack
25+
direction="horizontal"
26+
gap="condensed"
27+
align="center"
28+
className="text-sm"
29+
>
30+
<input
31+
type="checkbox"
32+
id={props.name}
33+
className="size-4 rounded-sm cursor-pointer"
34+
checked={props.checked}
35+
onChange={props.onChange}
36+
disabled={props.disabled}
37+
data-testid={`checkbox-${props.name}`}
38+
/>
3439

35-
<label
36-
htmlFor={props.name}
37-
className={cn(
38-
'font-medium text-gitify-font cursor-pointer',
39-
props.disabled && 'line-through',
40+
<label
41+
htmlFor={props.name}
42+
className={cn(
43+
'font-medium text-gitify-font cursor-pointer',
44+
props.disabled && 'line-through',
45+
)}
46+
>
47+
{props.label}
48+
</label>
49+
{props.tooltip && (
50+
<Tooltip name={`tooltip-${props.name}`} tooltip={props.tooltip} />
4051
)}
41-
>
42-
{props.label}
43-
</label>
44-
{props.tooltip && (
45-
<Tooltip name={`tooltip-${props.name}`} tooltip={props.tooltip} />
46-
)}
47-
</Stack>
52+
</Stack>
53+
)
4854
);
4955
};

0 commit comments

Comments
 (0)