Skip to content

Commit

Permalink
feat(field): add isActive prop to button & IconButton
Browse files Browse the repository at this point in the history
  • Loading branch information
thoomasbro committed Jul 4, 2023
1 parent 0a5e38e commit 13025e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/elements/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'childre
Icon?: FunctionComponent<IconProps> | undefined
accent?: Accent | undefined
children?: string | undefined
isActive?: boolean | undefined
isFullWidth?: boolean | undefined
size?: Size | undefined
/** Prevent onClick event propagation. */
Expand All @@ -26,6 +27,7 @@ export function Button({
children,
className,
Icon,
isActive = false,
isFullWidth = false,
onClick,
size = Size.NORMAL,
Expand Down Expand Up @@ -60,14 +62,15 @@ export function Button({
() => ({
as: StyledButton,
children: commonChildren,
className: classnames('Element-Button', className),
className: classnames('Element-Button', isActive && '_active', className),
isActive,
isFullWidth,
onClick: handleClick,
size,
type,
...nativeProps
}),
[className, commonChildren, handleClick, isFullWidth, nativeProps, size, type]
[className, commonChildren, handleClick, isActive, isFullWidth, nativeProps, size, type]
)

switch (accent) {
Expand Down
7 changes: 5 additions & 2 deletions src/elements/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type IconButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'chi
color?: string | undefined
/** In pixels, override `size` prop default values. */
iconSize?: number | undefined
isActive?: boolean | undefined
size?: Size | undefined
/** Prevent onClick event propagation. */
withUnpropagatedClick?: boolean | undefined
Expand All @@ -29,6 +30,7 @@ export function IconButton({
color,
Icon,
iconSize,
isActive = false,
onClick,
size = Size.NORMAL,
type = 'button',
Expand Down Expand Up @@ -56,13 +58,14 @@ export function IconButton({
const commonProps = useMemo(
() => ({
children: commonChildren,
className: classnames('Element-IconButton', className),
className: classnames('Element-IconButton', isActive && '_active', className),
isActive,
onClick: handleClick,
size,
type,
...nativeProps
}),
[className, commonChildren, handleClick, nativeProps, size, type]
[className, commonChildren, handleClick, isActive, nativeProps, size, type]
)

switch (accent) {
Expand Down

0 comments on commit 13025e4

Please sign in to comment.