Skip to content

The Open Standard for Generative UI

15.3 KB
Raw Blame
@use "../../cssUtils" as cssUtils;

$sidebar-width: 272px;
$sidebar-padding-y: cssUtils.$space-m-l;
$sidebar-padding-x: cssUtils.$space-m;
$sidebar-header-inline-offset: 0px;
$sidebar-collapsed-control-size: 32px;
// Expanded nav rows (New Chat) run a step smaller than the rail's buttons, to
// match the 12px nav type.
$sidebar-nav-row-height: 28px;
$sidebar-nav-icon-size: 14px;
$sidebar-logo-size: 30px;
$sidebar-collapsed-padding-x: 18px;
$sidebar-collapsed-mark-width: 36px;
$sidebar-collapsed-width: calc(
  #{$sidebar-collapsed-control-size} + #{$sidebar-collapsed-padding-x} +
    #{$sidebar-collapsed-padding-x} + #{$sidebar-header-inline-offset}
);
$sidebar-mobile-width: 294px;
$sidebar-mobile-padding-y: cssUtils.$space-l;
$sidebar-mobile-padding-x: cssUtils.$space-000;
$sidebar-fade-duration: 90ms;
$sidebar-resize-duration: 160ms;
$sidebar-mobile-slide-duration: 400ms;
$sidebar-motion-ease: cubic-bezier(0.22, 1, 0.36, 1);
// The brand and toggle cross-fade a touch slower than the body text so the
// swap between mascot and wordmark reads as one move, not a blink.
$sidebar-header-fade-duration: 140ms;

.openui-agent-sidebar-container {
  position: relative;
  height: 100%;
  // Set by SidebarResizeEdge when the edge is dragged.
  width: var(--openui-agent-sidebar-width, #{$sidebar-width});
  padding: $sidebar-padding-y $sidebar-padding-x;
  display: flex;
  flex-direction: column;
  gap: cssUtils.$space-2xl;
  // Sits directly on the shell surface; the thread card provides the edge.
  background-color: transparent;
  z-index: 999;
  transition:
    width $sidebar-resize-duration $sidebar-motion-ease,
    height $sidebar-resize-duration $sidebar-motion-ease,
    transform $sidebar-resize-duration $sidebar-motion-ease,
    background-color $sidebar-resize-duration $sidebar-motion-ease,
    box-shadow $sidebar-resize-duration $sidebar-motion-ease;

  .openui-agent-container--mobile & {
    width: $sidebar-mobile-width;
    padding: $sidebar-mobile-padding-y $sidebar-mobile-padding-x;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 1000;
    background-color: cssUtils.$foreground;
    border-radius: 0;
    transition: left $sidebar-mobile-slide-duration $sidebar-motion-ease;
  }

  &--collapsed {
    width: $sidebar-collapsed-width;
    padding: cssUtils.$space-m-l $sidebar-collapsed-padding-x;
    transform: translateX(0);
    background-color: transparent;
    cursor: default;

    .openui-agent-container--mobile & {
      width: $sidebar-mobile-width;
      height: 100%;
      left: -$sidebar-mobile-width;
      transform: none;
      cursor: default;
    }
  }

  &--hidden {
    display: none;
  }

  // Follow the pointer while the edge is dragged, no easing.
  &--resizing {
    transition: none;
  }

  &[data-sidebar-visual-state="collapsing"],
  &[data-sidebar-visual-state="expanding"] {
    .openui-agent-sidebar-content,
    .openui-agent-new-chat-button__label,
    .openui-agent-sidebar-item__label,
    .openui-agent-sidebar-item__trailing,
    .openui-agent-sidebar-header__agent-name {
      opacity: 0;
      pointer-events: none;
    }

    // The wordmark eases in from where the mascot sat.
    .openui-agent-sidebar-header__agent-name {
      transform: translateX(-6px);
    }

    // Mascot and toggle both stand aside while the width moves: the mascot
    // fades before the rail grows and fades back once it has shrunk, and the
    // toggle appears only once it has reached its resting edge, instead of
    // popping in at the rail and sliding across.
    .openui-agent-sidebar-header__logo,
    .openui-agent-sidebar-header__toggle-button {
      opacity: 0;
      pointer-events: none;
    }
  }
}

.openui-agent-sidebar-header {
  display: flex;
  flex-direction: column;
  gap: cssUtils.$space-s;

  .openui-agent-container--mobile & {
    padding: 0 cssUtils.$space-m-l;
  }

  &__top-row {
    display: flex;
    align-items: center;
    gap: cssUtils.$space-s;
    min-height: $sidebar-collapsed-control-size;
    transition: opacity $sidebar-fade-duration $sidebar-motion-ease;

    .openui-agent-container--mobile & {
      gap: cssUtils.$space-m;
    }
  }

  &__logo {
    display: block;
    width: $sidebar-logo-size;
    height: $sidebar-logo-size;
    margin-left: 1px;
    align-self: flex-start;
    flex-shrink: 0;
    border-radius: cssUtils.$radius-s;
    transition: opacity $sidebar-header-fade-duration $sidebar-motion-ease;

    .openui-agent-container--mobile & {
      width: 36px;
      height: 36px;
      margin-left: 0;
      border-radius: cssUtils.$radius-m;
    }
  }

  &__agent-name {
    @include cssUtils.typography(label, small);
    flex-grow: 1;
    min-width: 0;
    overflow: hidden;
    color: cssUtils.$text-neutral-primary;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition:
      opacity $sidebar-header-fade-duration $sidebar-motion-ease,
      transform $sidebar-header-fade-duration $sidebar-motion-ease;

    .openui-agent-sidebar-container--collapsed & {
      display: none;
    }

    .openui-agent-container--mobile & {
      @include cssUtils.typography(label, large);
    }

    // An image wordmark (e.g. `agentName={<img … />}`) at the row's height.
    img {
      display: block;
      height: 28px;
      width: auto;
    }
  }

  // The logo is the collapsed rail's mark; expanded, the agent name takes its
  // place, inset to line up with the New Chat icon below it.
  &:not(&--collapsed) {
    .openui-agent-sidebar-header__logo {
      display: none;
    }

    .openui-agent-sidebar-header__agent-name {
      padding-left: cssUtils.$space-s;
    }
  }

  &--collapsed {
    align-items: flex-start;

    .openui-agent-sidebar-header__top-row {
      display: block;
      position: relative;
      width: $sidebar-collapsed-control-size;
      min-height: $sidebar-collapsed-control-size;
      align-items: flex-start;
    }

    .openui-agent-sidebar-header__logo,
    .openui-agent-sidebar-header__toggle-button {
      position: absolute;
      top: 0;
      left: 0;
    }

    // The brand mark is wider than the 32px control column; centre it on
    // the column so it lines up with the round actions below.
    .openui-agent-sidebar-header__logo {
      width: $sidebar-collapsed-mark-width;
      max-width: none;
      height: auto;
      margin-left: 0;
      left: calc((#{$sidebar-collapsed-control-size} - #{$sidebar-collapsed-mark-width}) / 2);
      border-radius: 0;
    }

    // Hide the toggle button at rest ONLY when a logo fills the slot (detected
    // with :has) — the logo is the resting face and the button appears on hover.
    // With no logo the slot is empty, so the button stays visible at rest
    // instead, keeping the open control discoverable.
    &:has(.openui-agent-sidebar-header__logo) .openui-agent-sidebar-header__toggle-button {
      opacity: 0;
      pointer-events: none;
    }
  }
}

.openui-agent-sidebar-content {
  width: calc(var(--openui-agent-sidebar-width, #{$sidebar-width}) - (#{$sidebar-padding-x} * 2));
  flex: 1;
  min-height: 0;

  .openui-agent-container--mobile & {
    width: 100%;
    padding: 0 cssUtils.$space-m-l;
  }

  display: flex;
  flex-direction: column;
  gap: cssUtils.$space-m;
  overflow: hidden;
  opacity: 1;
  transition: opacity $sidebar-fade-duration $sidebar-motion-ease;

  &--collapsed {
    width: 100%;
    align-items: flex-start;
    opacity: 0;
    pointer-events: none;
  }
}

.openui-agent-sidebar-separator {
  height: 1px;
  width: 100%;
  background-color: cssUtils.$border-default;
}

.openui-agent-sidebar-header__toggle-button {
  transition: opacity $sidebar-header-fade-duration $sidebar-motion-ease;

  .openui-agent-container--mobile & {
    display: none;
  }
}

// Collapsed rail: logo at rest, open button on hovering the logo's slot (not
// the whole rail) or keyboard focus. Key off the binary --collapsed class (the
// same isCollapsedLayout state that hides the button above), never
// data-sidebar-visual-state — its transitional values open
// a window where the button is hidden but cannot be revealed. Keyboard focus is
// matched via :focus-visible so the residual focus a mouse click leaves on the
// toggle doesn't pin the button over the logo at rest.
.openui-agent-sidebar-container--collapsed .openui-agent-sidebar-header__top-row:hover,
.openui-agent-sidebar-container--collapsed:has(:focus-visible) {
  .openui-agent-sidebar-header__logo {
    opacity: 0;
    pointer-events: none;
  }

  .openui-agent-sidebar-header__toggle-button {
    opacity: 1;
    pointer-events: auto;
  }
}

// No hover on touch devices: show the open button at rest instead of the logo.
// The header class keeps specificity equal to the :has() hide rule above so
// source order lets this win.
@media (hover: none) {
  .openui-agent-sidebar-container--collapsed {
    .openui-agent-sidebar-header__logo {
      opacity: 0;
      pointer-events: none;
    }

    .openui-agent-sidebar-header--collapsed .openui-agent-sidebar-header__toggle-button {
      opacity: 1;
      pointer-events: auto;
    }
  }
}

.openui-agent-sidebar-container__overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: cssUtils.$overlay;
  transition: opacity $sidebar-resize-duration $sidebar-motion-ease;
  z-index: 99;

  &--collapsed {
    opacity: 0;
    pointer-events: none;
  }
}

.openui-agent-sidebar-item {
  @include cssUtils.button-reset;
  @include cssUtils.typography(label, extra-small);

  display: flex;
  align-items: center;
  gap: cssUtils.$space-2xs;
  width: 100%;
  border-radius: calc(cssUtils.$radius-s + 1px);
  color: cssUtils.$text-neutral-primary;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  padding-right: cssUtils.$space-xs;
  transition: background-color $sidebar-fade-duration $sidebar-motion-ease;

  .openui-agent-container--mobile & {
    @include cssUtils.typography(label, default);

    gap: cssUtils.$space-s-m;
  }

  &:not(:disabled):hover {
    background-color: cssUtils.$highlight;
  }

  &--selected,
  &--selected:not(:disabled):hover {
    background-color: cssUtils.$sunk-deep;
  }

  .openui-agent-sidebar-container--collapsed & {
    width: $sidebar-collapsed-control-size;
    gap: 0;
    padding-right: 0;
    background-color: transparent;

    &:not(:disabled):hover {
      background-color: transparent;

      .openui-agent-sidebar-item__icon {
        background-color: cssUtils.$highlight;
      }
    }

    &.openui-agent-sidebar-item--selected {
      background-color: transparent;

      .openui-agent-sidebar-item__icon {
        background-color: cssUtils.$sunk-deep;
      }
    }

    &.openui-agent-sidebar-item--selected:not(:disabled):hover {
      .openui-agent-sidebar-item__icon {
        background-color: cssUtils.$sunk-deep;
      }
    }
  }
}

.openui-agent-sidebar-item__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: $sidebar-collapsed-control-size;
  height: $sidebar-collapsed-control-size;
  flex-shrink: 0;
  border: 1px solid transparent;
  border-radius: cssUtils.$radius-s;
  font-size: 16px;
  color: cssUtils.$text-neutral-primary;
  transition:
    background-color $sidebar-fade-duration $sidebar-motion-ease,
    border-color $sidebar-fade-duration $sidebar-motion-ease,
    color $sidebar-fade-duration $sidebar-motion-ease,
    box-shadow $sidebar-fade-duration $sidebar-motion-ease;
}

.openui-agent-sidebar-item__label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transition: opacity $sidebar-fade-duration $sidebar-motion-ease;

  .openui-agent-sidebar-container--collapsed & {
    width: 0;
    opacity: 0;
  }
}

.openui-agent-sidebar-item__trailing {
  @include cssUtils.typography(number, extra-small);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 18px;
  padding: 0 cssUtils.$space-xs;
  flex-shrink: 0;
  border-radius: cssUtils.$radius-xs;
  background-color: cssUtils.$highlight-strong;
  color: cssUtils.$text-neutral-secondary;
  opacity: 1;
  transition: opacity $sidebar-fade-duration $sidebar-motion-ease;

  .openui-agent-container--mobile & {
    @include cssUtils.typography(number, small);
  }

  .openui-agent-sidebar-container--collapsed & {
    width: 0;
    opacity: 0;
  }
}

// SidebarFooter: pinned under the thread list. The container's 36px gap is
// pulled in to 8px so the footer sits close to the list's faded bottom edge.
.openui-agent-sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: cssUtils.$space-2xs;
  flex-shrink: 0;
  margin-top: calc(#{cssUtils.$space-s} - #{cssUtils.$space-2xl});

  .openui-agent-container--mobile & {
    margin-top: 0;
    padding: 0 cssUtils.$space-m-l;
  }
}

// Draggable right edge (SidebarResizeEdge). No visual of its own.
.openui-agent-sidebar-resize-edge {
  position: absolute;
  top: 0;
  right: -4px;
  bottom: 0;
  width: 8px;
  z-index: 1;
  cursor: col-resize;
  touch-action: none;
}

@media (prefers-reduced-motion: reduce) {
  .openui-agent-sidebar-container,
  .openui-agent-sidebar-header__logo,
  .openui-agent-sidebar-header__agent-name,
  .openui-agent-sidebar-header__toggle-button {
    transition: none;
  }

  .openui-agent-sidebar-container[data-sidebar-visual-state]
    .openui-agent-sidebar-header__agent-name {
    transform: none;
  }
}

// Expanded New Chat is a plain nav item laid out like a thread row: its icon
// shares the thread icons' column and its label the thread titles' column.
// The 28px box is pulled 1px left so the 14px glyph inside it lands on that
// column, and the 1px gap puts the label on the titles' column. It shows as
// selected while on a fresh chat.
.openui-agent-sidebar-container
  .openui-agent-new-chat-button:not(.openui-agent-new-chat-button--collapsed) {
  @include cssUtils.typography(label, small);

  // Bleed 6px past the column each side (padding puts the content back) so
  // the selected/hover rect has room around the icon and label.
  width: calc(100% + 12px);
  height: $sidebar-nav-row-height;
  // The 2px top and bottom keep its centre level with the rail's 32px button.
  margin: 2px -6px;
  padding-left: 6px;
  gap: 1px;
  border-radius: calc(cssUtils.$radius-s + 3px);

  &.openui-agent-new-chat-button--selected,
  &.openui-agent-new-chat-button--selected:hover {
    background-color: cssUtils.$sunk-deep;
  }

  .openui-agent-new-chat-button__icon {
    width: $sidebar-nav-row-height;
    height: $sidebar-nav-row-height;
    margin: 0 0 0 -1px;
    font-size: $sidebar-nav-icon-size;
  }
}

// Open sidebar uses the rail's 12px gap under the header too, so New Chat
// sits at the same height whether the sidebar is open or collapsed.
.openui-agent-container:not(.openui-agent-container--mobile) .openui-agent-sidebar-actions {
  gap: cssUtils.$space-m;
}

// Tighter step from the actions (New Chat) down to the Threads list.
.openui-agent-container:not(.openui-agent-container--mobile) .openui-agent-sidebar-container {
  gap: cssUtils.$space-l;
}

// Room for the thread rows' 6px bleed: the content area and the thread list
// both clip, so each grows 6px past the column with padding putting their
// children back in place.
.openui-agent-container:not(.openui-agent-container--mobile) {
  .openui-agent-sidebar-content:not(.openui-agent-sidebar-content--collapsed) {
    width: calc(
      var(--openui-agent-sidebar-width, #{$sidebar-width}) - (#{$sidebar-padding-x} * 2) + 12px
    );
    margin: 0 -6px;
    padding: 0 6px;
  }

  .openui-agent-sidebar-content .openui-agent-thread-list {
    margin: 0 -6px;
    padding: 0 6px;
  }
}