Zum Inhalt

src/ui/SelectRow.tsx

import { type Component, For, Show, createMemo } from 'solid-js';
import { Tooltip } from './Tooltip';
import { PARAM_HELP } from './paramHelp';

export interface SelectOption {
  value: string;
  label: string;
}

interface Props {
  label: string;
  value: string;
  options: readonly SelectOption[];
  onChange: (value: string) => void;
  info?: string;
}

export const SelectRow: Component<Props> = (props) => {
  const helpText = createMemo(() => props.info ?? PARAM_HELP[props.label]);
  return (
    <div style={{ display: 'flex', 'align-items': 'center', gap: '12px', padding: '4px 0' }}>
      <span
        style={{
          flex: '1',
          'font-family': 'var(--font-body)',
          'font-size': '12.5px',
          'font-weight': '500',
          color: 'var(--fg-primary)',
        }}
      >
        {props.label}
      </span>
      <Show when={helpText()}>
        <Tooltip text={helpText() ?? ''} />
      </Show>
      <select
        class="phys-mono"
        value={props.value}
        onChange={(e) => props.onChange(e.currentTarget.value)}
        style={{
          background: 'var(--surface-inset)',
          color: 'var(--fg-primary)',
          border: '1px solid var(--border-default)',
          'border-radius': 'var(--radius-md)',
          padding: '5px 8px',
          'font-size': '11px',
          cursor: 'pointer',
        }}
      >
        <For each={props.options}>{(o) => <option value={o.value}>{o.label}</option>}</For>
      </select>
    </div>
  );
};