Skip to content

Commit

Permalink
V6 - feat(DragDrop): add multiple drop zone support (#10771)
Browse files Browse the repository at this point in the history
* feat(DragDrop next): add multiple drop zone support (#10614)

* feat(DragDrop-next): add multiple drop zone support

* update dupe ids

* pass 2 - fixed collision bugs and ref passthrough

* refactor DragDropSort to use DragDropContainer

* move DraggableObject to Container

* updated import, remove unused context

* remove green styling for dragover

* fix overlay styling, glob import

* lock

* revert glob

* update type

* fix doubled directory and merge changes into base

* lock

* fix var/tokens, remove double example, fix DLS context import

* fix variant descriptions, remove TableComposable variant

* snap
  • Loading branch information
kmcfaul authored Jul 23, 2024
1 parent bdf4931 commit abc1d0f
Show file tree
Hide file tree
Showing 34 changed files with 811 additions and 1,069 deletions.
118 changes: 53 additions & 65 deletions packages/react-core/src/components/DataList/DataList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/DataList/data-list';
import { PickOptional } from '../../helpers/typeUtils';

const gridBreakpointClasses = {
none: styles.modifiers.gridNone,
Expand All @@ -19,7 +18,7 @@ export enum DataListWrapModifier {
breakWord = 'breakWord'
}

export interface DataListProps extends Omit<React.HTMLProps<HTMLUListElement>, 'ref'> {
export interface DataListProps extends React.HTMLProps<HTMLUListElement> {
/** Content rendered inside the DataList list */
children?: React.ReactNode;
/** Additional classes added to the DataList list */
Expand All @@ -38,6 +37,8 @@ export interface DataListProps extends Omit<React.HTMLProps<HTMLUListElement>, '
wrapModifier?: DataListWrapModifier | 'nowrap' | 'truncate' | 'breakWord';
/** Object that causes the data list to render hidden inputs which improve selectable item a11y */
onSelectableRowChange?: (event: React.FormEvent<HTMLInputElement>, id: string) => void;
/** @hide custom ref of the DataList */
innerRef?: React.RefObject<HTMLUListElement>;
}

interface DataListContextProps {
Expand All @@ -51,71 +52,58 @@ export const DataListContext = React.createContext<Partial<DataListContextProps>
isSelectable: false
});

class DataList extends React.Component<DataListProps> {
static displayName = 'DataList';
static defaultProps: PickOptional<DataListProps> = {
children: null,
className: '',
selectedDataListItemId: '',
isCompact: false,
gridBreakpoint: 'md',
wrapModifier: null
};
ref = React.createRef<HTMLUListElement>();

constructor(props: DataListProps) {
super(props);
}
export const DataListBase: React.FunctionComponent<DataListProps> = ({
children = null,
className = '',
'aria-label': ariaLabel,
onSelectDataListItem,
selectedDataListItemId = '',
isCompact = false,
gridBreakpoint = 'md',
wrapModifier = null,
onSelectableRowChange,
innerRef,
...props
}: DataListProps) => {
const isSelectable = onSelectDataListItem !== undefined;

getIndex = (id: string) => Array.from(this.ref.current.children).findIndex((item) => item.id === id);
const updateSelectedDataListItem = (event: React.MouseEvent | React.KeyboardEvent, id: string) => {
onSelectDataListItem(event, id);
};

render() {
const {
className,
children,
'aria-label': ariaLabel,
onSelectDataListItem,
selectedDataListItemId,
isCompact,
wrapModifier,
gridBreakpoint,
onSelectableRowChange,
...props
} = this.props;
const isSelectable = onSelectDataListItem !== undefined;
return (
<DataListContext.Provider
value={{
isSelectable,
selectedDataListItemId,
updateSelectedDataListItem,
onSelectableRowChange
}}
>
<ul
className={css(
styles.dataList,
isCompact && styles.modifiers.compact,
gridBreakpointClasses[gridBreakpoint],
wrapModifier && styles.modifiers[wrapModifier],
className
)}
style={props.style}
role="list"
aria-label={ariaLabel}
ref={innerRef}
{...props}
>
{children}
</ul>
</DataListContext.Provider>
);
};

const updateSelectedDataListItem = (event: React.MouseEvent | React.KeyboardEvent, id: string) => {
onSelectDataListItem(event, id);
};
DataListBase.displayName = 'DataListBase';

return (
<DataListContext.Provider
value={{
isSelectable,
selectedDataListItemId,
updateSelectedDataListItem,
onSelectableRowChange
}}
>
<ul
className={css(
styles.dataList,
isCompact && styles.modifiers.compact,
gridBreakpointClasses[gridBreakpoint],
wrapModifier && styles.modifiers[wrapModifier],
className
)}
style={props.style}
role="list"
aria-label={ariaLabel}
{...props}
ref={this.ref}
>
{children}
</ul>
</DataListContext.Provider>
);
}
}
export const DataList = React.forwardRef((props: DataListProps, ref: React.Ref<HTMLUListElement>) => (
<DataListBase innerRef={ref as React.MutableRefObject<any>} {...props} />
));

export { DataList };
DataList.displayName = 'DataList';
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import { DualListSelectorListContext } from './DualListSelectorContext';
export interface DualListSelectorListProps extends React.HTMLProps<HTMLUListElement> {
/** Content rendered inside the dual list selector list. */
children?: React.ReactNode;
/** @hide forwarded ref */
innerRef?: React.RefObject<HTMLUListElement>;
}

export const DualListSelectorList: React.FunctionComponent<DualListSelectorListProps> = ({
export const DualListSelectorListBase: React.FunctionComponent<DualListSelectorListProps> = ({
children,
innerRef,
...props
}: DualListSelectorListProps) => {
const { isTree, ariaLabelledBy, focusedOption, displayOption, selectedOptions, id, options, isDisabled } =
Expand All @@ -31,6 +34,7 @@ export const DualListSelectorList: React.FunctionComponent<DualListSelectorListP
'aria-activedescendant': focusedOption
})}
aria-disabled={isDisabled ? 'true' : undefined}
ref={innerRef}
{...props}
>
{options.length === 0
Expand All @@ -54,4 +58,12 @@ export const DualListSelectorList: React.FunctionComponent<DualListSelectorListP
</ul>
);
};
DualListSelectorListBase.displayName = 'DualListSelectorListBase';

export const DualListSelectorList = React.forwardRef(
(props: DualListSelectorListProps, ref: React.Ref<HTMLUListElement>) => (
<DualListSelectorListBase innerRef={ref as React.MutableRefObject<any>} {...props} />
)
);

DualListSelectorList.displayName = 'DualListSelectorList';
Loading

0 comments on commit abc1d0f

Please sign in to comment.