-
Notifications
You must be signed in to change notification settings - Fork 215
feat: add label/value object support for Select options, streamlines normalization #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ba22628:
|
Co-authored-by: gsimone <[email protected]>
Co-authored-by: gsimone <[email protected]>
Co-authored-by: gsimone <[email protected]>
| export const ValueLabelObjectsWithFunctions = () => { | ||
| const fn1 = () => console.log('Function 1') | ||
| const fn2 = () => console.log('Function 2') | ||
| const fn3 = () => console.log('Function 3') | ||
|
|
||
| const values = useControls({ | ||
| myFunction: { | ||
| options: [ | ||
| { value: fn1, label: 'First Function' }, | ||
| { value: fn2, label: 'Second Function' }, | ||
| { value: fn3, label: 'Third Function' }, | ||
| ], | ||
| }, | ||
| }) | ||
|
|
||
| return ( | ||
| <div> | ||
| <pre>Selected: {values.myFunction.name || 'anonymous function'}</pre> | ||
| <button onClick={values.myFunction}>Call selected function</button> | ||
| </div> | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot This is out of scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the ValueLabelObjectsWithFunctions story in commit 5579ffe. The ValueLabelObjects story remains to demonstrate the new API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~
|
@copilot Fix the comments and add a story for the new api |
Co-authored-by: gsimone <[email protected]>
4504a50 to
ba22628
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the Select input component to support a new {value, label} object array format for options, replaces the v8n validation library with Zod, and adds comprehensive test coverage using Vitest.
- Adds support for
[{ value: T, label?: string }]format for select options - Migrates validation from v8n to Zod for better type safety and clearer error messages
- Introduces Vitest 4.0.6 for testing with 361 lines of comprehensive test coverage
Reviewed Changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds [email protected] and [email protected] dependencies with related packages |
| packages/leva/package.json | Adds zod@^4.1.12 as a dependency |
| package.json | Adds vitest@^4.0.6 as a dev dependency |
| packages/leva/src/types/public.ts | Updates SelectInput types to support new SelectOption format |
| packages/leva/src/plugins/Select/select-types.ts | Adds SelectOption type definition and updates SelectSettings |
| packages/leva/src/plugins/Select/select-plugin.ts | Replaces v8n with Zod validation and implements new option format handling |
| packages/leva/src/plugins/Select/select-plugin.test.ts | Adds comprehensive test coverage for all select plugin functions |
| packages/leva/src/types/public.test.ts | Adds type tests for the new value/label object format |
| packages/leva/stories/inputs/Select.stories.tsx | Updates stories with better documentation and new ValueLabelObjects example |
| packages/leva/stories/advanced/Busy.stories.tsx | Fixes deprecated array-in-array option format |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
packages/leva/src/plugins/Select/select-plugin.ts:38
- Unused variable allUsecases.
const allUsecases = z.union([arrayOfPrimitivesSchema, keyAsLabelObjectSchema, arrayOfValueLabelObjectsSchema])
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| const arrayOfValueLabelObjectsSchema = z.array(valueLabelObjectSchema) | ||
|
|
||
| const allUsecases = z.union([arrayOfPrimitivesSchema, keyAsLabelObjectSchema, arrayOfValueLabelObjectsSchema]) |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The allUsecases schema is defined but never used in the code. Consider removing this unused variable or utilizing it if it was intended for validation purposes.
Enables human-readable labels for Select option values, particularly useful when values are hex codes or other technical representations.
Changes
Core logic (
select-plugin.ts):{value, label}objects by checking first element{value, label}objectsType definitions:
SelectOption<T>type toselect-types.tsandpublic.tsSelectSettingsto acceptSelectOption<U>[]Examples (
Select.stories.tsx):ValueLabelObjectsstory demonstrating hex colors with friendly namesUsage
Backward compatible with existing array and object formats.
Demo
Labels display in the dropdown while hex color values are returned.
optionsbindings? #551Original prompt
optionsbindings? #551💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.