diff --git a/src/runtime/components/Tree.vue b/src/runtime/components/Tree.vue index ebef2f61a7..94f59c9187 100644 --- a/src/runtime/components/Tree.vue +++ b/src/runtime/components/Tree.vue @@ -25,11 +25,11 @@ export type TreeItem = { onToggle?(e: Event): void onSelect?(e?: Event): void class?: any - ui?: Pick + ui?: Pick [key: string]: any } -export interface TreeProps = 'value', M extends boolean = false> extends Pick, 'expanded' | 'defaultExpanded' | 'selectionBehavior' | 'propagateSelect' | 'disabled' | 'bubbleSelect'> { +export interface TreeProps = 'value', M extends boolean = false> extends Pick, 'expanded' | 'defaultExpanded' | 'selectionBehavior' | 'propagateSelect' | 'disabled' | 'bubbleSelect'> { /** * The element or component this component should render as. * @defaultValue 'ul' @@ -52,7 +52,7 @@ export interface TreeProps + labelKey?: keyof T /** * The icon displayed on the right side of a parent node. * @defaultValue appConfig.ui.icons.chevronDown @@ -71,7 +71,7 @@ export interface TreeProps /** The value of the Tree when initially rendered. Use when you do not need to control the state of the Tree. */ @@ -79,16 +79,18 @@ export interface TreeProps> + indent?: Partial> ui?: Tree['slots'] } -export type TreeEmits | undefined, M extends boolean> = Omit & GetModelValueEmits +export type TreeEmits | undefined, M extends boolean> = Omit & GetModelValueEmits -type SlotProps = (props: { item: T, index: number, level: number, expanded: boolean, selected: boolean }) => any +type SlotProps = (props: { item: NestedItem, index: number, level: number, expanded: boolean, selected: boolean }) => any export type TreeSlots< - A extends TreeItem[] = TreeItem[], - T extends NestedItem = NestedItem + A extends TreeItem = TreeItem, + T extends NestedItem = NestedItem > = { 'item-wrapper': SlotProps 'item': SlotProps @@ -99,10 +101,10 @@ export type TreeSlots< - - diff --git a/src/theme/tree.ts b/src/theme/tree.ts index 2a07534cbb..f0fd60eec4 100644 --- a/src/theme/tree.ts +++ b/src/theme/tree.ts @@ -3,11 +3,11 @@ import type { ModuleOptions } from '../module' export default (options: Required) => ({ slots: { root: 'relative isolate', - item: '', - listWithChildren: 'ms-4.5 border-s border-default', - itemWithChildren: 'ps-1.5 -ms-px', + item: 'relative', + itemWithChildren: 'relative ps-[calc(var(--level)*calc(var(--indent)+0.25em))]', link: 'relative group w-full flex items-center text-sm before:absolute before:inset-y-px before:inset-x-0 before:z-[-1] before:rounded-md focus:outline-none focus-visible:outline-none focus-visible:before:ring-inset focus-visible:before:ring-2', linkLeadingIcon: 'shrink-0', + connector: 'relative before:absolute before:content-[\'\'] before:top-0 before:bottom-0 before:left-[var(--line-offset)] before:pointer-events-none before:w-[calc(var(--level)*(var(--indent)+0.25em))] before:bg-[repeating-linear-gradient(to_right,transparent,transparent_calc(50%-0.5px),var(--ui-border)_calc(50%-0.5px),var(--ui-border)_calc(50%+0.5px),transparent_calc(50%+0.5px))] before:bg-[size:calc(var(--indent)+0.25em)_100%]', linkLabel: 'truncate', linkTrailing: 'ms-auto inline-flex gap-1.5 items-center', linkTrailingIcon: 'shrink-0 transform transition-transform duration-200 group-data-expanded:rotate-180' @@ -36,16 +36,19 @@ export default (options: Required) => ({ link: 'px-2.5 py-1.5 text-sm gap-1.5', linkLeadingIcon: 'size-5', linkTrailingIcon: 'size-5' + }, lg: { link: 'px-3 py-2 text-sm gap-2', linkLeadingIcon: 'size-5', linkTrailingIcon: 'size-5' + }, xl: { link: 'px-3 py-2 text-base gap-2', linkLeadingIcon: 'size-6', linkTrailingIcon: 'size-6' + } }, selected: { diff --git a/test/components/__snapshots__/Tree-vue.spec.ts.snap b/test/components/__snapshots__/Tree-vue.spec.ts.snap index 83c03b4162..f49cf7784c 100644 --- a/test/components/__snapshots__/Tree-vue.spec.ts.snap +++ b/test/components/__snapshots__/Tree-vue.spec.ts.snap @@ -2,534 +2,350 @@ exports[`Tree > renders with as correctly 1`] = ` "
-
  • - -
  • -
  • - -
  • -
  • - -
  • +
  • +
  • +
  • " `; exports[`Tree > renders with class correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with collapsedIcon correctly 1`] = ` "
      -
    • - -
    • +
    " `; exports[`Tree > renders with default slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with defaultExpanded correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with defaultValue correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with defautExpanded item correctly 1`] = ` "
      -
    • -
        -
      • - -
      • -
      • - -
      • -
      • - -
      • -
      -
    • +
    • +
    • +
    • +
    " `; exports[`Tree > renders with disabled correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with disabled item correctly 1`] = ` "
      -
    • - -
    • +
    " `; exports[`Tree > renders with dynamic slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with expanded correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with expandedIcon correctly 1`] = ` "
      -
    • -
        -
      • - -
      • -
      • - -
      • -
      • - -
      • -
      -
    • +
    • +
    • +
    • +
    " `; exports[`Tree > renders with item slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with item-leading slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with item-trailing slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with item-wrapper slot correctly 1`] = ` "
      -
    • - -
    • -
    • wrapper slot - -
    • -
    • wrapper slot - -
    • +
    • +
    • wrapper slot
    • +
    • wrapper slot
    " `; exports[`Tree > renders with items correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with labelKey correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with modelValue correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with multiple and defaultValue correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with multiple and modelValue correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with multiple correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with neutral color correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size lg correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size md correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size sm correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size xl correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size xs correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with trailingIcon correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with ui correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with valueKey correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; diff --git a/test/components/__snapshots__/Tree.spec.ts.snap b/test/components/__snapshots__/Tree.spec.ts.snap index 4c44d639d7..35f36274b8 100644 --- a/test/components/__snapshots__/Tree.spec.ts.snap +++ b/test/components/__snapshots__/Tree.spec.ts.snap @@ -2,534 +2,350 @@ exports[`Tree > renders with as correctly 1`] = ` "
    -
  • - -
  • -
  • - -
  • -
  • - -
  • +
  • +
  • +
  • " `; exports[`Tree > renders with class correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with collapsedIcon correctly 1`] = ` "
      -
    • - -
    • +
    " `; exports[`Tree > renders with default slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with defaultExpanded correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with defaultValue correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with defautExpanded item correctly 1`] = ` "
      -
    • -
        -
      • - -
      • -
      • - -
      • -
      • - -
      • -
      -
    • +
    • +
    • +
    • +
    " `; exports[`Tree > renders with disabled correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with disabled item correctly 1`] = ` "
      -
    • - -
    • +
    " `; exports[`Tree > renders with dynamic slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with expanded correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with expandedIcon correctly 1`] = ` "
      -
    • -
        -
      • - -
      • -
      • - -
      • -
      • - -
      • -
      -
    • +
    • +
    • +
    • +
    " `; exports[`Tree > renders with item slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with item-leading slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with item-trailing slot correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with item-wrapper slot correctly 1`] = ` "
      -
    • - -
    • -
    • wrapper slot - -
    • -
    • wrapper slot - -
    • +
    • +
    • wrapper slot
    • +
    • wrapper slot
    " `; exports[`Tree > renders with items correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with labelKey correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with modelValue correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with multiple and defaultValue correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with multiple and modelValue correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with multiple correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with neutral color correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size lg correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size md correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size sm correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size xl correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with size xs correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with trailingIcon correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with ui correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `; exports[`Tree > renders with valueKey correctly 1`] = ` "
      -
    • - -
    • -
    • - -
    • -
    • - -
    • +
    • +
    • +
    " `;