You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `Badge` component is a lightweight, versatile component for displaying status indicators, labels, or tags in your application. Built with React and Tailwind CSS, it offers various styles and types to match your design needs.
4
+
5
+
## Usage
6
+
7
+
Import and use the Badge component in your React components to display short pieces of information, status indicators, or labels.
8
+
9
+
```jsx
10
+
import { Badge } from'@wedevs/tail-react';
11
+
12
+
functionMyComponent() {
13
+
return (
14
+
<div className="space-x-2">
15
+
<Badge label="New"/>
16
+
<Badge label="Success" type="success"/>
17
+
<Badge label="Warning" type="warning"/>
18
+
<Badge label="Error" type="error"/>
19
+
<Badge label="Info" type="info"/>
20
+
</div>
21
+
);
22
+
}
23
+
```
24
+
25
+
## Props
26
+
27
+
The Badge component accepts the following props:
28
+
29
+
-`label` (React.ReactNode, required): The content to display inside the badge. Can be text or any valid React node.
30
+
31
+
-`type` ('success' | 'warning' | 'error' | 'info' | 'neutral', optional, default: 'neutral'): Determines the color scheme and style of the badge.
32
+
33
+
-`neutral`: Gray color scheme (default)
34
+
-`success`: Green color scheme for positive or successful states
35
+
-`warning`: Yellow color scheme for warning states
36
+
-`error`: Red color scheme for error states
37
+
-`info`: Blue color scheme for informational states
38
+
39
+
-`border` (boolean, optional, default: true): When true, adds a subtle border ring around the badge. Set to false for a flat appearance.
40
+
41
+
-`className` (string, optional): Additional CSS classes to be applied to the badge. These will be merged with the default styles.
The Badge component comes with two main style variations:
92
+
93
+
1.**Bordered** (default, `border={true}`):
94
+
95
+
- Includes a subtle border ring
96
+
- Lighter background color
97
+
- Provides more depth and definition
98
+
99
+
2.**Flat** (`border={false}`):
100
+
- No border
101
+
- Slightly darker background color
102
+
- Clean, minimal appearance
103
+
104
+
## Color Schemes
105
+
106
+
Each type has its own color scheme that automatically adjusts based on the `border` prop:
107
+
108
+
-**Neutral** (`type="neutral"`):
109
+
110
+
- Border: Gray-50 background with Gray-600 text
111
+
- Flat: Gray-100 background with Gray-600 text
112
+
113
+
-**Success** (`type="success"`):
114
+
115
+
- Border: Green-50 background with Green-700 text
116
+
- Flat: Green-100 background with Green-700 text
117
+
118
+
-**Warning** (`type="warning"`):
119
+
120
+
- Border: Yellow-50 background with Yellow-800 text
121
+
- Flat: Yellow-100 background with Yellow-800 text
122
+
123
+
-**Error** (`type="error"`):
124
+
125
+
- Border: Red-50 background with Red-700 text
126
+
- Flat: Red-100 background with Red-700 text
127
+
128
+
-**Info** (`type="info"`):
129
+
- Border: Blue-50 background with Blue-700 text
130
+
- Flat: Blue-100 background with Blue-700 text
131
+
132
+
## Customization
133
+
134
+
The Badge component can be customized in several ways:
135
+
136
+
1.**Via Props**: Use the `type` and `border` props to change the appearance
137
+
2.**Via className**: Add custom classes to override or extend the default styles
138
+
3.**Via Content**: Use React nodes as labels to create more complex badge content
139
+
140
+
## Accessibility
141
+
142
+
The Badge component is rendered as a `<span>` element with appropriate text contrast ratios for all color schemes. When using custom content via the `label` prop, ensure that:
143
+
144
+
1. Color contrast meets WCAG guidelines
145
+
2. Any interactive elements are properly focusable
146
+
3. Screen reader text is provided where necessary
147
+
148
+
## Best Practices
149
+
150
+
1. Keep badge labels short and concise
151
+
2. Use appropriate types to convey meaning (e.g., 'error' for error states)
152
+
3. Maintain consistent usage patterns throughout your application
153
+
4. Consider using the flat style (border={false}) when displaying multiple badges in close proximity
154
+
155
+
For further customization and integration with your application, refer to the official documentation of React and Tailwind CSS.
Copy file name to clipboardExpand all lines: src/Components/Button/README.md
+70-26Lines changed: 70 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,8 @@ The `Button` component accepts the following props:
22
22
23
23
-`disabled` (boolean, optional, default: false): If true, the button will be disabled and not clickable.
24
24
25
+
-`loading` (boolean, optional, default: false): If true, displays a spinning loading indicator before the button content.
26
+
25
27
-`as` (React.ElementType, optional, default: 'button'): The HTML element type or React component to be used as the underlying element. This allows you to render the button as an anchor (`<a>`) or any other valid HTML element.
26
28
27
29
-`className` (string, optional): Additional CSS classes to be applied to the button.
@@ -34,29 +36,56 @@ The `Button` component accepts the following props:
34
36
35
37
-`rel` (string, optional): If `href` is provided and `as` is set to 'a', the value of the `rel` attribute for the anchor element.
In this example, the `Button` component is used with different styles, sizes, and states. When the button is clicked, the `handleButtonClick` function is executed, and the console will log "Button clicked!". The last button is disabled and cannot be clicked due to the `disabled` prop being set to `true`.
69
-
70
97
## Styles Object
71
98
72
99
The `Button` component uses a predefined `Styles` object to handle the visual styles based on the provided `variant` and `style` props. The styles are defined using Tailwind CSS classes.
@@ -75,23 +102,40 @@ The `Styles` object includes the following style options:
75
102
76
103
- Primary Styles:
77
104
78
-
-`primary:fill`: Primary button with a solid background.
79
-
-`primary:outline`: Primary button with a border and transparent background.
80
-
-`primary:link`: Primary button styled as a link with no background.
105
+
-`primary:fill`: Primary button with a solid background and hover effects
106
+
-`primary:outline`: Primary button with a border and transparent background
107
+
-`primary:link`: Primary button styled as a link with no background
81
108
82
109
- Secondary Styles:
83
110
84
-
-`secondary:fill`: Secondary button with a solid background.
85
-
-`secondary:outline`: Secondary button with a border and transparent background.
86
-
-`secondary:link`: Secondary button styled as a link with no background.
111
+
-`secondary:fill`: Secondary button with a solid background
112
+
-`secondary:outline`: Secondary button with a border and transparent background
113
+
-`secondary:link`: Secondary button styled as a link with no background
87
114
88
115
- Danger Styles:
89
-
-`danger:fill`: Danger button with a solid background.
90
-
-`danger:outline`: Danger button with a border and transparent background.
91
-
-`danger:link`: Danger button styled as a link with no background.
116
+
-`danger:fill`: Danger button with a solid background
117
+
-`danger:outline`: Danger button with a border and transparent background
118
+
-`danger:link`: Danger button styled as a link with no background
119
+
120
+
## Dark Mode Support
121
+
122
+
The Button component includes built-in dark mode support through Tailwind CSS's dark mode classes. The styles automatically adjust when dark mode is enabled in your application.
123
+
124
+
## Accessibility
125
+
126
+
The Button component follows accessibility best practices:
127
+
128
+
- Uses semantic HTML elements
129
+
- Maintains proper focus states
130
+
- Disables interaction when the `disabled` prop is true
131
+
- Provides visual feedback during loading states
92
132
93
133
## Customization
94
134
95
-
You can customize the appearance and behavior of the `Button` component by adjusting the `Styles` object or adding custom CSS classes to the `className` prop.
135
+
You can customize the appearance and behavior of the `Button` component by:
136
+
137
+
1. Using the provided props to configure the button
138
+
2. Adding custom CSS classes through the `className` prop
139
+
3. Extending the `Styles` object in your theme configuration
96
140
97
-
Please note that this documentation assumes you have set up your project with React and Tailwind CSS properly. For further customization and integration with your application, refer to the official documentation of React and Tailwind CSS.
141
+
For further customization and integration with your application, refer to the official documentation of React and Tailwind CSS.
0 commit comments