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 Oct 25, 2023
1 parent 20773fc commit c52d6ad
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
/** Remove button border and padding. */
isCompact?: boolean | undefined
size?: Size | undefined
Expand All @@ -31,6 +32,7 @@ export function IconButton({
color,
Icon,
iconSize,
isActive = false,
isCompact,
onClick,
size = Size.NORMAL,
Expand Down Expand Up @@ -59,14 +61,15 @@ export function IconButton({
const commonProps = useMemo(
() => ({
children: commonChildren,
className: classnames('Element-IconButton', className),
className: classnames('Element-IconButton', isActive && '_active', className),
isActive,
isCompact,
onClick: handleClick,
size,
type,
...nativeProps
}),
[className, commonChildren, handleClick, isCompact, nativeProps, size, type]
[className, commonChildren, handleClick, isActive, isCompact, nativeProps, size, type]
)

switch (accent) {
Expand Down

0 comments on commit c52d6ad

Please sign in to comment.