Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shayan/74991/checkbox component ts migration #27

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0a42512
refactor: migrating to ts [WIP]
Sep 14, 2022
1185eae
Merge branch 'master' of github.com:binary-com/deriv-app into shayan/…
Sep 14, 2022
5e17ec7
fix : fixed all TS errors [WIP]
Sep 14, 2022
b34b258
fix: added missed value
Sep 14, 2022
68214d6
chore: uncomment Icon and Text component usage
Sep 14, 2022
6c3f96e
Merge branch 'master' of github.com:binary-com/deriv-app into shayan/…
Sep 14, 2022
d365b50
chore: removed checkbox.types.ts
Sep 14, 2022
ab52610
Merge branch 'master' into shayan/74991/checkbox-component-ts-migration
shayan-deriv Sep 15, 2022
caff429
Merge branch 'master' into shayan/74991/checkbox-component-ts-migration
shayan-deriv Sep 15, 2022
8c6a137
Update packages/components/src/components/checkbox/checkbox.tsx
shayan-deriv Sep 15, 2022
cc419d0
refactor: added pr review suggestions
Sep 15, 2022
fc28036
Merge branch 'shayan/74991/checkbox-component-ts-migration' of github…
Sep 15, 2022
37c892e
Merge branch 'master' into shayan/74991/checkbox-component-ts-migration
shayan-deriv Sep 15, 2022
95ed287
Merge branch 'master' into shayan/74991/checkbox-component-ts-migration
shayan-deriv Sep 18, 2022
67dbb4c
Merge branch 'master' into shayan/74991/checkbox-component-ts-migration
shayan-deriv Sep 26, 2022
e25f16f
Merge branch 'components-shared-ts-migration-parent' of github.com:ji…
Sep 28, 2022
dc1e376
Merge branch 'components-shared-ts-migration-parent' of github.com:ji…
Sep 28, 2022
50af559
chore: added some changes
Sep 28, 2022
48efa25
Merge branch 'components-shared-ts-migration-parent' of github.com:ji…
Oct 2, 2022
2e7e8e0
fix: resolve pr comments
Oct 2, 2022
de657e6
Merge branch 'components-shared-ts-migration-parent' of github.com:ji…
Oct 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ const PersonalDetails = ({
{title}
</Text>
)}
withTabIndex='0'
withTabIndex={0}
data-testid='tax_identification_confirm'
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import Icon from '../icon';
import Text from '../text';

const Checkbox = React.forwardRef(
type TCheckBoxProps = Omit<React.HTMLProps<HTMLInputElement>, 'value'> & {
className?: string;
classNameLabel?: string;
defaultChecked?: boolean;
disabled?: boolean;
greyDisabled?: boolean;
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
id?: string;
label: string;
onChange: (e: React.ChangeEvent<HTMLInputElement> | React.KeyboardEvent<HTMLSpanElement>) => void;
value?: boolean;
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
withTabIndex?: number;
};

const Checkbox = React.forwardRef<HTMLInputElement, TCheckBoxProps>(
(
{
className,
classNameLabel,
disabled,
disabled = false,
id,
label,
defaultChecked,
onChange, // This needs to be here so it's not included in `otherProps`
value,
withTabIndex,
value = false,
withTabIndex = 0,
greyDisabled = false,
...otherProps
},
ref
) => {
const [checked, setChecked] = React.useState(defaultChecked || value);
const input_ref = React.useRef();

const setRef = el_input => {
input_ref.current = el_input;
if (ref) ref.current = el_input;
};

React.useEffect(() => {
setChecked(defaultChecked || value);
}, [value, defaultChecked]);

const onInputChange = e => {
const onInputChange: React.ChangeEventHandler<HTMLInputElement> = e => {
e.persist();
setChecked(!checked);
onChange(e);
};

const handleKeyDown = e => {
const handleKeyDown: React.KeyboardEventHandler<HTMLSpanElement> = e => {
// Enter or space
if (!disabled && (e.key === 'Enter' || e.keyCode === 32)) {
onChange({ target: { name: input_ref.current.name, checked: !checked } });
onChange(e);
setChecked(!checked);
}
};
Expand All @@ -59,11 +64,11 @@ const Checkbox = React.forwardRef(
className='dc-checkbox__input'
type='checkbox'
id={id}
ref={setRef}
ref={ref}
disabled={disabled}
onChange={onInputChange}
defaultChecked={checked}
value={value}
checked={value}
{...otherProps}
/>
<span
Expand All @@ -72,8 +77,7 @@ const Checkbox = React.forwardRef(
'dc-checkbox__box--disabled': disabled,
'dc-checkbox--grey-disabled': disabled && greyDisabled,
})}
{...(withTabIndex?.length > 0 ? { tabIndex: withTabIndex } : {})}
tabIndex='0'
tabIndex={withTabIndex}
onKeyDown={handleKeyDown}
>
{!!checked && <Icon icon='IcCheckmark' color='active' />}
Expand All @@ -88,17 +92,4 @@ const Checkbox = React.forwardRef(

Checkbox.displayName = 'Checkbox';

Checkbox.propTypes = {
className: PropTypes.string,
classNameLabel: PropTypes.string,
defaultChecked: PropTypes.bool,
disabled: PropTypes.bool,
greyDisabled: PropTypes.bool,
id: PropTypes.string,
label: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
onChange: PropTypes.func,
value: PropTypes.bool,
withTabIndex: PropTypes.string,
};

export default Checkbox;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Checkbox from './checkbox.jsx';
import Checkbox from './checkbox';
import './checkbox.scss';

export default Checkbox;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import Checkbox from '../checkbox/checkbox.jsx';
import Checkbox from '../checkbox/checkbox';
import Text from '../text';

const CompositeCheckbox = ({ name, value, onChange, className, label, id, description, children, ...props }) => {
Expand Down