From d57e8a6a542ebcaeb033c01ffc4274c6c8194c5e Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Wed, 24 May 2023 08:37:33 -0400 Subject: [PATCH 1/2] feat(Select,Dropdown): renamed itemId prop to value --- .../CalendarMonth/CalendarMonth.tsx | 28 ++++---- .../components/Form/examples/FormState.tsx | 10 +-- .../examples/LoginPageLanguageSelect.tsx | 14 ++-- .../src/components/Select/Select.tsx | 8 +-- .../src/components/Select/SelectOption.tsx | 5 +- .../Select/examples/SelectBasic.tsx | 12 ++-- .../Select/examples/SelectCheckbox.tsx | 18 ++--- .../Select/examples/SelectFooter.tsx | 12 ++-- .../Select/examples/SelectGrouped.tsx | 18 ++--- .../Select/examples/SelectMultiTypeahead.tsx | 32 ++++----- .../examples/SelectMultiTypeaheadCheckbox.tsx | 34 +++++----- .../SelectMultiTypeaheadCreatable.tsx | 38 +++++------ .../examples/SelectOptionVariations.tsx | 18 ++--- .../Select/examples/SelectTypeahead.tsx | 34 +++++----- .../examples/SelectTypeaheadCreatable.tsx | 40 +++++------ .../Select/examples/SelectViewMore.tsx | 34 +++++----- .../ToolbarComponentManagedToggleGroups.tsx | 12 ++-- .../ToolbarConsumerManagedToggleGroups.tsx | 12 ++-- .../ToolbarCustomChipGroupContent.tsx | 58 ++++------------ .../Toolbar/examples/ToolbarGroups.tsx | 30 ++++---- .../Toolbar/examples/ToolbarStacked.tsx | 4 +- .../Toolbar/examples/ToolbarWithFilters.tsx | 14 ++-- .../Tooltip/examples/TooltipOptions.tsx | 57 ++++++++++------ packages/react-core/src/demos/Card/Card.md | 68 ++++++++++++++----- packages/react-core/src/demos/CardDemos.md | 30 ++++---- .../CustomMenus/examples/ActionsMenuDemo.tsx | 20 +++--- .../CustomMenus/examples/DateSelectDemo.tsx | 12 ++-- .../CustomMenus/examples/OptionsMenuDemo.tsx | 14 ++-- packages/react-core/src/demos/Toolbar.md | 2 +- .../Table/examples/TableSortableCustom.tsx | 31 +++------ .../examples/LegacyTableSortableCustom.tsx | 41 ++++------- packages/react-table/src/docs/demos/Table.md | 56 +++++++-------- .../src/docs/demos/table-demos/Compact.jsx | 28 ++++---- .../demos/table-demos/CompoundExpansion.jsx | 8 +-- .../demos/table-demos/SortableResponsive.jsx | 28 +++----- .../table-demos/StaticBottomPagination.jsx | 26 ++++--- 36 files changed, 454 insertions(+), 452 deletions(-) diff --git a/packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx b/packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx index e312b83bca4..4678274d6a6 100644 --- a/packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx +++ b/packages/react-core/src/components/CalendarMonth/CalendarMonth.tsx @@ -106,7 +106,7 @@ const buildCalendar = (year: number, month: number, weekStart: number, validator const date = new Date(firstDayOfWeek); week.push({ date, - isValid: validators.every(validator => validator(date)) + isValid: validators.every((validator) => validator(date)) }); firstDayOfWeek.setDate(firstDayOfWeek.getDate() + 1); } @@ -129,10 +129,10 @@ const today = new Date(); export const CalendarMonth = ({ date: dateProp, locale = undefined, - monthFormat = date => date.toLocaleDateString(locale, { month: 'long' }), - weekdayFormat = date => date.toLocaleDateString(locale, { weekday: 'narrow' }), - longWeekdayFormat = date => date.toLocaleDateString(locale, { weekday: 'long' }), - dayFormat = date => date.getDate(), + monthFormat = (date) => date.toLocaleDateString(locale, { month: 'long' }), + weekdayFormat = (date) => date.toLocaleDateString(locale, { weekday: 'narrow' }), + longWeekdayFormat = (date) => date.toLocaleDateString(locale, { weekday: 'long' }), + dayFormat = (date) => date.getDate(), weekStart = 0, // Use the American Sunday as a default onChange = () => {}, validators = [() => true], @@ -148,7 +148,9 @@ export const CalendarMonth = ({ inlineProps, ...props }: CalendarProps) => { - const longMonths = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(monthNum => new Date(1990, monthNum)).map(monthFormat); + const longMonths = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] + .map((monthNum) => new Date(1990, monthNum)) + .map(monthFormat); const [isSelectOpen, setIsSelectOpen] = React.useState(false); // eslint-disable-next-line prefer-const const [focusedDate, setFocusedDate] = React.useState(() => { @@ -168,7 +170,7 @@ export const CalendarMonth = ({ const [hiddenMonthId] = React.useState(getUniqueId('hidden-month-span')); const [shouldFocus, setShouldFocus] = React.useState(false); - const isValidated = (date: Date) => validators.every(validator => validator(date)); + const isValidated = (date: Date) => validators.every((validator) => validator(date)); const focusedDateValidated = isValidated(focusedDate); useEffect(() => { if (isValidDate(dateProp) && !isSameDate(focusedDate, dateProp)) { @@ -224,12 +226,10 @@ export const CalendarMonth = ({ const nextMonth = addMonth(1); const focusedYear = focusedDate.getFullYear(); const focusedMonth = focusedDate.getMonth(); - const calendar = React.useMemo(() => buildCalendar(focusedYear, focusedMonth, weekStart, validators), [ - focusedYear, - focusedMonth, - weekStart, - validators - ]); + const calendar = React.useMemo( + () => buildCalendar(focusedYear, focusedMonth, weekStart, validators), + [focusedYear, focusedMonth, weekStart, validators] + ); if (!focusedDateValidated) { const toFocus = calendar .reduce((acc, cur) => [...acc, ...cur], []) @@ -299,7 +299,7 @@ export const CalendarMonth = ({ > {longMonths.map((longMonth, index) => ( - + {longMonth} ))} diff --git a/packages/react-core/src/components/Form/examples/FormState.tsx b/packages/react-core/src/components/Form/examples/FormState.tsx index e51d701127f..b3cbd9f53e5 100644 --- a/packages/react-core/src/components/Form/examples/FormState.tsx +++ b/packages/react-core/src/components/Form/examples/FormState.tsx @@ -76,15 +76,15 @@ export const FormState = () => { )} onOpenChange={(isOpen) => setIsSelectOpen(isOpen)} - onSelect={(_, itemId) => { - setValue('select-id', itemId as string); + onSelect={(_, value) => { + setValue('select-id', value as string); setIsSelectOpen(false); }} > - Option 1 - Option 2 - Option 3 + Option 1 + Option 2 + Option 3 diff --git a/packages/react-core/src/components/LoginPage/examples/LoginPageLanguageSelect.tsx b/packages/react-core/src/components/LoginPage/examples/LoginPageLanguageSelect.tsx index fa82ac9e63f..9606508b16b 100644 --- a/packages/react-core/src/components/LoginPage/examples/LoginPageLanguageSelect.tsx +++ b/packages/react-core/src/components/LoginPage/examples/LoginPageLanguageSelect.tsx @@ -39,25 +39,25 @@ export const LoginPageLanguageSelect: React.FunctionComponent = () => { const headerUtilsOptions = ( - + {i18n.English} - + {i18n.Mandarin} - + {i18n.Hindi} - + {i18n.Spanish} - + {i18n.Portuguese} - + {i18n.Arabic} - + {i18n.Bengali} diff --git a/packages/react-core/src/components/Select/Select.tsx b/packages/react-core/src/components/Select/Select.tsx index 4a492d812d5..d3f71d5862f 100644 --- a/packages/react-core/src/components/Select/Select.tsx +++ b/packages/react-core/src/components/Select/Select.tsx @@ -37,14 +37,14 @@ export interface SelectProps extends MenuProps, OUIAProps { className?: string; /** Flag to indicate if select is open */ isOpen?: boolean; - /** Single itemId for single select menus, or array of itemIds for multi select. You can also specify isSelected on the SelectOption. */ + /** Single select option value for single select menus, or array of select option values for multi select. You can also specify isSelected on the SelectOption. */ selected?: any | any[]; /** Select toggle. The toggle should either be a renderer function which forwards the given toggle ref, or a direct ReactNode that should be passed along with the toggleRef property. */ toggle: SelectToggleProps | ((toggleRef: React.RefObject) => React.ReactNode); /** Flag indicating the toggle should be focused after a selection. If this use case is too restrictive, the optional toggleRef property with a node toggle may be used to control focus. */ shouldFocusToggleOnSelect?: boolean; /** Function callback when user selects an option. */ - onSelect?: (event?: React.MouseEvent, itemId?: string | number) => void; + onSelect?: (event?: React.MouseEvent, value?: string | number) => void; /** Callback to allow the select component to change the open state of the menu. * Triggered by clicking outside of the menu, or by pressing any keys specificed in onOpenChangeKeys. */ onOpenChange?: (isOpen: boolean) => void; @@ -135,8 +135,8 @@ const SelectBase: React.FunctionComponent = ({ role={role} className={css(className)} ref={menuRef} - onSelect={(event, itemId) => { - onSelect && onSelect(event, itemId); + onSelect={(event, value) => { + onSelect && onSelect(event, value); shouldFocusToggleOnSelect && toggleRef.current.focus(); }} isPlain={isPlain} diff --git a/packages/react-core/src/components/Select/SelectOption.tsx b/packages/react-core/src/components/Select/SelectOption.tsx index 5c941f39e7e..ba050908dd2 100644 --- a/packages/react-core/src/components/Select/SelectOption.tsx +++ b/packages/react-core/src/components/Select/SelectOption.tsx @@ -14,7 +14,7 @@ export interface SelectOptionProps extends Omit { /** @hide Forwarded ref */ innerRef?: React.Ref; /** Identifies the component in the Select onSelect callback */ - itemId?: any; + value?: any; /** Indicates the option has a checkbox */ hasCheckbox?: boolean; /** Indicates the option is disabled */ @@ -37,9 +37,10 @@ const SelectOptionBase: React.FunctionComponent = ({ children, className, innerRef, + value, ...props }: SelectOptionProps) => ( - + {children} ); diff --git a/packages/react-core/src/components/Select/examples/SelectBasic.tsx b/packages/react-core/src/components/Select/examples/SelectBasic.tsx index 9a7f56af78c..a149e5d3994 100644 --- a/packages/react-core/src/components/Select/examples/SelectBasic.tsx +++ b/packages/react-core/src/components/Select/examples/SelectBasic.tsx @@ -10,11 +10,11 @@ export const SelectBasic: React.FunctionComponent = () => { setIsOpen(!isOpen); }; - const onSelect = (_event: React.MouseEvent | undefined, itemId: string | number | undefined) => { + const onSelect = (_event: React.MouseEvent | undefined, value: string | number | undefined) => { // eslint-disable-next-line no-console - console.log('selected', itemId); + console.log('selected', value); - setSelected(itemId as string); + setSelected(value as string); setIsOpen(false); }; @@ -53,9 +53,9 @@ export const SelectBasic: React.FunctionComponent = () => { shouldFocusToggleOnSelect > - Option 1 - Option 2 - Option 3 + Option 1 + Option 2 + Option 3 diff --git a/packages/react-core/src/components/Select/examples/SelectCheckbox.tsx b/packages/react-core/src/components/Select/examples/SelectCheckbox.tsx index c6c2fbe0e85..41525ea1803 100644 --- a/packages/react-core/src/components/Select/examples/SelectCheckbox.tsx +++ b/packages/react-core/src/components/Select/examples/SelectCheckbox.tsx @@ -9,14 +9,14 @@ export const SelectCheckbox: React.FunctionComponent = () => { setIsOpen(!isOpen); }; - const onSelect = (_event: React.MouseEvent | undefined, itemId: string | number | undefined) => { + const onSelect = (_event: React.MouseEvent | undefined, value: string | number | undefined) => { // eslint-disable-next-line no-console - console.log('selected', itemId); + console.log('selected', value); - if (selectedItems.includes(itemId as number)) { - setSelectedItems(selectedItems.filter((id) => id !== itemId)); + if (selectedItems.includes(value as number)) { + setSelectedItems(selectedItems.filter((id) => id !== value)); } else { - setSelectedItems([...selectedItems, itemId as number]); + setSelectedItems([...selectedItems, value as number]); } }; @@ -47,16 +47,16 @@ export const SelectCheckbox: React.FunctionComponent = () => { toggle={toggle} > - + Debug - + Info - + Warn - + Error diff --git a/packages/react-core/src/components/Select/examples/SelectFooter.tsx b/packages/react-core/src/components/Select/examples/SelectFooter.tsx index 19f14cc8dc6..5172816e5af 100644 --- a/packages/react-core/src/components/Select/examples/SelectFooter.tsx +++ b/packages/react-core/src/components/Select/examples/SelectFooter.tsx @@ -24,12 +24,12 @@ export const SelectFooter: React.FunctionComponent = () => { ); - function onSelect(event: React.MouseEvent | undefined, itemId: string | number | undefined) { - if (typeof itemId === 'undefined') { + function onSelect(event: React.MouseEvent | undefined, value: string | number | undefined) { + if (typeof value === 'undefined') { return; } - setSelected(itemId.toString()); + setSelected(value.toString()); } return ( @@ -43,9 +43,9 @@ export const SelectFooter: React.FunctionComponent = () => { selected={selected} > - Option 1 - Option 2 - Option 3 + Option 1 + Option 2 + Option 3