Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/app/src/components/dialog-select-model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ const ModelList: Component<{

export function ModelSelectorPopover<T extends ValidComponent = "div">(props: {
provider?: string
children?: JSX.Element
children?: JSX.Element | ((open: boolean) => JSX.Element)
triggerAs?: T
triggerProps?: ComponentProps<T>
triggerProps?: ComponentProps<T>,
gutter?: number
}) {
const [store, setStore] = createStore<{
open: boolean
Expand Down Expand Up @@ -175,14 +176,14 @@ export function ModelSelectorPopover<T extends ValidComponent = "div">(props: {
}}
modal={false}
placement="top-start"
gutter={8}
gutter={props.gutter ?? 8}
>
<Kobalte.Trigger
ref={(el) => setStore("trigger", el)}
as={props.triggerAs ?? "div"}
{...(props.triggerProps as any)}
>
{props.children}
{typeof props.children === "function" ? props.children(store.open) : props.children}
</Kobalte.Trigger>
<Kobalte.Portal>
<Kobalte.Content
Expand Down
153 changes: 96 additions & 57 deletions packages/app/src/components/prompt-input.tsx

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions packages/app/src/components/settings-general.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@ export const SettingsGeneral: Component = () => {
const actions =
platform.update && platform.restart
? [
{
label: language.t("toast.update.action.installRestart"),
onClick: async () => {
await platform.update!()
await platform.restart!()
},
{
label: language.t("toast.update.action.installRestart"),
onClick: async () => {
await platform.update!()
await platform.restart!()
},
{
label: language.t("toast.update.action.notYet"),
onClick: "dismiss" as const,
},
]
},
{
label: language.t("toast.update.action.notYet"),
onClick: "dismiss" as const,
},
]
: [
{
label: language.t("toast.update.action.notYet"),
onClick: "dismiss" as const,
},
]
{
label: language.t("toast.update.action.notYet"),
onClick: "dismiss" as const,
},
]

showToast({
persistent: true,
Expand Down Expand Up @@ -226,7 +226,7 @@ export const SettingsGeneral: Component = () => {
variant="secondary"
size="small"
triggerVariant="settings"
triggerStyle={{ "font-family": monoFontFamily(settings.appearance.font()), "min-width": "180px" }}
triggerStyle={{ "font-family": monoFontFamily(settings.appearance.font()), "field-sizing": "content" }}
>
{(option) => (
<span style={{ "font-family": monoFontFamily(option?.value) }}>
Expand Down
29 changes: 15 additions & 14 deletions packages/ui/src/components/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
user-select: none;
cursor: default;
outline: none;
padding: 4px 8px;
white-space: nowrap;
transition-property: background-color, border-color, color, box-shadow, opacity;
transition-duration: var(--transition-duration);
transition-timing-function: var(--transition-easing);
outline: none;
line-height: 20px;

&[data-variant="primary"] {
background-color: var(--button-primary-base);
Expand Down Expand Up @@ -94,7 +100,6 @@
&:active:not(:disabled) {
background-color: var(--button-secondary-base);
scale: 0.99;
transition: all 150ms ease-out;
}
&:disabled {
border-color: var(--border-disabled);
Expand All @@ -109,34 +114,31 @@
}

&[data-size="small"] {
height: 22px;
padding: 0 8px;
padding: 4px 8px;
&[data-icon] {
padding: 0 12px 0 4px;
padding: 4px 12px 4px 4px;
}

font-size: var(--font-size-small);
line-height: var(--line-height-large);
gap: 4px;

/* text-12-medium */
font-family: var(--font-family-sans);
font-size: var(--font-size-small);
font-size: var(--font-size-base);
font-style: normal;
font-weight: var(--font-weight-medium);
line-height: var(--line-height-large); /* 166.667% */
letter-spacing: var(--letter-spacing-normal);
}

&[data-size="normal"] {
height: 24px;
line-height: 24px;
padding: 0 6px;
padding: 4px 6px;
&[data-icon] {
padding: 0 12px 0 4px;
padding: 4px 12px 4px 4px;
}

&[aria-haspopup] {
padding: 4px 6px 4px 8px;
}

font-size: var(--font-size-small);
gap: 6px;

/* text-12-medium */
Expand All @@ -148,7 +150,6 @@
}

&[data-size="large"] {
height: 32px;
padding: 6px 12px;

&[data-icon] {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Icon, IconProps } from "./icon"

export interface ButtonProps
extends ComponentProps<typeof Kobalte>,
Pick<ComponentProps<"button">, "class" | "classList" | "children"> {
Pick<ComponentProps<"button">, "class" | "classList" | "children" | "style"> {
size?: "small" | "normal" | "large"
variant?: "primary" | "secondary" | "ghost"
icon?: IconProps["name"]
Expand Down
49 changes: 49 additions & 0 deletions packages/ui/src/components/cycle-label.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.cycle-label {
--c-duration: 200ms;
--c-stagger: 30ms;
--c-opacity-start: 0;
--c-opacity-end: 1;
--c-blur-start: 0px;
--c-blur-end: 0px;
--c-skew: 10deg;

display: inline-flex;
position: relative;

transform-style: preserve-3d;
perspective: 500px;
transition: width var(--transition-duration) var(--transition-easing);
will-change: width;
overflow: hidden;

.cycle-char {
display: inline-block;
transform-style: preserve-3d;
min-width: 0.25em;
backface-visibility: hidden;

transition-property: transform, opacity, filter;
transition-duration: var(--transition-duration);
transition-timing-function: var(--transition-easing);
transition-delay: calc(var(--i, 0) * var(--c-stagger));

&.enter {
opacity: var(--c-opacity-end);
filter: blur(var(--c-blur-end));
transform: translateY(0) rotateX(0) skewX(0);
}

&.exit {
opacity: var(--c-opacity-start);
filter: blur(var(--c-blur-start));
transform: translateY(50%) rotateX(90deg) skewX(var(--c-skew));
}

&.pre {
opacity: var(--c-opacity-start);
filter: blur(var(--c-blur-start));
transition: none;
transform: translateY(-50%) rotateX(-90deg) skewX(calc(var(--c-skew) * -1));
}
}
}
132 changes: 132 additions & 0 deletions packages/ui/src/components/cycle-label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import "./cycle-label.css"
import { createEffect, createSignal, JSX, on } from "solid-js"

export interface CycleLabelProps extends JSX.HTMLAttributes<HTMLSpanElement> {
value: string
onValueChange?: (value: string) => void
duration?: number | ((value: string) => number)
stagger?: number
opacity?: [number, number]
blur?: [number, number]
skewX?: number
onAnimationStart?: () => void
onAnimationEnd?: () => void
}

const segmenter =
typeof Intl !== "undefined" && Intl.Segmenter ? new Intl.Segmenter("en", { granularity: "grapheme" }) : null

const getChars = (text: string): string[] =>
segmenter ? Array.from(segmenter.segment(text), (s) => s.segment) : text.split("")

const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

export function CycleLabel(props: CycleLabelProps) {
const getDuration = (text: string) => {
const d = props.duration ?? Number(getComputedStyle(document.documentElement).getPropertyValue("--transition-duration")) ?? 200
return typeof d === "function" ? d(text) : d
}
const stagger = () => props?.stagger ?? 30
const opacity = () => props?.opacity ?? [0, 1]
const blur = () => props?.blur ?? [0, 0]
const skewX = () => props?.skewX ?? 10

let containerRef: HTMLSpanElement | undefined
let isAnimating = false
const [currentText, setCurrentText] = createSignal(props.value)

const setChars = (el: HTMLElement, text: string, state: "enter" | "exit" | "pre" = "enter") => {
el.innerHTML = ""
const chars = getChars(text)
chars.forEach((char, i) => {
const span = document.createElement("span")
span.textContent = char === " " ? "\u00A0" : char
span.className = `cycle-char ${state}`
span.style.setProperty("--i", String(i))
el.appendChild(span)
})
}

const animateToText = async (newText: string) => {
if (!containerRef || isAnimating) return
if (newText === currentText()) return

isAnimating = true
props.onAnimationStart?.()

const dur = getDuration(newText)
const stag = stagger()

containerRef.style.width = containerRef.offsetWidth + "px"

const oldChars = containerRef.querySelectorAll(".cycle-char")
oldChars.forEach((c) => c.classList.replace("enter", "exit"))

const clone = containerRef.cloneNode(false) as HTMLElement
Object.assign(clone.style, {
position: "absolute",
visibility: "hidden",
width: "auto",
transition: "none",
})
setChars(clone, newText)
document.body.appendChild(clone)
const nextWidth = clone.offsetWidth
clone.remove()

const exitTime = oldChars.length * stag + dur
await wait(exitTime * 0.3)

containerRef.style.width = nextWidth + "px"

const widthDur = 200
await wait(widthDur * 0.3)

setChars(containerRef, newText, "pre")
containerRef.offsetWidth

Array.from(containerRef.children).forEach((c) => (c.className = "cycle-char enter"))
setCurrentText(newText)
props.onValueChange?.(newText)

const enterTime = getChars(newText).length * stag + dur
await wait(enterTime)

containerRef.style.width = ""
isAnimating = false
props.onAnimationEnd?.()
}

createEffect(
on(
() => props.value,
(newValue) => {
if (newValue !== currentText()) {
animateToText(newValue)
}
},
),
)

const initRef = (el: HTMLSpanElement) => {
containerRef = el
setChars(el, props.value)
}

return (
<span
ref={initRef}
class={`cycle-label ${props.class ?? ""}`}
style={{
"--c-duration": `${getDuration(currentText())}ms`,
"--c-stagger": `${stagger()}ms`,
"--c-opacity-start": opacity()[0],
"--c-opacity-end": opacity()[1],
"--c-blur-start": `${blur()[0]}px`,
"--c-blur-end": `${blur()[1]}px`,
"--c-skew": `${skewX()}deg`,
...(typeof props.style === "object" ? props.style : {}),
}}
/>
)
}
Loading
Loading