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

feat: button and input: adds neutral button, exports components, renames enum to better match others #48

Merged
merged 2 commits into from
Apr 8, 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: 11 additions & 1 deletion src/components/Button/BaseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { FC, Ref } from 'react';
import { ButtonSize, ButtonTheme, ButtonWidth, InternalButtonProps } from './';
import {
ButtonShape,
ButtonSize,
ButtonTheme,
ButtonWidth,
InternalButtonProps,
} from './';
import { Icon, IconName, IconSize } from '../Icon';
import { Breakpoints, useMatchMedia } from '../../hooks/useMatchMedia';
import { classNames } from '../../shared/utilities';
Expand All @@ -14,11 +20,13 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(
checked = false,
className,
disabled = false,
dropShadow = false,
htmlType,
icon,
iconColor,
id,
onClick,
shape = ButtonShape.Rectangle,
size = ButtonSize.Flex,
style,
text,
Expand Down Expand Up @@ -59,6 +67,8 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(
{ [styles.buttonPadding2]: size === ButtonSize.Medium },
{ [styles.buttonPadding3]: size === ButtonSize.Small },
{ [styles.buttonStretch]: buttonWidth === ButtonWidth.fill },
{ [styles.pillShape]: shape === ButtonShape.Pill },
{ [styles.dropShadow]: dropShadow },
{ [styles.dark]: theme === ButtonTheme.dark },
{ [styles.disabled]: allowDisabledFocus || disabled },
]);
Expand Down
110 changes: 110 additions & 0 deletions src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React, { FC } from 'react';
import {
ButtonShape,
ButtonSize,
ButtonWidth,
DefaultButton,
NeutralButton,
PrimaryButton,
SecondaryButton,
} from './index';
Expand Down Expand Up @@ -30,6 +33,17 @@ export const Primary = () => (
/>
<br />
<br />
<h2>Default Flex (Fill)</h2>
<div style={{ width: '50%' }}>
<PrimaryButton
ariaLabel="Primary Button"
buttonWidth={ButtonWidth.fill}
icon={IconName.mdiCardsHeart}
onClick={_alertClicked}
text="Primary Button"
/>
</div>
<br />
<h2>Text only</h2>
<PrimaryButton
ariaLabel="Primary Button"
Expand All @@ -39,6 +53,16 @@ export const Primary = () => (
/>
<br />
<br />
<h2>Text only (Pill)</h2>
<PrimaryButton
ariaLabel="Primary Button"
onClick={_alertClicked}
size={ButtonSize.Large}
shape={ButtonShape.Pill}
text="Primary Button"
/>
<br />
<br />
<h2>Icon only</h2>
<PrimaryButton
ariaLabel="Primary Button"
Expand Down Expand Up @@ -81,6 +105,16 @@ export const Secondary = () => (
/>
<br />
<br />
<h2>Text only (Pill)</h2>
<SecondaryButton
ariaLabel="Secondary Button"
onClick={_alertClicked}
shape={ButtonShape.Pill}
size={ButtonSize.Large}
text="Secondary Button"
/>
<br />
<br />
<h2>Icon only</h2>
<SecondaryButton
ariaLabel="Secondary Button"
Expand Down Expand Up @@ -123,6 +157,17 @@ export const Default = () => (
/>
<br />
<br />
<h2>Text only (Pill)</h2>
<DefaultButton
ariaLabel="Default Button"
dropShadow
onClick={_alertClicked}
shape={ButtonShape.Pill}
size={ButtonSize.Large}
text="Default Button"
/>
<br />
<br />
<h2>Icon only</h2>
<DefaultButton
ariaLabel="Default Button"
Expand All @@ -140,13 +185,67 @@ export const Default = () => (
size={ButtonSize.Large}
text="Default Button"
/>
<br />
<br />
<h2>Disruptive</h2>
<DefaultButton
ariaLabel="Default Button"
disruptive
onClick={_alertClicked}
size={ButtonSize.Large}
text="Default Button"
/>
</>
);

export const Neutral = () => (
<>
<h1>Neutral Button</h1>
<h2>Text only</h2>
<NeutralButton
ariaLabel="Neutral Button"
onClick={_alertClicked}
size={ButtonSize.Large}
text="Neutral Button"
/>
<br />
<br />
<h2>Text only (Pill)</h2>
<NeutralButton
ariaLabel="Neutral Button"
dropShadow
onClick={_alertClicked}
shape={ButtonShape.Pill}
size={ButtonSize.Large}
text="Neutral Button"
/>
<br />
<br />
<h2>Icon only</h2>
<NeutralButton
ariaLabel="Neutral Button"
icon={IconName.mdiCardsHeart}
onClick={_alertClicked}
size={ButtonSize.Large}
/>
<br />
<br />
<h2>Text + Icon</h2>
<NeutralButton
ariaLabel="Neutral Button"
icon={IconName.mdiCardsHeart}
onClick={_alertClicked}
size={ButtonSize.Large}
text="Neutral Button"
/>
</>
);

export const Toggle: FC<ToggleButtonExampleProps> = ({ checked }) => {
const [skill1Added, { toggle: set1Added }] = useBoolean(false);
const [skill2Added, { toggle: set2Added }] = useBoolean(false);
const [skill3Added, { toggle: set3Added }] = useBoolean(false);
const [skill4Added, { toggle: set4Added }] = useBoolean(false);
return (
<>
<h1>Toggle With Text + Icon</h1>
Expand Down Expand Up @@ -187,6 +286,17 @@ export const Toggle: FC<ToggleButtonExampleProps> = ({ checked }) => {
toggle
/>
</span>
<span>
<NeutralButton
ariaLabel="Neutral Button"
checked={skill4Added || checked}
icon={skill4Added ? IconName.mdiMinus : IconName.mdiPlus}
onClick={set4Added}
size={ButtonSize.Medium}
text="Neutral Button"
toggle
/>
</span>
</>
);
};
Expand Down
30 changes: 23 additions & 7 deletions src/components/Button/Button.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ export enum ButtonWidth {
fill = 'fill',
}

export enum ButtonShape {
Rectangle = 'rectangle',
Pill = 'pill',
}

export enum ButtonTheme {
light = 'light',
dark = 'dark',
}

export enum ButtonType {
Default = 'default',
Neutral = 'neutral',
Primary = 'primary',
Secondary = 'secondary',
}
Expand Down Expand Up @@ -65,6 +71,11 @@ export interface ButtonProps extends NativeButtonProps {
* @default false
*/
disruptive?: boolean;
/**
* The button drop shadow state.
* @default false
*/
dropShadow?: boolean;
/**
* The button html type.
*/
Expand All @@ -90,14 +101,10 @@ export interface ButtonProps extends NativeButtonProps {
*/
primaryColor?: string;
/**
* The button text.
* Shape of the button.
* @default ButtonShape.Rectangle
*/
text?: string;
/**
* The button theme.
* @default light
*/
theme?: ButtonTheme;
shape?: ButtonShape;
/**
* The button size.
* @default ButtonSize.Medium
Expand All @@ -120,6 +127,15 @@ export interface ButtonProps extends NativeButtonProps {
* The button style.
*/
style?: React.CSSProperties;
/**
* The button text.
*/
text?: string;
/**
* The button theme.
* @default light
*/
theme?: ButtonTheme;
/**
* The button is a toggle button with distinct on and off states.
*/
Expand Down
12 changes: 11 additions & 1 deletion src/components/Button/DefaultButton/DefaultButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { FC, Ref } from 'react';
import { BaseButton, ButtonProps, ButtonSize, ButtonType } from '../';
import {
ButtonShape,
BaseButton,
ButtonProps,
ButtonSize,
ButtonType,
} from '../';
import { classNames } from '../../../shared/utilities';

import styles from '../button.module.scss';
Expand All @@ -12,12 +18,14 @@ export const DefaultButton: FC<ButtonProps> = React.forwardRef(
checked = false,
className,
disabled = false,
dropShadow = false,
htmlType,
icon,
iconColor,
onClick,
text,
theme,
shape = ButtonShape.Rectangle,
size = ButtonSize.Flex,
style,
toggle,
Expand All @@ -43,10 +51,12 @@ export const DefaultButton: FC<ButtonProps> = React.forwardRef(
checked={checked}
className={buttonClassNames}
disabled={disabled}
dropShadow={dropShadow}
htmlType={htmlType}
icon={icon}
iconColor={iconColor}
onClick={onClick}
shape={shape}
size={size}
style={style}
text={text}
Expand Down
68 changes: 68 additions & 0 deletions src/components/Button/NeutralButton/NeutralButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, { FC, Ref } from 'react';
import {
ButtonShape,
BaseButton,
ButtonProps,
ButtonSize,
ButtonType,
} from '../';
import { classNames } from '../../../shared/utilities';

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

export const NeutralButton: FC<ButtonProps> = React.forwardRef(
(
{
allowDisabledFocus = false,
ariaLabel,
checked = false,
className,
disabled = false,
dropShadow = false,
htmlType,
icon,
iconColor,
onClick,
text,
theme,
shape = ButtonShape.Rectangle,
size = ButtonSize.Flex,
style,
toggle,
buttonWidth,
...rest
},
ref: Ref<HTMLButtonElement>
) => {
const buttonClassNames: string = classNames([
className,
styles.button,
styles.buttonNeutral,
]);

return (
<BaseButton
{...rest}
ref={ref}
allowDisabledFocus={allowDisabledFocus}
ariaLabel={ariaLabel}
checked={checked}
className={buttonClassNames}
disabled={disabled}
dropShadow={dropShadow}
htmlType={htmlType}
icon={icon}
iconColor={iconColor}
onClick={onClick}
shape={shape}
size={size}
style={style}
text={text}
theme={theme}
type={ButtonType.Neutral}
toggle={toggle}
buttonWidth={buttonWidth}
/>
);
}
);
Loading