|
| 1 | +--- |
| 2 | +title: Alert |
| 3 | +description: A notification to capture user attention. |
| 4 | +--- |
| 5 | + |
| 6 | +{/* prettier-ignore-start */} |
| 7 | +{/* prettier-ignore-end */} |
| 8 | + |
| 9 | +import Code from '@/components/Code.astro'; |
| 10 | +import { LinkButton } from '@/components/react/LinkButton'; |
| 11 | +import { Tabs, TabItem } from '@astrojs/starlight/components'; |
| 12 | +import importedCode from '@rnr/reusables/components/ui/alert?raw'; |
| 13 | + |
| 14 | +<LinkButton href='/components/text'>Text Component</LinkButton> |
| 15 | +<LinkButton target='_blank' href='https://rnr-showcase.vercel.app/alert'> |
| 16 | + Demo |
| 17 | +</LinkButton> |
| 18 | + |
| 19 | +<br /> |
| 20 | + |
| 21 | +A notification to capture user attention. |
| 22 | + |
| 23 | +### Installation |
| 24 | +<Tabs> |
| 25 | + <TabItem label='CLI'> |
| 26 | + ```bash |
| 27 | + npx @react-native-reusables/cli@latest add alert |
| 28 | + ``` |
| 29 | + </TabItem> |
| 30 | + <TabItem label='Manual'> |
| 31 | + |
| 32 | + **Copy/paste the following code to `~/components/ui/alert.tsx`:** |
| 33 | + |
| 34 | + <Code code={importedCode} lang='tsx' title='~/components/ui/alert.tsx' /> |
| 35 | + </TabItem> |
| 36 | +</Tabs> |
| 37 | +### Usage |
| 38 | + |
| 39 | +```tsx |
| 40 | +import { Alert, AlertDescription, AlertTitle } from '~/components/ui/alert'; |
| 41 | +import { AlertTriangle } from '~/lib/icons/AlertTriangle'; |
| 42 | +import { Terminal } from '~/lib/icons/Terminal'; |
| 43 | + |
| 44 | +function AlertExample() { |
| 45 | + return ( |
| 46 | + <Alert icon={Terminal} className='max-w-xl'> |
| 47 | + <AlertTitle>Heads up!</AlertTitle> |
| 48 | + <AlertDescription> |
| 49 | + You can use a terminal to run commands on your computer. |
| 50 | + </AlertDescription> |
| 51 | + </Alert> |
| 52 | + <Alert icon={AlertTriangle} variant='destructive' className='max-w-xl'> |
| 53 | + <AlertTitle>Danger!</AlertTitle> |
| 54 | + <AlertDescription> |
| 55 | + High voltage. Do not touch. Risk of electric shock. Keep away from children. |
| 56 | + </AlertDescription> |
| 57 | + </Alert> |
| 58 | + ); |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +## Props |
| 63 | + |
| 64 | +### Alert |
| 65 | + |
| 66 | +Extends [`View`](https://reactnative.dev/docs/view#props) props |
| 67 | + |
| 68 | +| Prop | Type | Note | |
| 69 | +| :-----------: | :----------------------------------------------------------: | :-------------------------------: | |
| 70 | +| `variant` | `"default"` \| `"destructive"` | _(optional)_ | |
| 71 | +| `icon` | [`LucideIcon`](https://lucide.dev/guide/packages/lucide-react-native) | _(required)_ | |
| 72 | +| `iconSize` | `number` | _(optional, default: `16`)_ | |
| 73 | +| iconClassName | `string` | _(optional)_ | |
| 74 | + |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +### AlertTitle |
| 79 | + |
| 80 | +Extends [`Text`](https://reactnative.dev/docs/text#props) props |
| 81 | + |
| 82 | +| Prop | Type | Note | |
| 83 | +| :-----: | :-----: | :----------: | |
| 84 | +| asChild | boolean | _(optional)_ | |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +### AlertDescription |
| 89 | + |
| 90 | +Extends [`Text`](https://reactnative.dev/docs/text#props) props |
| 91 | + |
| 92 | +| Prop | Type | Note | |
| 93 | +| :-----: | :-----: | :----------: | |
| 94 | +| asChild | boolean | _(optional)_ | |
0 commit comments