feat: initialize Vue component library and aligned documentation

This commit is contained in:
maoyingjie
2026-10-21 09:06:28 +08:00
commit 9d40dc0ecb
149 changed files with 13208 additions and 0 deletions
+199
View File
@@ -0,0 +1,199 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to the Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by the Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding any notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. Please also get an approval
from the project maintainers before using the Apache License.
Copyright 2025 NextUI Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+161
View File
@@ -0,0 +1,161 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
/* Button component styles */
/* Base button styles */
.hv-button {
@apply relative isolate inline-flex h-10 w-fit origin-center items-center justify-center gap-2 rounded-3xl px-4 text-sm font-medium whitespace-nowrap outline-none select-none no-highlight md:h-9;
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
transform 250ms var(--ease-smooth),
background-color 100ms var(--ease-out),
box-shadow 100ms var(--ease-out);
@apply transform-gpu motion-reduce:transition-none;
/* Cursor */
cursor: var(--cursor-interactive);
/* Default tokens (fallback behavior) */
--button-bg: transparent;
--button-bg-hover: var(--button-bg);
--button-bg-pressed: var(--button-bg-hover);
--button-fg: currentColor;
background-color: var(--button-bg);
color: var(--button-fg);
/* Focus state */
&:focus-visible:not([data-focused]),
&[data-focus-visible="true"] {
@apply status-focused;
}
/* Disabled state */
&:disabled,
&[aria-disabled="true"] {
@apply status-disabled;
}
/* Pending state */
&[data-pending="true"] {
@apply status-pending;
}
/* Active / pressed */
&:active,
&[data-pressed="true"] {
@apply will-change-transform;
background-color: var(--button-bg-pressed);
transform: scale(0.97);
}
/* Hover */
@media (hover: hover) {
&:hover,
&[data-hovered="true"] {
background-color: var(--button-bg-hover);
}
}
/* SVG icon styling - exclude spinner and link-icon svgs */
& svg:not([data-slot="spinner"] svg, [data-slot="link-icon"] svg) {
@apply pointer-events-none -mx-0.5 my-0.5 size-5 shrink-0 self-center sm:my-1 sm:size-4;
}
}
/* Size variants */
.hv-button--sm {
@apply h-9 px-3 md:h-8;
& svg:not([data-slot="spinner"] svg, [data-slot="link-icon"] svg) {
@apply size-4;
}
&:active,
&[data-pressed="true"] {
transform: scale(0.98);
}
}
.hv-button--md {
/* No styles as this is the default size */
}
.hv-button--lg {
@apply h-11 text-base md:h-10;
&:active,
&[data-pressed="true"] {
transform: scale(0.96);
}
}
/* Color variants - only set custom property values */
.hv-button--primary {
--button-bg: var(--accent);
--button-bg-hover: var(--accent-hover);
--button-bg-pressed: var(--accent-hover);
--button-fg: var(--accent-foreground);
}
.hv-button--secondary {
--button-bg: var(--default);
--button-bg-hover: var(--default-hover);
--button-bg-pressed: var(--default-hover);
--button-fg: var(--accent-soft-foreground);
}
.hv-button--tertiary {
--button-bg: var(--default);
--button-bg-hover: var(--default-hover);
--button-bg-pressed: var(--default-hover);
}
.hv-button--ghost,
.hv-button--outline {
--button-bg: transparent;
--button-bg-hover: var(--default);
--button-bg-pressed: var(--default);
--button-fg: var(--default-foreground);
}
.hv-button--outline {
@apply border border-border;
--button-bg-hover: color-mix(in srgb, var(--default) 60%, transparent);
}
.hv-button--danger {
--button-bg: var(--danger);
--button-bg-hover: var(--danger-hover);
--button-bg-pressed: var(--danger-hover);
--button-fg: var(--danger-foreground);
}
.hv-button--danger-soft {
--button-bg: var(--danger-soft);
--button-bg-hover: var(--danger-soft-hover);
--button-bg-pressed: var(--danger-soft-hover);
--button-fg: var(--danger-soft-foreground);
}
/* Icon-only modifier */
.hv-button--icon-only {
@apply w-10 p-0 md:w-9;
}
.hv-button--icon-only.hv-button--sm {
@apply w-9 md:w-8;
}
.hv-button--icon-only.hv-button--lg {
@apply w-11 md:w-10;
}
/* Full width modifier */
.hv-button--full-width {
@apply w-full;
}
+53
View File
@@ -0,0 +1,53 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
/* Card component styles */
/* Block */
.hv-card {
@apply relative flex flex-col gap-3 overflow-visible p-4;
@apply shadow-surface;
border-radius: min(32px, var(--radius-3xl));
}
/* Element - header */
.hv-card__header {
@apply flex flex-col;
}
/* Element - title */
.hv-card__title {
@apply text-sm leading-6 font-medium text-foreground;
}
/* Element - description */
.hv-card__description {
@apply text-sm leading-5 text-muted;
}
/* Element - content */
.hv-card__content {
@apply flex flex-1 flex-col gap-1;
}
/* Element - footer */
.hv-card__footer {
@apply flex flex-row items-center;
}
/* Modifier - variant */
.hv-card--transparent {
@apply border-none bg-transparent shadow-none;
}
.hv-card--default {
@apply bg-surface;
}
.hv-card--secondary {
@apply bg-surface-secondary;
}
.hv-card--tertiary {
@apply bg-surface-tertiary;
}
@@ -0,0 +1,67 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
/* Close Button component styles */
/* Base close button styles */
.hv-close-button {
@apply relative isolate inline-flex h-6 w-6 shrink-0 origin-center items-center justify-center rounded-xl p-1 select-none no-highlight;
/* Cursor */
cursor: var(--cursor-interactive);
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
transform 250ms var(--ease-out-quart),
color 150ms var(--ease-out),
background-color 100ms var(--ease-out),
box-shadow 150ms var(--ease-out);
@apply transform-gpu motion-reduce:transition-none;
/* Focus visible state */
&:focus-visible:not([data-focused]),
&[data-focus-visible="true"] {
@apply status-focused;
}
/* Disabled state */
&:disabled,
&[aria-disabled="true"] {
@apply status-disabled;
}
/* Pending state */
&[data-pending="true"] {
@apply status-pending;
}
/* SVG icon styling*/
& svg {
@apply pointer-events-none;
@apply size-4 shrink-0 self-center;
@apply -mx-0.5 my-0.5;
}
}
/* Variants */
.hv-close-button--default {
@apply bg-default text-muted;
&:active,
&[data-pressed="true"] {
}
@media (hover: hover) {
&:hover,
&[data-hovered="true"] {
@apply bg-default-hover;
}
}
&:active,
&[data-pressed="true"] {
transform: scale(0.93);
}
}
@@ -0,0 +1,6 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
/* Base description styles */
.hv-description {
@apply text-xs text-wrap wrap-break-word text-muted;
}
+88
View File
@@ -0,0 +1,88 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
.hv-input {
@apply rounded-field border bg-field px-3 py-2 text-base text-field-foreground shadow-field outline-none placeholder:text-field-placeholder sm:text-sm;
border-width: var(--border-width-field);
border-color: var(--field-border);
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
background-color 150ms var(--ease-smooth),
border-color 150ms var(--ease-smooth),
box-shadow 150ms var(--ease-out);
@apply motion-reduce:transition-none;
@media (hover: hover) {
&:hover:not(:focus):not(:focus-visible),
&[data-hovered="true"]:not([data-focused="true"]):not(
[data-focus-visible="true"]
) {
@apply bg-field-hover;
border-color: var(--field-border-hover);
}
}
/* Focus state */
&:focus,
&[data-focused="true"] {
@apply status-focused-field;
border-color: var(--field-border-focus);
background-color: var(--field-focus);
}
/* Invalid state */
&[data-invalid="true"] {
@apply status-invalid-field;
background-color: var(--field-focus);
}
/* Disabled state */
&:disabled,
&[data-disabled="true"],
&[aria-disabled="true"] {
@apply status-disabled;
}
}
/* Variant property definitions */
.hv-input--primary {
/* Default styles */
}
.hv-input--secondary {
@apply shadow-none;
background-color: var(--input-bg);
--input-bg: var(--default);
--input-bg-hover: var(--default-hover);
--input-bg-focus: var(--default);
@media (hover: hover) {
&:hover:not(:focus):not(:focus-visible),
&[data-hovered="true"]:not([data-focus-visible="true"]):not(
[data-focused="true"]
) {
background-color: var(--input-bg-hover);
}
}
&:focus,
&[data-focused="true"] {
background-color: var(--input-bg-focus);
}
/* Invalid state */
&[data-invalid="true"] {
@apply status-invalid-field;
background-color: var(--input-bg-focus);
}
}
/* Full width modifier */
.hv-input--full-width {
@apply w-full;
}
+33
View File
@@ -0,0 +1,33 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
/* Base label styles */
.hv-label {
/* Base styling */
@apply text-sm font-medium text-foreground;
}
/*
* Exclude group-level components (RadioGroup, CheckboxGroup) and radio/checkbox items
* to ensure asterisks only appear on atomic form field labels and group labels,
* not on individual options within those groups
*/
.hv-label--required,
[data-required="true"]:not([role="group"]):not([role="radiogroup"]):not(
[role="checkboxgroup"]
)
> .hv-label,
[data-required="true"]:not([data-slot="radio"]):not([data-slot="checkbox"])
> .hv-label {
@apply after:ms-0.5 after:text-danger after:content-['*'];
}
.hv-label--disabled,
[data-disabled="true"] .hv-label {
@apply status-disabled;
}
.hv-label--invalid,
[data-invalid="true"] .hv-label,
[aria-invalid="true"] .hv-label {
@apply text-danger;
}
@@ -0,0 +1,18 @@
/* Adapted from HeroUI ce90ea3. Copyright 2025 NextUI Inc. See third-party/HEROUI-LICENSE. */
/* Switch Group styles */
.hv-switch-group {
@apply flex flex-col gap-6;
}
.hv-switch-group__items {
@apply flex gap-4;
}
/* Orientation modifiers */
.hv-switch-group--horizontal .hv-switch-group__items {
@apply flex-row;
}
.hv-switch-group--vertical .hv-switch-group__items {
@apply flex-col;
}
+249
View File
@@ -0,0 +1,249 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
/* Switch base styles */
.hv-switch {
@apply flex flex-col items-start gap-1 no-highlight;
/* Cursor */
cursor: var(--cursor-interactive);
/* Default tokens for switch control states */
--switch-control-bg: var(--default);
--switch-control-bg-hover: color-mix(
in oklab,
var(--switch-control-bg),
transparent 20%
);
--switch-control-bg-pressed: var(--switch-control-bg-hover);
--switch-control-bg-checked: var(--accent);
--switch-control-bg-checked-hover: var(--accent-hover);
/* Disabled state */
&[data-disabled="true"] {
@apply status-disabled;
[data-slot="description"],
[data-slot="field-error"] {
@apply status-disabled;
}
.hv-switch__thumb {
@apply bg-default-foreground/20;
}
}
/* Field-level help text below the control + label row */
& > [data-slot="description"] {
@apply w-full min-w-0 ps-[calc(2.5rem+0.75rem)];
}
& > [data-slot="field-error"] {
@apply w-full min-w-0 ps-[calc(2.5rem+0.75rem)] text-xs text-muted;
}
&.hv-switch--sm > [data-slot="description"] {
@apply ps-[calc(2rem+0.75rem)];
}
&.hv-switch--sm > [data-slot="field-error"] {
@apply ps-[calc(2rem+0.75rem)];
}
&.hv-switch--lg > [data-slot="description"] {
@apply ps-[calc(3rem+0.75rem)];
}
&.hv-switch--lg > [data-slot="field-error"] {
@apply ps-[calc(3rem+0.75rem)];
}
/* Disabled + Selected state */
&:disabled[aria-checked="true"],
&:disabled[data-selected="true"],
&[data-disabled="true"][aria-checked="true"],
&[data-disabled="true"][data-selected="true"],
&[aria-disabled="true"][aria-checked="true"],
&[aria-disabled="true"][data-selected="true"] {
.hv-switch__thumb {
opacity: 0.4;
}
}
}
/* Size variants - default is medium */
.hv-switch--sm {
/* Small size modifier */
}
.hv-switch--md {
/* Medium size - no styles as this is the default */
}
.hv-switch--lg {
/* Large size modifier */
}
/* Switch control (track) */
.hv-switch__control {
/* Default size (medium) */
@apply relative flex shrink-0 items-center overflow-hidden rounded-xl;
height: 1.25rem; /* 20px on desktop (14px base), 20px on mobile (16px base) - scales with font-size */
width: 2.5rem; /* 35px on desktop, 40px on mobile - scales with font-size */
background-color: var(--switch-control-bg);
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
background-color 250ms var(--ease-smooth),
box-shadow 150ms var(--ease-out);
@apply motion-reduce:transition-none;
/* Focus states */
.hv-switch:focus-visible &,
.hv-switch:has([data-slot="switch-content"][data-focus-visible="true"]) &,
.hv-switch [data-slot="switch-content"][data-focus-visible="true"] & {
@apply status-focused;
}
/* Hover states */
.hv-switch:hover &,
.hv-switch:has([data-slot="switch-content"][data-hovered="true"]) &,
.hv-switch [data-slot="switch-content"][data-hovered="true"] & {
background-color: var(--switch-control-bg-hover);
}
/* Pressed states */
.hv-switch:active &,
.hv-switch:has([data-slot="switch-content"][data-pressed="true"]) &,
.hv-switch [data-slot="switch-content"][data-pressed="true"] & {
background-color: var(--switch-control-bg-pressed);
@apply motion-reduce:transform-none;
}
/* Checked states */
.hv-switch[aria-checked="true"] &,
.hv-switch[data-selected="true"] & {
background-color: var(--switch-control-bg-checked);
}
/* Checked + Hover states */
.hv-switch[aria-checked="true"]:hover &,
.hv-switch[data-selected="true"]:hover &,
.hv-switch[aria-checked="true"][data-hovered="true"] &,
.hv-switch[data-selected="true"][data-hovered="true"] &,
.hv-switch:has(
[data-slot="switch-content"][data-hovered="true"]
)[data-selected="true"]
& {
background-color: var(--switch-control-bg-checked-hover);
}
/* Checked + Pressed states */
.hv-switch[aria-checked="true"]:active &,
.hv-switch[data-selected="true"]:active &,
.hv-switch[aria-checked="true"][data-pressed="true"] &,
.hv-switch[data-selected="true"][data-pressed="true"] &,
.hv-switch:has(
[data-slot="switch-content"][data-pressed="true"]
)[data-selected="true"]
& {
background-color: var(--switch-control-bg-checked-hover);
}
}
/* Switch content — the clickable label (control + label text) */
.hv-switch__content {
@apply relative inline-flex cursor-[inherit] items-center gap-3 text-sm font-medium text-foreground outline-none select-none no-highlight;
}
/* Size-specific control dimensions */
.hv-switch--sm .hv-switch__control {
@apply rounded-lg;
height: 1rem; /* ~14px on desktop, ~16px on mobile */
width: 2rem; /* ~32px on desktop, ~36px on mobile */
}
.hv-switch--md .hv-switch__control {
/* No styles as this is the default size */
}
.hv-switch--lg .hv-switch__control {
height: 1.5rem; /* ~21px on desktop, ~24px on mobile */
width: 3rem; /* ~48px on desktop, ~56px on mobile */
}
/* Switch thumb */
.hv-switch__thumb {
/* Default size (medium) with margin-based positioning */
@apply ms-0.5 flex origin-center rounded-lg bg-white text-black shadow-field;
height: 1rem; /* ~14px on desktop, ~16px on mobile */
width: 1.375rem; /* ~19px on desktop, ~22px on mobile */
/**
* Transitions
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
*/
transition:
margin 300ms var(--ease-out-fluid),
background-color 200ms var(--ease-out);
@apply motion-reduce:transition-none;
/* Selected/checked state - use margin instead of translate */
.hv-switch[aria-checked="true"] &,
.hv-switch[data-selected="true"] & {
@apply ms-[calc(100%-1.5rem)] bg-accent-foreground text-accent;
box-shadow:
0px 0px 5px 0px rgb(0 0 0 / 0.02),
0px 2px 10px 0px rgb(0 0 0 / 0.06),
0px 0px 1px 0px rgb(0 0 0 / 0.3);
}
.hv-switch:active &,
.hv-switch[data-pressed="true"] & {
}
}
/* Size-specific thumb dimensions */
.hv-switch--sm .hv-switch__thumb {
@apply rounded-md;
height: 0.75rem; /* ~10.5px on desktop, ~12px on mobile */
width: 1.03125rem; /* ~14.4px on desktop, ~16.5px on mobile - maintains 1.375:1 ratio */
/* Small selected state positioning */
.hv-switch[aria-checked="true"] &,
.hv-switch[data-selected="true"] & {
@apply ms-[calc(100%-1.15625rem)];
}
}
.hv-switch--lg .hv-switch__thumb {
@apply rounded-xl;
height: 1.25rem; /* ~17.5px on desktop, ~20px on mobile */
width: 1.71875rem; /* ~24px on desktop, ~27.5px on mobile - maintains 1.375:1 ratio */
/* Large selected state positioning */
.hv-switch[aria-checked="true"] &,
.hv-switch[data-selected="true"] & {
@apply ms-[calc(100%-1.84375rem)];
}
}
/* Switch thumb content container */
.hv-switch__thumb > * {
@apply flex size-full items-center justify-center;
}
.hv-switch [data-slot="label"] {
@apply select-none;
}
.hv-switch__content [data-slot="label"] {
cursor: var(--cursor-interactive);
}
.hv-switch [data-slot="description"] {
@apply cursor-default select-none;
}
+64
View File
@@ -0,0 +1,64 @@
@layer theme, base, components, utilities;
@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/preflight.css" layer(base);
@import "./themes/shared/theme.css";
@import "./themes/default/variables.css";
@import "./utilities/index.css";
@import "./variants/index.css";
@import "./components/button.css" layer(components);
@import "./components/close-button.css" layer(components);
@import "./components/card.css" layer(components);
@import "./components/input.css" layer(components);
@import "./components/switch.css" layer(components);
@import "./components/switch-group.css" layer(components);
@import "./components/label.css" layer(components);
@import "./components/description.css" layer(components);
/* The Vue Switch uses Reka's native button for its clickable content. */
@layer components {
.hv-switch:has(.hv-switch__content:focus-visible) .hv-switch__control {
@apply status-focused;
}
.hv-switch__content {
border: 0;
background: transparent;
padding: 0;
font: inherit;
}
.hv-spinner {
width: 1em;
height: 1em;
border: 2px solid currentColor;
border-right-color: transparent;
border-radius: 50%;
animation: hv-spin 0.75s linear infinite;
}
@keyframes hv-spin {
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: reduce) {
.hv-spinner {
animation: none;
}
}
}
@layer components {
.hv-switch__input {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
border: 0;
clip-path: inset(50%);
overflow: hidden;
white-space: nowrap;
}
.hv-field-error,
.hv-switch > .hv-field-error {
color: var(--danger);
font-size: var(--text-xs);
}
}
+30
View File
@@ -0,0 +1,30 @@
{
"name": "@heroui-vue/styles",
"version": "0.0.1",
"private": true,
"type": "module",
"files": [
"dist",
"LICENSE"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./css": "./dist/styles.css"
},
"sideEffects": [
"**/*.css"
],
"scripts": {
"build": "vite build"
},
"dependencies": {
"tailwind-variants": "^3.1.0"
},
"devDependencies": {
"@tailwindcss/vite": "^4.1.0",
"tailwindcss": "^4.1.0"
}
}
+129
View File
@@ -0,0 +1,129 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
import { tv, type VariantProps } from "tailwind-variants";
export const buttonVariants = tv({
base: "hv-button",
defaultVariants: {
fullWidth: false,
isIconOnly: false,
size: "md",
variant: "primary",
},
variants: {
fullWidth: {
false: "",
true: "hv-button--full-width",
},
isIconOnly: {
true: "hv-button--icon-only",
},
size: {
lg: "hv-button--lg",
md: "hv-button--md",
sm: "hv-button--sm",
},
variant: {
danger: "hv-button--danger",
"danger-soft": "hv-button--danger-soft",
ghost: "hv-button--ghost",
outline: "hv-button--outline",
primary: "hv-button--primary",
secondary: "hv-button--secondary",
tertiary: "hv-button--tertiary",
},
},
});
export type ButtonVariants = VariantProps<typeof buttonVariants>;
const cardVariants = tv({
defaultVariants: {
variant: "default",
},
slots: {
base: "hv-card",
content: "hv-card__content",
description: "hv-card__description",
footer: "hv-card__footer",
header: "hv-card__header",
title: "hv-card__title",
},
variants: {
variant: {
default: {
base: "hv-card--default",
},
secondary: {
base: "hv-card--secondary",
},
tertiary: {
base: "hv-card--tertiary",
},
transparent: {
base: "hv-card--transparent",
},
},
},
});
export { cardVariants };
export type CardVariants = VariantProps<typeof cardVariants>;
export const inputVariants = tv({
base: "hv-input",
defaultVariants: {
fullWidth: false,
variant: "primary",
},
variants: {
fullWidth: {
false: "",
true: "hv-input--full-width",
},
variant: {
primary: "hv-input--primary",
secondary: "hv-input--secondary",
},
},
});
export type InputVariants = VariantProps<typeof inputVariants>;
export const switchVariants = tv({
defaultVariants: {
size: "md",
},
slots: {
base: "hv-switch",
content: "hv-switch__content",
control: "hv-switch__control",
icon: "hv-switch__icon",
thumb: "hv-switch__thumb",
},
variants: {
size: {
lg: {
base: "hv-switch--lg",
},
md: {
base: "hv-switch--md",
},
sm: {
base: "hv-switch--sm",
},
},
},
});
export type SwitchVariants = VariantProps<typeof switchVariants>;
export { tv, cn, type VariantProps } from "tailwind-variants";
export const closeButtonVariants = tv({
base: "hv-close-button",
defaultVariants: { variant: "default" },
variants: { variant: { default: "hv-close-button--default" } },
});
export type CloseButtonVariants = VariantProps<typeof closeButtonVariants>;
+1
View File
@@ -0,0 +1 @@
import "./index.css";
@@ -0,0 +1,493 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
@layer base {
/* HeroUI Default Theme */
/*
* == Common Variables ==
* Identical in every theme, so they are also declared on `:host`: `:root` matches
* nothing inside a shadow tree, and the theme blocks below never re-declare these.
*/
:root,
:host {
/* Primitive Colors (Do not change between light and dark) */
--white: oklch(100% 0 0);
--black: oklch(0% 0 0);
--snow: oklch(0.9911 0 0);
--eclipse: oklch(0.2103 0.0059 285.89);
/* Spacing scale */
--spacing: 0.25rem;
/* Border */
--border-width: 1px;
--field-border-width: 0px;
--disabled-opacity: 0.5;
/* Ring offset - Used for focus ring */
--ring-offset-width: 2px;
/* Cursor */
--cursor-interactive: pointer;
--cursor-disabled: not-allowed;
/* Radius */
--radius: 0.5rem;
--field-radius: calc(var(--radius) * 1.5);
/* Accent and status hues (shared with the dark theme) */
--accent: oklch(0.6204 0.195 253.83);
--accent-foreground: var(--snow);
--success: oklch(0.7329 0.1935 150.81);
--success-foreground: var(--eclipse);
/* no border by default on form fields */
--field-border: transparent;
/* Skeleton Default Global Animation */
--skeleton-animation: shimmer; /* shimmer, pulse, none */
/* Tooltip Default Delays */
--tooltip-delay: 1500ms;
--tooltip-close-delay: 500ms;
}
:root,
.light,
.default,
[data-theme="light"],
[data-theme="default"],
:host(.light),
:host(.default),
:host([data-theme="light"]),
:host([data-theme="default"]) {
color-scheme: light;
/* == Light Theme Variables == */
/* Base Colors */
--background: oklch(0.9702 0 0);
--foreground: var(--eclipse);
/* Surface: Used for non-overlay components (cards, accordions, disclosure groups) */
--surface: var(--white);
--surface-foreground: var(--foreground);
--surface-secondary: oklch(0.9524 0.0013 286.37);
--surface-secondary-foreground: var(--foreground);
--surface-tertiary: oklch(0.9373 0.0013 286.37);
--surface-tertiary-foreground: var(--foreground);
/* Overlay: Used for floating/overlay components (tooltips, popovers, modals, menus) */
--overlay: var(--white);
--overlay-foreground: var(--foreground);
--muted: oklch(0.5517 0.0138 285.94);
--scrollbar: var(--scrollbar-thumb);
--scrollbar-thumb: color-mix(in oklch, var(--foreground) 15%, transparent);
--scrollbar-track: transparent;
--scrollbar-gutter: auto;
--scrollbar-width: thin;
--scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
--default: oklch(94% 0.001 286.375);
--default-foreground: var(--eclipse);
/* Form Fields */
--field-background: var(--white);
--field-foreground: oklch(0.2103 0.0059 285.89);
--field-placeholder: var(--muted);
/* Status Colors */
--warning: oklch(0.7819 0.1585 72.33);
--warning-foreground: var(--eclipse);
--danger: oklch(0.6532 0.2328 25.74);
--danger-foreground: var(--snow);
/* Component Colors */
--segment: var(--white);
--segment-foreground: var(--eclipse);
/* Misc Colors */
--border: oklch(90% 0.004 286.32);
--separator: oklch(92% 0.004 286.32);
--focus: var(--accent);
--link: var(--foreground);
/* Backdrop */
--backdrop: rgba(0, 0, 0, 0.5);
/* Calculated Colors */
--surface-hover: color-mix(
in oklab,
var(--surface) 92%,
var(--surface-foreground) 8%
);
--background-secondary: color-mix(
in oklab,
var(--background) 96%,
var(--foreground) 4%
);
--background-tertiary: color-mix(
in oklab,
var(--background) 92%,
var(--foreground) 8%
);
--background-inverse: var(--foreground);
--default-hover: color-mix(
in oklab,
var(--default) 96%,
var(--default-foreground) 4%
);
--accent-hover: color-mix(
in oklab,
var(--accent) 90%,
var(--accent-foreground) 10%
);
--success-hover: color-mix(
in oklab,
var(--success) 90%,
var(--success-foreground) 10%
);
--warning-hover: color-mix(
in oklab,
var(--warning) 90%,
var(--warning-foreground) 10%
);
--danger-hover: color-mix(
in oklab,
var(--danger) 90%,
var(--danger-foreground) 10%
);
--field-hover: color-mix(
in oklab,
var(--field-background, var(--default)) 90%,
var(--field-foreground, var(--foreground)) 2%
);
--field-focus: var(--field-background, var(--default));
--field-border-hover: color-mix(
in oklab,
var(--field-border, var(--border)) 88%,
var(--field-foreground, var(--foreground)) 10%
);
--field-border-focus: color-mix(
in oklab,
var(--field-border, var(--border)) 74%,
var(--field-foreground, var(--foreground)) 22%
);
--default-soft: color-mix(in oklab, var(--default) 50%, transparent);
--default-soft-foreground: var(--default-foreground);
--default-soft-hover: color-mix(in oklab, var(--default) 60%, transparent);
--accent-soft: color-mix(in oklab, var(--accent) 15%, transparent);
--accent-soft-foreground: color-mix(
in oklab,
var(--accent) 70%,
var(--foreground) 30%
);
--accent-soft-hover: color-mix(in oklab, var(--accent) 20%, transparent);
--danger-soft: color-mix(in oklab, var(--danger) 15%, transparent);
--danger-soft-foreground: color-mix(
in oklab,
var(--danger) 70%,
var(--foreground) 40%
);
--danger-soft-hover: color-mix(in oklab, var(--danger) 20%, transparent);
--warning-soft: color-mix(in oklab, var(--warning) 15%, transparent);
--warning-soft-foreground: color-mix(
in oklab,
var(--warning) 80%,
var(--foreground) 70%
);
--warning-soft-hover: color-mix(in oklab, var(--warning) 20%, transparent);
--success-soft: color-mix(in oklab, var(--success) 15%, transparent);
--success-soft-foreground: color-mix(
in oklab,
var(--success) 80%,
var(--foreground) 60%
);
--success-soft-hover: color-mix(in oklab, var(--success) 20%, transparent);
--separator-secondary: color-mix(
in oklab,
var(--surface) 85%,
var(--surface-foreground) 15%
);
--separator-tertiary: color-mix(
in oklab,
var(--surface) 81%,
var(--surface-foreground) 19%
);
--border-secondary: color-mix(
in oklab,
var(--surface) 78%,
var(--surface-foreground) 22%
);
--border-tertiary: color-mix(
in oklab,
var(--surface) 66%,
var(--surface-foreground) 34%
);
/* Shadows */
/* --surface-shadow: 0 0px 0px 0 rgba(24, 24, 27, 0.03), 0 2px 10px 0 rgba(24, 24, 27, 0.08); */
--surface-shadow:
0 2px 4px 0 rgba(0, 0, 0, 0.04), 0 1px 2px 0 rgba(0, 0, 0, 0.06),
0 0 1px 0 rgba(0, 0, 0, 0.06);
/* Overlay shadow */
--overlay-shadow:
0 2px 8px 0 rgba(0, 0, 0, 0.06), 0 -6px 12px 0 rgba(0, 0, 0, 0.03),
0 14px 28px 0 rgba(0, 0, 0, 0.08);
--field-shadow:
0 2px 4px 0 rgba(0, 0, 0, 0.04), 0 1px 2px 0 rgba(0, 0, 0, 0.06),
0 0 1px 0 rgba(0, 0, 0, 0.06);
}
.dark,
[data-theme="dark"],
:host(.dark),
:host([data-theme="dark"]) {
color-scheme: dark;
/* == Dark Theme Variables == */
/* Base Colors */
--background: oklch(12% 0.005 285.823);
--foreground: var(--snow);
/* Surface: Used for non-overlay components (cards, accordions, disclosure groups) */
--surface: oklch(0.2103 0.0059 285.89);
--surface-foreground: var(--foreground);
--surface-secondary: oklch(0.257 0.0037 286.14);
--surface-secondary-foreground: var(--foreground);
--surface-tertiary: oklch(0.2721 0.0024 247.91);
--surface-tertiary-foreground: var(--foreground);
/* Overlay: Used for floating/overlay components (tooltips, popovers, modals, menus) - lighter for contrast */
--overlay: oklch(0.2103 0.0059 285.89);
--overlay-foreground: var(--foreground);
--muted: oklch(70.5% 0.015 286.067);
--scrollbar: var(--scrollbar-thumb);
--scrollbar-thumb: color-mix(in oklch, var(--foreground) 15%, transparent);
--scrollbar-track: transparent;
--scrollbar-gutter: auto;
--scrollbar-width: thin;
--scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
--default: oklch(27.4% 0.006 286.033);
--default-foreground: var(--snow);
/* Form Fields */
--field-background: oklch(0.2103 0.0059 285.89);
--field-foreground: var(--foreground);
--field-placeholder: var(--muted);
/* Status Colors */
--warning: oklch(0.8203 0.1388 76.34);
--warning-foreground: var(--eclipse);
--danger: oklch(0.594 0.1967 24.63);
--danger-foreground: var(--snow);
/* Component Colors */
--segment: oklch(0.3964 0.01 285.93);
--segment-foreground: var(--foreground);
/* Misc Colors */
--border: oklch(28% 0.006 286.033);
--separator: oklch(25% 0.006 286.033);
--focus: var(--accent);
--link: var(--foreground);
/* Backdrop */
--backdrop: rgba(0, 0, 0, 0.6);
/* Shadows */
--surface-shadow: 0 0 0 0 transparent inset; /* No shadow on dark mode */
--overlay-shadow: 0 0 1px 0 rgba(255, 255, 255, 0.3) inset;
--field-shadow: 0 0 0 0 transparent inset; /* Transparent shadow to allow ring utilities to work */
/* Calculated Colors */
--surface-hover: color-mix(
in oklab,
var(--surface) 92%,
var(--surface-foreground) 8%
);
--background-secondary: color-mix(
in oklab,
var(--background) 96%,
var(--foreground) 4%
);
--background-tertiary: color-mix(
in oklab,
var(--background) 92%,
var(--foreground) 8%
);
--background-inverse: var(--foreground);
--default-hover: color-mix(
in oklab,
var(--default) 96%,
var(--default-foreground) 4%
);
--accent-hover: color-mix(
in oklab,
var(--accent) 90%,
var(--accent-foreground) 10%
);
--success-hover: color-mix(
in oklab,
var(--success) 90%,
var(--success-foreground) 10%
);
--warning-hover: color-mix(
in oklab,
var(--warning) 90%,
var(--warning-foreground) 10%
);
--danger-hover: color-mix(
in oklab,
var(--danger) 90%,
var(--danger-foreground) 10%
);
--field-hover: color-mix(
in oklab,
var(--field-background, var(--default)) 90%,
var(--field-foreground, var(--foreground)) 2%
);
--field-focus: var(--field-background, var(--default));
--field-border-hover: color-mix(
in oklab,
var(--field-border, var(--border)) 88%,
var(--field-foreground, var(--foreground)) 10%
);
--field-border-focus: color-mix(
in oklab,
var(--field-border, var(--border)) 74%,
var(--field-foreground, var(--foreground)) 22%
);
--default-soft: color-mix(in oklab, var(--default) 50%, transparent);
--default-soft-foreground: var(--default-foreground);
--default-soft-hover: color-mix(in oklab, var(--default) 60%, transparent);
--accent-soft: color-mix(in oklab, var(--accent) 12%, transparent);
--accent-soft-foreground: color-mix(
in oklab,
var(--accent) 80%,
var(--foreground) 30%
);
--accent-soft-hover: color-mix(in oklab, var(--accent) 16%, transparent);
--danger-soft: color-mix(in oklab, var(--danger) 15%, transparent);
--danger-soft-foreground: color-mix(
in oklab,
var(--danger) 80%,
var(--foreground) 30%
);
--danger-soft-hover: color-mix(in oklab, var(--danger) 20%, transparent);
--warning-soft: color-mix(in oklab, var(--warning) 12%, transparent);
--warning-soft-foreground: color-mix(
in oklab,
var(--warning) 80%,
var(--foreground) 30%
);
--warning-soft-hover: color-mix(in oklab, var(--warning) 16%, transparent);
--success-soft: color-mix(in oklab, var(--success) 12%, transparent);
--success-soft-foreground: color-mix(
in oklab,
var(--success) 80%,
var(--foreground) 30%
);
--success-soft-hover: color-mix(in oklab, var(--success) 16%, transparent);
--separator-secondary: color-mix(
in oklab,
var(--surface) 85%,
var(--surface-foreground) 15%
);
--separator-tertiary: color-mix(
in oklab,
var(--surface) 81%,
var(--surface-foreground) 19%
);
--border-secondary: color-mix(
in oklab,
var(--surface) 78%,
var(--surface-foreground) 22%
);
--border-tertiary: color-mix(
in oklab,
var(--surface) 66%,
var(--surface-foreground) 34%
);
}
/* Vibrant palette - more saturated soft foregrounds, less contrast */
[data-vibrant-palette="true"]:not(.dark):not([data-theme="dark"]) {
--accent-soft-foreground: color-mix(
in oklab,
var(--accent) 92%,
var(--foreground) 8%
);
--danger-soft-foreground: color-mix(
in oklab,
var(--danger) 92%,
var(--foreground) 8%
);
--warning-soft-foreground: color-mix(
in oklab,
var(--warning) 92%,
var(--foreground) 8%
);
--success-soft-foreground: color-mix(
in oklab,
var(--success) 92%,
var(--foreground) 8%
);
}
[data-vibrant-palette="true"].dark,
[data-vibrant-palette="true"][data-theme="dark"] {
--accent-soft-foreground: color-mix(
in oklab,
var(--accent) 92%,
var(--foreground) 8%
);
--danger-soft-foreground: color-mix(
in oklab,
var(--danger) 92%,
var(--foreground) 8%
);
--warning-soft-foreground: color-mix(
in oklab,
var(--warning) 92%,
var(--foreground) 8%
);
--success-soft-foreground: color-mix(
in oklab,
var(--success) 92%,
var(--foreground) 8%
);
}
}
+168
View File
@@ -0,0 +1,168 @@
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-surface: var(--surface);
--color-surface-foreground: var(--surface-foreground);
--color-surface-hover: var(--surface-hover);
--color-surface-secondary: var(--surface-secondary);
--color-surface-secondary-foreground: var(--surface-secondary-foreground);
--color-surface-tertiary: var(--surface-tertiary);
--color-surface-tertiary-foreground: var(--surface-tertiary-foreground);
--color-overlay: var(--overlay);
--color-overlay-foreground: var(--overlay-foreground);
--color-muted: var(--muted);
--color-accent: var(--accent);
--color-accent-foreground: var(--accent-foreground);
--color-segment: var(--segment);
--color-segment-foreground: var(--segment-foreground);
--color-border: var(--border);
--color-separator: var(--separator);
--color-focus: var(--focus);
--color-link: var(--link);
--color-default: var(--default);
--color-default-foreground: var(--default-foreground);
--color-success: var(--success);
--color-success-foreground: var(--success-foreground);
--color-warning: var(--warning);
--color-warning-foreground: var(--warning-foreground);
--color-danger: var(--danger);
--color-danger-foreground: var(--danger-foreground);
--color-backdrop: var(--backdrop);
--shadow-surface: var(--surface-shadow);
--shadow-overlay: var(--overlay-shadow);
--shadow-field: var(--field-shadow);
/* Form Field Tokens */
--color-field: var(--field-background, var(--default));
--color-field-hover: var(--field-hover);
--color-field-foreground: var(--field-foreground, var(--foreground));
--color-field-placeholder: var(--field-placeholder, var(--muted));
--color-field-border: var(--field-border, var(--border));
--radius-field: var(--field-radius, calc(var(--radius) * 1.5));
--border-width-field: var(--field-border-width, var(--border-width));
/* Color Tokens */
--color-background-secondary: var(--background-secondary);
--color-background-tertiary: var(--background-tertiary);
--color-background-inverse: var(--background-inverse);
--color-default-hover: var(--default-hover);
--color-accent-hover: var(--accent-hover);
--color-success-hover: var(--success-hover);
--color-warning-hover: var(--warning-hover);
--color-danger-hover: var(--danger-hover);
/* Form Field Colors */
--color-field-focus: var(--field-focus);
--color-field-border-hover: var(--field-border-hover);
--color-field-border-focus: var(--field-border-focus);
/* Soft Colors */
--color-default-soft: var(--default-soft);
--color-default-soft-foreground: var(--default-soft-foreground);
--color-default-soft-hover: var(--default-soft-hover);
--color-accent-soft: var(--accent-soft);
--color-accent-soft-foreground: var(--accent-soft-foreground);
--color-accent-soft-hover: var(--accent-soft-hover);
--color-danger-soft: var(--danger-soft);
--color-danger-soft-foreground: var(--danger-soft-foreground);
--color-danger-soft-hover: var(--danger-soft-hover);
--color-warning-soft: var(--warning-soft);
--color-warning-soft-foreground: var(--warning-soft-foreground);
--color-warning-soft-hover: var(--warning-soft-hover);
--color-success-soft: var(--success-soft);
--color-success-soft-foreground: var(--success-soft-foreground);
--color-success-soft-hover: var(--success-soft-hover);
/* Separator Colors - Levels */
--color-separator-secondary: var(--separator-secondary);
--color-separator-tertiary: var(--separator-tertiary);
/* Border Colors - Levels */
--color-border-secondary: var(--border-secondary);
--color-border-tertiary: var(--border-tertiary);
/* Radius and default sizes - defaults can change by just changing the --radius */
--radius-xs: calc(var(--radius) * 0.25); /* 0.125rem (2px) */
--radius-sm: calc(var(--radius) * 0.5); /* 0.25rem (4px) */
--radius-md: calc(var(--radius) * 0.75); /* 0.375rem (6px) */
--radius-lg: calc(var(--radius) * 1); /* 0.5rem (8px) */
--radius-xl: calc(var(--radius) * 1.5); /* 0.75rem (12px) */
--radius-2xl: calc(var(--radius) * 2); /* 1rem (16px) */
--radius-3xl: calc(var(--radius) * 3); /* 1.5rem (24px) */
--radius-4xl: calc(var(--radius) * 4); /* 2rem (32px) */
/* Transition Timing Functions */
--ease-smooth: ease; /* same as transition: ease; */
/* These custom curves are made by https://twitter.com/bdc */
/* From smoother to faster */
--ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);
--ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
--ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);
--ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
--ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035);
--ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335);
/* From slower to faster */
--ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
--ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);
--ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
--ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
--ease-out-circ: cubic-bezier(0.075, 0.82, 0.165, 1);
/* Custom smooth-out curve: fast start, smooth stop - Apple style */
--ease-out-fluid: cubic-bezier(0.32, 0.72, 0, 1);
/* From slower to faster */
--ease-in-out-quad: cubic-bezier(0.455, 0.03, 0.515, 0.955);
--ease-in-out-cubic: cubic-bezier(0.645, 0.045, 0.355, 1);
--ease-in-out-quart: cubic-bezier(0.77, 0, 0.175, 1);
--ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);
--ease-in-out-expo: cubic-bezier(1, 0, 0, 1);
--ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86);
/* Linear */
--ease-linear: linear;
/* Animations */
--animate-spin-fast: spin 0.75s linear infinite;
--animate-skeleton: skeleton 2s linear infinite;
--animate-caret-blink: caret-blink 1.2s ease-out infinite;
@keyframes skeleton {
100% {
transform: translateX(200%);
}
}
@keyframes caret-blink {
0%,
70%,
100% {
opacity: 1;
}
20%,
50% {
opacity: 0;
}
}
}
+96
View File
@@ -0,0 +1,96 @@
/* === Focus Ring === */
@utility focus-ring {
@apply ring-2 ring-focus ring-offset-0 ring-offset-background outline-none;
/* Overrides the ring offset from the theme variables */
--tw-ring-offset-width: var(--ring-offset-width);
}
@utility focus-field-ring {
@apply ring-2 ring-focus ring-offset-0 outline-none;
/* No separation - ring sits directly against the element */
--tw-ring-offset-width: 0px;
}
@utility invalid-field-ring {
/* Unfocused: show 1px outline */
@apply outline-1 outline-danger outline-solid;
--tw-ring-offset-width: 3px;
/* Focused: show 2px ring in danger color, remove outline */
&:focus,
&:focus-visible,
&[data-focused="true"],
&[data-focus-visible="true"],
&:focus-within,
&[data-focus-within="true"] {
@apply ring-2 ring-danger ring-offset-0;
--tw-ring-offset-width: 0px;
}
}
@utility no-highlight {
-webkit-tap-highlight-color: transparent;
}
/**
* Widens the pressable area of a control smaller than the 24px minimum target size
* (WCAG 2.5.8) with a transparent centred overlay, leaving its size, its visible content
* and the surrounding layout untouched. The host must establish a containing block
* (`relative` or `absolute`), otherwise the overlay escapes to the nearest one.
*/
@utility touch-target {
&::after {
content: "";
@apply absolute top-1/2 left-1/2 size-6 -translate-x-1/2 -translate-y-1/2;
}
}
/* === Statuses === */
@utility status-focused {
@apply focus-ring;
}
@utility status-focused-field {
@apply focus-field-ring;
}
@utility status-invalid-field {
@apply invalid-field-ring;
}
@utility status-disabled {
opacity: var(--disabled-opacity);
cursor: var(--cursor-disabled);
pointer-events: none;
}
@utility status-pending {
@apply pointer-events-none;
}
/* === Scrollbars (standards-only; apply per scroll slot in component CSS) === */
@utility scrollbar {
scrollbar-width: var(--scrollbar-width);
scrollbar-color: var(--scrollbar-color);
scrollbar-gutter: var(--scrollbar-gutter);
}
@utility scrollbar-thin {
scrollbar-width: thin;
scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
scrollbar-gutter: auto;
}
@utility scrollbar-default {
scrollbar-width: auto;
scrollbar-color: auto;
scrollbar-gutter: auto;
}
/* Direct properties only — does not inherit none to nested scroll slots */
@utility scrollbar-none {
scrollbar-width: none;
scrollbar-color: auto;
scrollbar-gutter: auto;
-ms-overflow-style: none;
}
+106
View File
@@ -0,0 +1,106 @@
/**
* ================================================================================================
* HeroUI Custom Tailwind CSS Variants
* ================================================================================================
*
* Custom variants with intelligent fallback: explicit controls override system preferences.
*
* Usage:
* motion-reduce:opacity-0 - Reduced motion accessibility
* motion-safe:animate-spin - Full motion effects
* dark:bg-gray-900 - Dark mode styles
*
* Priority: Explicit data attributes/classes → System preferences (fallback)
* ================================================================================================
*/
/* -------------------------------------------------------------------------------------------------
* motion-reduce — Minimize animations for accessibility
* Priority: data-reduce-motion="true" → prefers-reduced-motion: reduce
* ------------------------------------------------------------------------------------------------- */
@custom-variant motion-reduce {
/* Explicit: data-reduce-motion="true" on element or ancestor */
&:is([data-reduce-motion="true"], [data-reduce-motion="true"] *) {
@slot;
&::before,
&::after {
@slot;
}
}
/* Fallback: system prefers-reduced-motion setting */
@media (prefers-reduced-motion: reduce) {
&:not(:is([data-reduce-motion="true"], [data-reduce-motion="true"] *)) {
@slot;
&::before,
&::after {
@slot;
}
}
}
}
/* -------------------------------------------------------------------------------------------------
* motion-safe — Enable full animations and transitions
* Priority: data-reduce-motion="false" → prefers-reduced-motion: no-preference
* ------------------------------------------------------------------------------------------------- */
@custom-variant motion-safe {
/* Explicit: data-reduce-motion="false" on element or ancestor */
&:is([data-reduce-motion="false"], [data-reduce-motion="false"] *) {
@slot;
&::before,
&::after {
@slot;
}
}
/* Fallback: system has no motion preference set */
@media (prefers-reduced-motion: no-preference) {
&:not(
:is(
[data-reduce-motion="true"],
[data-reduce-motion="true"] *,
[data-reduce-motion="false"],
[data-reduce-motion="false"] *
)
) {
@slot;
&::before,
&::after {
@slot;
}
}
}
}
/* -------------------------------------------------------------------------------------------------
* dark — Dark mode styles
* Priority: .dark class / data-theme="dark" → prefers-color-scheme: dark
* ------------------------------------------------------------------------------------------------- */
@custom-variant dark {
/* Explicit: .dark class or data-theme="dark" on element or ancestor */
&:is(.dark, .dark *, [data-theme="dark"], [data-theme="dark"] *) {
@slot;
&::before,
&::after {
@slot;
}
}
/* Fallback: system prefers dark color scheme */
@media (prefers-color-scheme: dark) {
&:not(:is(.dark, .dark *, [data-theme="dark"], [data-theme="dark"] *)) & {
@slot;
&::before,
&::after {
@slot;
}
}
}
}
+22
View File
@@ -0,0 +1,22 @@
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
plugins: [
tailwindcss(),
dts({
tsconfigPath: "../../tsconfig.json",
include: ["src"],
entryRoot: "src",
}),
],
build: {
lib: {
entry: { index: "src/index.ts", styles: "styles-entry.ts" },
formats: ["es"],
fileName: (_, name) => `${name}.js`,
cssFileName: "styles",
},
rollupOptions: { external: ["tailwind-variants"] },
},
});
+28
View File
@@ -0,0 +1,28 @@
{
"name": "@heroui-vue/components",
"version": "0.0.1",
"private": true,
"type": "module",
"files": [
"dist"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"sideEffects": false,
"scripts": {
"build": "vite build"
},
"dependencies": {
"@heroui-vue/styles": "workspace:*",
"reka-ui": "^2.11.0"
},
"peerDependencies": {
"vue": "^3.5.0"
}
}
@@ -0,0 +1,93 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { Primitive } from "reka-ui";
import type { ButtonHTMLAttributes } from "vue";
import { buttonVariants, type ButtonVariants } from "@heroui-vue/styles";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
variant?: ButtonVariants["variant"];
size?: ButtonVariants["size"];
fullWidth?: boolean;
isDisabled?: boolean;
isPending?: boolean;
isIconOnly?: boolean;
asChild?: boolean;
disabled?: boolean;
loading?: boolean;
type?: ButtonHTMLAttributes["type"];
}>(),
{ type: "button" },
);
const pending = computed(() => props.isPending || props.loading);
const disabled = computed(() => props.isDisabled || props.disabled);
const hovered = ref(false),
pressed = ref(false),
focused = ref(false),
focusVisible = ref(false);
watch(
[pending, disabled],
([isPending, isDisabled]) => {
if (isPending || isDisabled) {
hovered.value = false;
pressed.value = false;
}
},
{ flush: "sync" },
);
function guard(e: MouseEvent) {
if (pending.value) {
e.preventDefault();
e.stopImmediatePropagation();
}
}
function focus(e: FocusEvent) {
focused.value = true;
focusVisible.value = (e.target as HTMLElement).matches(":focus-visible");
}
</script>
<template>
<Primitive
as="button"
:as-child="asChild"
v-bind="$attrs"
:type="type"
:class="buttonVariants({ variant, size, fullWidth, isIconOnly })"
:disabled="disabled"
:aria-disabled="pending || disabled || undefined"
:aria-busy="pending || undefined"
:data-pending="pending || undefined"
:data-hovered="(!pending && !disabled && hovered) || undefined"
:data-pressed="(!pending && !disabled && pressed) || undefined"
:data-focused="focused || undefined"
:data-focus-visible="focusVisible || undefined"
data-slot="button"
@click.capture="guard"
@pointerenter="hovered = !pending && !disabled"
@pointerleave="
hovered = false;
pressed = false;
"
@pointerdown="pressed = !pending && !disabled"
@pointerup="pressed = false"
@keydown.space="pressed = !pending && !disabled"
@keydown.enter="pressed = !pending && !disabled"
@keyup="pressed = false"
@focus="focus"
@blur="
focused = false;
focusVisible = false;
pressed = false;
"
>
<span v-if="loading && !asChild" class="hv-spinner" aria-hidden="true" />
<slot
:is-pending="Boolean(pending)"
:is-disabled="Boolean(disabled)"
:is-hovered="hovered"
:is-pressed="pressed"
:is-focused="focused"
:is-focus-visible="focusVisible"
/>
</Primitive>
</template>
+16
View File
@@ -0,0 +1,16 @@
<script setup lang="ts">
import { cardVariants, type CardVariants } from "@heroui-vue/styles";
withDefaults(
defineProps<{ variant?: CardVariants["variant"]; as?: string }>(),
{ variant: "default", as: "div" },
);
</script>
<template>
<component
:is="as"
:class="cardVariants({ variant }).base()"
data-slot="card"
>
<slot />
</component>
</template>
@@ -0,0 +1,8 @@
<script setup lang="ts">
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
</script>
<template>
<component :is="as" class="hv-card__content" data-slot="card-content">
<slot />
</component>
</template>
@@ -0,0 +1,8 @@
<script setup lang="ts">
withDefaults(defineProps<{ as?: string }>(), { as: "p" });
</script>
<template>
<component :is="as" class="hv-card__description" data-slot="card-description">
<slot />
</component>
</template>
@@ -0,0 +1,8 @@
<script setup lang="ts">
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
</script>
<template>
<component :is="as" class="hv-card__footer" data-slot="card-footer">
<slot />
</component>
</template>
@@ -0,0 +1,8 @@
<script setup lang="ts">
withDefaults(defineProps<{ as?: string }>(), { as: "div" });
</script>
<template>
<component :is="as" class="hv-card__header" data-slot="card-header">
<slot />
</component>
</template>
@@ -0,0 +1,8 @@
<script setup lang="ts">
withDefaults(defineProps<{ as?: string }>(), { as: "h3" });
</script>
<template>
<component :is="as" class="hv-card__title" data-slot="card-title">
<slot />
</component>
</template>
@@ -0,0 +1,17 @@
<script setup lang="ts">
import { inject, onBeforeUnmount, useId, useAttrs } from "vue";
import { switchKey } from "../switch/context";
const ctx = inject(switchKey, undefined);
const attrs = useAttrs();
const id = String(attrs.id ?? useId());
if (ctx) ctx.descriptionIds.value = [...ctx.descriptionIds.value, id];
onBeforeUnmount(() => {
if (ctx)
ctx.descriptionIds.value = ctx.descriptionIds.value.filter(
(value) => value !== id,
);
});
</script>
<template>
<p :id="id" class="hv-description" data-slot="description"><slot /></p>
</template>
@@ -0,0 +1,73 @@
<script setup lang="ts">
import { inputVariants, type InputVariants } from "@heroui-vue/styles";
import {
computed,
ref,
onMounted,
onBeforeUnmount,
nextTick,
useAttrs,
} from "vue";
defineOptions({ inheritAttrs: false });
const props = defineProps<{
modelValue?: string;
defaultValue?: string;
invalid?: boolean;
variant?: InputVariants["variant"];
fullWidth?: boolean;
type?: string;
}>();
const attrs = useAttrs();
const invalidState = computed(
() =>
props.invalid ||
attrs["aria-invalid"] === true ||
attrs["aria-invalid"] === "true",
);
const emit = defineEmits<{ "update:modelValue": [value: string] }>();
const internal = ref(props.defaultValue ?? "");
const value = computed(() => props.modelValue ?? internal.value);
const element = ref<HTMLInputElement>();
function update(event: Event) {
const next = (event.target as HTMLInputElement).value;
internal.value = next;
emit("update:modelValue", next);
void nextTick(() => {
if (element.value && element.value.value !== value.value)
element.value.value = value.value;
});
}
function reset(event: Event) {
void nextTick(() => {
if (event.defaultPrevented) return;
internal.value = props.defaultValue ?? "";
if (element.value) element.value.value = value.value;
});
}
let form: HTMLFormElement | null = null;
onMounted(() => {
form = element.value?.form ?? null;
form?.addEventListener("reset", reset);
});
onBeforeUnmount(() => form?.removeEventListener("reset", reset));
defineExpose({ focus: () => element.value?.focus(), element });
</script>
<template>
<input
ref="element"
v-bind="$attrs"
:value="value"
:class="inputVariants({ variant, fullWidth })"
:type="type ?? 'text'"
:data-invalid="invalidState || undefined"
:aria-invalid="invalidState || undefined"
:aria-readonly="
$attrs.readonly === '' ||
$attrs.readonly === true ||
$attrs.readOnly === true ||
undefined
"
data-slot="input"
@input="update"
/>
</template>
@@ -0,0 +1,25 @@
<script setup lang="ts">
import { inject, useAttrs } from "vue";
import { switchKey } from "../switch/context";
const ctx = inject(switchKey, undefined);
const attrs = useAttrs();
defineProps<{
isRequired?: boolean;
isDisabled?: boolean;
isInvalid?: boolean;
}>();
</script>
<template>
<component
:is="ctx && !attrs.for ? 'span' : 'label'"
class="hv-label"
:class="{
'hv-label--required': isRequired,
'hv-label--disabled': isDisabled,
'hv-label--invalid': isInvalid,
}"
data-slot="label"
>
<slot />
</component>
</template>
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { inject, onBeforeUnmount, useId } from "vue";
import { switchKey } from "./context";
const ctx = inject(switchKey, undefined);
const id = useId();
if (ctx) ctx.errorIds.value = [...ctx.errorIds.value, id];
onBeforeUnmount(() => {
if (ctx)
ctx.errorIds.value = ctx.errorIds.value.filter((value) => value !== id);
});
</script>
<template>
<p
v-if="!ctx || ctx.invalid.value"
:id="id"
data-slot="field-error"
class="hv-field-error"
role="alert"
>
<slot :validation-errors="ctx?.error.value ? [ctx.error.value] : []">
{{ ctx?.error.value }}
</slot>
</p>
</template>
@@ -0,0 +1,201 @@
<script setup lang="ts">
import {
computed,
provide,
ref,
useId,
useAttrs,
onMounted,
onBeforeUnmount,
nextTick,
watchEffect,
watch,
} from "vue";
import { switchVariants, type SwitchVariants } from "@heroui-vue/styles";
import { Primitive } from "reka-ui";
import { switchKey } from "./context";
import SwitchContent from "./SwitchContent.vue";
import SwitchControl from "./SwitchControl.vue";
import SwitchThumb from "./SwitchThumb.vue";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
checked?: boolean;
isSelected?: boolean;
defaultChecked?: boolean;
defaultSelected?: boolean;
isDisabled?: boolean;
disabled?: boolean;
isReadOnly?: boolean;
isInvalid?: boolean;
isRequired?: boolean;
required?: boolean;
name?: string;
value?: string;
id?: string;
size?: SwitchVariants["size"];
asChild?: boolean;
validate?: (value: boolean) => string | string[] | true | null | undefined;
validationBehavior?: "native" | "aria";
}>(),
{
checked: undefined,
isSelected: undefined,
defaultChecked: undefined,
defaultSelected: undefined,
},
);
const emit = defineEmits<{
"update:checked": [value: boolean];
"update:isSelected": [value: boolean];
change: [value: boolean];
}>();
const attrs = useAttrs();
const rootAttrs = () =>
Object.fromEntries(
Object.entries(attrs).filter(
([key]) => key === "class" || key === "style" || key.startsWith("data-"),
),
);
const controlAttrs = () =>
Object.fromEntries(
Object.entries(attrs).filter(
([key]) => key !== "class" && key !== "style" && !key.startsWith("data-"),
),
);
const initial = props.defaultSelected ?? props.defaultChecked ?? false;
const internal = ref(initial);
const element = computed(
() => input.value?.previousElementSibling as HTMLElement | undefined,
);
const input = ref<HTMLInputElement>();
const hovered = ref(false),
pressed = ref(false),
focusVisible = ref(false);
const error = ref("");
const showError = ref(false);
const checked = computed(
() => props.isSelected ?? props.checked ?? internal.value,
);
const disabled = computed(() => props.isDisabled || props.disabled);
const readOnly = computed(() => props.isReadOnly);
const required = computed(() => props.isRequired || props.required);
const invalid = computed(
() => props.isInvalid || (showError.value && Boolean(error.value)),
);
const generated = useId();
const descriptionIds = ref<string[]>([]);
const errorIds = ref<string[]>([]);
function update(value: boolean) {
if (disabled.value || readOnly.value) return;
internal.value = value;
emit("update:checked", value);
emit("update:isSelected", value);
emit("change", value);
}
watch([disabled, readOnly], () => {
hovered.value = false;
pressed.value = false;
});
provide(switchKey, {
hovered,
pressed,
focusVisible,
descriptionIds,
errorIds,
error,
controlAttrs,
checked,
disabled,
readOnly,
required,
invalid,
id: computed(() => props.id ?? generated),
update,
});
watchEffect(() => {
const result = props.validate?.(checked.value);
error.value =
typeof result === "string"
? result
: Array.isArray(result)
? result.join(" ")
: required.value && !checked.value
? "请开启此选项。"
: "";
if (props.validationBehavior === "aria") showError.value = true;
input.value?.setCustomValidity(
props.validationBehavior === "aria" || disabled.value || readOnly.value
? ""
: error.value,
);
});
function onInvalid(event: Event) {
event.preventDefault();
showError.value = true;
element.value?.querySelector<HTMLButtonElement>("[role=switch]")?.focus();
}
function reset(event: Event) {
void nextTick(() => {
if (event.defaultPrevented) return;
internal.value = initial;
showError.value = false;
if (input.value) input.value.checked = checked.value;
});
}
let form: HTMLFormElement | null = null;
onMounted(() => {
form = input.value?.form ?? null;
form?.addEventListener("reset", reset);
});
onBeforeUnmount(() => form?.removeEventListener("reset", reset));
defineExpose({
focus: () =>
element.value?.querySelector<HTMLButtonElement>("[role=switch]")?.focus(),
});
</script>
<template>
<Primitive
as="div"
:as-child="asChild"
v-bind="rootAttrs()"
:class="switchVariants({ size }).base()"
:data-selected="checked"
:data-disabled="disabled || undefined"
:data-readonly="readOnly || undefined"
:data-invalid="invalid || undefined"
:data-required="required || undefined"
data-slot="switch"
>
<slot
:is-selected="checked"
:is-disabled="Boolean(disabled)"
:is-read-only="Boolean(readOnly)"
:is-invalid="Boolean(invalid)"
:is-required="Boolean(required)"
:state="{
isSelected: checked,
setSelected: update,
toggle: () => update(!checked),
}"
>
<SwitchContent>
<SwitchControl><SwitchThumb /></SwitchControl>
</SwitchContent>
</slot>
</Primitive>
<input
ref="input"
class="hv-switch__input"
type="checkbox"
tabindex="-1"
aria-hidden="true"
:name="name"
:value="value ?? 'on'"
:checked="checked"
:disabled="disabled"
:required="required && !readOnly && validationBehavior !== 'aria'"
@invalid="onInvalid"
@change="update(($event.target as HTMLInputElement).checked)"
/>
</template>
@@ -0,0 +1,71 @@
<script setup lang="ts">
import { inject } from "vue";
import { SwitchRoot } from "reka-ui";
import { switchKey } from "./context";
const ctx = inject(switchKey);
if (!ctx) throw new Error("SwitchContent must be inside Switch");
function guard(event: Event) {
if (ctx?.readOnly.value) {
event.preventDefault();
event.stopImmediatePropagation();
}
}
</script>
<template>
<SwitchRoot
:id="ctx.id.value"
v-bind="ctx.controlAttrs()"
class="hv-switch__content"
data-slot="switch-content"
:model-value="ctx.checked.value"
:disabled="ctx.disabled.value"
:aria-required="ctx.required.value || undefined"
:aria-describedby="
[
ctx.controlAttrs()['aria-describedby'],
...ctx.descriptionIds.value,
...(ctx.invalid.value ? ctx.errorIds.value : []),
]
.filter(Boolean)
.join(' ') || undefined
"
:aria-readonly="ctx.readOnly.value || undefined"
:aria-invalid="ctx.invalid.value || undefined"
:data-hovered="ctx.hovered.value || undefined"
:data-pressed="ctx.pressed.value || undefined"
:data-focus-visible="ctx.focusVisible.value || undefined"
@pointerenter="ctx.hovered.value = !ctx.disabled.value"
@pointerleave="
ctx.hovered.value = false;
ctx.pressed.value = false;
"
@pointerdown="
ctx.pressed.value = !ctx.disabled.value && !ctx.readOnly.value
"
@pointerup="ctx.pressed.value = false"
@focus="
ctx.focusVisible.value = ($event.target as HTMLElement).matches(
':focus-visible',
)
"
@blur="
ctx.focusVisible.value = false;
ctx.pressed.value = false;
"
@keydown.space="
ctx.pressed.value = !ctx.disabled.value && !ctx.readOnly.value
"
@keyup="ctx.pressed.value = false"
@click.capture="guard"
@keydown.enter.capture="guard"
@keydown.space.capture="guard"
@update:model-value="ctx.update"
>
<slot
:is-selected="ctx.checked.value"
:is-hovered="ctx.hovered.value"
:is-pressed="ctx.pressed.value"
:is-focus-visible="ctx.focusVisible.value"
/>
</SwitchRoot>
</template>
@@ -0,0 +1,16 @@
<script setup lang="ts">
import { inject } from "vue";
import { switchKey } from "./context";
const ctx = inject(switchKey);
if (!ctx) throw new Error("SwitchControl must be inside Switch");
</script>
<template>
<span class="hv-switch__control" data-slot="switch-control">
<slot
:is-selected="ctx.checked.value"
:is-hovered="ctx.hovered.value"
:is-pressed="ctx.pressed.value"
:is-focus-visible="ctx.focusVisible.value"
/>
</span>
</template>
@@ -0,0 +1,17 @@
<script setup lang="ts">
withDefaults(defineProps<{ orientation?: "horizontal" | "vertical" }>(), {
orientation: "vertical",
});
</script>
<template>
<div
role="group"
class="hv-switch-group"
:class="`hv-switch-group--${orientation}`"
data-slot="switch-group"
>
<div class="hv-switch-group__items" data-slot="switch-group-items">
<slot />
</div>
</div>
</template>
@@ -0,0 +1,3 @@
<template>
<span class="hv-switch__icon" data-slot="switch-icon"><slot /></span>
</template>
@@ -0,0 +1,3 @@
<template>
<span class="hv-switch__thumb" data-slot="switch-thumb"><slot /></span>
</template>
@@ -0,0 +1,19 @@
import type { ComputedRef, InjectionKey, Ref } from "vue";
export interface SwitchContext {
hovered: Ref<boolean>;
pressed: Ref<boolean>;
focusVisible: Ref<boolean>;
checked: ComputedRef<boolean>;
disabled: ComputedRef<boolean>;
readOnly: ComputedRef<boolean>;
required: ComputedRef<boolean>;
invalid: ComputedRef<boolean>;
descriptionIds: Ref<string[]>;
errorIds: Ref<string[]>;
error: Ref<string>;
controlAttrs: () => Record<string, unknown>;
id: ComputedRef<string>;
update: (value: boolean) => void;
}
export const switchKey: InjectionKey<SwitchContext> =
Symbol("HeroUIVue.Switch");
+38
View File
@@ -0,0 +1,38 @@
export { default as Button } from "./components/button/Button.vue";
export { default as Card } from "./components/card/Card.vue";
export { default as Input } from "./components/input/Input.vue";
export { default as Switch } from "./components/switch/Switch.vue";
export { default as CardHeader } from "./components/card/CardHeader.vue";
export { default as CardTitle } from "./components/card/CardTitle.vue";
export { default as CardDescription } from "./components/card/CardDescription.vue";
export { default as CardContent } from "./components/card/CardContent.vue";
export { default as CardFooter } from "./components/card/CardFooter.vue";
export { default as SwitchContent } from "./components/switch/SwitchContent.vue";
export { default as SwitchControl } from "./components/switch/SwitchControl.vue";
export { default as SwitchThumb } from "./components/switch/SwitchThumb.vue";
export { default as SwitchIcon } from "./components/switch/SwitchIcon.vue";
export { default as Label } from "./components/label/Label.vue";
export { default as Description } from "./components/description/Description.vue";
export {
buttonVariants,
cardVariants,
inputVariants,
switchVariants,
type ButtonVariants,
type CardVariants,
type InputVariants,
type SwitchVariants,
} from "@heroui-vue/styles";
export type {
ButtonProps,
CardProps,
InputProps,
SwitchProps,
SwitchGroupProps,
LabelProps,
} from "./types";
export { tv, cn, type VariantProps } from "@heroui-vue/styles";
export { default as SwitchGroup } from "./components/switch/SwitchGroup.vue";
export { default as FieldError } from "./components/switch/FieldError.vue";
+14
View File
@@ -0,0 +1,14 @@
import type Button from "./components/button/Button.vue";
import type Card from "./components/card/Card.vue";
import type Input from "./components/input/Input.vue";
import type Switch from "./components/switch/Switch.vue";
export type ButtonProps = InstanceType<typeof Button>["$props"];
export type CardProps = InstanceType<typeof Card>["$props"];
export type InputProps = InstanceType<typeof Input>["$props"];
export type SwitchProps = InstanceType<typeof Switch>["$props"];
import type SwitchGroup from "./components/switch/SwitchGroup.vue";
import type Label from "./components/label/Label.vue";
export type SwitchGroupProps = InstanceType<typeof SwitchGroup>["$props"];
export type LabelProps = InstanceType<typeof Label>["$props"];
+18
View File
@@ -0,0 +1,18 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import dts from "vite-plugin-dts";
export default defineConfig({
plugins: [
vue(),
dts({
tsconfigPath: "../../tsconfig.json",
include: ["src"],
entryRoot: "src",
aliasesExclude: ["@heroui-vue/styles"],
}),
],
build: {
lib: { entry: "src/index.ts", formats: ["es"], fileName: "index" },
rollupOptions: { external: ["vue", "reka-ui", "@heroui-vue/styles"] },
},
});