-
Notifications
You must be signed in to change notification settings - Fork 350
refactor(pill-cloud): migrate PillCloud from Flow to TypeScript #4723
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: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import * as React from 'react'; | ||
| import classNames from 'classnames'; | ||
| import isEqual from 'lodash/isEqual'; | ||
|
|
||
| import Button from '../button'; | ||
| import { ButtonProps } from '../button/Button'; | ||
|
|
||
| export interface PillCloudOption { | ||
| /** Text shown on the pill */ | ||
| displayText: string; | ||
| id?: string; | ||
| /** Value used as the pill key and resin target */ | ||
| value: string | number | null; | ||
| } | ||
|
|
||
| export interface PillCloudProps { | ||
| /** Props forwarded to each pill Button */ | ||
| buttonProps?: Partial<ButtonProps> & Record<string, unknown>; | ||
| /** Called with the option when a pill is clicked */ | ||
| onSelect?: (option: PillCloudOption) => void; | ||
| /** Options to render as pills */ | ||
| options: Array<PillCloudOption>; | ||
| /** Currently selected options */ | ||
| selectedOptions?: Array<PillCloudOption>; | ||
| } | ||
|
|
||
| const PillCloud = ({ options, onSelect, selectedOptions = [], buttonProps = {} }: PillCloudProps) => ( | ||
| <div className="bdl-PillCloud pill-cloud-container"> | ||
| {options?.map(option => ( | ||
| <Button | ||
| key={option.value} | ||
| className={classNames('bdl-Pill', 'bdl-PillCloud-button', 'pill', 'pill-cloud-button', { | ||
| 'is-selected': selectedOptions.find(op => isEqual(op, option)), | ||
| })} | ||
| onClick={onSelect ? () => onSelect(option) : undefined} | ||
| data-resin-target={option.value} | ||
| {...buttonProps} | ||
|
Comment on lines
+27
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Protect internally controlled PillCloud props in both implementations. Both implementations spread
📍 Affects 2 files
🤖 Prompt for AI Agents |
||
| > | ||
| {option.displayText} | ||
| </Button> | ||
| ))} | ||
| </div> | ||
| ); | ||
|
|
||
| export default PillCloud; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { default } from './PillCloud'; | ||
| export type { PillCloudOption, PillCloudProps } from './PillCloud'; |
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: box/box-ui-elements
Length of output: 50375
🏁 Script executed:
Repository: box/box-ui-elements
Length of output: 5776
🏁 Script executed:
Repository: box/box-ui-elements
Length of output: 8614
Use a stable, unique option key for
PillCloud.option.valueis nullable and not required to be unique, but it is used as both the React key anddata-resin-targetat lines 31 and 36. Duplicate values can destabilize React reconciliation, andidis optional; prefer a guaranteed unique non-null key or validate this contract, including regression tests for duplicate/nullvalues.🤖 Prompt for AI Agents