Skip to content

Commit ff11204

Browse files
committed
feat: small alert
1 parent 39e89c0 commit ff11204

File tree

7 files changed

+189
-45
lines changed

7 files changed

+189
-45
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
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
@@ -72,4 +72,10 @@ describe('alert', () => {
7272
Sample Alert
7373
</Alert>,
7474
))
75+
test('renders correctly small', () =>
76+
shouldMatchSnapshot(
77+
<Alert className="small" size="small" title="title">
78+
Sample Alert
79+
</Alert>,
80+
))
7581
})

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type AlertProps = {
4747
*/
4848
disabled?: boolean
4949
style?: CSSProperties
50+
size?: 'medium' | 'small'
5051
}
5152

5253
/**
@@ -63,6 +64,7 @@ export const Alert = ({
6364
className,
6465
disabled,
6566
'data-testid': dataTestId,
67+
size = 'medium',
6668
style,
6769
}: AlertProps) => {
6870
const [opened, setOpened] = useState(true)
@@ -74,7 +76,7 @@ export const Alert = ({
7476

7577
return (
7678
<Stack
77-
className={`${className ? `${className} ` : ''}${alert({ sentiment })}`}
79+
className={`${className ? `${className} ` : ''}${alert({ sentiment, size })}`}
7880
data-testid={dataTestId}
7981
direction="row"
8082
gap={1}
@@ -88,27 +90,39 @@ export const Alert = ({
8890
justifyContent="space-between"
8991
wrap
9092
>
91-
<Stack alignItems="start" direction="row" flex="1 1 auto" gap={2}>
93+
<Stack
94+
alignItems="start"
95+
direction="row"
96+
flex="1 1 auto"
97+
gap={size === 'small' ? 1 : 2}
98+
>
9299
<Icon
93100
aria-hidden="true"
94101
prominence={sentiment === 'neutral' ? 'strong' : undefined}
95102
sentiment={sentiment}
96103
size="large"
97104
/>
98105
<Stack
106+
alignItems="center"
99107
className={textAlert}
100108
direction="row"
101109
flex="1 1 auto"
102110
gap={1.5}
103111
wrap
104112
>
105113
{title ? (
106-
<Text as="span" sentiment={sentiment} variant="bodyStronger">
114+
<Text
115+
as="span"
116+
sentiment={sentiment}
117+
variant={
118+
size === 'small' ? 'bodySmallStronger' : 'bodyStronger'
119+
}
120+
>
107121
{title}
108122
</Text>
109123
) : null}
110124
{typeof children === 'string' ? (
111-
<Text as="p" variant="body">
125+
<Text as="p" variant={size === 'small' ? 'bodySmall' : 'body'}>
112126
{children}
113127
</Text>
114128
) : (
@@ -118,7 +132,7 @@ export const Alert = ({
118132
</Stack>
119133
{buttonText ? (
120134
<Button
121-
className={buttonAlert}
135+
className={buttonAlert[size]}
122136
disabled={disabled}
123137
onClick={onClickButton}
124138
sentiment={sentiment}

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

Lines changed: 18 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

@@ -42,10 +50,16 @@ export const wrapAlert = style({
4250

4351
export const textAlert = style({
4452
color: theme.colors.neutral.text,
53+
paddingTop: theme.space['0.25'],
4554
})
4655

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

5165
export const buttonCloseAlert = style({

0 commit comments

Comments
 (0)