Sort Direction

Ascending or descending order.

Order

html

<div class="sortdir">
  <span class="sortdir__label" id="sortdir-label">Order</span>
  <button type="button" role="switch" aria-checked="true" aria-labelledby="sortdir-label sortdir-state" class="sortdir__btn sortdir__btn--Arrow" style="--accent:#F5C2E0;">
    <svg class="sortdir__icon-arrow" width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><path d="M7 12V2M3 6l4-4 4 4" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>
    <svg class="sortdir__icon-chevron" width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><path d="M3 9l4-4 4 4" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>
    <span id="sortdir-state" class="sortdir__state">Ascending</span>
  </button>
</div>
<style>
.sortdir { display: flex; align-items: center; gap: 10px; font: 14px system-ui, sans-serif; color: #241430; }
.sortdir__label { font-weight: 500; }
.sortdir__btn { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid #24143040; background: #FAF7F2; color: #241430; padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; }
.sortdir__btn:hover, .sortdir__btn:focus-visible { border-color: var(--accent); outline: none; }
.sortdir__icon-arrow, .sortdir__icon-chevron { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .sortdir__icon-arrow, .sortdir__icon-chevron { transition: transform .15s ease; }
}
.sortdir__btn--Arrow .sortdir__icon-arrow { display: inline-block; }
.sortdir__btn--Chevron .sortdir__icon-chevron { display: inline-block; }
.sortdir__btn--desc svg { transform: rotate(180deg); }
</style>

tailwind

<div class="flex items-center gap-2.5 font-sans text-sm text-[#241430]">
  <span id="sortdir-label-tw" class="font-medium">Order</span>
  <button type="button" role="switch" aria-checked="true" aria-labelledby="sortdir-label-tw sortdir-state-tw" class="inline-flex items-center gap-1.5 border-[1.5px] border-[#24143040] bg-[#FAF7F2] text-[#241430] px-3 py-1.5 rounded-lg cursor-pointer focus-visible:outline-none sortdir-btn-tw sortdir-btn-tw--Arrow">
    <svg class="sortdir-icon-arrow-tw" width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><path d="M7 12V2M3 6l4-4 4 4" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>
    <svg class="sortdir-icon-chevron-tw" width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><path d="M3 9l4-4 4 4" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>
    <span id="sortdir-state-tw">Ascending</span>
  </button>
</div>
<style>
.sortdir-btn-tw:hover, .sortdir-btn-tw:focus-visible { border-color: #F5C2E0; }
.sortdir-icon-arrow-tw, .sortdir-icon-chevron-tw { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .sortdir-icon-arrow-tw, .sortdir-icon-chevron-tw { transition: transform .15s ease; }
}
.sortdir-btn-tw--Arrow .sortdir-icon-arrow-tw { display: inline-block; }
.sortdir-btn-tw--Chevron .sortdir-icon-chevron-tw { display: inline-block; }
.sortdir-btn-tw--desc svg { transform: rotate(180deg); }
</style>

react

export function SortDirection({
  label = "Order",
  ascending = true,
  icon = "Arrow",
  accent = "#F5C2E0",
}) {
  const rotate = ascending ? "none" : "rotate(180deg)";
  return (
    <div style={{ display: "flex", alignItems: "center", gap: 10, fontFamily: "system-ui, sans-serif", fontSize: 14, color: "#241430" }}>
      <span id="sortdir-label-react" style={{ fontWeight: 500 }}>{label}</span>
      <button type="button" role="switch" aria-checked={ascending} aria-labelledby="sortdir-label-react sortdir-state-react" style={{
        display: "inline-flex", alignItems: "center", gap: 6, border: `1.5px solid ${accent}`, background: "#FAF7F2",
        color: "#241430", padding: "7px 12px", borderRadius: 8, cursor: "pointer", font: "inherit",
      }}>
        <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true" className="sortdir-icon" style={{ transform: rotate }}>
          {icon === "Chevron"
            ? <path d="M3 9l4-4 4 4" stroke="currentColor" strokeWidth="1.5" fill="none" strokeLinecap="round" strokeLinejoin="round" />
            : <path d="M7 12V2M3 6l4-4 4 4" stroke="currentColor" strokeWidth="1.5" fill="none" strokeLinecap="round" strokeLinejoin="round" />}
        </svg>
        <span id="sortdir-state-react">{ascending ? "Ascending" : "Descending"}</span>
      </button>
      <style>{`
        @media (prefers-reduced-motion: no-preference) {
          .sortdir-icon { transition: transform .15s ease; }
        }
      `}</style>
    </div>
  );
}