React
LoadingLoading React…
No event yet
Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.
CompareOverlays
The same example, live in each framework. One core underneath, so they should behave the same.
Loading React…
No event yet
Loading Vue…
No event yet
Loading Svelte…
No event yet
Loading Solid…
No event yet
Loading Angular…
No event yet
The attributes each framework puts on the open popup, read from the page.
| Attribute | React | Vue | Svelte | Solid | Angular |
|---|---|---|---|---|---|
role | Closed | Closed | Closed | Closed | Closed |
aria-modal | Closed | Closed | Closed | Closed | Closed |
aria-labelledby | Closed | Closed | Closed | Closed | Closed |
data-open | Closed | Closed | Closed | Closed | Closed |
Nothing open. Open a tile to fill its column.
Each tile sets modal to false, so five popups can be open at once; that is why aria-modal reads absent.
Each tile above runs this file.
import * as React from 'react'
import { Autocomplete } from '@hamur/react/autocomplete'
import { getHotkeyKeys } from '@hamur/react/hotkeys'
import { Spotlight } from '@hamur/react/spotlight'
interface Command {
id: string
label: string
}
interface CommandGroup {
value: string
items: Command[]
}
const commands: CommandGroup[] = [
{
value: 'Navigation',
items: [
{ id: 'go-dashboard', label: 'Go to Dashboard' },
{ id: 'go-projects', label: 'Go to Projects' },
{ id: 'go-settings', label: 'Go to Settings' },
],
},
{
value: 'Actions',
items: [
{ id: 'create-project', label: 'Create project' },
{ id: 'invite', label: 'Invite teammate' },
{ id: 'toggle-theme', label: 'Toggle theme' },
{ id: 'copy-link', label: 'Copy link' },
],
},
]
const glyphs: Record<string, string> = { Meta: '⌘', Control: 'Ctrl' }
const keys = getHotkeyKeys('Mod+K')[0]
const shortcut = keys.map((key) => glyphs[key] ?? key).join(keys.includes('Meta') ? '' : '+')
export default function SpotlightExample() {
const [query, setQuery] = React.useState('')
const [lastCommand, setLastCommand] = React.useState<Command | null>(null)
const { contains } = Autocomplete.useFilter({ sensitivity: 'base' })
const results = commands.reduce(
(total, group) => total + group.items.filter((c) => contains(c.label, query.trim())).length,
0,
)
return (
<Spotlight.Root
items={commands}
hotkey="Mod+K"
value={query}
onValueChange={(next) => setQuery(next)}
>
<div className="stack">
<div className="row">
<Spotlight.Trigger className="button">
Open command palette <kbd aria-hidden="true">{shortcut}</kbd>
</Spotlight.Trigger>
</div>
<p className="muted">Last command: {lastCommand ? lastCommand.label : 'none'}</p>
</div>
<Spotlight.Portal>
<Spotlight.Backdrop className="backdrop" />
<Spotlight.Popup className="dialog">
<Spotlight.Title className="dialog-title">
Command palette
</Spotlight.Title>
<Spotlight.Description className="muted">
Type to filter. Up and Down move through the commands, Enter runs one, Escape closes.
</Spotlight.Description>
<label className="field">
<span className="select-label">Search commands</span>
<Spotlight.Input className="input" placeholder="Type a command" />
</label>
<Spotlight.Empty>
<div className="combobox-empty">No commands match "{query}".</div>
</Spotlight.Empty>
<Spotlight.List className="select-list">
<Spotlight.Collection>
{(group: CommandGroup) => (
<Spotlight.Group
key={group.value}
items={group.items}
className="select-group"
>
<Spotlight.GroupLabel className="select-group-label">
{group.value}
</Spotlight.GroupLabel>
<Spotlight.Collection>
{(command: Command) => (
<Spotlight.Item
key={command.id}
value={command}
className="select-item plain"
onClick={() => setLastCommand(command)}
>
{command.label}
</Spotlight.Item>
)}
</Spotlight.Collection>
</Spotlight.Group>
)}
</Spotlight.Collection>
</Spotlight.List>
<Spotlight.Status>
<div className="combobox-status">
{results === 1 ? '1 result' : `${results} results`}
</div>
</Spotlight.Status>
<div className="actions">
<Spotlight.Close className="button">
Close
</Spotlight.Close>
</div>
</Spotlight.Popup>
</Spotlight.Portal>
</Spotlight.Root>
)
}
The frameworks against each other only, on the same machine and the same example.
| Framework | Tests | Size | Open | Close | Memory |
|---|---|---|---|---|---|
| React | 68 | 97.3 KiB | Not measured yet | Not measured yet | Not measured yet |
| Vue | 118 | 104.0 KiB | Not measured yet | Not measured yet | Not measured yet |
| Svelte | 114 | 99.3 KiB | Not measured yet | Not measured yet | Not measured yet |
| Solid | 124 | 99.5 KiB | Not measured yet | Not measured yet | Not measured yet |
| Angular | 88 | 106.1 KiB | Not measured yet | Not measured yet | Not measured yet |
Size is the gzip of the component's entry with core and dom. Open, Close and Memory are medians in Chromium 156 on Apple M3 Max; Memory is what one open and close leaves on the heap. Tests are Spotlight's passing tests in each framework's suites. [N] is a value not measured yet.
The Spotlight.Root names in each framework's own syntax.
| Prop | React | Vue | Svelte | Solid | Angular |
|---|---|---|---|---|---|
| open | open | open | open | open | [open] |
| defaultOpen | defaultOpen | default-open | defaultOpen | defaultOpen | [defaultOpen] |
| onOpenChangeevent | onOpenChange | @open-change | onOpenChange | onOpenChange | (openChange) |
| onOpenChangeCompleteevent | onOpenChangeComplete | @open-change-complete | onOpenChangeComplete | onOpenChangeComplete | (openChangeComplete) |
| modal | modal | modal | modal | modal | [modal] |
| disablePointerDismissal | disablePointerDismissal | disable-pointer-dismissal | disablePointerDismissal | disablePointerDismissal | [disablePointerDismissal] |
| actionsRef | actionsRef | actions-ref | actionsRef | actionsRef | [actionsRef] |
| handle | handle | handle | handle | handle | [handle] |
| triggerId | triggerId | trigger-id | triggerId | triggerId | [triggerId] |
| defaultTriggerId | defaultTriggerId | default-trigger-id | defaultTriggerId | defaultTriggerId | [defaultTriggerId] |
| hotkey | hotkey | hotkey | hotkey | hotkey | [hotkey] |
| items | items | items | items | items | [items] |
| filteredItems | filteredItems | filtered-items | filteredItems | filteredItems | [filteredItems] |
| filter | filter | filter | filter | filter | [filter] |
| limit | limit | limit | limit | limit | [limit] |
| locale | locale | locale | locale | locale | [locale] |
| value | value | value | value | value | [value] |
| defaultValue | defaultValue | default-value | defaultValue | defaultValue | [defaultValue] |
| onValueChangeevent | onValueChange | @value-change | onValueChange | onValueChange | (valueChange) |
| itemToStringValue | itemToStringValue | item-to-string-value | itemToStringValue | itemToStringValue | [itemToStringValue] |
| onItemHighlightedevent | onItemHighlighted | @item-highlighted | onItemHighlighted | onItemHighlighted | (itemHighlighted) |
| highlightItemOnHover | highlightItemOnHover | highlight-item-on-hover | highlightItemOnHover | highlightItemOnHover | [highlightItemOnHover] |
| loopFocus | loopFocus | loop-focus | loopFocus | loopFocus | [loopFocus] |
| virtualized | virtualized | virtualized | virtualized | virtualized | [virtualized] |
| children | children | #default | children | children | ng-content |