Skip to content

Commit

Permalink
Merge pull request #21 from miksrv/develop
Browse files Browse the repository at this point in the history
New UI Message Component
  • Loading branch information
miksrv authored Oct 9, 2024
2 parents 28ac372 + aec1380 commit 2ece24b
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 37 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# simple-react-ui-kit

## 1.2.4

### Patch Changes

- Added new UI Message component
- Implemented Unit tests for Message component
- Implemented stories for Message component
- Fixed Container component margin top for header
- Fixed Checkbox component styles
- Added CSS vars colors: --color-(green|orange|red|main)-background
- Updated Readme (Message component, Style Variables Customization)
- Updated UI libraries (typescript, globals)

## 1.2.3

### Patch Changes
Expand Down
70 changes: 64 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Welcome to the **Simple React UI Kit** repository! This project is designed to p
- [Container](#container-component)
- [Dropdown](#dropdown-component)
- [Icon](#icon-component)
- [Message](#message-component)
- [Popout](#popout-component)
- [Skeleton](#skeleton-component)
- [Spinner](#spinner-component)
Expand Down Expand Up @@ -443,6 +444,55 @@ The `Icon` component is ideal for applications requiring a variety of icons, suc

For more detailed examples and interactive demonstrations, visit the [Storybook Documentation](https://miksrv.github.io/simple-react-ui-kit/?path=/docs/components-icon--docs).

### Message Component

The `Message` component is a versatile message display box that supports different visual styles (`error`, `warning`, `success`, and `info`). It is used to present messages to users, providing a title and content area, with the ability to customize the type of message displayed.

Check out the full documentation and examples in Storybook: [Message Component Storybook](https://miksrv.github.io/simple-react-ui-kit/?path=/docs/components-message--docs).

#### Props:
- **`type`**: Defines the visual style of the message. Accepts one of the following values: `'error'`, `'warning'`, `'success'`, or `'info'`.
- **`title`**: The title of the message that appears at the top (optional).
- **`children`**: The content inside the message box, which can be any React node (optional).

#### Example Usage:

```tsx
import React from 'react';
import { Message } from 'simple-react-ui-kit';

const App = () => (
<div>
{/* Error message with title and content */}
<Message type="error" title="Error!">
There was an issue with your request.
</Message>

{/* Success message without title */}
<Message type="success">
Operation completed successfully!
</Message>

{/* Info message with custom content */}
<Message type="info" title="Information">
<ul>
<li>First info item</li>
<li>Second info item</li>
</ul>
</Message>
</div>
);

export default App;
```

In this example:
- The first `Message` displays an error with a title and content.
- The second `Message` shows a success message without a title.
- The third `Message` provides information with a custom list as its content.

For more details and live examples, check out the [Storybook Documentation](https://miksrv.github.io/simple-react-ui-kit/?path=/docs/components-message--docs).

### Popout Component

The `Popout` component is designed to create a floating container that opens and closes when triggered, often used for menus, tooltips, or additional actions. It provides a button as a trigger and offers flexible positioning for the popout content, either to the left or right of the button.
Expand Down Expand Up @@ -673,19 +723,23 @@ The components in this UI Kit are designed to be highly customizable, allowing y
Here is a list of all the CSS variables you can override to customize the look and feel of the components:

- **Primary Colors:**
- `--color-contrast`: Contrast color (typically used for text on colored backgrounds).
- `--color-green`: Default green color.
- `--color-green-hover`: Hover state for green color.
- `--color-green-active`: Active state for green color.
- `--color-green-background`: Background green color (for success input, message etc.).
- `--color-orange`: Default orange color.
- `--color-orange-hover`: Hover state for orange color.
- `--color-orange-active`: Active state for orange color.
- `--color-orange-background`: Background orange color (for warning input, message etc.).
- `--color-red`: Default red color.
- `--color-red-hover`: Hover state for red color.
- `--color-red-active`: Active state for red color.
- `--color-contrast`: Contrast color (typically used for text on colored backgrounds).
- `--color-red-background`: Background red color (for error input, message etc.).
- `--color-main`: Main base color, used for buttons, links, checkbox icons.
- `--color-main-hover`: Hover state for main color.
- `--color-main-active`: Active state for main color.
- `--color-main-background`: Background main color (for info input, message etc.).

- **Text and Typography:**
- `--font-size`: Default font size.
Expand Down Expand Up @@ -747,23 +801,27 @@ To customize the theme, simply override the default values in your stylesheet:
```css
:root {
/* Primary Colors */
--color-contrast: #FFF;

--color-green: #4bb34b;
--color-green-hover: #48AC4A;
--color-green-active: #45A64A;
--color-green-background: #e5ffe5; /* For dark: #2E3E2B */

--color-orange: #F8A01C;
--color-orange-hover: #EE9A1D;
--color-orange-active: #E4941F;
--color-orange-background: #fff2db; /* For dark: #5e5443 */

--color-red: #e64646;
--color-red-hover: #DD4446;
--color-red-active: #D44245;
--color-red-background: #ffdddd; /* For dark: #522e2e */

--color-contrast: #FFF;

--color-main: #3770b1;
--color-main-hover: #356cac;
--color-main-active: #3368a8;
--color-main: #2688eb;
--color-main-hover: #2483e4;
--color-main-active: #237edd;
--color-main-background: #d6eaff; /* For dark: #3c4957 */

/* Text and Typography */
--font-size: 14px;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-react-ui-kit",
"version": "1.2.3",
"version": "1.2.4",
"description": "A lightweight and flexible UI framework for building responsive React applications with customizable components.",
"repository": "https://github.com/miksrv/simple-react-ui-kit.git",
"scripts": {
Expand Down Expand Up @@ -63,7 +63,7 @@
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-react": "^7.37.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"globals": "^15.10.0",
"globals": "^15.11.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
Expand All @@ -78,7 +78,7 @@
"style-loader": "^4.0.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"typescript": "^5.6.3",
"typescript-eslint": "^8.8.1"
},
"dependencies": {
Expand Down
12 changes: 2 additions & 10 deletions src/components/checkbox/styles.module.sass
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@

svg
fill: var(--input-border-color)
width: 18px
height: 18px
width: 20px
height: 20px

&.checked
svg
fill: var(--color-main)

&:hover:not(.disabled)
svg
fill: var(--color-main-hover)

&:active:not(.disabled)
svg
fill: var(--color-main-active)

label
color: var(--text-color-primary)
font-size: var(--font-size)
Expand Down
2 changes: 1 addition & 1 deletion src/components/container/styles.module.sass
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
width: 100%

.header
margin: 0 0 5px 0
margin: -5px 0 5px 0
display: flex
justify-content: space-between

Expand Down
45 changes: 45 additions & 0 deletions src/components/message/Message.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react'

import '@testing-library/jest-dom'

import Message from './Message'

import { render, screen } from '@testing-library/react'

describe('Message Component', () => {
it('renders the Message component with title and children', () => {
render(<Message title='Test Title'>This is a test message</Message>)

const titleElement = screen.getByText(/Test Title/i)
expect(titleElement).toBeInTheDocument()

const contentElement = screen.getByText(/This is a test message/i)
expect(contentElement).toBeInTheDocument()
})

it('applies correct styles based on message type', () => {
render(
<Message
type='warning'
title='Warning Title'
>
Warning content
</Message>
)

const titleElement = screen.getByText(/Warning Title/i)
expect(titleElement).toBeInTheDocument()

const sectionElement = titleElement.closest('section')
expect(sectionElement).toHaveClass('warning')
})

it('renders correctly without a title or list', () => {
render(<Message>This message has no title or list</Message>)

const contentElement = screen.getByText(/This message has no title or list/i)
expect(contentElement).toBeInTheDocument()

expect(screen.queryByRole('heading')).not.toBeInTheDocument()
})
})
29 changes: 29 additions & 0 deletions src/components/message/Message.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'

import { cn } from '../../utils'

import styles from './styles.module.sass'

/**
* Message component properties
*/
export interface MessageProps extends React.HTMLAttributes<HTMLDivElement> {
/** Type of the message that defines the visual style ('negative', 'positive', 'warning', or 'info') */
type?: 'error' | 'warning' | 'success' | 'info'
/** Title to be displayed at the top of the message */
title?: string
/** Content or children elements inside the message */
children?: React.ReactNode
}

const Message: React.FC<MessageProps> = ({ title, children, type, ...props }) => (
<section
{...props}
className={cn(styles.message, type && styles[type])}
>
{title && <div className={styles.title}>{title}</div>}
{children && <div className={styles.content}>{children}</div>}
</section>
)

export default Message
2 changes: 2 additions & 0 deletions src/components/message/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './Message'
export type { MessageProps } from './Message'
32 changes: 32 additions & 0 deletions src/components/message/styles.module.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.message
border-radius: var(--border-radius)
font-family: var(--font-family), sans-serif
font-size: var(--font-size)
box-sizing: border-box
width: 100%
padding: 8px 12px
position: relative

&.error
background-color: var(--color-red-background)
color: var(--color-red)

&.warning
background-color: var(--color-orange-background)
color: var(--color-orange)

&.success
background-color: var(--color-green-background)
color: var(--color-green)

&.info
background-color: var(--color-main-background)
color: var(--color-main)

.title
margin: 0 0 5px
font-weight: 600

.content, ul
margin: 0
font-size: var(--font-size-small)
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export { default as Icon } from './components/icon'
export { iconNames } from './components/icon'
export type { IconTypes } from './components/icon'

// Message Component
export { default as Message } from './components/message'
export type { MessageProps } from './components/message'

// Popout Component
export { default as Popout } from './components/popout'
export type { PopoutProps, PopoutHandleProps } from './components/popout'
Expand Down
9 changes: 6 additions & 3 deletions src/styles/global.css
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
/* global.css */
:root {
/* Primary Colors */
--color-contrast: #FFF;

--color-green: #4bb34b;
--color-green-hover: #48AC4A;
--color-green-active: #45A64A;
--color-green-background: #e5ffe5; /* For dark: #2E3E2B */

--color-orange: #F8A01C;
--color-orange-hover: #EE9A1D;
--color-orange-active: #E4941F;
--color-orange-background: #fff2db; /* For dark: #5e5443 */

--color-red: #e64646;
--color-red-hover: #DD4446;
--color-red-active: #D44245;

--color-contrast: #FFF;
--color-red-background: #ffdddd; /* For dark: #522e2e */

--color-main: #2688eb;
--color-main-hover: #2483e4;
--color-main-active: #237edd;
--color-main-background: #d6eaff; /* For dark: #3c4957 */

/* Text and Typography */
--font-size: 14px;
Expand Down Expand Up @@ -46,7 +50,6 @@
--input-border: 0.5px solid var(--input-border-color);
/*--input-border-focus-color: #1976d2;*/
/*--input-background-content: #ffffff;*/
/*--input-background-color-error: var(--container-error-background-color);*/

/* Buttons */
--button-font-weight: 500;
Expand Down
Loading

0 comments on commit 2ece24b

Please sign in to comment.