Skip to content

Commit

Permalink
Merge pull request #33 from jim-deriv/Jim/74985/button-and-loading-co…
Browse files Browse the repository at this point in the history
…mponents-ts-migration-new

Jim/74985/button and loading components ts migration new
  • Loading branch information
jim-deriv committed Sep 29, 2022
2 parents 431bc56 + 7daf957 commit be2caff
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import HighlightWrapper from './button-highlight-wrapper.jsx';
import Button from '../button/button.jsx';
import Counter from '../counter/counter';
import Button from '../button/button';

const ButtonToggle = ({ buttons_arr, className, has_rounded_button, id, is_animated, name, onChange, value }) => {
const changeValue = selected_value => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import ButtonLoading from './button_loading.jsx';
import ButtonLoading from './button_loading';
import Icon from '../icon';
import Text from '../text';

const ButtonGroup = ({ children, className }) => (
type TButtonProps = React.PropsWithChildren<React.ButtonHTMLAttributes<HTMLButtonElement>> & {
alternate: boolean;
blue: boolean;
classNameSpan: string;
green: boolean;
has_effect: boolean;
icon: React.ReactNode;
is_button_toggle: boolean;
is_circular: boolean;
is_circle: boolean;
is_disabled: boolean;
is_loading: boolean;
is_plus: boolean;
is_submit_success: boolean;
large: boolean;
medium: boolean;
primary: boolean;
primary_light: boolean;
renderText: (param: React.ReactNode) => React.ReactNode;
rounded: boolean;
secondary: boolean;
small: boolean;
tertiary: boolean;
text: string;
transparent: boolean;
type: 'button' | 'submit' | 'reset';
wrapperClassName: string;
};

const ButtonGroup = ({ children, className }: React.PropsWithChildren<HTMLDivElement>) => (
<div className={classNames('dc-btn__group', className)}>{children}</div>
);
const Button = ({
Expand All @@ -28,7 +56,7 @@ const Button = ({
medium,
onClick,
rounded,
tabIndex,
tabIndex = 0,
text,
wrapperClassName,
type,
Expand All @@ -41,7 +69,7 @@ const Button = ({
tertiary,
renderText,
...props
}) => {
}: Partial<TButtonProps>) => {
const classes = classNames(
'dc-btn',
{
Expand Down Expand Up @@ -71,9 +99,9 @@ const Button = ({
<button
id={id}
className={classes}
onClick={onClick || undefined}
onClick={onClick}
disabled={is_disabled}
tabIndex={tabIndex || '0'}
tabIndex={tabIndex}
type={is_submit_success ? 'button' : type || 'submit'}
{...props}
>
Expand All @@ -100,40 +128,6 @@ const Button = ({
return wrapperClassName ? wrapper : button;
};

Button.propTypes = {
blue: PropTypes.bool,
children: PropTypes.node,
className: PropTypes.string,
classNameSpan: PropTypes.string,
green: PropTypes.bool,
has_effect: PropTypes.bool,
icon: PropTypes.node,
id: PropTypes.string,
is_disabled: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]),
is_loading: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
is_circle: PropTypes.bool,
is_plus: PropTypes.bool,
is_submit_success: PropTypes.bool,
large: PropTypes.bool,
medium: PropTypes.bool,
onClick: PropTypes.func,
primary: PropTypes.bool,
primary_light: PropTypes.bool,
rounded: PropTypes.bool,
secondary: PropTypes.bool,
small: PropTypes.bool,
tertiary: PropTypes.bool,
transparent: PropTypes.bool,
text: PropTypes.string,
wrapperClassName: PropTypes.string,
is_button_toggle: PropTypes.bool,
is_circular: PropTypes.bool,
tabIndex: PropTypes.string,
type: PropTypes.string,
alternate: PropTypes.bool,
renderText: PropTypes.func,
};

Button.Group = ButtonGroup;

export default Button;
9 changes: 0 additions & 9 deletions packages/components/src/components/button/button_loading.jsx

This file was deleted.

11 changes: 11 additions & 0 deletions packages/components/src/components/button/button_loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import Loading, { TLoadingProps } from '../loading/loading';
import '../loading/loading.scss';

const ButtonLoading = (
props: Omit<TLoadingProps, 'is_fullscreen' | 'className' | 'is_slow_loading' | 'status' | 'theme'>
) => {
return <Loading {...props} is_fullscreen={false} className='initial-loader--btn' />;
};

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

export default Button;
2 changes: 1 addition & 1 deletion packages/components/src/components/carousel/carousel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Swipeable } from 'react-swipeable';
import Card from './carousel-card.jsx';
import Nav from './carousel-nav.jsx';
import Icon from '../icon';
import Button from '../button/button.jsx';
import Button from '../button/button';
import { useInterval } from '../../hooks';

const Carousel = ({
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/dialog/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import classNames from 'classnames';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import { CSSTransition } from 'react-transition-group';
import Button from '../button/button.jsx';
import Icon from '../icon/icon';
import Button from '../button/button';
import Text from '../text';
import { useOnClickOutside } from '../../hooks';

Expand Down
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 Button from '../button/button.jsx';
import Button from '../button/button';

const FormCancelButton = ({ className, is_center, is_disabled, is_absolute, label, onCancel, ...props }) => {
return (
Expand Down
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 Button from '../button/button.jsx';
import Button from '../button/button';
import Text from '../text';

const FormSubmitButton = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Loading from './loading.jsx';
import Loading from './loading';
import './loading.scss';

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

const Loading = ({ className, id, is_fullscreen = true, is_slow_loading, status, theme }) => {
export type TLoadingProps = React.HTMLProps<HTMLDivElement> & {
is_fullscreen: boolean;
is_slow_loading: boolean;
status: string[];
theme: string;
};

const Loading = ({ className, id, is_fullscreen = true, is_slow_loading, status, theme }: Partial<TLoadingProps>) => {
const theme_class = theme ? `barspinner-${theme}` : 'barspinner-light';
return (
<div
Expand All @@ -27,7 +33,7 @@ const Loading = ({ className, id, is_fullscreen = true, is_slow_loading, status,
))}
</div>
{is_slow_loading &&
status.map((text, inx) => (
status?.map((text, inx) => (
<Text as='h3' color='prominent' size='xs' align='center' key={inx}>
{text}
</Text>
Expand All @@ -36,12 +42,4 @@ const Loading = ({ className, id, is_fullscreen = true, is_slow_loading, status,
);
};

Loading.propTypes = {
className: PropTypes.string,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
is_fullscreen: PropTypes.bool,
is_slow_loading: PropTypes.bool,
status: PropTypes.array,
theme: PropTypes.string,
};
export default Loading;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import Button from '../button/button.jsx';
import Button from '../button/button';
import Text from '../text';

const NumberButton = ({ onSelect, className, number }) => (
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/numpad/numpad.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classNames from 'classnames';
import NumberGrid from './number-grid.jsx';
import StepInput from './step-input.jsx';
import Text from '../text';
import Button from '../button/button.jsx';
import Button from '../button/button';
import { useLongPress } from '../../hooks';

const concatenate = (number, default_value) => default_value.toString().concat(number);
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/numpad/step-input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import { isCryptocurrency } from '@deriv/shared';
import Input from '../input/input.jsx';
import Button from '../button/button.jsx';
import Button from '../button/button';

const getDecimals = val => {
const array_value = typeof val === 'string' ? val.split('.') : val.toString().split('.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { isMobile } from '@deriv/shared';
import Button from '../button/button';
import Modal from '../modal/modal';
import Button from '../button/button.jsx';
import Popover from '../popover/popover.jsx';
import Text from '../text/text';
import './popover-mobile.scss';
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/popup/popup-overlay.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { createPortal } from 'react-dom';
import PropTypes from 'prop-types';
import Button from '../button/button.jsx';
import Text from '../text/text';
import Button from '../button/button';

const PopupOverlay = ({ title, descriptions, overlay_ref, toggleOverlay, done_text }) =>
createPortal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';
import { PlatformContext } from '@deriv/shared';
import Button from '../button/button.jsx';
import Icon from '../icon/icon';
import Button from '../button/button';
import Text from '../text';

const SendEmailTemplate = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classNames from 'classnames';
import React from 'react';
import throttle from 'lodash.throttle';
import { useSwipeable } from 'react-swipeable';
import Button from '../button/button.jsx';
import Button from '../button/button';
import Icon from '../icon';
import Text from '../text';

Expand Down

0 comments on commit be2caff

Please sign in to comment.