Skip to content

Commit fa7bfb5

Browse files
authored
feat: Support heading-less inline alerts (#8872)
* feat: Support heading-less inline alerts * apply set width and add chromatic story
1 parent 7df2296 commit fa7bfb5

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

packages/@react-spectrum/s2/chromatic/InlineAlert.stories.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,13 @@ const DynamicExampleRender = (args: InlineAlertProps): ReactElement => {
5757
export const DynamicExample: StoryObj<typeof DynamicExampleRender> = {
5858
render: (args) => <DynamicExampleRender {...args} />
5959
};
60+
61+
export const NoHeading: Story = {
62+
render: () => (
63+
<InlineAlert variant="informative">
64+
<Content>
65+
There was an error processing your payment. Please check that your card information is correct, then try again.
66+
</Content>
67+
</InlineAlert>
68+
)
69+
};

packages/@react-spectrum/s2/src/InlineAlert.tsx

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const inlineAlert = style<InlineStylesProps & {isFocusVisible?: boolean}>({
121121
}, getAllowedOverrides());
122122

123123
const icon = style<InlineStylesProps>({
124-
gridArea: 'icon',
124+
float: 'inline-end',
125125
'--iconPrimary': {
126126
type: 'fill',
127127
value: {
@@ -155,18 +155,6 @@ const icon = style<InlineStylesProps>({
155155
}
156156
});
157157

158-
const grid = style({
159-
display: 'grid',
160-
columnGap: 24,
161-
gridTemplateColumns: '1fr auto',
162-
gridTemplateRows: 'auto auto auto',
163-
width: 'full',
164-
gridTemplateAreas: [
165-
'heading icon',
166-
'content content'
167-
]
168-
});
169-
170158
let ICONS = {
171159
informative: InfoCircle,
172160
positive: CheckmarkCircle,
@@ -177,7 +165,6 @@ let ICONS = {
177165

178166
const heading = style({
179167
marginTop: 0,
180-
gridArea: 'heading',
181168
font: 'title-sm',
182169
color: {
183170
default: 'title',
@@ -193,7 +180,6 @@ const heading = style({
193180
});
194181

195182
const content = style({
196-
gridArea: 'content',
197183
font: 'body-sm',
198184
color: {
199185
default: 'body',
@@ -256,18 +242,15 @@ export const InlineAlert = /*#__PURE__*/ forwardRef(function InlineAlert(props:
256242
fillStyle,
257243
isFocusVisible
258244
}, props.styles)}>
259-
<div
260-
className={grid}>
261-
<Provider
262-
values={[
263-
[HeadingContext, {styles: heading({fillStyle})}],
264-
[ContentContext, {styles: content({fillStyle})}],
265-
[IconContext, {styles: icon({variant, fillStyle})}]
266-
]}>
267-
{Icon && <Icon aria-label={iconAlt} />}
268-
{children}
269-
</Provider>
270-
</div>
245+
<Provider
246+
values={[
247+
[HeadingContext, {styles: heading({fillStyle})}],
248+
[ContentContext, {styles: content({fillStyle})}],
249+
[IconContext, {styles: icon({variant, fillStyle})}]
250+
]}>
251+
{Icon && <Icon aria-label={iconAlt} />}
252+
{children}
253+
</Provider>
271254
</div>
272255
);
273256
});

packages/@react-spectrum/s2/stories/InlineAlert.stories.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import {Button, Content, Heading, InlineAlert, InlineAlertProps} from '../src';
1414
import type {Meta, StoryObj} from '@storybook/react';
1515
import {ReactElement, useState} from 'react';
16+
import {style} from '../style' with {type: 'macro'};
1617

1718
const meta: Meta<typeof InlineAlert> = {
1819
component: InlineAlert,
@@ -61,3 +62,30 @@ const DynamicExampleRender = (args: InlineAlertProps): ReactElement => {
6162
export const DynamicExample: StoryObj<typeof DynamicExampleRender> = {
6263
render: (args) => <DynamicExampleRender {...args} />
6364
};
65+
66+
let NoHeadingExample = (args: InlineAlertProps & {showHeading: boolean, content: string}): ReactElement => {
67+
let {showHeading = false, content} = args;
68+
return (
69+
<InlineAlert {...args}>
70+
{showHeading && <Heading>Payment Information</Heading>}
71+
<Content>
72+
{content}
73+
</Content>
74+
</InlineAlert>
75+
);
76+
};
77+
78+
export const NoHeading: StoryObj<typeof NoHeadingExample> = {
79+
render: (args) => (
80+
<NoHeadingExample {...args} styles={style({width: 400})} />
81+
),
82+
args: {
83+
showHeading: false,
84+
content: 'There was an error processing your payment. Please check that your card information is correct, then try again.'
85+
},
86+
parameters: {
87+
docs: {
88+
disable: true
89+
}
90+
}
91+
};

0 commit comments

Comments
 (0)