Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add success variant for infobox component #464

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions react/src/Infobox/Infobox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Error.args = {
children: `Only 30 MyInfo fields are allowed in Email mode (30/30).`,
}

export const Success = InfoboxTemplate.bind({})
Success.args = {
variant: 'success',
children: `You are your mother's proudest moment.`,
}

export const CustomIcon = InfoboxTemplate.bind({})
CustomIcon.args = {
variant: 'info',
Expand All @@ -44,23 +50,17 @@ CustomIcon.args = {

export const Sizes = () => (
<SimpleGrid columns={2} gap="1rem">
<Infobox variant="info" size="sm" height="fit-content">
Small info
</Infobox>
<Infobox variant="info" size="md" height="fit-content">
Medium info
</Infobox>
<Infobox variant="warning" size="sm" height="fit-content">
Small warning
</Infobox>
<Infobox variant="warning" size="md" height="fit-content">
Medium warning
</Infobox>
<Infobox variant="error" size="sm" height="fit-content">
Small error
</Infobox>
<Infobox variant="error" size="md" height="fit-content">
Medium error
</Infobox>
{['info', 'warning', 'error', 'success'].map((variant) =>
['sm', 'md'].map((size) => (
<Infobox
key={`${variant}-${size}`}
variant={variant as InfoboxProps['variant']}
size={size}
height="fit-content"
>
{`${size === 'sm' ? 'Small' : 'Medium'} ${variant}`}
</Infobox>
)),
)}
</SimpleGrid>
)
15 changes: 8 additions & 7 deletions react/src/Infobox/Infobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useMultiStyleConfig,
} from '@chakra-ui/react'

import { BxsErrorCircle, BxsInfoCircle } from '~/icons'
import { BxsCheckCircle, BxsErrorCircle, BxsInfoCircle } from '~/icons'
import { InfoboxVariant } from '~/theme/components/Infobox'

export interface InfoboxProps extends FlexProps {
Expand Down Expand Up @@ -39,12 +39,13 @@ export const Infobox = ({
if (iconProp) {
return <Box __css={styles.icon}>{iconProp}</Box>
}
return (
<Icon
as={variant !== 'error' ? BxsInfoCircle : BxsErrorCircle}
__css={styles.icon}
/>
)
if (variant === 'error') {
return <Icon as={BxsErrorCircle} __css={styles.icon} />
}
if (variant === 'success') {
return <Icon as={BxsCheckCircle} __css={styles.icon} />
}
return <Icon as={BxsInfoCircle} __css={styles.icon} />
}, [iconProp, styles.icon, variant])

return (
Expand Down
12 changes: 11 additions & 1 deletion react/src/theme/components/Infobox.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createMultiStyleConfigHelpers } from '@chakra-ui/react'
import { anatomy } from '@chakra-ui/theme-tools'

export type InfoboxVariant = 'info' | 'error' | 'warning'
export type InfoboxVariant = 'info' | 'error' | 'warning' | 'success'

const parts = anatomy('infobox').parts('messagebox', 'icon')

Expand Down Expand Up @@ -43,6 +43,15 @@ const variantError = definePartsStyle({
},
})

const variantSuccess = definePartsStyle({
messagebox: {
bg: 'utility.feedback.success-subtle',
},
icon: {
color: 'utility.feedback.success',
},
})

const sizes = {
sm: definePartsStyle({
messagebox: {
Expand Down Expand Up @@ -71,6 +80,7 @@ const variants = {
info: variantInfo,
warning: variantWarning,
error: variantError,
success: variantSuccess,
}

export const Infobox = defineMultiStyleConfig({
Expand Down