feat: Add `framed` optional property for IconElement `ui-kit` component (#37726)
Co-authored-by: Douglas Gubert <1810309+d-gubert@users.noreply.github.com>pull/37715/merge
parent
855fae239d
commit
d3538e7045
@ -0,0 +1,6 @@ |
|||||||
|
--- |
||||||
|
"@rocket.chat/fuselage-ui-kit": minor |
||||||
|
"@rocket.chat/ui-kit": minor |
||||||
|
--- |
||||||
|
|
||||||
|
Introduces a new variation of the `Icon` element to `ui-kit` through the new `framed` optional property. |
||||||
@ -1,24 +1,46 @@ |
|||||||
import { Icon } from '@rocket.chat/fuselage'; |
import { Icon, FramedIcon } from '@rocket.chat/fuselage'; |
||||||
import type * as UiKit from '@rocket.chat/ui-kit'; |
import type * as UiKit from '@rocket.chat/ui-kit'; |
||||||
import type { ReactElement } from 'react'; |
import type { ComponentProps, ReactElement } from 'react'; |
||||||
|
|
||||||
import type { BlockProps } from '../utils/BlockProps'; |
import type { BlockProps } from '../utils/BlockProps'; |
||||||
|
|
||||||
type IconElementProps = BlockProps<UiKit.IconElement>; |
type IconElementProps = BlockProps<UiKit.FrameableIconElement>; |
||||||
|
|
||||||
const getVariantColor = (variant: UiKit.IconElement['variant']): string => { |
const getVariantColor = (variant: UiKit.FrameableIconElement['variant']): string => { |
||||||
switch (variant) { |
switch (variant) { |
||||||
case 'default': |
|
||||||
return 'default'; |
|
||||||
case 'danger': |
case 'danger': |
||||||
return 'danger'; |
return 'danger'; |
||||||
case 'secondary': |
case 'secondary': |
||||||
return 'secondary-info'; |
return 'secondary-info'; |
||||||
|
case 'warning': |
||||||
|
return 'status-font-on-warning'; |
||||||
|
case 'default': |
||||||
|
default: |
||||||
|
return 'default'; |
||||||
} |
} |
||||||
}; |
}; |
||||||
|
|
||||||
const IconElement = ({ block }: IconElementProps): ReactElement => ( |
const getFramedIconProps = ( |
||||||
<Icon size={20} name={block.icon} color={getVariantColor(block.variant)} /> |
variant: UiKit.FrameableIconElement['variant'], |
||||||
); |
): Pick<ComponentProps<typeof FramedIcon>, 'warning' | 'danger' | 'neutral'> => { |
||||||
|
switch (variant) { |
||||||
|
case 'danger': |
||||||
|
return { danger: true }; |
||||||
|
case 'warning': |
||||||
|
return { warning: true }; |
||||||
|
case 'default': |
||||||
|
case 'secondary': |
||||||
|
default: |
||||||
|
return { neutral: true }; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
const IconElement = ({ block }: IconElementProps): ReactElement => { |
||||||
|
const { icon, variant, framed } = block; |
||||||
|
if (framed) { |
||||||
|
return <FramedIcon size={20} icon={icon} {...getFramedIconProps(variant)} />; |
||||||
|
} |
||||||
|
return <Icon size={20} name={icon} color={getVariantColor(variant)} />; |
||||||
|
}; |
||||||
|
|
||||||
export default IconElement; |
export default IconElement; |
||||||
|
|||||||
@ -1,7 +1,11 @@ |
|||||||
type AvailableIcons = 'phone-off' | 'phone-issue' | 'clock' | 'arrow-forward' | 'info'; |
type AvailableIcons = 'phone-off' | 'phone-issue' | 'clock' | 'arrow-forward' | 'info' /* | 'phone-question-mark' */; // TODO add new icon when available in fuselage
|
||||||
|
|
||||||
export type IconElement = { |
export type IconElement = { |
||||||
type: 'icon'; |
type: 'icon'; |
||||||
icon: AvailableIcons; |
icon: AvailableIcons; |
||||||
variant: 'default' | 'danger' | 'secondary'; |
variant: 'default' | 'danger' | 'secondary' | 'warning'; |
||||||
|
}; |
||||||
|
|
||||||
|
export type FrameableIconElement = IconElement & { |
||||||
|
framed?: boolean; |
||||||
}; |
}; |
||||||
|
|||||||
Loading…
Reference in new issue