Skip to content

Commit f413df2

Browse files
committed
Add CSS class to SVG icons in success and error toast notifications
1 parent e3c5a88 commit f413df2

File tree

3 files changed

+161
-44
lines changed

3 files changed

+161
-44
lines changed

README.md

Lines changed: 157 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33

44
# ClipX.js -Maximize Clipboard Power with Minimal Size
55

6-
7-
ClipX.js is an ultra-light JavaScript library that simplifies clipboard tasks and enriches user feedback. It offers straightforward `copy, cut, and paste` capabilities, and `built-in toast notifications` that you can easily customize, providing a quick and efficient way to handle clipboard and notification needs. ——— The Smarter Clipboard Solution.
6+
ClipX.js is an ultra-light JavaScript library that simplifies clipboard tasks and enriches user feedback. It offers straightforward `copy, cut, and paste` capabilities, and `built-in toast notifications` that you can easily customize, providing a quick and efficient way to handle clipboard and notification needs. ——— The Smarter Clipboard Solution.
87

98
---
9+
1010
## Official Website
1111

1212
For more information about this project, please visit our official website: [ClipX](https://clipx.dzr.app/)
1313

1414
---
15+
1516
## Table of Contents 📑
1617

1718
1. [Why Choose ClipX.js?](#why-choose-clipxjs)
@@ -43,19 +44,29 @@ For more information about this project, please visit our official website: [Cli
4344
7. [Demo](#demo--get-start-code)
4445

4546
---
47+
4648
## Why Choose ClipX.js?
4749

4850
### Lightweight & Fast
51+
4952
- At only 2KB, ClipX.js is smaller and faster than most clipboard libraries.
53+
5054
### Built-in Feedback
55+
5156
- Includes customizable toast notifications for clipboard actions—no need for additional UI libraries.
57+
5258
### Flexible Customization
59+
5360
- Easily style toasts, control message display, and integrate seamlessly with your app's design.
61+
5462
### Easy Integration
63+
5564
- Simple API with minimal setup, ensuring broad compatibility across modern and older browsers.
65+
5666
### Robust Error Handling
67+
5768
- Provides clear, customizable error feedback to enhance user experience and simplify debugging.
58-
69+
5970
---
6071

6172
## Installation
@@ -65,7 +76,8 @@ For more information about this project, please visit our official website: [Cli
6576
```bash
6677
npm i clipxjs
6778
```
68-
### Via CDN
79+
80+
### Via CDN
6981

7082
Use only one `CDN`
7183

@@ -82,7 +94,9 @@ Use only one `CDN`
8294
```html
8395
<script src="https://unpkg.com/clipxjs/dist/clipx.min.js"></script>
8496
```
97+
8598
---
99+
86100
## Initializing ClipX.js
87101

88102
To get started with ClipX.js, follow these steps to set up and configure the library according to your needs:
@@ -118,10 +132,21 @@ Customize the appearance of toast notifications by providing CSS styles. For exa
118132

119133
```javascript
120134
clipx.setCustomStyles({
121-
toast: "background-color: #333; color: #fff; padding: 12px; border-radius: 5px;"
135+
toast:
136+
"background-color: #333; color: #fff; padding: 12px; border-radius: 5px;",
122137
});
123138
```
124139

140+
### 4. Hide SVG Icon
141+
142+
To hide Svg Icon from toast
143+
144+
```css
145+
.clipx-js-svg-icon {
146+
display: none;
147+
}
148+
```
149+
125150
## Attaching ClipX Functionality
126151

127152
To bind ClipX.js functionality to elements, use the `attach` method with appropriate selectors. This method will enable clipboard operations on elements with the specified attributes or classes.
@@ -131,22 +156,23 @@ To bind ClipX.js functionality to elements, use the `attach` method with appropr
131156
Apply ClipX.js to elements with `data-clipx-text` or `data-clipx-target` attributes.
132157

133158
```javascript
134-
clipx.attach('[data-clipx-text], [data-clipx-target]');
159+
clipx.attach("[data-clipx-text], [data-clipx-target]");
135160
```
136161

137162
### Example: Using Class Names
138163

139164
Alternatively, apply ClipX.js to elements with specific classes.
140165

141166
```javascript
142-
clipx.attach('.clipx, .copy-btn, .your-class');
167+
clipx.attach(".clipx, .copy-btn, .your-class");
143168
```
144169

145-
146170
---
171+
147172
## Attributes Overview
148173

149174
### This All Are Attributes
175+
150176
- **`data-clipx-target`**: Element selector for text source.
151177
- **`data-clipx-text`**: Static text to copy or cut.
152178
- **`data-clipx-cut`**: Toggle cut operation.
@@ -159,14 +185,14 @@ clipx.attach('.clipx, .copy-btn, .your-class');
159185

160186
---
161187

162-
163-
## Example
188+
## Example
164189

165190
### `data-clipx-target`
166191

167192
**Description:** Specifies the target element whose text will be copied to the clipboard when the button is clicked.
168193

169194
**Example:**
195+
170196
```html
171197
<button class="copy-btn" data-clipx-target="#text-to-copy">Copy Text</button>
172198
<p id="text-to-copy">This is the text to be copied.</p>
@@ -177,117 +203,208 @@ clipx.attach('.clipx, .copy-btn, .your-class');
177203
**Description:** Defines a static text string that will be copied to the clipboard when the button is clicked.
178204

179205
**Example:**
206+
180207
```html
181-
<button class="copy-btn" data-clipx-text="Static text to copy">Copy Static Text</button>
208+
<button class="copy-btn" data-clipx-text="Static text to copy">
209+
Copy Static Text
210+
</button>
182211
```
183212

184213
### `data-clipx-cut`
185214

186215
**Description:** Cuts the text from the specified element, copying it to the clipboard and clearing the element's content.
187216

188217
**Example:**
218+
189219
```html
190220
<textarea id="text-to-cut">This text will be cut.</textarea>
191-
<button class="copy-btn" data-clipx-target="#text-to-cut" data-clipx-cut>Cut Text</button>
221+
<button class="copy-btn" data-clipx-target="#text-to-cut" data-clipx-cut>
222+
Cut Text
223+
</button>
192224
```
193225

194226
### `data-clipx-msg`
195227

196228
**Description:** Copies the specified text to the clipboard and shows a toast notification with a custom message.
197229

198230
**Example:**
231+
199232
```html
200-
<button class="copy-btn" data-clipx-text="Another static text" data-clipx-msg="Text copied successfully!">Copy with Custom Message</button>
233+
<button
234+
class="copy-btn"
235+
data-clipx-text="Another static text"
236+
data-clipx-msg="Text copied successfully!"
237+
>
238+
Copy with Custom Message
239+
</button>
201240
```
202241

203242
### `data-clipx-toast`
204243

205244
**Description:** Displays a toast notification with the copied text. The button text remains unchanged.
206245

207246
**Example:**
247+
208248
```html
209-
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-toast>Copy with Toast Only</button>
249+
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-toast>
250+
Copy with Toast Only
251+
</button>
210252
```
211253

212254
### `data-clipx-disable-msg`
213255

214256
**Description:** Shows a toast notification without changing the button's text content.
215257

216258
**Example:**
259+
217260
```html
218-
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-disable-msg>Copy with Toast Only, No Text Change</button>
261+
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-disable-msg>
262+
Copy with Toast Only, No Text Change
263+
</button>
219264
```
220265

221-
### `USE data-clipx-disable-toast & data-clipx-disable-msg`
266+
### `USE data-clipx-disable-toast & data-clipx-disable-msg`
222267

223268
**Description:** Copies the specified text to the clipboard without showing a toast notification And Changing Text Contents.
224269

225270
**Example:**
271+
226272
```html
227-
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-disable-toast data-clipx-disable-msg>Copy without Toast & with Change Text</button>
273+
<button
274+
class="copy-btn"
275+
data-clipx-text="Text to copy"
276+
data-clipx-disable-toast
277+
data-clipx-disable-msg
278+
>
279+
Copy without Toast & with Change Text
280+
</button>
228281
```
229282

230283
### `data-clipx-disable-toast`
231284

232285
**Description:** Copies the specified text to the clipboard without showing a toast notification.
233286

234287
**Example:**
288+
235289
```html
236-
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-disable-toast>Copy without Toast</button>
290+
<button
291+
class="copy-btn"
292+
data-clipx-text="Text to copy"
293+
data-clipx-disable-toast
294+
>
295+
Copy without Toast
296+
</button>
237297
```
238298

239299
### `data-clipx-toast-position`
240300

241301
**Description:** Defines the position of the toast notification (top or bottom).
242302

243303
**Example:**
304+
244305
```html
245-
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-toast data-clipx-toast-position="top">Copy with Toast on Top</button>
246-
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-toast data-clipx-toast-position="bottom">Copy with Toast on Bottom</button>
306+
<button
307+
class="copy-btn"
308+
data-clipx-text="Text to copy"
309+
data-clipx-toast
310+
data-clipx-toast-position="top"
311+
>
312+
Copy with Toast on Top
313+
</button>
314+
<button
315+
class="copy-btn"
316+
data-clipx-text="Text to copy"
317+
data-clipx-toast
318+
data-clipx-toast-position="bottom"
319+
>
320+
Copy with Toast on Bottom
321+
</button>
247322
```
248323

249324
### `data-clipx-duration`
250325

251326
**Description:** Sets the duration (in milliseconds) for which the toast notification is visible before it fades out.
252327

253328
**Example:**
329+
254330
```html
255-
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-toast data-clipx-duration="3000">Copy with 3 Seconds Toast</button>
256-
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-duration="3000">Copy with 3 Seconds Toast & Content Change</button>
257-
<button class="copy-btn" data-clipx-text="Text to copy" data-clipx-disable-toast data-clipx-duration="3000">Copy 3 sec Content Change</button>
331+
<button
332+
class="copy-btn"
333+
data-clipx-text="Text to copy"
334+
data-clipx-toast
335+
data-clipx-duration="3000"
336+
>
337+
Copy with 3 Seconds Toast
338+
</button>
339+
<button
340+
class="copy-btn"
341+
data-clipx-text="Text to copy"
342+
data-clipx-duration="3000"
343+
>
344+
Copy with 3 Seconds Toast & Content Change
345+
</button>
346+
<button
347+
class="copy-btn"
348+
data-clipx-text="Text to copy"
349+
data-clipx-disable-toast
350+
data-clipx-duration="3000"
351+
>
352+
Copy 3 sec Content Change
353+
</button>
258354
```
355+
259356
---
260357

261358
## Demo || Get Start Code
262359

263360
```html
264-
265361
<h1>ClipX.js Demo</h1>
266362

267-
<button class="copy-btn" data-clipx-text="Static text to copy" data-clipx-msg="Static text copied!">Copy Static Text</button>
268-
269-
<button class="copy-btn" data-clipx-target="#text-to-copy" data-clipx-cut>Cut Text</button>
363+
<button
364+
class="copy-btn"
365+
data-clipx-text="Static text to copy"
366+
data-clipx-msg="Static text copied!"
367+
>
368+
Copy Static Text
369+
</button>
370+
371+
<button class="copy-btn" data-clipx-target="#text-to-copy" data-clipx-cut>
372+
Cut Text
373+
</button>
270374
<button class="copy-btn" data-clipx-target="#text-to-copy">Copy Text</button>
271375

272376
<p id="text-to-copy">This text will be cut and copied to the clipboard.</p>
273377

274-
<button class="copy-btn" data-clipx-text="Another static text" data-clipx-toast data-clipx-toast-position="bottom">Copy with Toast Only</button>
275-
276-
<button class="copy-btn" data-clipx-text="Text with 5 seconds toast" data-clipx-toast data-clipx-duration="5000">Copy with 5 Seconds Toast</button>
277-
378+
<button
379+
class="copy-btn"
380+
data-clipx-text="Another static text"
381+
data-clipx-toast
382+
data-clipx-toast-position="bottom"
383+
>
384+
Copy with Toast Only
385+
</button>
386+
387+
<button
388+
class="copy-btn"
389+
data-clipx-text="Text with 5 seconds toast"
390+
data-clipx-toast
391+
data-clipx-duration="5000"
392+
>
393+
Copy with 5 Seconds Toast
394+
</button>
278395

279396
<script src="https://cdn.jsdelivr.net/npm/clipxjs/dist/clipx.min.js"></script>
280397
<script>
281-
// Initialize ClipX.js instance
282-
var clipx = new clipx();
398+
// Initialize ClipX.js instance
399+
var clipx = new clipx();
283400
284-
// Optional: Set custom styles for toast notifications
285-
clipx.setCustomStyles({
286-
toast: "background-color: #333; color: #fff; padding: 12px; border-radius: 5px;"
287-
});
401+
// Optional: Set custom styles for toast notifications
402+
clipx.setCustomStyles({
403+
toast:
404+
"background-color: #333; color: #fff; padding: 12px; border-radius: 5px;",
405+
});
288406
289-
// Attach ClipX.js functionality to elements
290-
clipx.attach('[data-clipx-text], [data-clipx-target]');
407+
// Attach ClipX.js functionality to elements
408+
clipx.attach("[data-clipx-text], [data-clipx-target]");
291409
</script>
292-
293410
```

0 commit comments

Comments
 (0)