mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: IconButton & RoundIconButton
This commit is contained in:
parent
38e5ee718c
commit
5c65f9e7f5
2 changed files with 65 additions and 0 deletions
49
src/components/IconButton.tsx
Normal file
49
src/components/IconButton.tsx
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { IconProps } from '@primer/octicons-react'
|
||||
import { Box, merge, SxProp, useTheme } from '@primer/react'
|
||||
import { getBaseStyles, getSizeStyles, getVariantStyles } from '@primer/react/lib/Button/styles'
|
||||
import {
|
||||
IconButtonProps as PrimerIconButtonProps,
|
||||
StyledButton
|
||||
} from '@primer/react/lib/Button/types'
|
||||
import React from 'react'
|
||||
import { is } from 'utils/is'
|
||||
|
||||
export type IconButtonProps = PrimerIconButtonProps & {
|
||||
iconSize?: IconProps['size']
|
||||
iconColor?: string
|
||||
}
|
||||
|
||||
// Modified version of @primer/react/lib/Button/Button.tsx
|
||||
// Added better support of colors & size
|
||||
|
||||
export function IconButton(props: IconButtonProps) {
|
||||
const {
|
||||
variant = 'default',
|
||||
size = 'medium',
|
||||
iconSize, // grow the icon to the same size as the button
|
||||
iconColor, // extra control of icon color
|
||||
sx: sxProp = {},
|
||||
icon: Icon,
|
||||
...rest
|
||||
} = props
|
||||
const { theme } = useTheme()
|
||||
const sxStyles = merge.all(
|
||||
[
|
||||
getBaseStyles(theme),
|
||||
getSizeStyles(size, variant, true),
|
||||
getVariantStyles(variant, theme),
|
||||
// Unsatisfied with preset color of the `invisible` variant
|
||||
{
|
||||
color: iconColor || (variant === 'invisible' ? 'fg.subtle' : undefined),
|
||||
},
|
||||
sxProp as SxProp,
|
||||
].filter(is.not.undefined),
|
||||
)
|
||||
return (
|
||||
<StyledButton sx={sxStyles} {...rest}>
|
||||
<Box as="span" sx={{ display: 'inline-block' }}>
|
||||
<Icon size={iconSize} />
|
||||
</Box>
|
||||
</StyledButton>
|
||||
)
|
||||
}
|
||||
16
src/components/RoundIconButton.tsx
Normal file
16
src/components/RoundIconButton.tsx
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import React from 'react'
|
||||
import { IconButton, IconButtonProps } from './IconButton'
|
||||
|
||||
export function RoundIconButton(props: IconButtonProps) {
|
||||
return (
|
||||
<IconButton
|
||||
variant="invisible"
|
||||
title={props['aria-label']}
|
||||
{...props}
|
||||
sx={{
|
||||
borderRadius: '20px',
|
||||
...props.sx,
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Loading…
Reference in a new issue