2022-06-24 03:16:01 +00:00
|
|
|
import type {
|
|
|
|
AnchorHTMLAttributes,
|
|
|
|
ButtonHTMLAttributes,
|
|
|
|
ReactNode,
|
|
|
|
} from 'react';
|
2022-03-30 09:49:48 +00:00
|
|
|
import { forwardRef } from 'react';
|
2022-03-01 09:26:26 +00:00
|
|
|
import classNames from 'classnames';
|
2022-03-30 09:49:48 +00:00
|
|
|
import type { IconName } from '../icon';
|
|
|
|
import { Icon } from '../icon';
|
2022-03-08 14:03:50 +00:00
|
|
|
import {
|
2022-03-09 13:05:42 +00:00
|
|
|
includesLeftPadding,
|
|
|
|
includesRightPadding,
|
|
|
|
includesBorderWidth,
|
2022-04-20 19:37:44 +00:00
|
|
|
includesHeight,
|
2022-03-08 14:03:50 +00:00
|
|
|
} from '../../utils/class-names';
|
2022-06-24 03:16:01 +00:00
|
|
|
import classnames from 'classnames';
|
2022-03-07 12:27:56 +00:00
|
|
|
|
2022-08-17 14:10:01 +00:00
|
|
|
type Variant = 'primary' | 'secondary' | 'trade' | 'accent' | 'inline-link';
|
2022-03-07 12:27:56 +00:00
|
|
|
interface CommonProps {
|
2022-06-24 03:16:01 +00:00
|
|
|
children?: ReactNode;
|
2022-08-17 14:10:01 +00:00
|
|
|
variant?: Variant;
|
2022-03-01 09:26:26 +00:00
|
|
|
className?: string;
|
2022-03-02 09:56:05 +00:00
|
|
|
prependIconName?: IconName;
|
|
|
|
appendIconName?: IconName;
|
2022-06-24 03:16:01 +00:00
|
|
|
boxShadow?: boolean;
|
2022-03-01 09:26:26 +00:00
|
|
|
}
|
2022-03-07 12:27:56 +00:00
|
|
|
export interface ButtonProps
|
|
|
|
extends ButtonHTMLAttributes<HTMLButtonElement>,
|
|
|
|
CommonProps {}
|
|
|
|
|
|
|
|
export interface AnchorButtonProps
|
|
|
|
extends AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
|
|
CommonProps {}
|
2022-03-01 09:26:26 +00:00
|
|
|
|
2022-06-24 03:16:01 +00:00
|
|
|
export const getButtonClasses = (
|
|
|
|
className?: string,
|
2022-08-17 14:10:01 +00:00
|
|
|
variant?: Variant,
|
2022-06-24 03:16:01 +00:00
|
|
|
boxShadow?: boolean
|
2022-03-07 21:16:06 +00:00
|
|
|
) => {
|
2022-06-24 03:16:01 +00:00
|
|
|
const paddingLeftProvided = includesLeftPadding(className);
|
|
|
|
const paddingRightProvided = includesRightPadding(className);
|
|
|
|
const borderWidthProvided = includesBorderWidth(className);
|
|
|
|
const heightProvided = includesHeight(className);
|
|
|
|
|
2022-03-23 15:48:50 +00:00
|
|
|
// Add classes into variables if there are multiple classes shared in multiple button styles
|
|
|
|
const sharedClasses =
|
2022-06-24 03:16:01 +00:00
|
|
|
'inline-flex items-center justify-center box-border transition-[background-color] ease-linear duration-50 disabled:no-underline';
|
|
|
|
const commonButtonClasses = classnames(
|
|
|
|
'relative disabled:static',
|
|
|
|
'text-ui font-semibold focus-visible:outline-none border no-underline hover:no-underline',
|
2022-06-28 13:41:43 +00:00
|
|
|
'py-[3px]',
|
2022-06-24 03:16:01 +00:00
|
|
|
{
|
|
|
|
'shadow-none': !boxShadow,
|
|
|
|
'shadow-[3px_3px_0_0] focus-visible:shadow-vega-pink dark:focus-visible:shadow-vega-yellow active:top-[1px] active:left-[1px] active:shadow-[2px_2px_0_0]':
|
|
|
|
boxShadow === undefined || boxShadow,
|
|
|
|
}
|
|
|
|
);
|
2022-03-23 15:48:50 +00:00
|
|
|
const commonDisabled =
|
2022-06-24 03:16:01 +00:00
|
|
|
'disabled:bg-black-10 dark:disabled:bg-white-10 disabled:text-black-60 dark:disabled:text-white-60 disabled:border-black-25 dark:disabled:border-white-25 disabled:shadow-none dark:disabled:shadow-none';
|
2022-03-23 15:48:50 +00:00
|
|
|
const inlineTextColour =
|
|
|
|
'text-black-95 dark:text-white-95 hover:text-black hover:dark:text-white active:text-black dark:active:text-vega-yellow';
|
2022-03-09 13:05:42 +00:00
|
|
|
|
2022-03-23 15:48:50 +00:00
|
|
|
const standardButtonPaddingLeft = `${
|
|
|
|
paddingLeftProvided ? paddingLeftProvided : 'pl-28'
|
|
|
|
}`;
|
|
|
|
const standardButtonPaddingRight = `${
|
|
|
|
paddingRightProvided ? paddingRightProvided : 'pr-28'
|
|
|
|
}`;
|
|
|
|
const inlineButtonPaddingLeft = `${
|
|
|
|
paddingLeftProvided ? paddingLeftProvided : 'pl-4'
|
|
|
|
}`;
|
|
|
|
const inlineButtonPaddingRight = `${
|
|
|
|
paddingRightProvided ? paddingRightProvided : 'pr-4'
|
|
|
|
}`;
|
|
|
|
const standardButtonBorderWidth = `${
|
|
|
|
borderWidthProvided ? borderWidthProvided : 'border'
|
|
|
|
}`;
|
2022-06-28 13:41:43 +00:00
|
|
|
const buttonHeight = `${heightProvided ? heightProvided : ''}`;
|
2022-03-03 11:11:36 +00:00
|
|
|
|
2022-03-23 15:48:50 +00:00
|
|
|
const primaryClasses = [
|
|
|
|
sharedClasses,
|
2022-06-24 03:16:01 +00:00
|
|
|
commonButtonClasses,
|
2022-03-23 15:48:50 +00:00
|
|
|
commonDisabled,
|
|
|
|
standardButtonPaddingLeft,
|
|
|
|
standardButtonPaddingRight,
|
|
|
|
standardButtonBorderWidth,
|
2022-04-20 19:37:44 +00:00
|
|
|
buttonHeight,
|
2022-06-24 03:16:01 +00:00
|
|
|
'bg-black dark:bg-white hover:bg-black-80 dark:hover:bg-white-90 active:bg-black-80 dark:active:bg-white-90',
|
|
|
|
'border-white dark:border-black shadow-black active:shadow-black dark:shadow-white-80 dark:active:shadow-white',
|
|
|
|
'text-white dark:text-black',
|
2022-03-23 15:48:50 +00:00
|
|
|
];
|
2022-03-01 09:26:26 +00:00
|
|
|
|
2022-03-23 15:48:50 +00:00
|
|
|
const secondaryClasses = [
|
|
|
|
sharedClasses,
|
2022-06-24 03:16:01 +00:00
|
|
|
commonButtonClasses,
|
2022-03-23 15:48:50 +00:00
|
|
|
commonDisabled,
|
|
|
|
standardButtonPaddingLeft,
|
|
|
|
standardButtonPaddingRight,
|
|
|
|
standardButtonBorderWidth,
|
2022-04-20 19:37:44 +00:00
|
|
|
buttonHeight,
|
2022-06-24 03:16:01 +00:00
|
|
|
'bg-white dark:bg-black hover:bg-black-25 dark:hover:bg-white-25',
|
|
|
|
'border-black dark:border-white shadow-black dark:shadow-white',
|
|
|
|
'text-black dark:text-white',
|
2022-03-23 15:48:50 +00:00
|
|
|
];
|
2022-03-03 14:48:40 +00:00
|
|
|
|
2022-06-24 03:16:01 +00:00
|
|
|
const tradeClasses = [
|
2022-03-23 15:48:50 +00:00
|
|
|
sharedClasses,
|
2022-06-24 03:16:01 +00:00
|
|
|
commonButtonClasses,
|
2022-03-23 15:48:50 +00:00
|
|
|
commonDisabled,
|
|
|
|
standardButtonPaddingLeft,
|
|
|
|
standardButtonPaddingRight,
|
|
|
|
standardButtonBorderWidth,
|
2022-04-20 19:37:44 +00:00
|
|
|
buttonHeight,
|
2022-06-24 03:16:01 +00:00
|
|
|
'bg-vega-green hover:bg-vega-green-medium',
|
|
|
|
'border-black disabled:shadow-none dark:disabled:shadow-none shadow-black dark:shadow-white',
|
|
|
|
'text-black',
|
2022-03-23 15:48:50 +00:00
|
|
|
];
|
2022-03-01 09:26:26 +00:00
|
|
|
|
2022-06-24 03:16:01 +00:00
|
|
|
const accentClasses = [
|
2022-03-23 15:48:50 +00:00
|
|
|
sharedClasses,
|
2022-06-24 03:16:01 +00:00
|
|
|
commonDisabled,
|
|
|
|
standardButtonPaddingLeft,
|
|
|
|
standardButtonPaddingRight,
|
|
|
|
standardButtonBorderWidth,
|
2022-04-20 19:37:44 +00:00
|
|
|
buttonHeight,
|
2022-06-24 03:16:01 +00:00
|
|
|
'bg-vega-yellow dark:bg-vega-yellow hover:bg-vega-yellow-dark dark:hover:bg-vega-yellow-dark active:bg-white dark:active:bg-black',
|
|
|
|
'uppercase text-black dark:text-black hover:text-white dark:hover:text-white active:text-black dark:active:text-white',
|
|
|
|
'border-transparent dark:border-transparent',
|
2022-03-23 15:48:50 +00:00
|
|
|
];
|
2022-03-01 09:26:26 +00:00
|
|
|
|
2022-03-23 15:48:50 +00:00
|
|
|
const inlineLinkClasses = [
|
|
|
|
sharedClasses,
|
|
|
|
inlineButtonPaddingLeft,
|
|
|
|
inlineButtonPaddingRight,
|
2022-04-20 19:37:44 +00:00
|
|
|
buttonHeight,
|
2022-03-23 15:48:50 +00:00
|
|
|
inlineTextColour,
|
2022-06-24 03:16:01 +00:00
|
|
|
'underline hover:underline hover:text-black-60 dark:hover:text-white-80',
|
2022-03-23 15:48:50 +00:00
|
|
|
'border-none',
|
|
|
|
];
|
2022-03-03 14:48:40 +00:00
|
|
|
|
2022-06-24 03:16:01 +00:00
|
|
|
let variantClasses: string[];
|
|
|
|
|
2022-03-23 15:48:50 +00:00
|
|
|
switch (variant) {
|
|
|
|
case 'primary':
|
2022-06-24 03:16:01 +00:00
|
|
|
variantClasses = primaryClasses;
|
|
|
|
break;
|
2022-03-23 15:48:50 +00:00
|
|
|
case 'secondary':
|
2022-06-24 03:16:01 +00:00
|
|
|
variantClasses = secondaryClasses;
|
|
|
|
break;
|
|
|
|
case 'trade':
|
|
|
|
variantClasses = tradeClasses;
|
|
|
|
break;
|
2022-03-23 15:48:50 +00:00
|
|
|
case 'accent':
|
2022-06-24 03:16:01 +00:00
|
|
|
variantClasses = accentClasses;
|
|
|
|
break;
|
2022-03-23 15:48:50 +00:00
|
|
|
case 'inline-link':
|
2022-06-24 03:16:01 +00:00
|
|
|
variantClasses = inlineLinkClasses;
|
|
|
|
break;
|
2022-03-23 15:48:50 +00:00
|
|
|
default:
|
2022-06-24 03:16:01 +00:00
|
|
|
variantClasses = [''];
|
2022-03-23 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 03:16:01 +00:00
|
|
|
return classNames(...variantClasses, className);
|
2022-03-07 21:16:06 +00:00
|
|
|
};
|
2022-03-07 12:27:56 +00:00
|
|
|
|
2022-06-24 03:16:01 +00:00
|
|
|
export const getButtonContent = (
|
|
|
|
children: ReactNode,
|
2022-03-07 12:27:56 +00:00
|
|
|
prependIconName?: IconName,
|
|
|
|
appendIconName?: IconName
|
|
|
|
) => {
|
2022-03-02 09:56:05 +00:00
|
|
|
const iconName = prependIconName || appendIconName;
|
2022-03-07 12:27:56 +00:00
|
|
|
if (iconName === undefined) {
|
|
|
|
return children;
|
2022-03-02 09:56:05 +00:00
|
|
|
}
|
2022-03-07 12:27:56 +00:00
|
|
|
const iconClassName = classNames(['fill-current'], {
|
|
|
|
'mr-8': prependIconName,
|
|
|
|
'ml-8': appendIconName,
|
|
|
|
});
|
|
|
|
const icon = <Icon name={iconName} className={iconClassName} size={16} />;
|
2022-03-01 09:26:26 +00:00
|
|
|
return (
|
2022-03-07 12:27:56 +00:00
|
|
|
<>
|
2022-03-02 09:56:05 +00:00
|
|
|
{prependIconName && icon}
|
2022-03-01 09:26:26 +00:00
|
|
|
{children}
|
2022-03-02 09:56:05 +00:00
|
|
|
{appendIconName && icon}
|
2022-03-07 12:27:56 +00:00
|
|
|
</>
|
2022-03-01 09:26:26 +00:00
|
|
|
);
|
2022-03-07 12:27:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
|
(
|
|
|
|
{
|
|
|
|
variant = 'primary',
|
Feat/63 Deal ticket (#82)
* scaffold dealticket package, remove trading views from react-helpers
* add deal ticket component, add intent utils, expand dialog and form group styles
* add splash component, show market not found message if market doesnt exist
* tidy up error handling
* add handleError method for vega tx hook
* add better testname for provider test, flesh out tests a bit more for deal ticket
* Add unit tests for useVegaTransaction and useOrderSubmit hooks
* add wrapper component for order dialog styles
* add vega styled loader to ui toolkit and use in order dialog
* add title prop to order dialog
* split limit and market tickets into own files
* add button radio component
* revert dialog styles
* move splash component to ui-toolkit, add story
* convert intent to enum
* Make button always type=button unless type prop is passed
* inline filter logic for tif selector
* add date-fns, add datetime to helpers
* add order types to wallet package, make price undefined if order type is market
* use enums in deal ticket logic
* tidy up order state by moving submit and transaction hooks out of deal ticket
* add comment for dialog styles
* remove decimal from price input
* add types package, delete old generated types from trading project
* rename types package to graphql
* update generate command to point to correct locations
* fix use order submit test
* use intent shadow helper
* remove date-fns and format manually, update submit button error to use input-error
* remove stray console.log
2022-03-17 19:35:46 +00:00
|
|
|
type = 'button',
|
2022-03-07 12:27:56 +00:00
|
|
|
children,
|
|
|
|
className,
|
|
|
|
prependIconName,
|
|
|
|
appendIconName,
|
2022-06-24 03:16:01 +00:00
|
|
|
boxShadow,
|
2022-03-07 20:45:39 +00:00
|
|
|
...props
|
2022-03-07 12:27:56 +00:00
|
|
|
},
|
|
|
|
ref
|
|
|
|
) => {
|
|
|
|
return (
|
Feat/63 Deal ticket (#82)
* scaffold dealticket package, remove trading views from react-helpers
* add deal ticket component, add intent utils, expand dialog and form group styles
* add splash component, show market not found message if market doesnt exist
* tidy up error handling
* add handleError method for vega tx hook
* add better testname for provider test, flesh out tests a bit more for deal ticket
* Add unit tests for useVegaTransaction and useOrderSubmit hooks
* add wrapper component for order dialog styles
* add vega styled loader to ui toolkit and use in order dialog
* add title prop to order dialog
* split limit and market tickets into own files
* add button radio component
* revert dialog styles
* move splash component to ui-toolkit, add story
* convert intent to enum
* Make button always type=button unless type prop is passed
* inline filter logic for tif selector
* add date-fns, add datetime to helpers
* add order types to wallet package, make price undefined if order type is market
* use enums in deal ticket logic
* tidy up order state by moving submit and transaction hooks out of deal ticket
* add comment for dialog styles
* remove decimal from price input
* add types package, delete old generated types from trading project
* rename types package to graphql
* update generate command to point to correct locations
* fix use order submit test
* use intent shadow helper
* remove date-fns and format manually, update submit button error to use input-error
* remove stray console.log
2022-03-17 19:35:46 +00:00
|
|
|
<button
|
|
|
|
ref={ref}
|
2022-06-24 03:16:01 +00:00
|
|
|
className={getButtonClasses(className, variant, boxShadow)}
|
Feat/63 Deal ticket (#82)
* scaffold dealticket package, remove trading views from react-helpers
* add deal ticket component, add intent utils, expand dialog and form group styles
* add splash component, show market not found message if market doesnt exist
* tidy up error handling
* add handleError method for vega tx hook
* add better testname for provider test, flesh out tests a bit more for deal ticket
* Add unit tests for useVegaTransaction and useOrderSubmit hooks
* add wrapper component for order dialog styles
* add vega styled loader to ui toolkit and use in order dialog
* add title prop to order dialog
* split limit and market tickets into own files
* add button radio component
* revert dialog styles
* move splash component to ui-toolkit, add story
* convert intent to enum
* Make button always type=button unless type prop is passed
* inline filter logic for tif selector
* add date-fns, add datetime to helpers
* add order types to wallet package, make price undefined if order type is market
* use enums in deal ticket logic
* tidy up order state by moving submit and transaction hooks out of deal ticket
* add comment for dialog styles
* remove decimal from price input
* add types package, delete old generated types from trading project
* rename types package to graphql
* update generate command to point to correct locations
* fix use order submit test
* use intent shadow helper
* remove date-fns and format manually, update submit button error to use input-error
* remove stray console.log
2022-03-17 19:35:46 +00:00
|
|
|
type={type}
|
|
|
|
{...props}
|
|
|
|
>
|
2022-06-24 03:16:01 +00:00
|
|
|
{getButtonContent(children, prependIconName, appendIconName)}
|
2022-03-07 12:27:56 +00:00
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export const AnchorButton = forwardRef<HTMLAnchorElement, AnchorButtonProps>(
|
|
|
|
(
|
|
|
|
{
|
|
|
|
variant = 'primary',
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
prependIconName,
|
|
|
|
appendIconName,
|
2022-06-24 03:16:01 +00:00
|
|
|
boxShadow,
|
2022-06-06 16:19:56 +00:00
|
|
|
...props
|
2022-03-07 12:27:56 +00:00
|
|
|
},
|
|
|
|
ref
|
|
|
|
) => {
|
|
|
|
return (
|
2022-06-24 03:16:01 +00:00
|
|
|
<a
|
|
|
|
ref={ref}
|
|
|
|
className={getButtonClasses(className, variant, boxShadow)}
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
{getButtonContent(children, prependIconName, appendIconName)}
|
2022-03-07 12:27:56 +00:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|