@jotnar/m-chip v0.1.1
@jotnar/m-chip
A reusable Vue 3 chip component with Tailwind CSS 4 styling and Font Awesome support. Customize your chips with sizes, colors, variants, and icons effortlessly!
đĻ Installation
Install the package via npm:
npm i @jotnar/m-chip@latestPrerequisites: Ensure your project has Vue 3 (version 3.4.0 or higher) and Tailwind CSS 4 set up, as this component relies on Tailwind CSS classes for styling and Vue 3 for functionality.
đ§âđģ Usage
You can use the m-chip component in your Vue 3 application either by registering it globally or locally in specific components.
đ Global Registration
Register the m-chip component globally in your Vue app:
- Import the component in your main JavaScript file (e.g., main.js):
import { createApp } from 'vue';
import App from './App.vue';
import { MChip } from '@jotnar/m-chip';
const app = createApp(App);
app.component('m-chip', MChip);
app.mount('#app');- Import the styles in your main CSS file (e.g., main.css):
@import '@jotnar/m-chip/style';
@import 'tailwindcss';;Once these steps are complete, you can use the component anywhere in your app.
đĻ Local Registration
Import and use the component in specific components:
<template>
<m-chip color="primary" rounded label="Click Me" />
</template>
<script setup>
import { MChip } from '@jotnar/m-chip';
</script>đī¸ Props
The m-chip component offers a range of props to customize its appearance and behavior:
| Prop | Type | Default | Description |
|---|---|---|---|
label | String | 'Chip' | The text displayed on the chip. Used as aria-label for icon-only chips. |
sm | Boolean | false | Sets small size (height: 1.5rem, text: xs). |
md | Boolean | false | Sets medium size (height: 1.75rem, text: sm). Default if sm/lg not set. |
lg | Boolean | false | Sets large size (height: 2rem, text: base). |
color | String | 'primary' | Color variant: primary, secondary, tertiary, accent, info, etc. |
outline | Boolean | false | Outline style with transparent background and colored border. |
text | Boolean | false | Text-only style with no background. |
elevated | Boolean | false | Elevated style with shadow and hover scale effect. |
icon | String | null | Font Awesome icon for icon-only chips (e.g., fas fa-check). |
licon | String | null | Font Awesome icon on the left side. |
ricon | String | null | Font Awesome icon on the right side. |
onlyIcon | Boolean | false | Renders an icon-only chip (no text, uses icon prop). |
link | String | null | Converts chip to an tag with the specified URL. |
autofocus | Boolean | false | Automatically focuses the button on render. |
disabled | Boolean | false | Disables the chip, applying opacity and grayscale. |
selectable | Boolean | false | Makes the chip clickable to toggle selection state. |
selected | Boolean | false | Indicates if the chip is selected (used with selectable). |
dismissible | Boolean | false | Adds a dismiss button (close icon) to the chip. |
⨠Examples
<template>
<div class="flex gap-2 flex-wrap">
<!-- Basic Chips -->
<m-chip label="Primary" color="primary" />
<m-chip label="Secondary" color="secondary" md />
<m-chip label="Error" color="error" lg />
<!-- Variants -->
<m-chip label="Outline" color="info" outline rounded />
<m-chip label="Text" color="success" text />
<m-chip label="Elevated" color="primary" elevated />
<!-- Icons -->
<m-chip label="Filter" color="info" licon="fas fa-filter" rounded />
<m-chip color="success" icon="fas fa-check" onlyIcon />
<!-- Selectable -->
<m-chip
label="Selectable"
color="accent"
selectable
:selected="selected"
@update:selected="selected = $event"
/>
<!-- Dismissible -->
<m-chip label="Dismissible" color="warning" dismissible @dismiss="onDismiss" />
<!-- Link -->
<m-chip label="Link" color="tertiary" link="https://example.com"é¨å<script setup>
import { ref } from 'vue';
const selected = ref(false);
const onDismiss = () => console.log('Chip dismissed');
</script>âšī¸ Notes
Custom Classes:
If a customclassprop (e.g.,class="bg-blue-500 text-white"), thecolorprop will be ignored, allowing your custom styles to take precedence.Icon Support:
Icons require Font Awesome to be set up in your project. Use the formatfa-solid fa-icon-name(e.g.,fa-solid fa-code).Accessibility:
For icon-only chips (onlyIcon), thelabelprop is used as thearia-labelandtitleto ensure accessibility for screen readers.
đ¨ Under Construction
The homepage for this project is currently under construction. In the meantime, you can find the source code and report issues on GitHub:
âī¸ License
MIT
đ¤ Author
Jotnar
9 months ago