-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap ActionIcon component to include automatically sized icon.
- Loading branch information
1 parent
7672111
commit a49c620
Showing
2 changed files
with
66 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
ActionIcon as ActionIconMantine, | ||
createPolymorphicComponent, | ||
} from '@mantine/core'; | ||
import type {ActionIconProps as ActionIconPropsMantine} from '@mantine/core/lib/components'; | ||
import Icon, { IconSize} from './icon'; | ||
import type {IconName} from 'jsapp/fonts/k-icons'; | ||
import {forwardRef} from 'react'; | ||
|
||
export interface ActionIconProps extends Omit<ActionIconPropsMantine, 'size'> { | ||
iconName: IconName; | ||
size: 'sm' | 'md' | 'lg'; | ||
} | ||
|
||
const ActionIcon = forwardRef<HTMLButtonElement, ActionIconProps>( | ||
({iconName, ...props}, ref) => { | ||
// Currently, our icon sizes only use a single letter instead of | ||
// Mantine's 'sm', 'md', etc. So here we grab the first letter. | ||
const iconSize = props.size[0] as IconSize; | ||
return ( | ||
<ActionIconMantine {...props} ref={ref}> | ||
<Icon name={iconName} size={iconSize} /> | ||
</ActionIconMantine> | ||
); | ||
} | ||
); | ||
|
||
export default createPolymorphicComponent<'button', ActionIconProps>( | ||
ActionIcon | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters