Skip to content

Commit

Permalink
feat: Added Alert component, fixed the type issues for atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit Agrawal committed Dec 31, 2023
1 parent 716f642 commit 3adcfb0
Show file tree
Hide file tree
Showing 39 changed files with 623 additions and 147 deletions.
48 changes: 8 additions & 40 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useState } from "react";
import {
useFonts,
Poppins_300Light,
Expand Down Expand Up @@ -58,19 +58,12 @@ import SlideDemo from "./demo/components/slide-demo";
import SlideFadeDemo from "./demo/components/slide-fade-demo";
import CollapseDemo from "./demo/components/collapse-demo";
import AccordionDemo from "./demo/components/accordion-demo";
import AlertDemo from "./demo/components/alert-demo";
import Stack, { HStack } from "./src/components/atoms/stack/stack";
import IconButton from "./src/components/molecules/icon-button/icon-button";
import Box from "./src/components/atoms/box/box";
import { FlatList, ScrollView } from "react-native";
import {
Accordion,
AccordionButton,
AccordionItem,
AccordionPanel,
useResponsiveProp,
useTheme,
} from "./src";
import { MotiView } from "moti";
import { useResponsiveProp, useTheme } from "./src";

const App = () => {
const [haveFontsLoaded] = useFonts({
Expand Down Expand Up @@ -158,6 +151,11 @@ const componentList: {
imageSrc: require("./demo/assets/accordion.png"),
component: <AccordionDemo />,
},
{
label: "Alert",
imageSrc: require("./demo/assets/alert.png"),
component: <AlertDemo />,
},
{
label: "Icon",
imageSrc: require("./demo/assets/icon.png"),
Expand Down Expand Up @@ -342,36 +340,6 @@ const Index = () => {
return null;
};

// return (
// <Screen>
// <Accordion>
// <AccordionItem>
// <AccordionButton>
// <Text>Accordion Section 1</Text>
// </AccordionButton>
// <AccordionPanel>
// <Text>
// This is the content for the first section of the accordion. It can
// be replaced with any content you like.
// </Text>
// </AccordionPanel>
// </AccordionItem>

// <AccordionItem>
// <AccordionButton>
// <Text>Accordion Section 2</Text>
// </AccordionButton>
// <AccordionPanel>
// <Text>
// This is the content for the second section of the accordion. It
// can be replaced with any content you like.
// </Text>
// </AccordionPanel>
// </AccordionItem>
// </Accordion>
// </Screen>
// );

return (
<Screen p="0" scrollable={false}>
<Stack direction="vertical" flex={1} spacing="0">
Expand Down
Binary file added demo/assets/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions demo/components/alert-demo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { VStack, Alert } from "../../src";
import DemoSection from "./demo-section";

const AlertDemo = () => {
return (
<VStack spacing="6">
<DemoSection label="Alert Variants">
<Alert
variant="success"
title="Operation Successful"
description="Your changes have been successfully saved."
/>

<Alert
variant="info"
title="Note"
description="Your password will expire in 3 days."
/>

<Alert
variant="warning"
title="Caution"
description="Your account will be locked after 5 more unsuccessful attempts."
/>

<Alert
variant="danger"
title="Uh oh!"
description="Unable to connect to the server. Please check your internet connection."
/>
</DemoSection>

<DemoSection label="With Close Button">
<Alert
withCloseButton
title="Operation Successful"
description="Your changes have been successfully saved."
/>
</DemoSection>

<DemoSection label="Alert Composition">
<Alert
py={4}
spacing="3"
direction="vertical"
atoms={{
stack: {
alignItems: "center",
justifyContent: "center",
},
description: {
textAlign: "center",
},
}}
title="Operation Successful"
description="Your changes have been successfully saved."
/>
</DemoSection>
</VStack>
);
};

export default AlertDemo;
6 changes: 6 additions & 0 deletions docs/docs/components/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import SpacerImage from "../../../demo/assets/spacer.png";
import TextImage from "../../../demo/assets/text.png";
import ListImage from "../../../demo/assets/list.png";
import AccordionImage from "../../../demo/assets/accordion.png";
import AlertImage from "../../../demo/assets/alert.png";

<div style={{ display: "flex", flexWrap: "wrap" }}>
<ComponentPreview
Expand All @@ -69,6 +70,11 @@ import AccordionImage from "../../../demo/assets/accordion.png";
imageSrc={AccordionImage}
docPath="data-display/Accordion"
/>
<ComponentPreview
label="Alert"
imageSrc={AlertImage}
docPath="data-display/Alert"
/>
</div>

## Forms
Expand Down
14 changes: 8 additions & 6 deletions docs/docs/components/data-display/Accordion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,14 @@ The `Accordion` component is a composition of the [Stack](../layout/Stack) compo

### Additional Properties

| Property Name | Required | Data Type | Default | Description |
| ---------------- | -------- | --------------- | ------- | ------------------------------------------------------------ |
| `allowMultiple` | No | <t>boolean</t> | `false` | If true, multiple accordion items can be expanded at once. |
| `allowToggle` | No | <t>boolean</t> | `false` | If true, any expanded accordion item can be collapsed again. |
| `defaultIndices` | No | <t>number[]</t> | `[]` | The initial index(es) of the expanded accordion item. |
| `reduceMotion` | No | <t>boolean</t> | `false` | If true, height animation and transitions will be disabled. |
| Property Name | Required | Data Type | Default | Description |
| ---------------- | -------- | -------------------------------------------------- | ------- | ------------------------------------------------------------ |
| `size` | No | <t>PearlTheme.components.Accordion["sizes"]</t> | | Determines the size of the accordion. |
| `variant` | No | <t>PearlTheme.components.Accordion["variants"]</t> | | Determines the variant of the accordion. |
| `allowMultiple` | No | <t>boolean</t> | `false` | If true, multiple accordion items can be expanded at once. |
| `allowToggle` | No | <t>boolean</t> | `false` | If true, any expanded accordion item can be collapsed again. |
| `defaultIndices` | No | <t>number[]</t> | `[]` | The initial index(es) of the expanded accordion item. |
| `reduceMotion` | No | <t>boolean</t> | `false` | If true, height animation and transitions will be disabled. |

## AccordionItem Component Properties

Expand Down
133 changes: 133 additions & 0 deletions docs/docs/components/data-display/Alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
sidebar_position: 4
title: Alert
---

import SourceButton from "../../../src/components/SourceButton/SourceButton";

<div style={{ display: "flex" }}>
<SourceButton
label="Source"
href="https://github.com/agrawal-rohit/pearl-ui/blob/main/src/components/molecules/alert/alert.tsx"
style={{ marginRight: "10px" }}
/>
<SourceButton
label="Theme Source"
href="https://github.com/agrawal-rohit/pearl-ui/blob/main/src/components/molecules/alert/alert.config.ts"
/>
</div>

The `Alert` component in Pearl UI is a versatile and customizable element used to display a short, important message in a way that attracts the user's attention without interrupting the user's task.

## Import

```jsx
import { Alert } from "pearl-ui";
```

## Usage

```jsx
<Alert
title="Alert Title"
description="This is the description of the alert."
/>
```

### Alert Variants

The `variant` prop allows you to specify the type of the alert. It can be one of the following: `success`, `info`, `warning`, `danger`.

```jsx
<Alert
variant="success"
title="Operation Successful"
description="Your changes have been successfully saved."
/>

<Alert
variant="info"
title="Note"
description="Your password will expire in 3 days."
/>

<Alert
variant="warning"
title="Caution"
description="Your account will be locked after 5 more unsuccessful attempts."
/>

<Alert
variant="danger"
title="Uh oh!"
description="Unable to connect to the server. Please check your internet connection."
/>
```

### Alert with Close Button

The `withCloseButton` prop allows you to display a close button in the alert. The `onClose` prop allows you to specify a function that will be called when the close button is clicked.

```jsx
<Alert
withCloseButton
onClose={() => {
console.log("Alert closed");
}}
title="Operation Successful"
description="Your changes have been successfully saved."
/>
```

### Alert Composition

The `Alert` component can be composed with other props to customize its appearance and behavior.

```jsx
<Alert
py={4}
spacing="3"
direction="vertical"
atoms={{
stack: {
alignItems: "center",
justifyContent: "center",
},
description: {
textAlign: "center",
},
}}
title="Operation Successful"
description="Your changes have been successfully saved."
/>
```

## Example

import Snack from "../../../src/components/ExpoSnack";

<Snack snackId="@agrawal-rohit/alert" />

## Accessibility

- `Alert` has the `role` of `alert`.
- When the `Alert` is displayed, it attracts the user's attention without interrupting the user's task.

## Alert Component Properties

### Supported Style Properties

The `Alert` component is a composition of the [Stack](../layout/Stack) component. Therefore, all properties related to the [Stack](../layout/Stack) component can be passed to the `Alert` component, in addition to the properties listed below.

### Additional Properties

| Property Name | Required | Data Type | Default | Description |
| ----------------- | -------- | ---------------------------------------------- | ----------- | ------------------------------------------------------------------------------ |
| `size` | No | <t>PearlTheme.components.Alert["sizes"]</t> | | Determines the size of the alert. |
| `variant` | No | <t>PearlTheme.components.Alert["variants"]</t> | `"success"` | Determines the variant of the alert. |
| `icon` | No | <t>React.ReactElement</t> | | Custom icon that overrides the default icon in the alert. |
| `withIcon` | No | <t>boolean</t> | `true` | Boolean flag to indicate if the alert should be displayed with an icon. |
| `title` | No | <t>string</t> | | Title text for the alert. |
| `description` | No | <t>string</t> | | Description text for the alert. |
| `withCloseButton` | No | <t>boolean</t> | `false` | Boolean flag to indicate if the alert should be displayed with a close button. |
| `onClose` | No | <t>() => void</t> | | Function to be called when the close button is clicked. |
8 changes: 5 additions & 3 deletions docs/docs/components/data-display/List.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ The `List` component is built upon the [Stack](./Stack) component, and as such,

### Additional Properties

| Name | Required | Type | Default | Description |
| ------------ | -------- | -------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `renderIcon` | No | <t>(index: number) => React.ReactElement</t> | | Function that returns a React element to be displayed as an icon next to each child. The function receives the index of the child as an argument. |
| Name | Required | Type | Default | Description |
| ------------ | -------- | --------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `size` | No | <t>PearlTheme.components.List["sizes"]</t> | | Determines the size of the list. |
| `variant` | No | <t>PearlTheme.components.List["variants"]</t> | | Determines the variant of the list. |
| `renderIcon` | No | <t>(index: number) => React.ReactElement</t> | | Function that returns a React element to be displayed as an icon next to each child. The function receives the index of the child as an argument. |
2 changes: 1 addition & 1 deletion docs/docs/overview/core-features/extensibility.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const CustomActionButton = ({
MoleculeComponentProps<"MyActionButton", ButtonProps, ActionButtonAtoms>,
"atoms"
> & {
atoms?: ActionButtonAtoms;
atoms?: Partial<ActionButtonAtoms>;
}) => {
return (
<ActionButton buttonColor={props.style.backgroundColor} {...atoms.button} />
Expand Down
Loading

0 comments on commit 3adcfb0

Please sign in to comment.