Skip to content
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

feat: introduce new select field based on shadcn implementation with custom interfaces #134

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: extract select field story values to separate file to hide …
…in UI
sjschlapbach committed Oct 5, 2024
commit 340c653e42e47a52a9dd00766d137a86ad0ed421
65 changes: 1 addition & 64 deletions packages/design-system/src/Select.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,69 +1,6 @@
import { useState } from 'react'
import Select from './Select'

export const fruitsValues = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'pear', label: 'Pear' },
{ value: 'watermelon', label: 'Watermelon' },
{ value: 'peach', label: 'Peach' },
{ value: 'mango', label: 'Mango' },
]
export const vegetablesValues = [
{ value: 'carrot', label: 'Carrot' },
{ value: 'cucumber', label: 'Cucumber' },
{ value: 'onion', label: 'Onion' },
{ value: 'potato', label: 'Potato' },
{ value: 'tomato', label: 'Tomato' },
{ value: 'broccoli', label: 'Broccoli' },
]
export const transportValues = [
{ value: 'car', label: 'Car' },
{ value: 'bike', label: 'Bike' },
{ value: 'train', label: 'Train' },
{ value: 'plane', label: 'Plane' },
{ value: 'boat', label: 'Boat' },
{ value: 'bus', label: 'Bus' },
]
export const programmingValues = [
{ value: 'javascript', label: 'JavaScript' },
{ value: 'typescript', label: 'TypeScript' },
{ value: 'python', label: 'Python' },
{ value: 'ruby', label: 'Ruby' },
{ value: 'java', label: 'Java' },
{ value: 'csharp', label: 'C#' },
]

export const programmingValuesDisabled = [
{ value: 'javascript', label: 'JavaScript (disabled)', disabled: true },
{ value: 'typescript', label: 'TypeScript' },
{ value: 'python', label: 'Python (disabled)', disabled: true },
{ value: 'ruby', label: 'Ruby' },
{ value: 'java', label: 'Java (disabled)' },
{ value: 'csharp', label: 'C#' },
]

export const groupValues = [
{ items: fruitsValues },
{ items: vegetablesValues, showSeparator: true },
{ items: transportValues, showSeparator: true, label: 'Transport' },
{
items: programmingValues,
showSeparator: true,
label: 'Programming Languages',
},
]

export const groupValuesDisabled = [
{ items: fruitsValues },
{ items: vegetablesValues, showSeparator: true },
{ items: transportValues, showSeparator: true, label: 'Transport' },
{
items: programmingValuesDisabled,
showSeparator: true,
label: 'Programming Languages',
},
]
import { fruitsValues, groupValues } from './values'

export const Default = () => {
return (
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import {
groupValues,
groupValuesDisabled,
programmingValuesDisabled,
} from '../Select.stories'
} from '../values'
import FormikSelectField from './FormikSelectField'

export const Default = () => {
2 changes: 1 addition & 1 deletion packages/design-system/src/forms/SelectField.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react'
import { fruitsValues, groupValues } from '../Select.stories'
import { fruitsValues, groupValues } from '../values'
import SelectField from './SelectField'

export const Default = () => {
63 changes: 63 additions & 0 deletions packages/design-system/src/values.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export const fruitsValues = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'pear', label: 'Pear' },
{ value: 'watermelon', label: 'Watermelon' },
{ value: 'peach', label: 'Peach' },
{ value: 'mango', label: 'Mango' },
]
export const vegetablesValues = [
{ value: 'carrot', label: 'Carrot' },
{ value: 'cucumber', label: 'Cucumber' },
{ value: 'onion', label: 'Onion' },
{ value: 'potato', label: 'Potato' },
{ value: 'tomato', label: 'Tomato' },
{ value: 'broccoli', label: 'Broccoli' },
]
export const transportValues = [
{ value: 'car', label: 'Car' },
{ value: 'bike', label: 'Bike' },
{ value: 'train', label: 'Train' },
{ value: 'plane', label: 'Plane' },
{ value: 'boat', label: 'Boat' },
{ value: 'bus', label: 'Bus' },
]
export const programmingValues = [
{ value: 'javascript', label: 'JavaScript' },
{ value: 'typescript', label: 'TypeScript' },
{ value: 'python', label: 'Python' },
{ value: 'ruby', label: 'Ruby' },
{ value: 'java', label: 'Java' },
{ value: 'csharp', label: 'C#' },
]

export const programmingValuesDisabled = [
{ value: 'javascript', label: 'JavaScript (disabled)', disabled: true },
{ value: 'typescript', label: 'TypeScript' },
{ value: 'python', label: 'Python (disabled)', disabled: true },
{ value: 'ruby', label: 'Ruby' },
{ value: 'java', label: 'Java (disabled)' },
{ value: 'csharp', label: 'C#' },
]
Comment on lines +34 to +41
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistency in disabled entries and consider UI implications.

The programmingValuesDisabled constant has a few issues:

  1. The "Java" entry is labeled as disabled but doesn't have the disabled: true property.
  2. Appending "(disabled)" to labels might be redundant if the UI can visually indicate disabled status.

Consider the following changes:

-  { value: 'javascript', label: 'JavaScript (disabled)', disabled: true },
+  { value: 'javascript', label: 'JavaScript', disabled: true },
   { value: 'typescript', label: 'TypeScript' },
-  { value: 'python', label: 'Python (disabled)', disabled: true },
+  { value: 'python', label: 'Python', disabled: true },
   { value: 'ruby', label: 'Ruby' },
-  { value: 'java', label: 'Java (disabled)' },
+  { value: 'java', label: 'Java', disabled: true },
   { value: 'csharp', label: 'C#' },

These changes ensure consistency across all entries and rely on the UI to indicate disabled status rather than modifying the labels.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const programmingValuesDisabled = [
{ value: 'javascript', label: 'JavaScript (disabled)', disabled: true },
{ value: 'typescript', label: 'TypeScript' },
{ value: 'python', label: 'Python (disabled)', disabled: true },
{ value: 'ruby', label: 'Ruby' },
{ value: 'java', label: 'Java (disabled)' },
{ value: 'csharp', label: 'C#' },
]
export const programmingValuesDisabled = [
{ value: 'javascript', label: 'JavaScript', disabled: true },
{ value: 'typescript', label: 'TypeScript' },
{ value: 'python', label: 'Python', disabled: true },
{ value: 'ruby', label: 'Ruby' },
{ value: 'java', label: 'Java', disabled: true },
{ value: 'csharp', label: 'C#' },
]


export const groupValues = [
{ items: fruitsValues },
{ items: vegetablesValues, showSeparator: true },
{ items: transportValues, showSeparator: true, label: 'Transport' },
{
items: programmingValues,
showSeparator: true,
label: 'Programming Languages',
},
]

export const groupValuesDisabled = [
{ items: fruitsValues },
{ items: vegetablesValues, showSeparator: true },
{ items: transportValues, showSeparator: true, label: 'Transport' },
{
items: programmingValuesDisabled,
showSeparator: true,
label: 'Programming Languages',
},
]