polymorph-ui-components-mcp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/docs/Accordion.md +45 -0
- package/build/docs/Avatar.md +80 -0
- package/build/docs/Badge.md +58 -0
- package/build/docs/Banner.md +134 -0
- package/build/docs/Book.md +111 -0
- package/build/docs/Browser.md +92 -0
- package/build/docs/Button.md +154 -0
- package/build/docs/CHANGELOG.md +0 -0
- package/build/docs/Calendar.md +129 -0
- package/build/docs/Carousel.md +73 -0
- package/build/docs/CheckListItem.md +76 -0
- package/build/docs/Checkbox.md +84 -0
- package/build/docs/Choicebox.md +71 -0
- package/build/docs/ColorPicker.md +83 -0
- package/build/docs/Combobox.md +336 -0
- package/build/docs/CommandMenu.md +208 -0
- package/build/docs/ContextMenu.md +132 -0
- package/build/docs/GUIDELINES.md +380 -0
- package/build/docs/Gauge.md +46 -0
- package/build/docs/GridItem.md +78 -0
- package/build/docs/Icon.md +66 -0
- package/build/docs/IconStack.md +68 -0
- package/build/docs/Img.md +56 -0
- package/build/docs/Input.md +151 -0
- package/build/docs/InputButton.md +246 -0
- package/build/docs/KeyboardInput.md +104 -0
- package/build/docs/ListItem.md +156 -0
- package/build/docs/Loader.md +55 -0
- package/build/docs/LoadingDots.md +45 -0
- package/build/docs/Menu.md +139 -0
- package/build/docs/Modal.md +221 -0
- package/build/docs/ModalAnimation.md +29 -0
- package/build/docs/OverlayAnimation.md +21 -0
- package/build/docs/Pagination.md +102 -0
- package/build/docs/Phone.md +82 -0
- package/build/docs/Pill.md +122 -0
- package/build/docs/Progress.md +53 -0
- package/build/docs/Radio.md +75 -0
- package/build/docs/RelativeTime.md +76 -0
- package/build/docs/Scroller.md +194 -0
- package/build/docs/Select.md +177 -0
- package/build/docs/Sheet.md +133 -0
- package/build/docs/Shimmer.md +76 -0
- package/build/docs/Slider.md +68 -0
- package/build/docs/Snippet.md +99 -0
- package/build/docs/SplitButton.md +157 -0
- package/build/docs/SplitInput.md +157 -0
- package/build/docs/Step.md +52 -0
- package/build/docs/Stepper.md +85 -0
- package/build/docs/Table.md +252 -0
- package/build/docs/Tabs.md +117 -0
- package/build/docs/ThemeSwitcher.md +125 -0
- package/build/docs/Toast.md +140 -0
- package/build/docs/Toggle.md +70 -0
- package/build/docs/Toolbar.md +100 -0
- package/build/docs/Tooltip.md +86 -0
- package/build/docs/_index.json +218 -0
- package/build/docs/templates/changelog.hbs +36 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +163 -0
- package/build/index.js.map +1 -0
- package/build/services/registry.d.ts +11 -0
- package/build/types.d.ts +4 -0
- package/package.json +34 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# ColorPicker
|
|
2
|
+
|
|
3
|
+
A color picker component that lets the user select a color using a saturation/brightness panel, a hue slider, and direct input fields. The `value` prop is bindable and holds the selected color as a HEX string (e.g. `#ff0000`). A trigger button displays the current color as a swatch, and optionally a text input shows the HEX value inline. Clicking the swatch opens a popover with a 2D saturation/brightness panel, a hue gradient slider (powered by the Slider component), a live preview swatch, and switchable input fields supporting HEX, RGB, and HSL modes. Supports `disabled` to prevent interaction.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```svelte
|
|
8
|
+
<script>
|
|
9
|
+
import { ColorPicker } from 'polymorph-ui-components';
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<ColorPicker value="#3b82f6" />
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Props
|
|
16
|
+
|
|
17
|
+
| Prop | Type | Required | Default | Description |
|
|
18
|
+
| --------- | --------- | -------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| value | `string` | Yes | `'#000000'` | Bindable. The current color as a 7-character HEX string (e.g. `#3b82f6`). Two-way bound so parent components can read and write the selected color. |
|
|
20
|
+
| label | `string` | No | `-` | Optional text label rendered above the trigger row. When provided, a `<span>` with the label text appears above the swatch button. |
|
|
21
|
+
| disabled | `boolean` | No | `false` | Whether the color picker is disabled. When true, the trigger button cannot be clicked, the popover cannot open, and the component is visually dimmed. |
|
|
22
|
+
| showValue | `boolean` | No | `false` | Whether to display a text input beside the swatch showing the current HEX value. When true, the user can type a HEX value directly into the inline input. |
|
|
23
|
+
| testId | `string` | No | `-` | Value for the `data-pw` attribute on the container element, used for end-to-end testing selectors. |
|
|
24
|
+
| classes | `string` | No | `-` | CSS class string applied to the component's top-level container element. Useful for theming — define classes with CSS variable overrides and pass them to create variant styles. |
|
|
25
|
+
|
|
26
|
+
## Events
|
|
27
|
+
|
|
28
|
+
| Event | Type | Description |
|
|
29
|
+
| -------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
30
|
+
| oninput | `(value: string) => void` | Fires when the color changes during interaction — as the user drags on the saturation panel, moves the hue slider, or types into an input field. Receives the new HEX string. Use this for live preview updates. |
|
|
31
|
+
| onchange | `(value: string) => void` | Fires alongside `oninput` whenever the color value is committed — after a saturation panel drag, hue slider adjustment, or valid input field entry. Receives the final HEX string. Use this for persisting the value. |
|
|
32
|
+
|
|
33
|
+
## CSS Variables
|
|
34
|
+
|
|
35
|
+
Override these custom properties to theme the component.
|
|
36
|
+
|
|
37
|
+
| Variable | Default | CSS Property | Description |
|
|
38
|
+
| -------------------------------------------- | ------------------------------------------------------------------ | -------------- | --------------------------------------------------------------------------------------- |
|
|
39
|
+
| `--color-picker-gap` | `8px` | gap | Vertical gap between the label and the trigger row. |
|
|
40
|
+
| `--color-picker-width` | `fit-content` | width | Width of the top-level container element. |
|
|
41
|
+
| `--color-picker-disabled-opacity` | `0.5` | opacity | Opacity of the entire component when disabled. |
|
|
42
|
+
| `--color-picker-label-font-size` | `14px` | font-size | Font size of the label text above the trigger. |
|
|
43
|
+
| `--color-picker-label-font-weight` | `500` | font-weight | Font weight of the label text. |
|
|
44
|
+
| `--color-picker-label-color` | `currentColor` | color | Text color of the label. |
|
|
45
|
+
| `--color-picker-label-letter-spacing` | `0.01em` | letter-spacing | Letter spacing of the label text. |
|
|
46
|
+
| `--color-picker-row-gap` | `0px` | gap | Horizontal gap between the swatch button and the inline hex input in the trigger row. |
|
|
47
|
+
| `--color-picker-swatch-btn-background` | `transparent` | background | Background color of the swatch trigger button. |
|
|
48
|
+
| `--color-picker-swatch-btn-border` | `1px solid #18181b` | border | Border of the swatch trigger button. |
|
|
49
|
+
| `--color-picker-swatch-btn-border-radius` | `6px 0 0 6px` (or `6px` when `showValue` is false) | border-radius | Border radius of the swatch trigger button. Rounded on all sides when standalone. |
|
|
50
|
+
| `--color-picker-swatch-btn-hover-background` | `transparent` | background | Background color of the swatch trigger button on hover. |
|
|
51
|
+
| `--color-picker-swatch-padding` | `5px` | padding | Padding inside the swatch trigger button around the color swatch. |
|
|
52
|
+
| `--color-picker-swatch-size` | `26px` | width, height | Width and height of the color swatch square inside the trigger button. |
|
|
53
|
+
| `--color-picker-swatch-border-radius` | `6px` | border-radius | Border radius of the color swatch square. |
|
|
54
|
+
| `--color-picker-swatch-inner-shadow` | `inset 0 0 0 1px rgba(0, 0, 0, 0.08)` | box-shadow | Inner shadow on the color swatch to provide contrast against similar background colors. |
|
|
55
|
+
| `--color-picker-mono-font` | `ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace` | font-family | Monospace font family used for the inline hex input and popover input fields. |
|
|
56
|
+
| `--color-picker-popover-z-index` | `50` | z-index | Z-index of the popover panel, controlling its stacking order. |
|
|
57
|
+
| `--color-picker-popover-width` | `280px` | width | Width of the popover panel. |
|
|
58
|
+
| `--color-picker-popover-padding` | `12px` | padding | Padding inside the popover panel. |
|
|
59
|
+
| `--color-picker-popover-background` | `#ffffff` | background | Background color of the popover panel. |
|
|
60
|
+
| `--color-picker-popover-border` | `1px solid currentColor` | border | Border of the popover panel. |
|
|
61
|
+
| `--color-picker-popover-border-radius` | `8px` | border-radius | Border radius of the popover panel. |
|
|
62
|
+
| `--color-picker-popover-shadow` | `0 4px 24px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06)` | box-shadow | Box shadow of the popover panel for elevation effect. |
|
|
63
|
+
| `--color-picker-panel-border-radius` | `8px` | border-radius | Border radius of the saturation/brightness panel inside the popover. |
|
|
64
|
+
| `--color-picker-field-border` | `currentColor` | border-color | Border color of the HEX/RGB/HSL input fields in the popover. |
|
|
65
|
+
| `--color-picker-field-color` | `currentColor` | color | Text color inside the popover input fields. |
|
|
66
|
+
| `--color-picker-field-background` | `#ffffff` | background | Background color of the popover input fields and the mode toggle button. |
|
|
67
|
+
| `--color-picker-field-focus-border` | `currentColor` | border-color | Border color of the popover input fields when focused. |
|
|
68
|
+
| `--color-picker-field-label-color` | `currentColor` | color | Text color of the field labels (HEX, R, G, B, H, S, L) and the mode toggle button icon. |
|
|
69
|
+
|
|
70
|
+
## Internal Dependencies
|
|
71
|
+
|
|
72
|
+
- **Button** — used for the swatch trigger button and the color mode toggle button.
|
|
73
|
+
- **Input** — used for the inline HEX text input (when `showValue` is true) and the HEX/RGB/HSL input fields in the popover.
|
|
74
|
+
- **Slider** — used for the hue gradient slider in the popover.
|
|
75
|
+
- **swap-vertical.svg** — SVG icon used inside the mode toggle button to indicate cycling between HEX, RGB, and HSL input modes.
|
|
76
|
+
|
|
77
|
+
## Web Component
|
|
78
|
+
|
|
79
|
+
Tag: `<pui-color-picker>`
|
|
80
|
+
|
|
81
|
+
```html
|
|
82
|
+
<pui-color-picker value="#3b82f6" label="Brand color" show-value></pui-color-picker>
|
|
83
|
+
```
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
# Combobox
|
|
2
|
+
|
|
3
|
+
A text input with an attached dropdown list that filters options as the user types. Built on the library's Input component internally, so it inherits Input's validation, text transformers, and formatting capabilities via the `inputProperties` pass-through. Implements the WAI-ARIA combobox pattern with full keyboard navigation (ArrowUp/Down to highlight, Enter to select, Escape to close, Tab to close and move focus). The dropdown opens on focus or typing and closes on outside click, Escape, or item selection. Supports disabled items, custom item rendering via a Snippet, custom filter logic, a custom empty-state Snippet, input prefix/suffix slots, dropdown header/footer slots, and bindable `value`, `inputValue`, `open`, and `highlightedIndex` state.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```svelte
|
|
8
|
+
<script>
|
|
9
|
+
import { Combobox } from 'polymorph-ui-components';
|
|
10
|
+
|
|
11
|
+
const fruits = [
|
|
12
|
+
{ id: 'apple', label: 'Apple' },
|
|
13
|
+
{ id: 'banana', label: 'Banana' },
|
|
14
|
+
{ id: 'cherry', label: 'Cherry' }
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
let selected = $state('');
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<Combobox items={fruits} bind:value={selected} placeholder="Search fruits..." />
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### With Custom Item Rendering
|
|
24
|
+
|
|
25
|
+
```svelte
|
|
26
|
+
<Combobox items={fruits} bind:value={selected}>
|
|
27
|
+
{#snippet itemSnippet(item, isHighlighted)}
|
|
28
|
+
<div class:highlighted={isHighlighted}>
|
|
29
|
+
<strong>{item.label}</strong>
|
|
30
|
+
<span>({item.id})</span>
|
|
31
|
+
</div>
|
|
32
|
+
{/snippet}
|
|
33
|
+
</Combobox>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### With Custom Filter
|
|
37
|
+
|
|
38
|
+
```svelte
|
|
39
|
+
<Combobox
|
|
40
|
+
items={fruits}
|
|
41
|
+
bind:value={selected}
|
|
42
|
+
filterFn={(item, query) => item.label.toLowerCase().startsWith(query.toLowerCase())}
|
|
43
|
+
/>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### With Custom Empty State
|
|
47
|
+
|
|
48
|
+
```svelte
|
|
49
|
+
<Combobox items={fruits} bind:value={selected}>
|
|
50
|
+
{#snippet emptySnippet()}
|
|
51
|
+
<div style="padding: 12px; text-align: center;">
|
|
52
|
+
<p>No matches found</p>
|
|
53
|
+
<button onclick={handleCreateNew}>Create new item</button>
|
|
54
|
+
</div>
|
|
55
|
+
{/snippet}
|
|
56
|
+
</Combobox>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### With Extra Item Data
|
|
60
|
+
|
|
61
|
+
TypeScript's structural typing lets you pass items with extra properties. Cast inside the snippet to access them.
|
|
62
|
+
|
|
63
|
+
```svelte
|
|
64
|
+
<script>
|
|
65
|
+
import type { ComboboxItem } from 'polymorph-ui-components';
|
|
66
|
+
|
|
67
|
+
type UserItem = ComboboxItem & { avatar: string; role: string };
|
|
68
|
+
|
|
69
|
+
const users: UserItem[] = [
|
|
70
|
+
{ id: '1', label: 'Alice', avatar: '/alice.png', role: 'Admin' },
|
|
71
|
+
{ id: '2', label: 'Bob', avatar: '/bob.png', role: 'User' }
|
|
72
|
+
];
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<Combobox items={users} bind:value={selected}>
|
|
76
|
+
{#snippet itemSnippet(item, isHighlighted)}
|
|
77
|
+
{@const user = item as UserItem}
|
|
78
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
79
|
+
<img src={user.avatar} alt="" width="24" height="24" />
|
|
80
|
+
<div>
|
|
81
|
+
<div>{user.label}</div>
|
|
82
|
+
<div style="font-size: 12px; color: #666;">{user.role}</div>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
{/snippet}
|
|
86
|
+
</Combobox>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### With Search Icon and Clear Button
|
|
90
|
+
|
|
91
|
+
```svelte
|
|
92
|
+
<Combobox items={fruits} bind:value={selected} bind:inputValue>
|
|
93
|
+
{#snippet inputPrefix()}
|
|
94
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
95
|
+
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.35-4.35" />
|
|
96
|
+
</svg>
|
|
97
|
+
{/snippet}
|
|
98
|
+
{#snippet inputSuffix()}
|
|
99
|
+
{#if inputValue.length > 0}
|
|
100
|
+
<button onclick={() => (inputValue = '')} style="border: none; background: none; cursor: pointer;">
|
|
101
|
+
×
|
|
102
|
+
</button>
|
|
103
|
+
{/if}
|
|
104
|
+
{/snippet}
|
|
105
|
+
</Combobox>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### With Dropdown Header and Footer
|
|
109
|
+
|
|
110
|
+
```svelte
|
|
111
|
+
<Combobox items={fruits} bind:value={selected}>
|
|
112
|
+
{#snippet dropdownHeader()}
|
|
113
|
+
<div style="padding: 8px 12px; font-size: 12px; color: #999; border-bottom: 1px solid #eee;">
|
|
114
|
+
Suggestions
|
|
115
|
+
</div>
|
|
116
|
+
{/snippet}
|
|
117
|
+
{#snippet dropdownFooter()}
|
|
118
|
+
<div style="padding: 8px 12px; border-top: 1px solid #eee;">
|
|
119
|
+
<button onclick={handleShowAll} style="width: 100%; border: none; background: none; color: #2563eb; cursor: pointer;">
|
|
120
|
+
Show all results
|
|
121
|
+
</button>
|
|
122
|
+
</div>
|
|
123
|
+
{/snippet}
|
|
124
|
+
</Combobox>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Server-Side Filtering
|
|
128
|
+
|
|
129
|
+
```svelte
|
|
130
|
+
<script>
|
|
131
|
+
let results = $state([]);
|
|
132
|
+
let loading = $state(false);
|
|
133
|
+
|
|
134
|
+
async function handleInput(query) {
|
|
135
|
+
loading = true;
|
|
136
|
+
const res = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
|
|
137
|
+
results = await res.json();
|
|
138
|
+
loading = false;
|
|
139
|
+
}
|
|
140
|
+
</script>
|
|
141
|
+
|
|
142
|
+
<Combobox
|
|
143
|
+
items={results}
|
|
144
|
+
filterFn={() => true}
|
|
145
|
+
oninput={handleInput}
|
|
146
|
+
placeholder="Search..."
|
|
147
|
+
>
|
|
148
|
+
{#snippet inputSuffix()}
|
|
149
|
+
{#if loading}
|
|
150
|
+
<span class="spinner" />
|
|
151
|
+
{/if}
|
|
152
|
+
{/snippet}
|
|
153
|
+
{#snippet emptySnippet()}
|
|
154
|
+
<div style="padding: 12px; text-align: center; color: #999;">
|
|
155
|
+
{loading ? 'Searching...' : 'No results found'}
|
|
156
|
+
</div>
|
|
157
|
+
{/snippet}
|
|
158
|
+
</Combobox>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Accessing the Input Element
|
|
162
|
+
|
|
163
|
+
```svelte
|
|
164
|
+
<script>
|
|
165
|
+
let comboboxRef = $state(null);
|
|
166
|
+
|
|
167
|
+
function focusInput() {
|
|
168
|
+
comboboxRef?.getInputRef()?.focus();
|
|
169
|
+
}
|
|
170
|
+
</script>
|
|
171
|
+
|
|
172
|
+
<Combobox items={fruits} bind:this={comboboxRef} />
|
|
173
|
+
<button onclick={focusInput}>Focus the combobox</button>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### With Input Validation
|
|
177
|
+
|
|
178
|
+
Pass Input props via `inputProperties` to enable validation, text formatting, and more.
|
|
179
|
+
|
|
180
|
+
```svelte
|
|
181
|
+
<Combobox
|
|
182
|
+
items={fruits}
|
|
183
|
+
bind:value={selected}
|
|
184
|
+
inputProperties={{
|
|
185
|
+
validationPattern: /^[a-zA-Z]+$/,
|
|
186
|
+
onErrorMessage: 'Letters only',
|
|
187
|
+
maxLength: 20
|
|
188
|
+
}}
|
|
189
|
+
inputEventProperties={{
|
|
190
|
+
onstatechange: (state) => console.log('Validation:', state)
|
|
191
|
+
}}
|
|
192
|
+
/>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Props
|
|
196
|
+
|
|
197
|
+
| Prop | Type | Required | Default | Description |
|
|
198
|
+
| ---------------- | ----------------------------------------------------------- | -------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
199
|
+
| items | `ComboboxItem[]` | Yes | `-` | Array of selectable items. Each item has an `id`, `label`, optional `disabled` flag, and any extra properties. See ComboboxItem type below. |
|
|
200
|
+
| value | `string` | No | `''` | Bindable. The `id` of the currently selected item. Updated when the user selects an item from the dropdown. |
|
|
201
|
+
| inputValue | `string` | No | `''` | Bindable. The current text in the input field. Used for filtering items. Updated on every keystroke and when an item is selected (set to the item's label). |
|
|
202
|
+
| open | `boolean` | No | `false` | Bindable. Controls whether the dropdown is visible. Opens on focus or typing; closes on selection, Escape, outside click, or Tab. |
|
|
203
|
+
| highlightedIndex | `number` | No | `-1` | Bindable. Index of the currently highlighted item within selectable (non-disabled) items. Set to -1 when nothing is highlighted. Useful for external highlight control. |
|
|
204
|
+
| placeholder | `string` | No | `''` | Placeholder text shown when the input is empty. |
|
|
205
|
+
| disabled | `boolean` | No | `false` | When true, the input is non-interactive and the dropdown cannot open. The component appears dimmed (opacity 0.5). |
|
|
206
|
+
| name | `string` | No | `-` | HTML `name` attribute on the input. Use for form submission. |
|
|
207
|
+
| testId | `string` | No | `-` | Value for the `data-pw` attribute on the container. The input gets `{testId}-input` and each option gets `{testId}-option-{id}`. |
|
|
208
|
+
| classes | `string` | No | `-` | CSS class string applied to the component's top-level element. Useful for theming — define classes with CSS variable overrides and pass them to create variant styles. |
|
|
209
|
+
| noResultsText | `string` | No | `'No results'` | Text shown in the dropdown when no items match the current input value. Ignored when `emptySnippet` is provided. |
|
|
210
|
+
| ariaLabel | `string` | No | `-` | Sets `aria-label` on the listbox dropdown. Provides an accessible name for screen readers (e.g., `"Search results"`). |
|
|
211
|
+
| inputProperties | `OptionalInputProperties` | No | `-` | Pass-through props for the internal Input component. Use for validation (`validators`, `validationPattern`, `inProgressPattern`), text formatting (`textTransformers`, `textViewPresentation`), `dataType`, `maxLength`, `minLength`, `useTextArea`, `label`, `onErrorMessage`, `infoMessage`, etc. See Input component docs for the full list. |
|
|
212
|
+
| inputEventProperties | `InputEventProperties` | No | `-` | Pass-through event handlers for the internal Input component. Use for `onpaste`, `onstatechange`, `onclick`, etc. Note: `oninput`, `onfocus`, `onblur`, and `onkeydown` are managed by Combobox and forwarded — use Combobox's own events for these. |
|
|
213
|
+
| filterFn | `(item: ComboboxItem, query: string) => boolean` | No | case-insensitive `includes` | Custom filter function called for each item when `inputValue` is non-empty. Return `true` to include the item. Use for startsWith, fuzzy matching, or server-side filtering (always return `true` and update `items` externally). |
|
|
214
|
+
|
|
215
|
+
## Snippets
|
|
216
|
+
|
|
217
|
+
Svelte 5 Snippet props — pass content blocks to the component.
|
|
218
|
+
|
|
219
|
+
| Snippet | Type | Description |
|
|
220
|
+
| -------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
221
|
+
| itemSnippet | `Snippet<[ComboboxItem, boolean]>` | Custom rendering for each dropdown item. Receives the `ComboboxItem` and a `boolean` indicating whether the item is currently highlighted. Cast the item to your extended type to access extra properties. |
|
|
222
|
+
| emptySnippet | `Snippet` | Custom content shown when the filter matches no items. Use for "create new" buttons, loading indicators, or styled empty states. When provided, overrides `noResultsText`. |
|
|
223
|
+
| inputPrefix | `Snippet` | Content rendered before the input inside the input wrapper (e.g., a search icon). Sits inside the border/focus ring. |
|
|
224
|
+
| inputSuffix | `Snippet` | Content rendered after the input inside the input wrapper (e.g., a clear button, spinner, or chevron). Sits inside the border/focus ring. |
|
|
225
|
+
| dropdownHeader | `Snippet` | Content rendered at the top of the dropdown, before the options list (e.g., a category label or pinned items). |
|
|
226
|
+
| dropdownFooter | `Snippet` | Content rendered at the bottom of the dropdown, after the options list (e.g., a "Show all results" link or action buttons). |
|
|
227
|
+
|
|
228
|
+
## Events
|
|
229
|
+
|
|
230
|
+
| Event | Type | Description |
|
|
231
|
+
| --------- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
232
|
+
| onselect | `(item: ComboboxItem) => void` | Fires when an item is selected from the dropdown (via click or Enter). Receives the full item object. Cast to your extended type to access extra properties. |
|
|
233
|
+
| oninput | `(value: string) => void` | Fires on every input change. Receives the current input text. Use for server-side filtering or analytics. |
|
|
234
|
+
| onopen | `() => void` | Fires when the dropdown opens (on focus, typing, or ArrowDown). |
|
|
235
|
+
| onclose | `() => void` | Fires when the dropdown closes (on selection, Escape, outside click, or Tab). |
|
|
236
|
+
| onkeydown | `(event: KeyboardEvent) => void` | Fires when a key is pressed in the input, before the component's built-in handling. Call `event.preventDefault()` to suppress the default behavior for that key. |
|
|
237
|
+
| onfocus | `(event: FocusEvent) => void` | Fires when the input element gains focus. |
|
|
238
|
+
| onblur | `(event: FocusEvent) => void` | Fires when the input element loses focus. |
|
|
239
|
+
|
|
240
|
+
## CSS Variables
|
|
241
|
+
|
|
242
|
+
Override these custom properties to theme the component.
|
|
243
|
+
|
|
244
|
+
| Variable | Default | CSS Property | Description |
|
|
245
|
+
| ---------------------------------------------- | ------------------------------------------------------------------- | ---------------- | ------------------------------------------------------------------------------ |
|
|
246
|
+
| `--combobox-width` | `100%` | width | Width of the combobox container. |
|
|
247
|
+
| `--combobox-font-family` | `inherit` | font-family | Font family for the input and dropdown text. |
|
|
248
|
+
| `--combobox-font-size` | `14px` | font-size | Font size for the input and dropdown text. |
|
|
249
|
+
| `--combobox-color` | `currentColor` | color | Text color for the input and dropdown. |
|
|
250
|
+
| `--combobox-disabled-opacity` | `0.5` | opacity | Opacity when the combobox is disabled. |
|
|
251
|
+
| `--combobox-disabled-cursor` | `not-allowed` | cursor | Cursor when the combobox is disabled. |
|
|
252
|
+
| `--combobox-input-padding` | `8px 12px` | padding | Inner padding of the input field. |
|
|
253
|
+
| `--combobox-input-background` | `#ffffff` | background | Background color of the input field. |
|
|
254
|
+
| `--combobox-input-border` | `1px solid currentColor` | border | Border of the input field in its default state. |
|
|
255
|
+
| `--combobox-input-border-radius` | `6px` | border-radius | Corner rounding of the input field. |
|
|
256
|
+
| `--combobox-input-transition` | `border-color 0.15s, box-shadow 0.15s` | transition | Transition animation for input border and shadow changes. |
|
|
257
|
+
| `--combobox-input-hover-border-color` | `currentColor` | border-color | Border color of the input on hover. |
|
|
258
|
+
| `--combobox-input-focus-border-color` | `currentColor` | border-color | Border color of the input when focused. |
|
|
259
|
+
| `--combobox-input-focus-shadow` | `0 0 0 2px currentColor` | box-shadow | Focus ring shadow around the input. |
|
|
260
|
+
| `--combobox-placeholder-color` | `currentColor` | color | Color of the placeholder text. |
|
|
261
|
+
| `--combobox-input-prefix-padding` | `8px` | padding-left | Left padding of the input prefix container. |
|
|
262
|
+
| `--combobox-input-suffix-padding` | `8px` | padding-right | Right padding of the input suffix container. |
|
|
263
|
+
| `--combobox-dropdown-top` | `100%` | top | Top position of the dropdown relative to the container. Change to open upward. |
|
|
264
|
+
| `--combobox-dropdown-left` | `0` | left | Left position of the dropdown relative to the container. |
|
|
265
|
+
| `--combobox-dropdown-right` | `0` | right | Right position of the dropdown relative to the container. |
|
|
266
|
+
| `--combobox-dropdown-gap` | `4px` | margin-top | Gap between the input and the dropdown panel. |
|
|
267
|
+
| `--combobox-dropdown-background` | `#ffffff` | background | Background color of the dropdown panel. |
|
|
268
|
+
| `--combobox-dropdown-border` | `1px solid currentColor` | border | Border of the dropdown panel. |
|
|
269
|
+
| `--combobox-dropdown-border-radius` | `8px` | border-radius | Corner rounding of the dropdown panel. |
|
|
270
|
+
| `--combobox-dropdown-shadow` | `0 4px 12px rgba(0, 0, 0, 0.1)` | box-shadow | Shadow of the dropdown panel. |
|
|
271
|
+
| `--combobox-dropdown-max-height` | `200px` | max-height | Maximum height of the dropdown before it scrolls. |
|
|
272
|
+
| `--combobox-dropdown-z-index` | `10` | z-index | Stack order of the dropdown panel. |
|
|
273
|
+
| `--combobox-dropdown-padding` | `0` | padding | Inner padding of the dropdown panel. |
|
|
274
|
+
| `--combobox-option-padding` | `8px 12px` | padding | Inner padding of each option. |
|
|
275
|
+
| `--combobox-option-color` | `currentColor` | color | Text color of options. |
|
|
276
|
+
| `--combobox-option-font-size` | `inherit` | font-size | Font size of option text. |
|
|
277
|
+
| `--combobox-option-font-weight` | `inherit` | font-weight | Font weight of option text. |
|
|
278
|
+
| `--combobox-option-hover-background` | `#f4f4f5` | background | Background color of an option on hover or when highlighted via keyboard. |
|
|
279
|
+
| `--combobox-option-hover-color` | `var(--combobox-option-color, currentColor)` | color | Text color of an option on hover. |
|
|
280
|
+
| `--combobox-option-selected-background` | `transparent` | background | Background color of the currently selected option. |
|
|
281
|
+
| `--combobox-option-selected-color` | `var(--combobox-option-color, currentColor)` | color | Text color of the currently selected option. |
|
|
282
|
+
| `--combobox-option-selected-font-weight` | `inherit` | font-weight | Font weight of the currently selected option. |
|
|
283
|
+
| `--combobox-option-selected-hover-background` | `var(--combobox-option-selected-background, #f4f4f5)` | background | Background color of the selected option when also hovered/highlighted. |
|
|
284
|
+
| `--combobox-option-disabled-opacity` | `0.4` | opacity | Opacity of disabled options. |
|
|
285
|
+
| `--combobox-option-disabled-cursor` | `not-allowed` | cursor | Cursor shown when hovering disabled options. |
|
|
286
|
+
| `--combobox-empty-padding` | `8px 12px` | padding | Padding of the "no results" message. |
|
|
287
|
+
| `--combobox-empty-color` | `currentColor` | color | Color of the "no results" message text. |
|
|
288
|
+
| `--combobox-empty-font-style` | `italic` | font-style | Font style of the "no results" message. |
|
|
289
|
+
| `--combobox-dropdown-header-border` | `none` | border-bottom | Bottom border of the dropdown header section. |
|
|
290
|
+
| `--combobox-dropdown-header-padding` | `0` | padding | Padding of the dropdown header section. |
|
|
291
|
+
| `--combobox-dropdown-footer-border` | `none` | border-top | Top border of the dropdown footer section. |
|
|
292
|
+
| `--combobox-dropdown-footer-padding` | `0` | padding | Padding of the dropdown footer section. |
|
|
293
|
+
|
|
294
|
+
## Type Reference
|
|
295
|
+
|
|
296
|
+
Custom types used by this component's props and events:
|
|
297
|
+
|
|
298
|
+
### ComboboxItem
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
type ComboboxItem = {
|
|
302
|
+
id: string; // Unique identifier for the item, used as the selected value
|
|
303
|
+
label: string; // Display text shown in the dropdown and input when selected
|
|
304
|
+
disabled?: boolean; // When true, the item is dimmed and cannot be selected
|
|
305
|
+
};
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
To pass extra data (icons, descriptions, etc.), extend the type: `type MyItem = ComboboxItem & { icon: string }` and cast inside `itemSnippet`.
|
|
309
|
+
|
|
310
|
+
## Internal Dependencies
|
|
311
|
+
|
|
312
|
+
This component uses the following library components internally:
|
|
313
|
+
|
|
314
|
+
- Input (for the text input field — inherits validation, text transformers, and ARIA support)
|
|
315
|
+
|
|
316
|
+
## Web Component
|
|
317
|
+
|
|
318
|
+
Tag: `<pui-combobox>`
|
|
319
|
+
|
|
320
|
+
```html
|
|
321
|
+
<pui-combobox placeholder="Search fruits...">
|
|
322
|
+
<svg slot="input-prefix">...</svg>
|
|
323
|
+
</pui-combobox>
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Slots
|
|
327
|
+
|
|
328
|
+
| Slot Name | Maps to Snippet | Description |
|
|
329
|
+
| ----------------- | ---------------- | ------------------------------------------------------- |
|
|
330
|
+
| `input-prefix` | `inputPrefix` | Content rendered before the input (e.g., a search icon).|
|
|
331
|
+
| `input-suffix` | `inputSuffix` | Content rendered after the input (e.g., a clear button).|
|
|
332
|
+
| `empty` | `emptySnippet` | Content shown when the filter matches no items. |
|
|
333
|
+
| `dropdown-header` | `dropdownHeader` | Content rendered at the top of the dropdown. |
|
|
334
|
+
| `dropdown-footer` | `dropdownFooter` | Content rendered at the bottom of the dropdown. |
|
|
335
|
+
|
|
336
|
+
> **Note:** `items`, `filterFn`, `inputProperties`, `inputEventProperties`, and `itemSnippet` are object/function props — set them via JavaScript properties. The `itemSnippet` (which receives per-item arguments) cannot be supplied through a slot.
|