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: Add Loc support and Form component #332

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
df70941
chore: form: initial commit of internal component
dkilgore-eightfold Aug 2, 2022
bc49e36
Merge branch 'main' into dkilgore-eightfold/add-form-component
dkilgore-eightfold Aug 8, 2022
7222cd7
chore: form: internal form component and unit tests
dkilgore-eightfold Aug 8, 2022
2baeb7c
Merge branch 'main' into dkilgore-eightfold/add-form-component
dkilgore-eightfold Aug 10, 2022
8ce8db3
feat: locale: adds locale provider and locale receiver
dkilgore-eightfold Aug 18, 2022
6cefba2
Merge branch 'main' into dkilgore-eightfold/add-form-component
dkilgore-eightfold Aug 18, 2022
637f724
feat: add shape context provider to config provider
dkilgore-eightfold Aug 23, 2022
6978fd5
Merge branch 'main' into dkilgore-eightfold/add-form-component
dkilgore-eightfold Aug 23, 2022
555eee5
feat: add size and shape context
dkilgore-eightfold Aug 24, 2022
6c52c73
Merge branch 'main' into dkilgore-eightfold/add-form-component
dkilgore-eightfold Aug 24, 2022
0a93b66
chore: form: adds stories
dkilgore-eightfold Aug 26, 2022
ce873a8
Merge branch 'main' into dkilgore-eightfold/add-form-component
dkilgore-eightfold Aug 27, 2022
295baa2
chore: adds type workaround for async validator
dkilgore-eightfold Aug 27, 2022
c83e0ab
chore: form: export form and forminstance
dkilgore-eightfold Aug 27, 2022
87df17a
chore: fix css compilation error
dkilgore-eightfold Aug 29, 2022
cac0ad5
chore: revert jest upgrade
dkilgore-eightfold Aug 29, 2022
baba557
chore: fix scss linter errors
dkilgore-eightfold Aug 29, 2022
567c511
chore: fix node sass error in ci
dkilgore-eightfold Aug 29, 2022
ac44980
chore: fixes import caps and more dart sass errors in ci
dkilgore-eightfold Aug 29, 2022
772ef57
chore: fixes more strict caps in imports
dkilgore-eightfold Aug 29, 2022
978aa85
chore: revert style changes
dkilgore-eightfold Aug 29, 2022
3187b99
chore: fix import cap
dkilgore-eightfold Aug 29, 2022
13008ca
Merge branch 'main' into dkilgore-eightfold/add-form-component
dkilgore-eightfold Aug 31, 2022
30d92dd
chore: address pr feedback
dkilgore-eightfold Sep 1, 2022
54cd6c5
chore: form: annotate interface props and consolidate
dkilgore-eightfold Sep 1, 2022
a500fa6
chore: form: fix button types in story and add annotations
dkilgore-eightfold Sep 1, 2022
198d185
chore: form: fixes unit test and removes unused imports
dkilgore-eightfold Sep 2, 2022
15a6da6
chore: form: add config context props and merged form item prop
dkilgore-eightfold Sep 2, 2022
153a053
chore: form: fix scroll to error and enable its unit tests
dkilgore-eightfold Sep 2, 2022
7a6628a
chore: form: remove success input styling
dkilgore-eightfold Sep 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@
"@floating-ui/react-dom-interactions": "0.6.3",
"@mdi/react": "1.5.0",
"@ngard/tiny-isequal": "1.1.0",
"@types/lodash": "4.14.182",
"@types/react-is": "17.0.3",
"@types/shallowequal": "1.1.1",
"async-validator": "4.1.0",
"bodymovin": "4.13.0",
"date-fns": "2.28.0",
"dayjs": "1.11.3",
"dom-align": "1.12.3",
"lottie-web": "5.8.1",
"memoize-one": "6.0.0",
dkilgore-eightfold marked this conversation as resolved.
Show resolved Hide resolved
"react-flip-toolkit": "7.0.13",
"react-is": "18.1.0",
"resize-observer-polyfill": "1.5.1",
"scroll-into-view-if-needed": "2.2.25",
"shallowequal": "1.1.0"
},
"peerDependencies": {
Expand Down
74 changes: 44 additions & 30 deletions src/components/Button/BaseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { FC, Ref } from 'react';
import React, { FC, Ref, useContext } from 'react';
import DisabledContext, { Disabled } from '../ConfigProvider/DisabledContext';
import { SizeContext, Size } from '../ConfigProvider';
import {
ButtonIconAlign,
ButtonShape,
ButtonSize,
ButtonTextAlign,
ButtonTheme,
ButtonWidth,
InternalButtonProps,
SplitButton,
Expand All @@ -27,6 +28,10 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(
buttonWidth = ButtonWidth.fitContent,
checked = false,
classNames,
configContextProps = {
noDisabledContext: false,
noSizeContext: false,
},
counter,
disabled = false,
disruptive = false,
Expand All @@ -38,13 +43,12 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(
onClick,
onContextMenu,
shape = ButtonShape.Pill,
size = ButtonSize.Flex,
size = ButtonSize.Medium,
split,
splitButtonChecked = false,
splitButtonProps,
style,
text,
theme,
toggle,
type,
loading = false,
Expand All @@ -57,6 +61,16 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(
const smallScreenActive: boolean = useMatchMedia(Breakpoints.Small);
const xSmallScreenActive: boolean = useMatchMedia(Breakpoints.XSmall);

const contextuallyDisabled: Disabled = useContext(DisabledContext);
const mergedDisabled: boolean = configContextProps.noDisabledContext
? disabled
: contextuallyDisabled || disabled;

const contextuallySized: Size = useContext(SizeContext);
const mergedSize = configContextProps.noSizeContext
? size
: contextuallySized || size;

const counterExists: boolean = !!counter;
const iconExists: boolean = !!iconProps;
const textExists: boolean = !!text;
Expand All @@ -65,30 +79,29 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(
classNames,
{
[styles.buttonSmall]:
size === ButtonSize.Flex && largeScreenActive,
mergedSize === ButtonSize.Flex && largeScreenActive,
},
{
[styles.buttonMedium]:
size === ButtonSize.Flex && mediumScreenActive,
mergedSize === ButtonSize.Flex && mediumScreenActive,
},
{
[styles.buttonMedium]:
size === ButtonSize.Flex && smallScreenActive,
mergedSize === ButtonSize.Flex && smallScreenActive,
},
{
[styles.buttonLarge]:
size === ButtonSize.Flex && xSmallScreenActive,
mergedSize === ButtonSize.Flex && xSmallScreenActive,
},
{ [styles.buttonLarge]: size === ButtonSize.Large },
{ [styles.buttonMedium]: size === ButtonSize.Medium },
{ [styles.buttonSmall]: size === ButtonSize.Small },
{ [styles.buttonLarge]: mergedSize === ButtonSize.Large },
{ [styles.buttonMedium]: mergedSize === ButtonSize.Medium },
{ [styles.buttonSmall]: mergedSize === ButtonSize.Small },
{ [styles.pillShape]: shape === ButtonShape.Pill },
{
[styles.roundShape]:
shape === ButtonShape.Round && !split && !textExists,
},
{ [styles.dropShadow]: dropShadow },
{ [styles.dark]: theme === ButtonTheme.dark },
{ [styles.floating]: floatingButtonProps?.enabled },
]);

Expand All @@ -106,30 +119,30 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(
[styles.iconRight]:
iconExists && alignIcon === ButtonIconAlign.Right,
},
{ [styles.disabled]: allowDisabledFocus || disabled },
{ [styles.disabled]: allowDisabledFocus || mergedDisabled },
{ [styles.loading]: loading },
]);

const buttonTextClassNames: string = mergeClasses([
{
[styles.buttonTextSmall]:
size === ButtonSize.Flex && largeScreenActive,
mergedSize === ButtonSize.Flex && largeScreenActive,
},
{
[styles.buttonTextMedium]:
size === ButtonSize.Flex && mediumScreenActive,
mergedSize === ButtonSize.Flex && mediumScreenActive,
},
{
[styles.buttonTextMedium]:
size === ButtonSize.Flex && smallScreenActive,
mergedSize === ButtonSize.Flex && smallScreenActive,
},
{
[styles.buttonTextLarge]:
size === ButtonSize.Flex && xSmallScreenActive,
mergedSize === ButtonSize.Flex && xSmallScreenActive,
},
{ [styles.buttonTextLarge]: size === ButtonSize.Large },
{ [styles.buttonTextMedium]: size === ButtonSize.Medium },
{ [styles.buttonTextSmall]: size === ButtonSize.Small },
{ [styles.buttonTextLarge]: mergedSize === ButtonSize.Large },
{ [styles.buttonTextMedium]: mergedSize === ButtonSize.Medium },
{ [styles.buttonTextSmall]: mergedSize === ButtonSize.Small },
]);

const badgeClassNames: string = mergeClasses([
Expand All @@ -139,20 +152,20 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(

const getButtonIconSize = (): IconSize => {
let iconSize: IconSize;
if (size === ButtonSize.Flex && largeScreenActive) {
if (mergedSize === ButtonSize.Flex && largeScreenActive) {
iconSize = IconSize.Small;
} else if (
size === ButtonSize.Flex &&
mergedSize === ButtonSize.Flex &&
(mediumScreenActive || smallScreenActive)
) {
iconSize = IconSize.Medium;
} else if (size === ButtonSize.Flex && xSmallScreenActive) {
} else if (mergedSize === ButtonSize.Flex && xSmallScreenActive) {
iconSize = IconSize.Large;
} else if (size === ButtonSize.Large) {
} else if (mergedSize === ButtonSize.Large) {
iconSize = IconSize.Large;
} else if (size === ButtonSize.Medium) {
} else if (mergedSize === ButtonSize.Medium) {
iconSize = IconSize.Medium;
} else if (size === ButtonSize.Small) {
} else if (mergedSize === ButtonSize.Small) {
iconSize = IconSize.Small;
}
return iconSize;
Expand Down Expand Up @@ -210,11 +223,13 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(
ref={ref}
{...rest}
aria-checked={toggle ? !!checked : undefined}
aria-disabled={disabled || loading}
aria-disabled={mergedDisabled || loading}
aria-label={ariaLabel}
aria-pressed={toggle ? !!checked : undefined}
defaultChecked={checked}
disabled={(!allowDisabledFocus && disabled) || loading}
disabled={
(!allowDisabledFocus && mergedDisabled) || loading
}
className={buttonBaseClassNames}
id={id}
onClick={!allowDisabledFocus ? onClick : null}
Expand Down Expand Up @@ -252,9 +267,8 @@ export const BaseButton: FC<InternalButtonProps> = React.forwardRef(
: null
}
shape={shape}
size={size}
size={mergedSize}
split={split}
theme={theme}
type={type}
/>
)}
Expand Down
16 changes: 7 additions & 9 deletions src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ButtonShape,
ButtonSize,
ButtonTextAlign,
ButtonTheme,
ButtonWidth,
DefaultButton,
NeutralButton,
Expand Down Expand Up @@ -39,14 +38,14 @@ export default {
<li>
There are four button sizes that may be
specified via the <b>size</b> prop and the{' '}
<b>ButtonSize</b>: <b>ButtonSize.Flex</b>,{' '}
<b>size</b>: <b>ButtonSize.Flex</b>,{' '}
<b>ButtonSize.Large</b>,{' '}
<b>ButtonSize.Medium</b>,{' '}
<b>ButtonSize.Small</b>.{' '}
<b>ButtonSize.Flex</b> is the default and
resizes the button automatically with the
viewport. To prevent this responsive
behavior, give the button a size.
<b>ButtonSize.Small</b>. <b>medium</b> is
the default and flex resizes the button
automatically with the viewport. To prevent
this responsive behavior, give the button a
size other than flex.
</li>
<li>
For dialog boxes and panels, where people
Expand Down Expand Up @@ -252,12 +251,11 @@ const buttonArgs: Object = {
},
id: 'myButton',
shape: ButtonShape.Pill,
size: ButtonSize.Flex,
size: ButtonSize.Medium,
split: false,
splitButtonChecked: false,
style: {},
text: 'Button',
theme: ButtonTheme.light,
toggle: false,
counter: 0,
loading: false,
Expand Down
19 changes: 7 additions & 12 deletions src/components/Button/Button.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Ref } from 'react';
import { IconProps } from '../Icon';
import { OcBaseProps } from '../OcBase';
import { ConfigContextProps, Shape, Size } from '../ConfigProvider';

export enum ButtonIconAlign {
Left = 'left',
Expand Down Expand Up @@ -31,11 +32,6 @@ export enum ButtonShape {
Round = 'round',
}

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

export enum ButtonType {
Default = 'default',
Neutral = 'neutral',
Expand Down Expand Up @@ -124,6 +120,10 @@ export interface ButtonProps extends NativeButtonProps {
* The button class names.
*/
classNames?: string;
/**
* Configure how contextual props are consumed
*/
configContextProps?: ConfigContextProps;
/**
* The button counter string.
*/
Expand Down Expand Up @@ -171,12 +171,12 @@ export interface ButtonProps extends NativeButtonProps {
* Shape of the button.
* @default ButtonShape.Pill
*/
shape?: ButtonShape;
shape?: ButtonShape | Shape;
/**
* The button size.
* @default ButtonSize.Medium
*/
size?: ButtonSize;
size?: ButtonSize | Size;
/**
* Determines whether this is a split button.
* @default false
Expand All @@ -198,11 +198,6 @@ export interface ButtonProps extends NativeButtonProps {
* 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
4 changes: 1 addition & 3 deletions src/components/Button/DefaultButton/DefaultButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ export const DefaultButton: FC<ButtonProps> = React.forwardRef(
iconProps,
onClick,
text,
theme,
shape = ButtonShape.Pill,
size = ButtonSize.Flex,
size = ButtonSize.Medium,
split,
splitButtonChecked,
splitButtonProps,
Expand Down Expand Up @@ -74,7 +73,6 @@ export const DefaultButton: FC<ButtonProps> = React.forwardRef(
splitButtonProps={splitButtonProps}
style={style}
text={text}
theme={theme}
toggle={toggle}
type={ButtonType.Default}
buttonWidth={buttonWidth}
Expand Down
6 changes: 2 additions & 4 deletions src/components/Button/NeutralButton/NeutralButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
BaseButton,
ButtonIconAlign,
ButtonProps,
ButtonSize,
ButtonShape,
ButtonSize,
ButtonTextAlign,
ButtonType,
} from '../';
Expand All @@ -29,9 +29,8 @@ export const NeutralButton: FC<ButtonProps> = React.forwardRef(
iconProps,
onClick,
text,
theme,
shape = ButtonShape.Pill,
size = ButtonSize.Flex,
size = ButtonSize.Medium,
split,
splitButtonProps,
splitButtonChecked = false,
Expand Down Expand Up @@ -72,7 +71,6 @@ export const NeutralButton: FC<ButtonProps> = React.forwardRef(
splitButtonProps={splitButtonProps}
style={style}
text={text}
theme={theme}
toggle={toggle}
type={ButtonType.Neutral}
buttonWidth={buttonWidth}
Expand Down
6 changes: 2 additions & 4 deletions src/components/Button/PrimaryButton/PrimaryButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
BaseButton,
ButtonIconAlign,
ButtonProps,
ButtonSize,
ButtonShape,
ButtonSize,
ButtonTextAlign,
ButtonType,
} from '../';
Expand All @@ -31,13 +31,12 @@ export const PrimaryButton: FC<ButtonProps> = React.forwardRef(
onClick,
onContextMenu,
shape = ButtonShape.Pill,
size = ButtonSize.Flex,
size = ButtonSize.Medium,
split,
splitButtonChecked = false,
splitButtonProps,
style,
text,
theme,
toggle,
buttonWidth,
...rest
Expand Down Expand Up @@ -77,7 +76,6 @@ export const PrimaryButton: FC<ButtonProps> = React.forwardRef(
splitButtonProps={splitButtonProps}
style={style}
text={text}
theme={theme}
toggle={toggle}
type={ButtonType.Primary}
buttonWidth={buttonWidth}
Expand Down
Loading