Skip to content

[Toolkit] Remove redundant code in Shadcn kit components #2711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div
class="{{ style.apply({variant}, attributes.render('class'))|tailwind_merge }}"
role="alert"
{{ attributes.defaults({role: 'alert'}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p
class="{{ 'text-sm [&_p]:leading-relaxed ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</p>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h5
class="{{ 'mb-1 font-medium leading-none tracking-tight ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</h5>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- props ratio, style = '' -%}
<div
style="aspect-ratio: {{ ratio }}; {{ style }}"
{{ attributes.defaults({}).without('style') }}
{{ attributes.without('style') }}
>
{%- block content %}{% endblock -%}
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<span
class="{{ 'relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</span>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img
class="{{ 'aspect-square h-full w-full ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({alt: ''}).without('class') }}
{{ attributes.defaults({alt: ''}) }}
/>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<span
class="{{ 'flex h-full w-full items-center justify-center rounded-full bg-muted ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</span>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
) -%}
<div
class="{{ style.apply({variant, outline}, attributes.render('class'))|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<span
class="{{ 'flex h-9 w-9 items-center justify-center ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
role="presentation"
aria-hidden="true"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<li
class="{{ 'inline-flex items-center gap-1.5 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</li>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<a
class="{{ 'transition-colors hover:text-foreground ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</a>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ol
class="{{ 'flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</ol>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<span
class="{{ 'font-normal text-foreground ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
role="link"
aria-disabled="true"
aria-current="page"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<li
class="{{ '[&>svg]:w-3.5 [&>svg]:h-3.5 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
role="presentation"
aria-hidden="true"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<{{ as }}
class="{{ style.apply({variant, outline, size}, attributes.render('class'))|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</{{ as }}>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
class="{{ 'rounded-lg border bg-card text-card-foreground shadow-sm ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
class="{{ 'p-6 pt-0 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
class="{{ 'text-sm text-muted-foreground ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
class="{{ 'flex items-center p-6 pt-0 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
class="{{ 'flex flex-col space-y-1.5 p-6 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
class="{{ 'text-2xl font-semibold leading-none tracking-tight ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<input
type="checkbox"
class="{{ 'peer size-4 inline-block align-middle accent-primary ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<input
type="{{ type }}"
class="{{ 'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<label
class="{{ ('text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 ' ~ attributes.render('class'))|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</label>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav
class="{{ 'mx-auto flex w-full justify-center ' ~ attributes.render('class')|tailwind_merge }}"
role="navigation"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</nav>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="{{ value }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
<div class="h-full w-full flex-1 bg-primary transition-all" style="transform: translateX(-{{ 100 - value }}%)"></div>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<select
class="{{ 'flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</select>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
{{ attributes.defaults({
role: decorative ? 'none' : 'separator',
'aria-orientation': decorative ? false : orientation,
}).without('class') }}
}) }}
>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div
class="{{ 'animate-pulse rounded-full bg-muted ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
></div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<label class="{{ 'relative inline-flex items-center cursor-pointer ' ~ attributes.render('class')|tailwind_merge }}">
<input type="checkbox" class="sr-only peer absolute inset-0 w-full h-full cursor-pointer" {{ attributes.defaults({}).without('class') }}>
<input type="checkbox" class="sr-only peer absolute inset-0 w-full h-full cursor-pointer" {{ attributes }}>
<div class="pointer-events-none w-11 h-6 bg-input rounded-full peer peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-primary peer-disabled:opacity-50 peer-disabled:cursor-not-allowed"></div>
</label>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="relative w-full overflow-auto">
<table
class="{{ 'w-full caption-bottom text-sm ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tbody
class="{{ '[&_tr:last-child]:border-0 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</tbody>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<caption
class="{{ 'mt-4 text-sm text-muted-foreground ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</caption>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<td
class="{{ 'p-4 align-middle [&:has([role=checkbox])]:pr-0 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</td>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tfoot
class="{{ 'border-t bg-muted/50 font-medium [&>tr]:last:border-b-0 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</tfoot>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<th
class="{{ 'h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</th>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<thead
class="{{ '[&_tr]:border-b ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</thead>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tr
class="{{ 'border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
>
{%- block content %}{% endblock -%}
</tr>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<textarea
class="{{ 'flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes.defaults({}).without('class') }}
{{ attributes }}
></textarea>
Loading