Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changeset/inline-message-optional-variant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

InlineMessage: Make `variant` prop optional, defaulting to the standard foreground color with an info icon
2 changes: 2 additions & 0 deletions packages/react/src/InlineMessage/InlineMessage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
grid-template-columns: auto 1fr;
align-items: start;

--inline-message-fgColor: var(--fgColor-default);

&[data-size='small'] {
--inline-message-fontSize: var(--text-body-size-small);
--inline-message-lineHeight: var(--text-body-lineHeight-small, 1.6666);
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/InlineMessage/InlineMessage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ describe('InlineMessage', () => {
expect(screen.getByTestId('container')).toHaveAttribute('data-variant', 'warning')
})

it('should not set data-variant when variant is not provided', () => {
render(<InlineMessage data-testid="container">test</InlineMessage>)
expect(screen.getByTestId('container')).not.toHaveAttribute('data-variant')
})

it('should render InfoIcon when variant is not provided', () => {
Comment thread
dylanatsmith marked this conversation as resolved.
const {container} = render(<InlineMessage>test without variant</InlineMessage>)
expect(screen.getByText('test without variant')).toBeInTheDocument()
const svg = container.querySelector('svg.octicon-info')
expect(svg).toBeInTheDocument()
})

it('should render leading visual', () => {
render(
<>
Expand Down
10 changes: 6 additions & 4 deletions packages/react/src/InlineMessage/InlineMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AlertFillIcon, AlertIcon, CheckCircleFillIcon, CheckCircleIcon} from '@primer/octicons-react'
import {AlertFillIcon, AlertIcon, CheckCircleFillIcon, CheckCircleIcon, InfoIcon} from '@primer/octicons-react'
import {clsx} from 'clsx'
import type React from 'react'
import {isValidElementType} from 'react-is'
Expand All @@ -14,7 +14,7 @@ export type InlineMessageProps = React.ComponentPropsWithoutRef<'div'> & {
/**
* Specify the type of the InlineMessage
*/
variant: MessageVariant
variant?: MessageVariant

/**
* A custom leading visual (icon or other element) to display instead of the default variant icon.
Expand Down Expand Up @@ -52,17 +52,19 @@ export function InlineMessage({
} else {
icon = LeadingVisual
}
} else {
} else if (variant) {
// Use default icon based on variant and size
icon = size === 'small' ? smallIcons[variant] : icons[variant]
} else {
icon = <InfoIcon className={classes.InlineMessageIcon} />
}
Comment thread
dylanatsmith marked this conversation as resolved.

return (
<div
{...rest}
className={clsx(className, classes.InlineMessage)}
data-size={size}
data-variant={variant}
data-variant={variant ?? undefined}
data-component="InlineMessage"
>
{icon}
Expand Down
Loading