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

fix: button: refines button prop and adds form type support #19

Merged
merged 3 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 7 additions & 5 deletions src/components/Button/BaseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React, { FC } from 'react';
import { classNames, invertForegroundColor } from '../../shared/utilities';
import { CSSVariables } from '../../shared/variables';
import {
ButtonSize,
ButtonTheme,
Expand All @@ -9,6 +7,8 @@ import {
} from './index';
import { Icon, IconName, IconSize } from '../Icon/index';
import { Breakpoints, useMatchMedia } from '../../shared/hooks';
import { CSSVariables } from '../../shared/variables';
import { classNames, invertForegroundColor } from '../../shared/utilities';

import styles from './button.module.scss';

Expand All @@ -19,15 +19,16 @@ export const BaseButton: FC<InternalButtonProps> = ({
className,
disabled = false,
disruptive = false,
htmlType,
icon,
id,
onClick,
primaryColor,
text,
theme,
type,
size = ButtonSize.Flex,
style,
text,
theme,
type = ButtonType.Default,
}) => {
const largeScreenActive: boolean = useMatchMedia(Breakpoints.Large);
const mediumScreenActive: boolean = useMatchMedia(Breakpoints.Medium);
Expand Down Expand Up @@ -152,6 +153,7 @@ export const BaseButton: FC<InternalButtonProps> = ({
id={id}
onClick={!allowDisabledFocus ? onClick : null}
style={buttonStyles()}
type={htmlType}
>
{iconExists && !textExists && getButtonIcon(icon)}
{iconExists && textExists && (
Expand Down
10 changes: 7 additions & 3 deletions src/components/Button/Button.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export interface ButtonProps {
* The button icon.
*/
icon?: IconName;
/**
* The button onClick event handler.
*/
/**
* The button id.
*/
id?: string;
/**
* The button onClick event handler.
*/
onClick?: React.MouseEventHandler<HTMLButtonElement>;
/**
* The button primary color.
Expand Down Expand Up @@ -100,4 +100,8 @@ export interface ButtonProps {
* The buton style.
*/
style?: React.CSSProperties;
/**
* The button html type.
*/
htmlType?: 'button' | 'submit' | 'reset';
}
8 changes: 5 additions & 3 deletions src/components/Button/DefaultButton/DefaultButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from 'react';
import { classNames } from '../../../shared/utilities';
import { BaseButton, ButtonProps, ButtonSize, ButtonType } from '../index';
import { classNames } from '../../../shared/utilities';

import styles from '../button.module.scss';

Expand All @@ -10,6 +10,7 @@ export const DefaultButton: FC<ButtonProps> = ({
checked = false,
className,
disabled = false,
htmlType,
icon,
onClick,
primaryColor,
Expand All @@ -31,14 +32,15 @@ export const DefaultButton: FC<ButtonProps> = ({
checked={checked}
className={buttonClassNames}
disabled={disabled}
htmlType={htmlType}
icon={icon}
onClick={onClick}
primaryColor={primaryColor}
size={size}
style={style}
text={text}
theme={theme}
type={ButtonType.Default}
size={size}
style={style}
/>
);
};
14 changes: 8 additions & 6 deletions src/components/Button/PrimaryButton/PrimaryButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from 'react';
import { classNames } from '../../../shared/utilities';
import { BaseButton, ButtonProps, ButtonSize, ButtonType } from '../index';
import { classNames } from '../../../shared/utilities';

import styles from '../button.module.scss';

Expand All @@ -11,13 +11,14 @@ export const PrimaryButton: FC<ButtonProps> = ({
className,
disabled = false,
disruptive = false,
htmlType,
icon,
onClick,
primaryColor,
text,
theme,
size = ButtonSize.Flex,
style,
text,
theme,
}) => {
const buttonClassNames: string = classNames([
className,
Expand All @@ -34,14 +35,15 @@ export const PrimaryButton: FC<ButtonProps> = ({
className={buttonClassNames}
disabled={disabled}
disruptive={disruptive}
htmlType={htmlType}
icon={icon}
onClick={onClick}
primaryColor={primaryColor}
text={text}
type={ButtonType.Primary}
theme={theme}
size={size}
style={style}
text={text}
theme={theme}
type={ButtonType.Primary}
/>
);
};
6 changes: 4 additions & 2 deletions src/components/Button/SecondaryButton/SecondaryButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const SecondaryButton: FC<ButtonProps> = ({
className,
disabled = false,
disruptive = false,
htmlType,
icon,
onClick,
primaryColor,
Expand All @@ -34,14 +35,15 @@ export const SecondaryButton: FC<ButtonProps> = ({
className={buttonClassNames}
disabled={disabled}
disruptive={disruptive}
htmlType={htmlType}
icon={icon}
onClick={onClick}
primaryColor={primaryColor}
size={size}
style={style}
text={text}
theme={theme}
type={ButtonType.Secondary}
size={size}
style={style}
/>
);
};