|
@@ -11,28 +11,25 @@ import {Reorder} from 'framer-motion';
|
|
|
|
|
|
import type {SelectOption} from 'sentry/components/compactSelect';
|
|
|
import {TabsContext} from 'sentry/components/tabs';
|
|
|
+import {type BaseTabProps, Tab} from 'sentry/components/tabs/tab';
|
|
|
import {OverflowMenu, useOverflowTabs} from 'sentry/components/tabs/tabList';
|
|
|
import {tabsShouldForwardProp} from 'sentry/components/tabs/utils';
|
|
|
import {space} from 'sentry/styles/space';
|
|
|
import {browserHistory} from 'sentry/utils/browserHistory';
|
|
|
-import type {Tab} from 'sentry/views/issueList/draggableTabBar';
|
|
|
|
|
|
-import {DraggableTab} from './draggableTab';
|
|
|
import type {DraggableTabListItemProps} from './item';
|
|
|
import {Item} from './item';
|
|
|
|
|
|
interface BaseDraggableTabListProps extends DraggableTabListProps {
|
|
|
items: DraggableTabListItemProps[];
|
|
|
- setTabs: (tabs: Tab[]) => void;
|
|
|
- tabs: Tab[];
|
|
|
}
|
|
|
|
|
|
function BaseDraggableTabList({
|
|
|
hideBorder = false,
|
|
|
className,
|
|
|
outerWrapStyles,
|
|
|
- tabs,
|
|
|
- setTabs,
|
|
|
+ onReorder,
|
|
|
+ tabVariant = 'filled',
|
|
|
...props
|
|
|
}: BaseDraggableTabListProps) {
|
|
|
const tabListRef = useRef<HTMLUListElement>(null);
|
|
@@ -108,7 +105,12 @@ function BaseDraggableTabList({
|
|
|
|
|
|
return (
|
|
|
<TabListOuterWrap style={outerWrapStyles}>
|
|
|
- <Reorder.Group axis="x" values={tabs} onReorder={setTabs} as="div">
|
|
|
+ <Reorder.Group
|
|
|
+ axis="x"
|
|
|
+ values={[...state.collection]}
|
|
|
+ onReorder={onReorder}
|
|
|
+ as="div"
|
|
|
+ >
|
|
|
<TabListWrap
|
|
|
{...tabListProps}
|
|
|
orientation={orientation}
|
|
@@ -119,10 +121,10 @@ function BaseDraggableTabList({
|
|
|
{[...state.collection].map(item => (
|
|
|
<Reorder.Item
|
|
|
key={item.key}
|
|
|
- value={tabs.find(tab => tab.key === item.key)}
|
|
|
+ value={item}
|
|
|
style={{display: 'flex', flexDirection: 'row'}}
|
|
|
>
|
|
|
- <DraggableTab
|
|
|
+ <Tab
|
|
|
key={item.key}
|
|
|
item={item}
|
|
|
state={state}
|
|
@@ -131,7 +133,9 @@ function BaseDraggableTabList({
|
|
|
orientation === 'horizontal' && overflowTabs.includes(item.key)
|
|
|
}
|
|
|
ref={element => (tabItemsRef.current[item.key] = element)}
|
|
|
+ variant={tabVariant}
|
|
|
/>
|
|
|
+
|
|
|
{state.selectedKey !== item.key &&
|
|
|
state.collection.getKeyAfter(item.key) !== state.selectedKey && (
|
|
|
<TabDivider />
|
|
@@ -157,23 +161,18 @@ const collectionFactory = (nodes: Iterable<Node<any>>) => new ListCollection(nod
|
|
|
export interface DraggableTabListProps
|
|
|
extends AriaTabListOptions<DraggableTabListItemProps>,
|
|
|
TabListStateOptions<DraggableTabListItemProps> {
|
|
|
- setTabs: (tabs: Tab[]) => void;
|
|
|
- tabs: Tab[];
|
|
|
+ onReorder: (newOrder: Node<DraggableTabListItemProps>[]) => void;
|
|
|
className?: string;
|
|
|
hideBorder?: boolean;
|
|
|
outerWrapStyles?: React.CSSProperties;
|
|
|
+ tabVariant?: BaseTabProps['variant'];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* To be used as a direct child of the <Tabs /> component. See example usage
|
|
|
* in tabs.stories.js
|
|
|
*/
|
|
|
-export function DraggableTabList({
|
|
|
- items,
|
|
|
- tabs,
|
|
|
- setTabs,
|
|
|
- ...props
|
|
|
-}: DraggableTabListProps) {
|
|
|
+export function DraggableTabList({items, ...props}: DraggableTabListProps) {
|
|
|
const collection = useCollection({items, ...props}, collectionFactory);
|
|
|
|
|
|
const parsedItems = useMemo(
|
|
@@ -191,13 +190,7 @@ export function DraggableTabList({
|
|
|
);
|
|
|
|
|
|
return (
|
|
|
- <BaseDraggableTabList
|
|
|
- tabs={tabs}
|
|
|
- items={parsedItems}
|
|
|
- disabledKeys={disabledKeys}
|
|
|
- setTabs={setTabs}
|
|
|
- {...props}
|
|
|
- >
|
|
|
+ <BaseDraggableTabList items={parsedItems} disabledKeys={disabledKeys} {...props}>
|
|
|
{item => <Item {...item} />}
|
|
|
</BaseDraggableTabList>
|
|
|
);
|
|
@@ -210,7 +203,7 @@ const TabDivider = styled('div')`
|
|
|
width: 1px;
|
|
|
border-radius: 6px;
|
|
|
background-color: ${p => p.theme.gray200};
|
|
|
- margin: 9px auto;
|
|
|
+ margin: 8px 4px;
|
|
|
`;
|
|
|
|
|
|
const TabListOuterWrap = styled('div')`
|
|
@@ -236,7 +229,6 @@ const TabListWrap = styled('ul', {
|
|
|
? `
|
|
|
grid-auto-flow: column;
|
|
|
justify-content: start;
|
|
|
- gap: ${space(0.5)};
|
|
|
${!p.hideBorder && `border-bottom: solid 1px ${p.theme.border};`}
|
|
|
stroke-dasharray: 4, 3;
|
|
|
`
|