chore: initial deploy for code base
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import React from 'react';
|
||||
import { render, screen,} from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import '@testing-library/jest-dom';
|
||||
import Checkbox from './Checkbox';
|
||||
|
||||
test('verify check', () => {
|
||||
const handleChange = () => {console.log("You clicked!")};
|
||||
render(<>
|
||||
<Checkbox onChange={handleChange}>One</Checkbox>
|
||||
</>);
|
||||
|
||||
// get checkbox by text
|
||||
const checkboxOne = screen.getByRole("checkbox", { name: "One" });
|
||||
userEvent.click(checkboxOne);
|
||||
|
||||
expect(checkboxOne).toBeChecked();
|
||||
});
|
||||
|
||||
test('disabled checkbox not clickable', () => {
|
||||
const handleChange = () => {console.log("You clicked!")};
|
||||
render(<>
|
||||
<Checkbox disabled onChange={handleChange}>One</Checkbox>
|
||||
</>);
|
||||
|
||||
// get checkbox by text
|
||||
const checkboxOne = screen.getByRole("checkbox", { name: "One" });
|
||||
userEvent.click(checkboxOne);
|
||||
|
||||
expect(checkboxOne).not.toBeChecked();
|
||||
});
|
||||
|
||||
test('checked checkbox becomes unchecked', () => {
|
||||
const handleChange = () => {console.log("You clicked!")};
|
||||
render(<>
|
||||
<Checkbox defaultChecked onChange={handleChange}>One</Checkbox>
|
||||
</>);
|
||||
|
||||
// get checkbox by text
|
||||
const checkboxOne = screen.getByRole("checkbox", { name: "One" });
|
||||
//make sure the checkbox is checked by default
|
||||
expect(checkboxOne).toBeChecked();
|
||||
//now uncheck it
|
||||
userEvent.click(checkboxOne);
|
||||
|
||||
expect(checkboxOne).not.toBeChecked();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import * as React from "react";
|
||||
import { Checkbox as AntCheckbox } from "antd";
|
||||
import { CheckboxChangeEvent } from "antd/lib/checkbox/Checkbox";
|
||||
import { logger } from "@strata/logging/lib/logger";
|
||||
|
||||
export { CheckboxChangeEvent } from "antd/lib/checkbox/Checkbox";
|
||||
|
||||
export interface ICheckboxProps {
|
||||
/** Default the checkbox to selected */
|
||||
defaultChecked?: boolean;
|
||||
|
||||
/** Is the checkbox selected */
|
||||
checked?: boolean;
|
||||
|
||||
/** Whether checkbox is in indeterminate state (tri-state mode) */
|
||||
indeterminate?: boolean;
|
||||
|
||||
/** Disable item */
|
||||
disabled?: boolean;
|
||||
|
||||
/** Get focus on load */
|
||||
autoFocus?: boolean;
|
||||
|
||||
/** Called on value change */
|
||||
onChange?: (e: CheckboxChangeEvent) => void;
|
||||
|
||||
/** Input name */
|
||||
name?: string;
|
||||
|
||||
/** HTML input ID */
|
||||
id?: string;
|
||||
|
||||
/** Additional log data */
|
||||
logData?: object;
|
||||
|
||||
/** Turn off logging. Default to false */
|
||||
disableLogging?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkboxes allows users to select a single option.
|
||||
*/
|
||||
const Checkbox: React.FC<ICheckboxProps> = (props) => {
|
||||
const { onChange, disableLogging = false, logData, ...validProps } = props;
|
||||
|
||||
const onChangeInternal = (e: CheckboxChangeEvent) => {
|
||||
!disableLogging && logger.log("checkbox click", props.name ?? props.id ?? "", logData);
|
||||
onChange && onChange(e);
|
||||
}
|
||||
|
||||
return (
|
||||
<AntCheckbox {...validProps} onChange={onChangeInternal}>{props.children}</AntCheckbox>
|
||||
);
|
||||
}
|
||||
|
||||
export default Checkbox;
|
||||
@@ -0,0 +1,4 @@
|
||||
import CheckBox, { ICheckboxProps, CheckboxChangeEvent } from "./Checkbox"
|
||||
|
||||
export default CheckBox;
|
||||
export { ICheckboxProps, CheckboxChangeEvent };
|
||||
Reference in New Issue
Block a user