Skip to content

Commit

Permalink
ComboBoxNormalized component (deephaven#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Jun 12, 2024
1 parent 5f68de3 commit 9b40dfe
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/code-studio/src/styleguide/Pickers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PickerNormalized,
Checkbox,
ComboBox,
ComboBoxNormalized,
} from '@deephaven/components';
import { vsPerson } from '@deephaven/icons';
import { Icon } from '@adobe/react-spectrum';
Expand Down Expand Up @@ -61,10 +62,24 @@ function PersonIcon(): JSX.Element {
}

export function Pickers(): JSX.Element {
const [selectedKey, setSelectedKey] = useState<ItemKey | null>(null);
const [selectedKey, setSelectedKey] = useState<ItemKey | null>(200);

const [showIcons, setShowIcons] = useState(true);

const [filteredItems, setFilteredItems] = useState(itemsWithIcons);

const onSearch = useCallback(
(searchText: string) =>
setFilteredItems(
searchText === ''
? itemsWithIcons
: itemsWithIcons.filter(
({ item }) => item?.textValue?.includes(searchText)
)
),
[]
);

const getInitialScrollPosition = useCallback(
async () =>
getPositionOfSelectedItem({
Expand Down Expand Up @@ -163,6 +178,17 @@ export function Pickers(): JSX.Element {
showItemIcons={showIcons}
onChange={onChange}
/>
<ComboBoxNormalized
label="ComboBox (Controlled)"
getInitialScrollPosition={getInitialScrollPosition}
normalizedItems={filteredItems}
selectedKey={selectedKey}
showItemIcons={showIcons}
onChange={onChange}
validationState={selectedKey == null ? 'invalid' : 'valid'}
errorMessage="Please select an item."
onInputChange={onSearch}
/>
</Flex>
</Flex>
</SampleSection>
Expand Down
31 changes: 31 additions & 0 deletions packages/components/src/spectrum/comboBox/ComboBoxNormalized.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ComboBox as SpectrumComboBox } from '@adobe/react-spectrum';
import { FocusableRef } from '@react-types/shared';
import cl from 'classnames';
import { PickerNormalizedPropsT, usePickerNormalizedProps } from '../picker';
import { ComboBoxProps } from './ComboBox';

export type ComboBoxNormalizedProps = PickerNormalizedPropsT<ComboBoxProps>;

export function ComboBoxNormalized({
UNSAFE_className,
...props
}: ComboBoxNormalizedProps): JSX.Element {
const { forceRerenderKey, ref, ...pickerProps } =
usePickerNormalizedProps<ComboBoxNormalizedProps>(props);

return (
<SpectrumComboBox
// eslint-disable-next-line react/jsx-props-no-spreading
{...pickerProps}
key={forceRerenderKey}
ref={ref as FocusableRef<HTMLElement>}
UNSAFE_className={cl(
'dh-combobox',
'dh-combobox-normalized',
UNSAFE_className
)}
/>
);
}

export default ComboBoxNormalized;
1 change: 1 addition & 0 deletions packages/components/src/spectrum/comboBox/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './ComboBox';
export * from './ComboBoxNormalized';
11 changes: 11 additions & 0 deletions packages/jsapi-components/src/spectrum/ComboBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { dh as DhType } from '@deephaven/jsapi-types';

export interface ComboBoxProps {
table: DhType.Table;
}

export function ComboBox({ table }: ComboBoxProps): JSX.Element {
return <>ComboBox</>;
}

export default ComboBox;

0 comments on commit 9b40dfe

Please sign in to comment.