Skip to content

Commit 11459a6

Browse files
authored
Merge pull request #2277 from gluestack/fix/alert
Fix/alert
2 parents c3796af + 7383319 commit 11459a6

File tree

3 files changed

+232
-44
lines changed

3 files changed

+232
-44
lines changed

example/storybook-nativewind/src/components/Alert/Alert.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const AlertMeta: ComponentMeta<typeof Alert> = {
1313
argTypes: {
1414
variant: {
1515
control: 'select',
16-
options: ['solid', 'accent', 'outline'],
16+
options: ['solid', 'outline'],
1717
},
1818
action: {
1919
control: 'select',

example/storybook-nativewind/src/components/Alert/index.nw.stories.mdx

Lines changed: 206 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@ import {
1919
AlertIcon,
2020
AlertText,
2121
InfoIcon,
22-
CheckCircleIcon,
23-
CloseCircleIcon,
24-
BellIcon,
25-
AlertCircleIcon,
22+
CloseIcon,
23+
RepeatIcon,
2624
Icon,
2725
VStack,
28-
Center,
2926
HStack,
27+
Text,
28+
Heading,
29+
Button,
30+
ButtonText,
31+
Input,
32+
InputField,
33+
InputSlot,
34+
InputIcon
3035
} from '../../core-components/nativewind';
31-
32-
36+
import { Bomb, EyeIcon, EyeOffIcon } from "lucide-react-native";
3337
import { transformedCode } from '../../utils';
3438
import {
3539
AppProvider,
@@ -51,10 +55,10 @@ This is an illustration of **Alert** component.
5155
showArgsController={true}
5256
metaData={{
5357
code: `
54-
<Alert className="mx-2.5" {...props}>
55-
<AlertIcon as={InfoIcon} className="mr-3" />
58+
<Alert {...props}>
59+
<AlertIcon as={InfoIcon} />
5660
<AlertText>
57-
We have updated our terms of service. Please review and accept to continue using our service.
61+
Description of alert!
5862
</AlertText>
5963
</Alert>
6064
`,
@@ -76,7 +80,7 @@ This is an illustration of **Alert** component.
7680
},
7781
variant: {
7882
control: 'select',
79-
options: ['accent', 'solid', 'outline'],
83+
options: ['solid', 'outline'],
8084
default: 'solid',
8185
},
8286
},
@@ -210,7 +214,7 @@ Alert component is created using View component from react-native. It extends al
210214
</Table.TText>
211215
</Table.TD>
212216
<Table.TD>
213-
<Table.TText>solid | outline | accent</Table.TText>
217+
<Table.TText>solid | outline</Table.TText>
214218
</Table.TD>
215219
<Table.TD>
216220
<Table.TText>solid</Table.TText>
@@ -225,42 +229,218 @@ Alert component is created using View component from react-native. It extends al
225229

226230
The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.
227231

228-
#### Alert with Heading
229-
230-
An example of an alert component with a heading, which further contains another alert component for displaying supplementary information.
232+
#### Alert with CTA
231233

232234
<Wrapper>
233235
<CodePreview
234236
showComponentRenderer={true}
235237
showArgsController={false}
238+
_rendererWrapper={{
239+
alignItems: 'stretch',
240+
padding: 20
241+
}}
236242
metaData={{
237243
code: `
238-
<Alert action='success'>
239-
<AlertIcon as={CheckCircleIcon} size="xl" className='mr-3' />
240-
<VStack space='xs'>
241-
<AlertText className='font-bold' >
242-
Congratulations!
243-
</AlertText >
244-
<AlertText >
245-
Thank you for your submission. You will receive a confirmation email shortly.
244+
<Alert
245+
action="success"
246+
className="gap-4 max-w-[585px] w-full self-center items-start min-[400px]:items-center"
247+
>
248+
<VStack className="gap-4 min-[400px]:flex-row justify-between flex-1 min-[400px]:items-center">
249+
<AlertText className="font-semibold text-typography-900" size="sm">
250+
Verify your phone number to create an API key
246251
</AlertText>
252+
<Button size="sm">
253+
<ButtonText>Start verification</ButtonText>
254+
</Button>
247255
</VStack>
256+
<Icon as={CloseIcon} />
248257
</Alert>
249258
`,
250259
transformCode: (code) => {
251260
return transformedCode(code);
252261
},
253262
scope: {
254263
Alert,
255-
AlertIcon,
256264
AlertText,
257265
Wrapper,
258-
CheckCircleIcon,
259266
VStack,
260267
Icon,
268+
CloseIcon,
269+
Button,
270+
ButtonText
271+
},
272+
argsType: {},
273+
}}
274+
/>
275+
</Wrapper>
276+
277+
#### Alert on cloud sync
278+
279+
<Wrapper>
280+
<CodePreview
281+
_rendererWrapper={{
282+
alignItems: 'stretch',
283+
padding: 20
284+
}}
285+
showComponentRenderer={true}
286+
showArgsController={false}
287+
metaData={{
288+
code: `
289+
<Alert
290+
action="warning"
291+
className="gap-4 max-w-[516px] w-full flex-row flex py-4 items-start self-center"
292+
>
293+
<AlertIcon as={RepeatIcon} />
294+
<HStack className="justify-between flex-1 items-center gap-1 sm:gap-8">
295+
<VStack className="flex-1">
296+
<Text className="font-semibold text-typography-900">
297+
Sync is disabled
298+
</Text>
299+
<AlertText className="text-typography-900" size="sm">
300+
Enable cloud sync to help safeguard your data
301+
</AlertText>
302+
</VStack>
303+
<Button size="xs">
304+
<ButtonText>Turn on</ButtonText>
305+
</Button>
306+
</HStack>
307+
</Alert>
308+
`,
309+
transformCode: (code) => {
310+
return transformedCode(code);
311+
},
312+
scope: {
313+
Alert,
314+
AlertIcon,
315+
AlertText,
316+
Wrapper,
317+
HStack,
318+
VStack,
319+
RepeatIcon,
320+
Button,
321+
ButtonText,
322+
Text
323+
},
324+
argsType: {},
325+
}}
326+
/>
327+
</Wrapper>
328+
329+
#### Warning alert
330+
331+
<Wrapper>
332+
<CodePreview
333+
_rendererWrapper={{
334+
padding: 20
335+
}}
336+
showComponentRenderer={true}
337+
showArgsController={false}
338+
metaData={{
339+
code: `
340+
<Alert action="error" className="gap-3 items-start">
341+
{/* Bomb is imported from 'lucide-react-native' */}
342+
<AlertIcon as={Bomb} size="lg" />
343+
<AlertText className="text-typography-900" size="sm">
344+
<Text className="mr-2 font-semibold text-typography-900">
345+
Heads up:
346+
</Text>
347+
Once done, this action cannot be undone
348+
</AlertText>
349+
</Alert>
350+
`,
351+
transformCode: (code) => {
352+
return transformedCode(code);
353+
},
354+
scope: {
355+
Alert,
356+
AlertIcon,
357+
AlertText,
358+
Wrapper,
359+
Text,
360+
Bomb
261361
},
262362
argsType: {},
263363
}}
264-
/>
364+
/>
365+
</Wrapper>
265366

367+
#### Alert on confirm password modal
368+
369+
<Wrapper>
370+
<CodePreview
371+
_rendererWrapper={{
372+
padding: 20
373+
}}
374+
showComponentRenderer={true}
375+
showArgsController={false}
376+
metaData={{
377+
code: `
378+
function Example() {
379+
const [showPassword, setShowPassword] = React.useState(false);
380+
const handleState = () => {
381+
setShowPassword((showState) => {
382+
return !showState;
383+
});
384+
};
385+
return (
386+
<VStack className="gap-5 sm:gap-8 p-6 sm:p-9 border border-outline-200 bg-background-0 rounded-xl shadow-hard-5 w-full max-w-[423px]">
387+
<VStack className="items-center gap-1">
388+
<Heading size="xl">Confirm our password?</Heading>
389+
<Text>johnsmith@gmail.com</Text>
390+
</VStack>
391+
<VStack className="gap-3 sm:gap-5">
392+
<Input className="rounded-md" size="sm">
393+
<InputField
394+
type={showPassword ? 'text' : 'password'}
395+
placeholder="Enter password"
396+
/>
397+
<InputSlot className="mr-3" onPress={handleState}>
398+
{/* EyeIcon, EyeOffIcon are both imported from 'lucide-react-native' */}
399+
<InputIcon
400+
size="xs"
401+
as={showPassword ? EyeIcon : EyeOffIcon}
402+
className="stroke-background-600"
403+
/>
404+
</InputSlot>
405+
</Input>
406+
<Button className="w-full rounded-md" size="sm">
407+
<ButtonText>Confirm</ButtonText>
408+
</Button>
409+
</VStack>
410+
<Alert className="items-start" action="muted">
411+
<AlertIcon as={InfoIcon} size="xs" className="stroke-background-500" />
412+
<AlertText className="text-typography-600" size="xs">
413+
Minimum 8 characters, with at least 1 uppercase, 1 lowercase, and 1
414+
number required.
415+
</AlertText>
416+
</Alert>
417+
</VStack>
418+
);
419+
};
420+
`,
421+
transformCode: (code) => {
422+
return transformedCode(code, 'function', 'Example');
423+
},
424+
scope: {
425+
Alert,
426+
AlertIcon,
427+
AlertText,
428+
Wrapper,
429+
HStack,
430+
VStack,
431+
Button,
432+
ButtonText,
433+
Text,
434+
Heading,
435+
Input,
436+
InputField,
437+
InputSlot,
438+
InputIcon,
439+
EyeIcon,
440+
EyeOffIcon,
441+
InfoIcon
442+
},
443+
argsType: {},
444+
}}
445+
/>
266446
</Wrapper>

example/storybook-nativewind/src/core-components/nativewind/alert/index.tsx

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,22 @@ import type { VariantProps } from '@gluestack-ui/nativewind-utils';
1414
const SCOPE = 'ALERT';
1515

1616
const alertStyle = tva({
17-
base: 'items-center p-3 rounded flex-row',
17+
base: 'items-center py-3 px-4 rounded-md flex-row gap-2 border-outline-100',
1818

1919
variants: {
2020
action: {
21-
error: 'bg-background-error border-error-300 ',
22-
warning: 'bg-background-warning border-warning-300',
23-
success: 'bg-background-success border-success-300',
24-
info: 'bg-background-info border-info-300',
25-
muted: 'bg-background-muted border-muted-300',
21+
error: 'bg-background-error',
22+
warning: 'bg-background-warning',
23+
success: 'bg-background-success',
24+
info: 'bg-background-info',
25+
muted: 'bg-background-muted',
2626
},
2727

2828
variant: {
2929
solid: '',
30-
outline: 'border bg-transparent',
31-
accent: 'border-l-4',
30+
outline: 'border bg-background-0',
3231
},
3332
},
34-
defaultVariants: {
35-
variant: 'solid',
36-
action: 'info',
37-
},
3833
});
3934

4035
const alertTextStyle = tva({
@@ -76,6 +71,15 @@ const alertTextStyle = tva({
7671
true: 'bg-yellow-500',
7772
},
7873
},
74+
parentVariants: {
75+
action: {
76+
error: 'text-error-800',
77+
warning: 'text-warning-800',
78+
success: 'text-success-800',
79+
info: 'text-info-800',
80+
muted: 'text-muted-800',
81+
},
82+
},
7983
});
8084

8185
const alertIconStyle = tva({
@@ -92,11 +96,11 @@ const alertIconStyle = tva({
9296
},
9397
parentVariants: {
9498
action: {
95-
error: 'text-error-500',
96-
warning: 'text-warning-500',
97-
success: 'text-success-500',
98-
info: 'text-info-500',
99-
muted: 'text-secondary-500',
99+
error: 'text-error-800',
100+
warning: 'text-warning-800',
101+
success: 'text-success-800',
102+
info: 'text-info-800',
103+
muted: 'text-secondary-800',
100104
},
101105
},
102106
});
@@ -218,6 +222,7 @@ const AlertText = React.forwardRef(
218222
}: { className?: string } & IAlertTextProps,
219223
ref?: any
220224
) => {
225+
const { action: parentAction } = useStyleContext(SCOPE);
221226
return (
222227
<UIAlert.Text
223228
// @ts-ignore
@@ -231,6 +236,9 @@ const AlertText = React.forwardRef(
231236
italic,
232237
highlight,
233238
class: className,
239+
parentVariants: {
240+
action: parentAction,
241+
},
234242
})}
235243
{...props}
236244
ref={ref}

0 commit comments

Comments
 (0)