Skip to content

Commit b7ab0e3

Browse files
authored
feat(Alert): small version (#5791)
* feat: small alert * fix: tests * fix: icon size
1 parent 80d7bcd commit b7ab0e3

File tree

9 files changed

+201
-52
lines changed

9 files changed

+201
-52
lines changed

.changeset/dirty-parks-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/ui": patch
3+
---
4+
5+
`Alert`: add "size" prop

packages/form/src/components/SubmitErrorAlert/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ exports[`submitErrorAlert > should display an alert when submitError is present
1717
Submit
1818
</button>
1919
<div
20-
class="uv_1b838gx0 uv_1b838gx1 uv_toi52u0 uv_toi52u31 uv_toi52u2j uv_toi52u7d uv_toi52u7 uv_toi52u5d"
20+
class="uv_1b838gx0 uv_1b838gx1 uv_1b838gx6 uv_toi52u0 uv_toi52u31 uv_toi52u2j uv_toi52u7d uv_toi52u7 uv_toi52u5d"
2121
>
2222
<div
23-
class="uv_1b838gx6 uv_toi52u0 uv_toi52u3d uv_toi52u2j uv_toi52u7j uv_toi52ud uv_toi52u6p"
23+
class="uv_1b838gx8 uv_toi52u0 uv_toi52u3d uv_toi52u2j uv_toi52u7j uv_toi52ud uv_toi52u6p"
2424
>
2525
<div
2626
class="uv_toi52u0 uv_toi52u3j uv_toi52u2j uv_toi52u7d uv_toi52ud uv_toi52u5d"
@@ -37,7 +37,7 @@ exports[`submitErrorAlert > should display an alert when submitError is present
3737
/>
3838
</svg>
3939
<div
40-
class="uv_1b838gx7 uv_toi52u0 uv_toi52u31 uv_toi52u2j uv_toi52u7j uv_toi52u27 uv_toi52u5d"
40+
class="uv_1b838gx9 uv_toi52u0 uv_toi52u3d uv_toi52u2j uv_toi52u7j uv_toi52u27 uv_toi52u5d"
4141
style="--uv_4k0ekn3: 1 1 auto;"
4242
>
4343
<p

packages/plus/src/components/EstimateCost/__tests__/__snapshots__/Regular.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,10 +3259,10 @@ exports[`estimateCost - Regular Item > render with alert 1`] = `
32593259
This summary provides a cost estimation based on your configuration, the amount of time you expect to use the resource for, and the scale of your expected usage. For the purposes of this calculation, we consider that 1 month equals to 730 hours.
32603260
</span>
32613261
<div
3262-
class="uv_1b838gx0 uv_1b838gx4 uv_toi52u0 uv_toi52u31 uv_toi52u2j uv_toi52u7d uv_toi52u7 uv_toi52u5d"
3262+
class="uv_1b838gx0 uv_1b838gx4 uv_1b838gx6 uv_toi52u0 uv_toi52u31 uv_toi52u2j uv_toi52u7d uv_toi52u7 uv_toi52u5d"
32633263
>
32643264
<div
3265-
class="uv_1b838gx6 uv_toi52u0 uv_toi52u3d uv_toi52u2j uv_toi52u7j uv_toi52ud uv_toi52u6p"
3265+
class="uv_1b838gx8 uv_toi52u0 uv_toi52u3d uv_toi52u2j uv_toi52u7j uv_toi52ud uv_toi52u6p"
32663266
>
32673267
<div
32683268
class="uv_toi52u0 uv_toi52u3j uv_toi52u2j uv_toi52u7d uv_toi52ud uv_toi52u5d"
@@ -3279,7 +3279,7 @@ exports[`estimateCost - Regular Item > render with alert 1`] = `
32793279
/>
32803280
</svg>
32813281
<div
3282-
class="uv_1b838gx7 uv_toi52u0 uv_toi52u31 uv_toi52u2j uv_toi52u7j uv_toi52u27 uv_toi52u5d"
3282+
class="uv_1b838gx9 uv_toi52u0 uv_toi52u3d uv_toi52u2j uv_toi52u7j uv_toi52u27 uv_toi52u5d"
32833283
style="--uv_4k0ekn3: 1 1 auto;"
32843284
>
32853285
<span
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import type { Decorator } from '@storybook/react-vite'
2+
import type { ComponentProps } from 'react'
3+
import { Stack } from '../../Stack'
4+
import { Alert } from '..'
5+
6+
export const Size = (props: ComponentProps<typeof Alert>) => (
7+
<>
8+
<Alert
9+
{...props}
10+
onClickButton={() => alert('Button clicked')}
11+
title="title"
12+
>
13+
This is an Alert.
14+
</Alert>
15+
16+
<Alert
17+
{...props}
18+
onClickButton={() => alert('Button clicked')}
19+
size="small"
20+
title="title"
21+
>
22+
This is a small alert
23+
</Alert>
24+
<Alert
25+
{...props}
26+
buttonText="More info"
27+
onClickButton={() => alert('Button clicked')}
28+
size="small"
29+
title="title"
30+
>
31+
Small alert with long children. Lorem ipsum dolor sit amet, consectetur
32+
adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
33+
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
34+
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
35+
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
36+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa
37+
qui officia deserunt mollit anim id est laborum.,
38+
</Alert>
39+
</>
40+
)
41+
42+
Size.decorators = [
43+
StoryComponent => (
44+
<Stack gap={2}>
45+
<StoryComponent />
46+
</Stack>
47+
),
48+
] as Decorator[]
49+
50+
Size.parameters = {
51+
docs: {
52+
description: {
53+
story:
54+
'Using `sentiment` prop you can change the sentiment of the component. Each sentiment has a default icon set.',
55+
},
56+
},
57+
}

packages/ui/src/components/Alert/__stories__/index.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export { Title } from './Title.stories'
1111
export { Button } from './Button.stories'
1212
export { Link } from './Link.stories'
1313
export { Sentiments } from './Sentiments.stories'
14+
export { Size } from './Size.stories'
1415
export { Closable } from './Closable.stories'
1516
export { LongChildren } from './LongChildren.stories'

packages/ui/src/components/Alert/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 83 additions & 36 deletions
Large diffs are not rendered by default.

packages/ui/src/components/Alert/__tests__/index.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ describe('alert', () => {
7575
Sample Alert
7676
</Alert>,
7777
))
78+
test('renders correctly small', () =>
79+
shouldMatchSnapshot(
80+
<Alert className="small" size="small" title="title">
81+
Sample Alert
82+
</Alert>,
83+
))
7884
})

packages/ui/src/components/Alert/index.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
alert,
1717
buttonAlert,
1818
buttonCloseAlert,
19+
smallIcon,
1920
textAlert,
2021
wrapAlert,
2122
} from './styles.css'
@@ -47,6 +48,7 @@ type AlertProps = {
4748
*/
4849
disabled?: boolean
4950
style?: CSSProperties
51+
size?: 'medium' | 'small'
5052
}
5153

5254
/**
@@ -63,6 +65,7 @@ export const Alert = ({
6365
className,
6466
disabled,
6567
'data-testid': dataTestId,
68+
size = 'medium',
6669
style,
6770
}: AlertProps) => {
6871
const [opened, setOpened] = useState(true)
@@ -74,7 +77,7 @@ export const Alert = ({
7477

7578
return (
7679
<Stack
77-
className={`${className ? `${className} ` : ''}${alert({ sentiment })}`}
80+
className={`${className ? `${className} ` : ''}${alert({ sentiment, size })}`}
7881
data-testid={dataTestId}
7982
direction="row"
8083
gap={1}
@@ -88,27 +91,40 @@ export const Alert = ({
8891
justifyContent="space-between"
8992
wrap
9093
>
91-
<Stack alignItems="start" direction="row" flex="1 1 auto" gap={2}>
94+
<Stack
95+
alignItems="start"
96+
direction="row"
97+
flex="1 1 auto"
98+
gap={size === 'small' ? 1 : 2}
99+
>
92100
<Icon
93101
aria-hidden="true"
102+
className={size === 'small' ? smallIcon : ''}
94103
prominence={sentiment === 'neutral' ? 'strong' : undefined}
95104
sentiment={sentiment}
96-
size="large"
105+
size={size === 'small' ? 'small' : 'large'}
97106
/>
98107
<Stack
108+
alignItems="center"
99109
className={textAlert}
100110
direction="row"
101111
flex="1 1 auto"
102112
gap={1.5}
103113
wrap
104114
>
105115
{title ? (
106-
<Text as="span" sentiment={sentiment} variant="bodyStronger">
116+
<Text
117+
as="span"
118+
sentiment={sentiment}
119+
variant={
120+
size === 'small' ? 'bodySmallStronger' : 'bodyStronger'
121+
}
122+
>
107123
{title}
108124
</Text>
109125
) : null}
110126
{typeof children === 'string' ? (
111-
<Text as="p" variant="body">
127+
<Text as="p" variant={size === 'small' ? 'bodySmall' : 'body'}>
112128
{children}
113129
</Text>
114130
) : (
@@ -118,7 +134,7 @@ export const Alert = ({
118134
</Stack>
119135
{buttonText ? (
120136
<Button
121-
className={buttonAlert}
137+
className={buttonAlert[size]}
122138
disabled={disabled}
123139
onClick={onClickButton}
124140
sentiment={sentiment}

packages/ui/src/components/Alert/styles.css.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { theme } from '@ultraviolet/themes'
2-
import { style } from '@vanilla-extract/css'
2+
import { style, styleVariants } from '@vanilla-extract/css'
33
import type { RecipeVariants } from '@vanilla-extract/recipes'
44
import { recipe } from '@vanilla-extract/recipes'
55
import type { AlertSentiment } from './type'
@@ -16,7 +16,6 @@ function createStyleAlert(sentiment: AlertSentiment) {
1616
export const alert = recipe({
1717
base: {
1818
borderRadius: theme.radii.default,
19-
padding: theme.space[2],
2019
},
2120
variants: {
2221
sentiment: {
@@ -30,9 +29,18 @@ export const alert = recipe({
3029
borderLeft: `4px solid ${theme.colors.neutral.borderStronger}`,
3130
},
3231
},
32+
size: {
33+
medium: {
34+
padding: theme.space[2],
35+
},
36+
small: {
37+
padding: theme.space['1.5'],
38+
},
39+
},
3340
},
3441
defaultVariants: {
3542
sentiment: 'danger',
43+
size: 'medium',
3644
},
3745
})
3846

@@ -44,12 +52,21 @@ export const textAlert = style({
4452
color: theme.colors.neutral.text,
4553
})
4654

47-
export const buttonAlert = style({
48-
marginLeft: theme.space[5],
55+
export const buttonAlert = styleVariants({
56+
medium: {
57+
marginLeft: theme.space[5],
58+
},
59+
small: {
60+
marginLeft: theme.space[3],
61+
},
4962
})
5063

5164
export const buttonCloseAlert = style({
5265
alignSelf: 'start',
5366
})
5467

5568
export type AlertVariants = NonNullable<RecipeVariants<typeof alert>>
69+
70+
export const smallIcon = style({
71+
marginTop: theme.space['0.25'],
72+
})

0 commit comments

Comments
 (0)