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

Updated selectable's Option type to reflect div vs button realities #28

Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 6 additions & 3 deletions src/components/selectable/selectable_list/selectable_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { CommonProps } from '../../common';
// eslint-disable-next-line import/named
import { List, AutoSizer, ListProps } from 'react-virtualized';
import { htmlIdGenerator } from '../../../services';
import { EuiSelectableListItem } from './selectable_list_item';
import {
EuiSelectableListItem,
EuiSelectableListItemProps,
} from './selectable_list_item';
import { EuiHighlight } from '../../highlight';
import { Option } from '../types';

Expand Down Expand Up @@ -172,7 +175,7 @@ export class EuiSelectableList extends Component<EuiSelectableListProps> {
className="euiSelectableList__groupLabel"
key={rowKey}
style={style}
{...optionRest}>
{...optionRest as HTMLAttributes<HTMLDivElement>}>
{prepend}
{label}
{append}
Expand All @@ -193,7 +196,7 @@ export class EuiSelectableList extends Component<EuiSelectableListProps> {
disabled={disabled}
prepend={prepend}
append={append}
{...optionRest}>
{...optionRest as EuiSelectableListItemProps}>
{renderOption ? (
renderOption(option, searchValue)
) : (
Expand Down
22 changes: 17 additions & 5 deletions src/components/selectable/types.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { CommonProps } from '../common';
import React, { ButtonHTMLAttributes, HTMLAttributes } from 'react';
import { CommonProps, ExclusiveUnion } from '../common';

export type OptionCheckedType = 'on' | 'off' | undefined;

export interface Option extends CommonProps {
export interface BaseOption extends CommonProps {
/**
* Visible label of option. Must be unique across items if `key` is not supplied
*/
Expand All @@ -21,9 +21,9 @@ export interface Option extends CommonProps {
checked?: OptionCheckedType;
disabled?: boolean;
/**
* Set to true to indicate object is just a grouping label, not a selectable item
* Optional boolean. Set to true to indicate object is just a grouping label, not a selectable item
*/
isGroupLabel?: boolean;
isGroupLabel?: false;
/**
* Node to add between the selection icon and the label
*/
Expand All @@ -34,3 +34,15 @@ export interface Option extends CommonProps {
append?: React.ReactNode;
ref?: (optionIndex: number) => void;
}

export interface GroupLabelOption
extends Omit<BaseOption, 'isGroupLabel'>,
HTMLAttributes<HTMLDivElement> {
isGroupLabel: true;
}

export interface SelectableOption
extends BaseOption,
ButtonHTMLAttributes<HTMLButtonElement> {}

export type Option = ExclusiveUnion<GroupLabelOption, SelectableOption>;