-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/blocks
- Loading branch information
Showing
6 changed files
with
121 additions
and
0 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,7 @@ | ||
--- | ||
'@saas-ui/theme': minor | ||
'@saas-ui/core': minor | ||
'@saas-ui/react': minor | ||
--- | ||
|
||
Added new IconBadge component |
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,64 @@ | ||
import { | ||
chakra, | ||
useStyleConfig, | ||
IconProps, | ||
ThemingProps, | ||
forwardRef, | ||
} from '@chakra-ui/react' | ||
import { cx } from '@chakra-ui/utils' | ||
import { cloneElement, isValidElement } from 'react' | ||
|
||
export interface IconBadgeProps | ||
extends IconProps, | ||
ThemingProps<'SuiIconBadge'> { | ||
/** | ||
* The icon to be used in the button. | ||
* @type React.ReactElement | ||
*/ | ||
icon?: React.ReactElement | ||
/** | ||
* If `true`, the badge will be perfectly round. Else, it'll be slightly round | ||
* | ||
* @default false | ||
*/ | ||
isRound?: boolean | ||
/** | ||
* A11y: A label that describes the icon | ||
*/ | ||
'aria-label'?: string | ||
} | ||
|
||
export const IconBadge = forwardRef<IconBadgeProps, 'div'>((props) => { | ||
const { icon, children, isRound, 'aria-label': ariaLabel, ...rest } = props | ||
const styles = useStyleConfig('SuiIconBadge', props) | ||
|
||
/** | ||
* Passing the icon as prop or children should work | ||
*/ | ||
const element = icon || children | ||
const _children = isValidElement(element) | ||
? cloneElement(element as any, { | ||
'aria-hidden': true, | ||
focusable: false, | ||
}) | ||
: null | ||
|
||
const __css = { | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
...styles, | ||
} | ||
|
||
return ( | ||
<chakra.div | ||
__css={__css} | ||
borderRadius={isRound ? 'full' : undefined} | ||
aria-label={ariaLabel} | ||
{...rest} | ||
className={cx('sui-icon-badge', props.className)} | ||
> | ||
{_children} | ||
</chakra.div> | ||
) | ||
}) |
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 @@ | ||
export { IconBadge, type IconBadgeProps } from './icon-badge' |
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
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,45 @@ | ||
import { defineStyleConfig } from '@chakra-ui/styled-system' | ||
|
||
export const iconBadgeTheme = defineStyleConfig({ | ||
baseStyle: { | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
variants: { | ||
outline: ({ colorScheme }) => { | ||
return { | ||
borderWidth: '1px', | ||
borderColor: colorScheme ? `${colorScheme}.500` : 'chakra-border-color', | ||
color: colorScheme ? `${colorScheme}.500` : 'currentColor', | ||
} | ||
}, | ||
solid: ({ colorScheme = 'gray' }) => { | ||
return { | ||
bg: `${colorScheme}.500`, | ||
color: 'white', | ||
} | ||
}, | ||
}, | ||
sizes: { | ||
sm: { | ||
borderRadius: 'sm', | ||
fontSize: '0.9em', | ||
p: 1, | ||
}, | ||
md: { | ||
borderRadius: 'md', | ||
fontSize: '1em', | ||
p: 2, | ||
}, | ||
lg: { | ||
borderRadius: 'md', | ||
fontSize: '1.3em', | ||
p: 3, | ||
}, | ||
}, | ||
defaultProps: { | ||
variant: 'outline', | ||
size: 'md', | ||
}, | ||
}) |
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