feat: add Fieldset and SearchField infrastructure
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
/* Adapted from HeroUI v3 ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
/* Base component styles */
|
||||
.hv-fieldset {
|
||||
@apply flex flex-col gap-6;
|
||||
/* fix flexbox issue in Safari when fieldset with legend is inside a flexbox */
|
||||
@apply shrink grow basis-0;
|
||||
}
|
||||
|
||||
.hv-fieldset__legend {
|
||||
@apply text-base font-medium text-foreground;
|
||||
}
|
||||
|
||||
.hv-fieldset__field-group {
|
||||
@apply w-full space-y-4;
|
||||
}
|
||||
|
||||
.hv-fieldset__actions {
|
||||
@apply flex items-center gap-2 pt-1;
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/* Adapted from HeroUI v3 ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
/* Search field styles */
|
||||
.hv-search-field {
|
||||
@apply flex flex-col gap-1;
|
||||
|
||||
&[data-invalid="true"],
|
||||
&[aria-invalid="true"] {
|
||||
[data-slot="description"] {
|
||||
@apply hidden;
|
||||
}
|
||||
}
|
||||
|
||||
[data-slot="label"] {
|
||||
@apply w-fit;
|
||||
}
|
||||
|
||||
&[data-empty="true"] {
|
||||
[data-slot="search-field-clear-button"] {
|
||||
@apply pointer-events-none opacity-0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hv-search-field__group {
|
||||
@apply relative inline-flex h-9 items-center overflow-hidden rounded-field border bg-field text-sm text-field-foreground shadow-field outline-none;
|
||||
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;
|
||||
|
||||
/* Hover state */
|
||||
@media (hover: hover) {
|
||||
&:hover:not(:focus-within),
|
||||
&[data-hovered="true"]:not([data-focus-within="true"]) {
|
||||
@apply bg-field-hover;
|
||||
border-color: var(--field-border-hover);
|
||||
}
|
||||
}
|
||||
|
||||
/* Focus within state */
|
||||
&[data-focus-within="true"],
|
||||
&:focus-within {
|
||||
@apply status-focused-field;
|
||||
}
|
||||
|
||||
/* Invalid state */
|
||||
&[data-invalid="true"] {
|
||||
@apply status-invalid-field;
|
||||
background-color: var(--field-focus);
|
||||
border-color: var(--color-field-border-invalid);
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&[data-disabled="true"],
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browser autofill state.
|
||||
* The user-agent paints `:-webkit-autofill`/`:autofill` on the inner <input>
|
||||
* only. Because the input has its border-radius stripped on whichever side
|
||||
* touches the search icon or clear button, the autofill highlight ends up
|
||||
* as a sharp-cornered rectangle and the sibling slots receive no highlight.
|
||||
* Lift the highlight onto the group so the rounded shell + icon + clear
|
||||
* button all share it.
|
||||
*/
|
||||
&:has([data-slot="search-field-input"]:-webkit-autofill),
|
||||
&:has([data-slot="search-field-input"]:autofill) {
|
||||
background-color: var(--field-focus);
|
||||
border-color: var(--field-border-focus);
|
||||
}
|
||||
}
|
||||
|
||||
.hv-search-field__input {
|
||||
@apply flex-1 rounded-none border-0 bg-transparent px-3 py-2 text-base shadow-none outline-none sm:text-sm;
|
||||
|
||||
/* Hide browser default search clear button */
|
||||
&::-webkit-search-cancel-button,
|
||||
&::-webkit-search-decoration {
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
/* Remove border radius on left side when search icon is present */
|
||||
.hv-search-field__group:has([data-slot="search-field-search-icon"]) & {
|
||||
@apply rounded-s-none ps-2;
|
||||
}
|
||||
|
||||
/* Remove border radius on right side when clear button is present */
|
||||
.hv-search-field__group:has([slot="clear"]) & {
|
||||
@apply rounded-e-none pe-2;
|
||||
}
|
||||
|
||||
/* Focus state - handled by group */
|
||||
&:focus,
|
||||
&:focus-visible {
|
||||
@apply outline-none;
|
||||
}
|
||||
|
||||
/**
|
||||
* Neutralize the browser's per-input autofill paint so the inner <input>
|
||||
* doesn't draw a sharp-cornered yellow rectangle. The unified highlight
|
||||
* is applied to `.hv-search-field__group` above. Preserve the autofilled
|
||||
* text and caret colors, and pin the background-color transition so the
|
||||
* inset box-shadow trick doesn't flicker on state changes.
|
||||
*/
|
||||
&:-webkit-autofill,
|
||||
&:-webkit-autofill:hover,
|
||||
&:-webkit-autofill:focus,
|
||||
&:-webkit-autofill:active,
|
||||
&:autofill {
|
||||
-webkit-box-shadow: 0 0 0 1000px transparent inset;
|
||||
box-shadow: 0 0 0 1000px transparent inset;
|
||||
-webkit-text-fill-color: var(--field-foreground);
|
||||
caret-color: var(--field-foreground);
|
||||
transition: background-color 9999s ease-in-out 0s;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-search-field__search-icon {
|
||||
@apply pointer-events-none shrink-0 text-field-placeholder;
|
||||
@apply ms-3 me-0 size-4;
|
||||
}
|
||||
|
||||
.hv-search-field__clear-button {
|
||||
@apply me-2 size-5 shrink-0;
|
||||
|
||||
/* Overrides close button default icon size from 16px to 12px */
|
||||
[data-slot="close-button-icon"] {
|
||||
@apply size-3;
|
||||
}
|
||||
}
|
||||
|
||||
/* Variant property definitions */
|
||||
.hv-search-field--primary {
|
||||
/* Default styles */
|
||||
}
|
||||
|
||||
.hv-search-field--secondary .hv-search-field__group {
|
||||
@apply shadow-none;
|
||||
background-color: var(--search-field-group-bg);
|
||||
|
||||
--search-field-group-bg: var(--default);
|
||||
--search-field-group-bg-hover: var(--default-hover);
|
||||
--search-field-group-bg-focus: var(--default);
|
||||
|
||||
@media (hover: hover) {
|
||||
&:hover:not(:focus-within),
|
||||
&[data-hovered="true"]:not([data-focus-within="true"]) {
|
||||
background-color: var(--search-field-group-bg-hover);
|
||||
}
|
||||
}
|
||||
|
||||
&:focus-within,
|
||||
&[data-focus-within="true"] {
|
||||
background-color: var(--search-field-group-bg-focus);
|
||||
}
|
||||
|
||||
/* Invalid state */
|
||||
&[data-invalid="true"] {
|
||||
@apply status-invalid-field;
|
||||
border-color: var(--color-field-border-invalid);
|
||||
background-color: var(--search-field-group-bg-focus);
|
||||
}
|
||||
|
||||
[data-slot="search-field-input"] {
|
||||
@apply bg-transparent;
|
||||
}
|
||||
}
|
||||
|
||||
/* Full width modifier */
|
||||
.hv-search-field--full-width {
|
||||
@apply w-full;
|
||||
}
|
||||
|
||||
.hv-search-field__group--full-width {
|
||||
@apply w-full;
|
||||
}
|
||||
@@ -60,3 +60,20 @@
|
||||
|
||||
@import "./components/textfield.css";
|
||||
@import "./components/field-error.css";
|
||||
|
||||
@import "./components/fieldset.css" layer(components);
|
||||
|
||||
@import "./components/search-field.css" layer(components);
|
||||
|
||||
/* Vue disabled scopes preserve native first-legend semantics. A label in the
|
||||
* exempt legend must not pick up the baseline blanket ancestor opacity rule.
|
||||
* Local and outer disabled labels still carry hv-label--disabled. */
|
||||
@layer components {
|
||||
.hv-fieldset[data-disabled="true"]
|
||||
> legend
|
||||
.hv-label:not(.hv-label--disabled) {
|
||||
opacity: 1;
|
||||
cursor: inherit;
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,3 +529,48 @@ export const inputGroupVariants = tv({
|
||||
});
|
||||
|
||||
export type InputGroupVariants = VariantProps<typeof inputGroupVariants>;
|
||||
|
||||
export const fieldsetVariants = tv({
|
||||
slots: {
|
||||
actions: "hv-fieldset__actions",
|
||||
base: "hv-fieldset",
|
||||
description: "hv-fieldset__description",
|
||||
fieldGroup: "hv-fieldset__field-group",
|
||||
legend: "hv-fieldset__legend",
|
||||
},
|
||||
});
|
||||
|
||||
export type FieldsetVariants = VariantProps<typeof fieldsetVariants>;
|
||||
|
||||
export const searchFieldVariants = tv({
|
||||
defaultVariants: {
|
||||
fullWidth: false,
|
||||
variant: "primary",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-search-field",
|
||||
clearButton: "hv-search-field__clear-button",
|
||||
group: "hv-search-field__group",
|
||||
input: "hv-search-field__input",
|
||||
searchIcon: "hv-search-field__search-icon",
|
||||
},
|
||||
variants: {
|
||||
fullWidth: {
|
||||
false: {},
|
||||
true: {
|
||||
base: "hv-search-field--full-width",
|
||||
group: "hv-search-field__group--full-width",
|
||||
},
|
||||
},
|
||||
variant: {
|
||||
primary: {
|
||||
base: "hv-search-field--primary",
|
||||
},
|
||||
secondary: {
|
||||
base: "hv-search-field--secondary",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type SearchFieldVariants = VariantProps<typeof searchFieldVariants>;
|
||||
|
||||
Reference in New Issue
Block a user