Skip to content

Build your personal knowledge base with Trilium Notes

4.1 KB
Raw Blame
:where(:root) {
    --sortable-grip-color: var(--muted-text-color);
    --sortable-grip-hover-color: var(--main-text-color);
    --sortable-selected-color: var(--main-text-color);
    /* Above and below, so a dragged segment reads as raised. The lower one is heavier. */
    --sortable-dragging-shadow: 0 -3px 8px rgba(0, 0, 0, 0.3),
                                                            0 5px 8px rgba(0, 0, 0, 0.3);
    /* Enough to read as lifted without washing out the text. */
    --sortable-dragging-opacity: 0.90;
}

.tn-card.tn-sortable-card {
    .tn-sortable-list {
        display: flex;
        /* Must be the dragged segment's offsetParent: it is positioned against this. */
        position: relative;
        flex-direction: column;
        gap: var(--card-section-gap);
    }

    .tn-sortable-segment {
        display: flex;
        align-items: center;
        gap: 0.5em;
        /* useFlip transforms a segment back for one frame and lets this transition carry it to its
              new position. Must match FLIP_DURATION_MS. */
        transition: transform 200ms ease;
    }

    /* A touch drags from anywhere on the segment, and a press that long raises the iOS callout and
          magnifier. Not applied to a mouse, which drags by the grip and can select the caption. */
    @media (pointer: coarse) {
        .tn-sortable-segment {
            -webkit-touch-callout: none;
            user-select: none;
        }
    }

    .tn-sortable-segment:focus-visible {
        outline: 2px solid var(--sortable-selected-color);
        outline-offset: -2px;
    }

    /* Inset, so a selected segment takes no more room than the rest. Painted only while an entry
          has the focus, not the creation row and not once the focus leaves the card. */
    .tn-sortable-list:has(.tn-sortable-segment:focus-within) .tn-sortable-selected {
        box-shadow: inset 0 0 0 1px var(--sortable-selected-color);
    }

    .tn-sortable-content {
        display: flex;
        flex-grow: 1;
        align-items: center;
        gap: 0.5em;
        min-width: 0;
    }

    .tn-sortable-caption {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .tn-sortable-grip {
        display: flex;
        flex-shrink: 0;
        align-items: center;
        padding: 0.2em 0.1em;
        color: var(--sortable-grip-color);
        cursor: grab;
        /* The page still scrolls from here. A drag is what calls preventDefault on touchmove. */
        touch-action: pan-y;
        -webkit-touch-callout: none;
        user-select: none;

        & svg {
            width: 1.1em;
            height: 1.1em;
            stroke: currentColor;
            stroke-width: 1.5;
            stroke-linecap: round;
        }

        &:hover {
            color: var(--sortable-grip-hover-color);
        }
    }

    /* A touch target wider than the icon. The negative margin cancels the padding, so the segment
          keeps its height. */
    @media (pointer: coarse) {
        .tn-sortable-grip {
            margin-block: -0.5em;
            margin-inline-end: calc(var(--card-padding-inline) / -2);
            padding: 0.7em calc(var(--card-padding-inline) / 2);
        }

        /* Placed first, the grip extends into the leading padding instead. */
        .tn-sortable-grip:first-child {
            margin-inline-start: calc(var(--card-padding-inline) / -2);
            margin-inline-end: 0;
        }
    }

    /* Follows the pointer directly: the sliding transition would leave it a frame behind. */
    .tn-sortable-dragging {
        z-index: 1;
        box-shadow: var(--sortable-dragging-shadow);
        opacity: var(--sortable-dragging-opacity);
        transition: none;

        & .tn-sortable-grip {
            cursor: grabbing;
        }
    }

    .tn-sortable-appearing {
        animation: tn-sortable-appear 400ms ease-out;
    }
}

@keyframes tn-sortable-appear {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .tn-card.tn-sortable-card .tn-sortable-segment {
        transition: none;
    }

    .tn-card.tn-sortable-card .tn-sortable-appearing {
        animation: none;
    }
}