@react-spectrum/s2
Version:
Spectrum 2 UI components in React
1,056 lines (1,033 loc) • 46.8 kB
JavaScript
import "./TableView.css";
import {Checkbox as $9b405e0f8095dce0$export$48513f6b9f8ce62d} from "./Checkbox.mjs";
import $4b69f02ec06b9226$export$2e2bcd8739ae039 from "./Chevron.mjs";
import {IconContext as $ac8c32e6775ddd1f$export$a49f528ae1a4d0ed} from "../icons/Icon.mjs";
import $auVFN$intlStringsmjs from "./intlStrings.mjs";
import {Menu as $13afb0ea5f0ed767$export$d9b273488cd8ce6f, MenuItem as $13afb0ea5f0ed767$export$2ce376c2cc3355c8, MenuSection as $13afb0ea5f0ed767$export$4b1545b4f2016d26, MenuTrigger as $13afb0ea5f0ed767$export$27d2ad3c5815583e} from "./Menu.mjs";
import {mergeStyles as $feb886035e0d4633$export$e618dc39ac9ad607} from "../icons/runtime.mjs";
import $1bdd184cd8a3d21d$export$2e2bcd8739ae039 from "./S2_MoveHorizontalTableWidget.mjs";
import {ProgressCircle as $41ddd91dbbf0c389$export$c79b9d6b4cc92af7} from "./ProgressCircle.mjs";
import $5a632e895c21f138$export$2e2bcd8739ae039 from "../icons/SortDown.mjs";
import $415c33109ddcfc45$export$2e2bcd8739ae039 from "../icons/SortUp.mjs";
import {useActionBarContainer as $f21f2186348fbc5b$export$13f32e21845e01d0} from "./ActionBar.mjs";
import {useScale as $859432f3b3573fcb$export$a8d2043b2d807f4d} from "./utils.mjs";
import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../icons/useSpectrumContextProps.mjs";
import {jsxs as $auVFN$jsxs, jsx as $auVFN$jsx, Fragment as $auVFN$Fragment} from "react/jsx-runtime";
import {Rect as $auVFN$Rect, TableLayout as $auVFN$TableLayout, ResizableTableContainer as $auVFN$ResizableTableContainer, Virtualizer as $auVFN$Virtualizer, Table as $auVFN$Table, UNSTABLE_TableLoadingSentinel as $auVFN$UNSTABLE_TableLoadingSentinel, Collection as $auVFN$Collection, TableBody as $auVFN$TableBody, Column as $auVFN$Column, Provider as $auVFN$Provider, Button as $auVFN$Button, ColumnResizer as $auVFN$ColumnResizer, useTableOptions as $auVFN$useTableOptions, TableHeader as $auVFN$TableHeader, useSlottedContext as $auVFN$useSlottedContext, CheckboxContext as $auVFN$CheckboxContext, Cell as $auVFN$Cell, Row as $auVFN$Row} from "react-aria-components";
import {createContext as $auVFN$createContext, forwardRef as $auVFN$forwardRef, useState as $auVFN$useState, useCallback as $auVFN$useCallback, useMemo as $auVFN$useMemo, useRef as $auVFN$useRef, useContext as $auVFN$useContext} from "react";
import {useDOMRef as $auVFN$useDOMRef} from "@react-spectrum/utils";
import {useLocalizedStringFormatter as $auVFN$useLocalizedStringFormatter} from "@react-aria/i18n";
import {VisuallyHidden as $auVFN$VisuallyHidden} from "react-aria";
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
let $0fcd5fb617970a1d$var$InternalTableContext = /*#__PURE__*/ (0, $auVFN$createContext)({});
const $0fcd5fb617970a1d$var$tableWrapper = " Ma91 Na91 sd91 _Bb91 __ca91 _Pc91 _Nb91 Pb91";
const $0fcd5fb617970a1d$var$table = function anonymous(props, overrides) {
let rules = " ";
let width = false;
let minHeight = false;
let minWidth = false;
let matches = (overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|Z|N|L|F|M|K)[^\s]+/g);
for (let p of matches){
if (p[1] === "Z") width = true;
if (p[1] === "M") minHeight = true;
if (p[1] === "N") minWidth = true;
rules += p[0];
}
if (!width) rules += ' Za91';
rules += ' _4c91';
if (!minHeight) rules += ' Ma91';
if (!minWidth) rules += ' Na91';
rules += ' ug91';
rules += ' uch91';
rules += ' udi91';
rules += ' uea91';
rules += ' ugb91';
rules += ' uhd91';
rules += ' uje91';
rules += ' uic91';
rules += ' wb91';
rules += ' xb91';
rules += ' _xa91';
rules += ' _Na91';
rules += ' Pa91';
if (props.isQuiet) rules += ' g991';
else rules += ' gX91';
rules += ' gla91';
rules += ' iq91';
rules += ' _jf91';
if (props.isQuiet) rules += ' _ka91';
else rules += ' _kb91';
if (props.isQuiet) rules += ' ha91';
else rules += ' hb91';
if (props.isQuiet) rules += ' ma91';
else rules += ' mb91';
if (props.isQuiet) rules += ' la91';
else rules += ' lb91';
if (props.isFocusVisible) rules += ' _Lf91';
else rules += ' _Le91';
rules += ' Oh91';
rules += ' _Mc91';
rules += ' _Ka91';
if (props.isQuiet) rules += ' od91';
else rules += ' of91';
if (props.isQuiet) rules += ' nd91';
else rules += ' nf91';
if (props.isQuiet) rules += ' kd91';
else rules += ' kf91';
if (props.isQuiet) rules += ' jd91';
else rules += ' jf91';
rules += ' _Um91';
if (props.isCheckboxSelection) rules += ' _Tk91';
return rules;
};
// component-height-100
const $0fcd5fb617970a1d$var$DEFAULT_HEADER_HEIGHT = {
medium: 32,
large: 40
};
const $0fcd5fb617970a1d$var$ROW_HEIGHTS = {
compact: {
medium: 32,
large: 40
},
regular: {
medium: 40,
large: 50
},
spacious: {
medium: 48,
large: 60
}
};
class $0fcd5fb617970a1d$export$4e03bdf0174fd602 extends (0, $auVFN$TableLayout) {
isStickyColumn(node) {
return node.props.isSticky;
}
buildCollection() {
let [header, body] = super.buildCollection();
if (!header) return [];
let { children: children, layoutInfo: layoutInfo } = body;
// TableLayout's buildCollection always sets the body width to the max width between the header width, but
// we want the body to be sticky and only as wide as the table so it is always in view if loading/empty
// TODO: we may want to adjust RAC layouts to do something simlar? Current users of RAC table will probably run into something similar
let isEmptyOrLoading = children?.length === 0 || children?.length === 1 && children[0].layoutInfo.type === 'loader';
if (isEmptyOrLoading) layoutInfo.rect.width = this.virtualizer.visibleRect.width - 80;
return [
header,
body
];
}
buildLoader(node, x, y) {
let layoutNode = super.buildLoader(node, x, y);
let { layoutInfo: layoutInfo } = layoutNode;
layoutInfo.allowOverflow = true;
layoutInfo.rect.width = this.virtualizer.visibleRect.width;
// If performing first load or empty, the body will be sticky so we don't want to apply sticky to the loader, otherwise it will
// affect the positioning of the empty state renderer
let collection = this.virtualizer.collection;
let isEmptyOrLoading = collection?.size === 0 || collection.size === 1 && collection.getItem(collection.getFirstKey()).type === 'loader';
layoutInfo.isSticky = !isEmptyOrLoading;
return layoutNode;
}
// y is the height of the headers
buildBody(y) {
let layoutNode = super.buildBody(y);
let { children: children, layoutInfo: layoutInfo } = layoutNode;
// Needs overflow for sticky loader
layoutInfo.allowOverflow = true;
// If loading or empty, we'll want the body to be sticky and centered
let isEmptyOrLoading = children?.length === 0 || children?.length === 1 && children[0].layoutInfo.type === 'loader';
if (isEmptyOrLoading) {
layoutInfo.rect = new (0, $auVFN$Rect)(40, 40, this.virtualizer.visibleRect.width - 80, this.virtualizer.visibleRect.height - 80);
layoutInfo.isSticky = true;
}
return {
...layoutNode,
layoutInfo: layoutInfo
};
}
buildRow(node, x, y) {
let layoutNode = super.buildRow(node, x, y);
layoutNode.layoutInfo.allowOverflow = true;
// Needs overflow for sticky selection/drag cells
return layoutNode;
}
buildTableHeader() {
let layoutNode = super.buildTableHeader();
// Needs overflow for sticky selection/drag column
layoutNode.layoutInfo.allowOverflow = true;
return layoutNode;
}
buildColumn(node, x, y) {
let layoutNode = super.buildColumn(node, x, y);
// Needs overflow for the resize handle
layoutNode.layoutInfo.allowOverflow = true;
return layoutNode;
}
}
const $0fcd5fb617970a1d$export$93e4b0b2cc49b648 = /*#__PURE__*/ (0, $auVFN$createContext)(null);
const $0fcd5fb617970a1d$export$b3c27e869d856b7 = /*#__PURE__*/ (0, $auVFN$forwardRef)(function TableView(props, ref) {
[props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $0fcd5fb617970a1d$export$93e4b0b2cc49b648);
let { UNSAFE_style: UNSAFE_style, UNSAFE_className: UNSAFE_className, isQuiet: isQuiet = false, density: density = 'regular', overflowMode: overflowMode = 'truncate', styles: styles, loadingState: loadingState, onResize: propsOnResize, onResizeStart: propsOnResizeStart, onResizeEnd: propsOnResizeEnd, onAction: onAction, onLoadMore: onLoadMore, ...otherProps } = props;
let domRef = (0, $auVFN$useDOMRef)(ref);
let scale = (0, $859432f3b3573fcb$export$a8d2043b2d807f4d)();
// Starts when the user selects resize from the menu, ends when resizing ends
// used to control the visibility of the resizer Nubbin
let [isInResizeMode, setIsInResizeMode] = (0, $auVFN$useState)(false);
let onResizeStart = (0, $auVFN$useCallback)((widths)=>{
propsOnResizeStart?.(widths);
}, [
propsOnResizeStart
]);
let onResizeEnd = (0, $auVFN$useCallback)((widths)=>{
setIsInResizeMode(false);
propsOnResizeEnd?.(widths);
}, [
propsOnResizeEnd,
setIsInResizeMode
]);
let context = (0, $auVFN$useMemo)(()=>({
isQuiet: isQuiet,
density: density,
overflowMode: overflowMode,
loadingState: loadingState,
onLoadMore: onLoadMore,
isInResizeMode: isInResizeMode,
setIsInResizeMode: setIsInResizeMode
}), [
isQuiet,
density,
overflowMode,
loadingState,
onLoadMore,
isInResizeMode,
setIsInResizeMode
]);
let scrollRef = (0, $auVFN$useRef)(null);
let isCheckboxSelection = props.selectionMode === 'multiple' || props.selectionMode === 'single';
let { selectedKeys: selectedKeys, onSelectionChange: onSelectionChange, actionBar: actionBar, actionBarHeight: actionBarHeight } = (0, $f21f2186348fbc5b$export$13f32e21845e01d0)({
...props,
scrollRef: scrollRef
});
return /*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$ResizableTableContainer), {
// TODO: perhaps this ref should be attached to the RACTable but it expects a table type ref which isn't true in the virtualized case
ref: domRef,
onResize: propsOnResize,
onResizeEnd: onResizeEnd,
onResizeStart: onResizeStart,
className: (UNSAFE_className || '') + (0, $feb886035e0d4633$export$e618dc39ac9ad607)($0fcd5fb617970a1d$var$tableWrapper, styles),
style: UNSAFE_style,
children: [
/*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Virtualizer), {
layout: $0fcd5fb617970a1d$export$4e03bdf0174fd602,
layoutOptions: {
rowHeight: overflowMode === 'wrap' ? undefined : $0fcd5fb617970a1d$var$ROW_HEIGHTS[density][scale],
estimatedRowHeight: overflowMode === 'wrap' ? $0fcd5fb617970a1d$var$ROW_HEIGHTS[density][scale] : undefined,
// No need for estimated headingHeight since the headers aren't affected by overflow mode: wrap
headingHeight: $0fcd5fb617970a1d$var$DEFAULT_HEADER_HEIGHT[scale],
loaderHeight: 60
},
children: /*#__PURE__*/ (0, $auVFN$jsx)($0fcd5fb617970a1d$var$InternalTableContext.Provider, {
value: context,
children: /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Table), {
ref: scrollRef,
style: {
// Fix webkit bug where scrollbars appear above the checkboxes/other table elements
WebkitTransform: 'translateZ(0)',
// Add padding at the bottom when the action bar is visible so users can scroll to the last items.
// Also add scroll padding so navigating with the keyboard doesn't go behind the action bar.
paddingBottom: actionBarHeight > 0 ? actionBarHeight + 8 : 0,
scrollPaddingBottom: actionBarHeight > 0 ? actionBarHeight + 8 : 0
},
className: (renderProps)=>$0fcd5fb617970a1d$var$table({
...renderProps,
isCheckboxSelection: isCheckboxSelection,
isQuiet: isQuiet
}),
selectionBehavior: "toggle",
onRowAction: onAction,
...otherProps,
selectedKeys: selectedKeys,
defaultSelectedKeys: undefined,
onSelectionChange: onSelectionChange
})
})
}),
actionBar
]
});
});
const $0fcd5fb617970a1d$var$centeredWrapper = " sd91 eb91 _Ca91 Za91 Fb91";
const $0fcd5fb617970a1d$export$76ccd210b9029917 = /*#__PURE__*/ (0, $auVFN$forwardRef)(function TableBody(props, ref) {
let { items: items, renderEmptyState: renderEmptyState, children: children, dependencies: dependencies = [] } = props;
let domRef = (0, $auVFN$useDOMRef)(ref);
let { loadingState: loadingState, onLoadMore: onLoadMore } = (0, $auVFN$useContext)($0fcd5fb617970a1d$var$InternalTableContext);
let isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
let emptyRender;
let renderer = children;
let stringFormatter = (0, $auVFN$useLocalizedStringFormatter)((0, ($parcel$interopDefault($auVFN$intlStringsmjs))), '@react-spectrum/s2');
// TODO: still is offset strangely if loadingMore when there aren't any items in the table, see http://localhost:6006/?path=/story/tableview--empty-state&args=loadingState:loadingMore
// This is because we don't distinguish between loadingMore and loading in the layout, resulting in a different rect being used to build the body. Perhaps can be considered as a user error
// if they pass loadingMore without having any other items in the table. Alternatively, could update the layout so it knows the current loading state.
let loadMoreSpinner = /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$UNSTABLE_TableLoadingSentinel), {
isLoading: loadingState === 'loadingMore',
onLoadMore: onLoadMore,
className: " Fb91 Za91",
children: /*#__PURE__*/ (0, $auVFN$jsx)("div", {
className: $0fcd5fb617970a1d$var$centeredWrapper,
children: /*#__PURE__*/ (0, $auVFN$jsx)((0, $41ddd91dbbf0c389$export$c79b9d6b4cc92af7), {
isIndeterminate: true,
"aria-label": stringFormatter.format('table.loadingMore')
})
})
});
// If the user is rendering their rows in dynamic fashion, wrap their render function in Collection so we can inject
// the loader. Otherwise it is a static renderer and thus we can simply add the table loader after
// TODO: this assumes that the user isn't providing their children in some wrapper though and/or isn't doing a map of children
// (though I guess they wouldn't provide items then so the check for this is still valid in the latter case)...
if (typeof children === 'function' && items) renderer = /*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Fragment), {
children: [
/*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Collection), {
items: items,
dependencies: dependencies,
children: children
}),
loadMoreSpinner
]
});
else renderer = /*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Fragment), {
children: [
children,
loadMoreSpinner
]
});
if (renderEmptyState != null && !isLoading) emptyRender = (props)=>/*#__PURE__*/ (0, $auVFN$jsx)("div", {
className: $0fcd5fb617970a1d$var$centeredWrapper,
children: renderEmptyState(props)
});
else if (loadingState === 'loading') emptyRender = ()=>/*#__PURE__*/ (0, $auVFN$jsx)("div", {
className: $0fcd5fb617970a1d$var$centeredWrapper,
children: /*#__PURE__*/ (0, $auVFN$jsx)((0, $41ddd91dbbf0c389$export$c79b9d6b4cc92af7), {
isIndeterminate: true,
"aria-label": stringFormatter.format('table.loading')
})
});
return /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$TableBody), {
// @ts-ignore
ref: domRef,
className: " Fb91",
...props,
renderEmptyState: emptyRender,
dependencies: [
loadingState
],
children: renderer
});
});
const $0fcd5fb617970a1d$var$cellFocus = {
outlineStyle: {
default: 'none',
isFocusVisible: 'solid'
},
outlineOffset: -2,
outlineWidth: 2,
outlineColor: 'focus-ring',
borderRadius: '[6px]'
};
function $0fcd5fb617970a1d$var$CellFocusRing() {
return /*#__PURE__*/ (0, $auVFN$jsx)("div", {
role: "presentation",
className: function anonymous(props) {
let rules = " ";
if (props.isFocusVisible) rules += ' _Lf91';
else rules += ' _Le91';
rules += ' _Kb91';
rules += ' _Mc91';
rules += ' Oh91';
rules += ' of91';
rules += ' nf91';
rules += ' kf91';
rules += ' jf91';
rules += ' _Pa91';
rules += ' Wr91';
rules += ' _lr91';
rules += ' _Ar91';
rules += ' _zr91';
return rules;
}({
isFocusVisible: true
})
});
}
const $0fcd5fb617970a1d$var$columnStyles = function anonymous(props) {
let rules = " ";
rules += ' F40ub4c91';
rules += ' _oa91';
if (props.isPressed) rules += ' po91';
else if (props.isFocusVisible) rules += ' po91';
else if (props.isHovered) rules += ' po91';
else rules += ' pt91';
rules += ' plb91';
if (props.isMenu) rules += ' Sd91';
else rules += ' Sf91';
if (props.isMenu) rules += ' Rd91';
else rules += ' Rf91';
if (props.align === "end") rules += ' _Wb91';
else if (props.align === "center") rules += ' _Wa91';
else if (props.align === "start") rules += ' _Wd91';
rules += ' _Le91';
rules += ' _Pc91';
if (props.size === "XL") {
rules += ' vg91';
rules += ' vsj91';
} else if (props.size === "L") {
rules += ' vp91';
rules += ' vsh91';
} else if (props.size === "S") {
rules += ' vb91';
rules += ' vse91';
} else if (props.size === "XS") {
rules += ' va91';
rules += ' vsc91';
} else {
rules += ' vd91';
rules += ' vsf91';
}
rules += ' ug91';
rules += ' uch91';
rules += ' udi91';
rules += ' uea91';
rules += ' ugb91';
rules += ' uhd91';
rules += ' uje91';
rules += ' uic91';
rules += ' wd91';
rules += ' xd91';
rules += ' _xa91';
rules += ' sd91';
rules += ' iq91';
rules += ' ila91';
if (props.isQuiet) rules += ' _kb91';
else rules += ' _ka91';
rules += ' hb91';
rules += ' ma91';
if (props.isMenu) rules += ' lb91';
else rules += ' la91';
rules += ' _jf91';
rules += ' _yb91';
return rules;
};
const $0fcd5fb617970a1d$export$816b5d811295e6bc = /*#__PURE__*/ (0, $auVFN$forwardRef)(function Column(props, ref) {
let { isQuiet: isQuiet } = (0, $auVFN$useContext)($0fcd5fb617970a1d$var$InternalTableContext);
let { allowsResizing: allowsResizing, children: children, align: align = 'start' } = props;
let domRef = (0, $auVFN$useDOMRef)(ref);
let isMenu = allowsResizing || !!props.menuItems;
return /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Column), {
...props,
ref: domRef,
style: {
borderInlineEndColor: 'transparent'
},
className: (renderProps)=>$0fcd5fb617970a1d$var$columnStyles({
...renderProps,
isMenu: isMenu,
align: align,
isQuiet: isQuiet
}),
children: ({ allowsSorting: allowsSorting, sortDirection: sortDirection, isFocusVisible: isFocusVisible, sort: sort, startResize: startResize })=>/*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Fragment), {
children: [
isFocusVisible && /*#__PURE__*/ (0, $auVFN$jsx)($0fcd5fb617970a1d$var$CellFocusRing, {}),
isMenu ? /*#__PURE__*/ (0, $auVFN$jsx)($0fcd5fb617970a1d$var$ColumnWithMenu, {
isColumnResizable: allowsResizing,
menuItems: props.menuItems,
allowsSorting: allowsSorting,
sortDirection: sortDirection,
sort: sort,
startResize: startResize,
align: align,
children: children
}) : /*#__PURE__*/ (0, $auVFN$jsx)($0fcd5fb617970a1d$var$ColumnContents, {
allowsSorting: allowsSorting,
sortDirection: sortDirection,
children: children
})
]
})
});
});
const $0fcd5fb617970a1d$var$columnContentWrapper = " Na91 sd91 eb91 Za91";
const $0fcd5fb617970a1d$var$sortIcon = function anonymous(props) {
let rules = " ";
rules += ' ZXJkxGe91';
rules += ' FXJkxGe91';
rules += ' _va91';
if (props.isButton) {
rules += ' Ht91';
rules += ' Hsu91';
} else rules += ' Hv91';
rules += ' _5b91';
rules += ' -_8sjo0b-t5ZbAob91';
return rules;
};
function $0fcd5fb617970a1d$var$ColumnContents(props) {
let { allowsSorting: allowsSorting, sortDirection: sortDirection, children: children } = props;
return /*#__PURE__*/ (0, $auVFN$jsxs)("div", {
className: $0fcd5fb617970a1d$var$columnContentWrapper,
children: [
allowsSorting && /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Provider), {
values: [
[
(0, $ac8c32e6775ddd1f$export$a49f528ae1a4d0ed),
{
styles: $0fcd5fb617970a1d$var$sortIcon({})
}
]
],
children: sortDirection != null && (sortDirection === 'ascending' ? /*#__PURE__*/ (0, $auVFN$jsx)((0, $415c33109ddcfc45$export$2e2bcd8739ae039), {}) : /*#__PURE__*/ (0, $auVFN$jsx)((0, $5a632e895c21f138$export$2e2bcd8739ae039), {}))
}),
/*#__PURE__*/ (0, $auVFN$jsx)("span", {
className: " _Nc91 Pc91 _Yb91 _7c91 Za91",
children: children
})
]
});
}
const $0fcd5fb617970a1d$var$resizableMenuButtonWrapper = function anonymous(props) {
let rules = " ";
if (props.isFocusVisible) rules += ' _Lf91';
else rules += ' _Le91';
rules += ' _Kb91';
rules += ' _Mc91';
rules += ' Oh91';
rules += ' of91';
rules += ' nf91';
rules += ' kf91';
rules += ' jf91';
rules += ' pt91';
rules += ' Za91';
rules += ' _Pc91';
rules += ' sd91';
rules += ' eb91';
if (props.align === "end") rules += ' _Cb91';
else if (props.align === "center") rules += ' _Ca91';
else if (props.align === "default") rules += ' _Cg91';
rules += ' Sf91';
rules += ' Rf91';
rules += ' g991';
rules += ' _je91';
if (props.size === "XL") {
rules += ' vg91';
rules += ' vsj91';
} else if (props.size === "L") {
rules += ' vp91';
rules += ' vsh91';
} else if (props.size === "S") {
rules += ' vb91';
rules += ' vse91';
} else if (props.size === "XS") {
rules += ' va91';
rules += ' vsc91';
} else {
rules += ' vd91';
rules += ' vsf91';
}
rules += ' ug91';
rules += ' uch91';
rules += ' udi91';
rules += ' uea91';
rules += ' ugb91';
rules += ' uhd91';
rules += ' uje91';
rules += ' uic91';
rules += ' wd91';
rules += ' xd91';
rules += ' _xa91';
return rules;
};
const $0fcd5fb617970a1d$var$resizerHandleContainer = function anonymous(props) {
let rules = " ";
if (props.isInResizeMode) rules += ' sb91';
else if (props.isResizing) rules += ' sb91';
else rules += ' sjBAxlb91';
rules += ' Zj91';
rules += ' Fb91';
rules += ' _Pa91';
rules += ' Wr91';
rules += ' _zdYbyj91';
if (props.resizableDirection === "both") rules += ' rk91';
else if (props.resizableDirection === "right") rules += ' rF91';
else if (props.resizableDirection === "left") rules += ' rj91';
else rules += ' rt91';
return rules;
};
const $0fcd5fb617970a1d$var$resizerHandle = function anonymous(props) {
let rules = " ";
if (props.isResizing) rules += ' g5qAiPc91';
else if (props.isFocusVisible) rules += ' g5qAiPc91';
else rules += ' gE91';
if (props.isResizing) rules += ' gle91';
else if (props.isFocusVisible) rules += ' gle91';
else rules += ' gla91';
if (props.isResizing) rules += ' Fc91';
else rules += ' Fb91';
if (props.isResizing) rules += ' Zf91';
else rules += ' Ze91';
rules += ' _Pa91';
rules += ' _AWJpoB91';
return rules;
};
const $0fcd5fb617970a1d$var$columnHeaderText = " _Nc91 Pc91 _Yb91 _7c91 NXJkxGe91 _ua91 _vb91 _sd91";
const $0fcd5fb617970a1d$var$chevronIcon = " _Sd91 It91 Isu91 NXJkxGe91 _va91 -_8sjo0b-t5ZbAob91";
const $0fcd5fb617970a1d$var$nubbin = " _Pa91 Wr91 _AlhfIS91 ZXJkxGe91 FXJkxGe91 t5qAiPc91 tla91 -_8sjo0b-tw91 -_8sjo0b-lt8pvGJ91";
function $0fcd5fb617970a1d$var$ColumnWithMenu(props) {
let { allowsSorting: allowsSorting, sortDirection: sortDirection, sort: sort, startResize: startResize, children: children, align: align, isColumnResizable: isColumnResizable, menuItems: menuItems } = props;
let { setIsInResizeMode: setIsInResizeMode, isInResizeMode: isInResizeMode } = (0, $auVFN$useContext)($0fcd5fb617970a1d$var$InternalTableContext);
let stringFormatter = (0, $auVFN$useLocalizedStringFormatter)((0, ($parcel$interopDefault($auVFN$intlStringsmjs))), '@react-spectrum/s2');
const onMenuSelect = (key)=>{
switch(key){
case 'sort-asc':
sort('ascending');
break;
case 'sort-desc':
sort('descending');
break;
case 'resize':
setIsInResizeMode?.(true);
startResize();
break;
}
};
let items = (0, $auVFN$useMemo)(()=>{
let options = [];
if (isColumnResizable) options = [
{
label: stringFormatter.format('table.resizeColumn'),
id: 'resize'
}
];
if (allowsSorting) options = [
{
label: stringFormatter.format('table.sortAscending'),
id: 'sort-asc'
},
{
label: stringFormatter.format('table.sortDescending'),
id: 'sort-desc'
},
...options
];
return options;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
allowsSorting,
isColumnResizable
]);
let buttonAlignment = 'start';
let menuAlign = 'start';
if (align === 'center') buttonAlignment = 'center';
else if (align === 'end') {
buttonAlignment = 'end';
menuAlign = 'end';
}
return /*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Fragment), {
children: [
/*#__PURE__*/ (0, $auVFN$jsxs)((0, $13afb0ea5f0ed767$export$27d2ad3c5815583e), {
align: menuAlign,
children: [
/*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Button), {
className: (renderProps)=>$0fcd5fb617970a1d$var$resizableMenuButtonWrapper({
...renderProps,
align: buttonAlignment
}),
children: [
allowsSorting && /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Provider), {
values: [
[
(0, $ac8c32e6775ddd1f$export$a49f528ae1a4d0ed),
{
styles: $0fcd5fb617970a1d$var$sortIcon({
isButton: true
})
}
]
],
children: sortDirection != null && (sortDirection === 'ascending' ? /*#__PURE__*/ (0, $auVFN$jsx)((0, $415c33109ddcfc45$export$2e2bcd8739ae039), {}) : /*#__PURE__*/ (0, $auVFN$jsx)((0, $5a632e895c21f138$export$2e2bcd8739ae039), {}))
}),
/*#__PURE__*/ (0, $auVFN$jsx)("div", {
className: $0fcd5fb617970a1d$var$columnHeaderText,
children: children
}),
/*#__PURE__*/ (0, $auVFN$jsx)((0, $4b69f02ec06b9226$export$2e2bcd8739ae039), {
size: "M",
className: $0fcd5fb617970a1d$var$chevronIcon
})
]
}),
/*#__PURE__*/ (0, $auVFN$jsxs)((0, $13afb0ea5f0ed767$export$d9b273488cd8ce6f), {
onAction: onMenuSelect,
styles: " Nn91",
children: [
items.length > 0 && /*#__PURE__*/ (0, $auVFN$jsx)((0, $13afb0ea5f0ed767$export$4b1545b4f2016d26), {
children: /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Collection), {
items: items,
children: (item)=>/*#__PURE__*/ (0, $auVFN$jsx)((0, $13afb0ea5f0ed767$export$2ce376c2cc3355c8), {
children: item?.label
})
})
}),
menuItems
]
})
]
}),
isColumnResizable && /*#__PURE__*/ (0, $auVFN$jsx)("div", {
"data-react-aria-prevent-focus": "true",
children: /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$ColumnResizer), {
"data-react-aria-prevent-focus": "true",
className: ({ resizableDirection: resizableDirection, isResizing: isResizing })=>$0fcd5fb617970a1d$var$resizerHandleContainer({
resizableDirection: resizableDirection,
isResizing: isResizing,
isInResizeMode: isInResizeMode
}),
children: ({ isFocusVisible: isFocusVisible, isResizing: isResizing })=>/*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Fragment), {
children: [
/*#__PURE__*/ (0, $auVFN$jsx)($0fcd5fb617970a1d$var$ResizerIndicator, {
isFocusVisible: isFocusVisible,
isResizing: isResizing
}),
(isFocusVisible || isInResizeMode) && isResizing && /*#__PURE__*/ (0, $auVFN$jsx)("div", {
className: $0fcd5fb617970a1d$var$nubbin,
children: /*#__PURE__*/ (0, $auVFN$jsx)((0, $1bdd184cd8a3d21d$export$2e2bcd8739ae039), {})
})
]
})
})
})
]
});
}
function $0fcd5fb617970a1d$var$ResizerIndicator({ isFocusVisible: isFocusVisible, isResizing: isResizing }) {
return /*#__PURE__*/ (0, $auVFN$jsx)("div", {
className: $0fcd5fb617970a1d$var$resizerHandle({
isFocusVisible: isFocusVisible,
isResizing: isResizing
})
});
}
const $0fcd5fb617970a1d$var$tableHeader = function anonymous(props) {
let rules = " ";
rules += ' Fb91';
rules += ' Za91';
rules += ' gL91';
rules += ' JLPOtrc91';
if (props.isHovered) rules += ' -xLp2wc-sb91';
else rules += ' -xLp2wc-sk91';
return rules;
};
const $0fcd5fb617970a1d$var$selectAllCheckbox = " IC91";
const $0fcd5fb617970a1d$var$selectAllCheckboxColumn = function anonymous(props) {
let rules = " ";
rules += ' Td91';
rules += ' Qd91';
rules += ' Sd91';
rules += ' Rd91';
rules += ' Fb91';
rules += ' _oa91';
rules += ' _Le91';
rules += ' _Pc91';
rules += ' _cb91';
rules += ' iq91';
rules += ' ila91';
rules += ' ma91';
rules += ' la91';
if (props.isQuiet) rules += ' _kb91';
else rules += ' _ka91';
rules += ' hb91';
rules += ' _jf91';
rules += ' gL91';
return rules;
};
const $0fcd5fb617970a1d$export$f850895b287ef28e = /*#__PURE__*/ (0, $auVFN$forwardRef)(function TableHeader({ columns: columns, dependencies: dependencies, children: children }, ref) {
let scale = (0, $859432f3b3573fcb$export$a8d2043b2d807f4d)();
let { selectionBehavior: selectionBehavior, selectionMode: selectionMode } = (0, $auVFN$useTableOptions)();
let { isQuiet: isQuiet } = (0, $auVFN$useContext)($0fcd5fb617970a1d$var$InternalTableContext);
let domRef = (0, $auVFN$useDOMRef)(ref);
return /*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$TableHeader), {
// @ts-ignore
ref: domRef,
className: $0fcd5fb617970a1d$var$tableHeader,
children: [
selectionBehavior === 'toggle' && // Also isSticky prop is applied just for the layout, will decide what the RAC api should be later
// @ts-ignore
/*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Column), {
isSticky: true,
width: scale === 'medium' ? 40 : 52,
minWidth: scale === 'medium' ? 40 : 52,
className: $0fcd5fb617970a1d$var$selectAllCheckboxColumn({
isQuiet: isQuiet
}),
children: ({ isFocusVisible: isFocusVisible })=>/*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Fragment), {
children: [
selectionMode === 'single' && /*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Fragment), {
children: [
isFocusVisible && /*#__PURE__*/ (0, $auVFN$jsx)($0fcd5fb617970a1d$var$CellFocusRing, {}),
/*#__PURE__*/ (0, $auVFN$jsx)($0fcd5fb617970a1d$var$VisuallyHiddenSelectAllLabel, {})
]
}),
selectionMode === 'multiple' && /*#__PURE__*/ (0, $auVFN$jsx)((0, $9b405e0f8095dce0$export$48513f6b9f8ce62d), {
isEmphasized: true,
styles: $0fcd5fb617970a1d$var$selectAllCheckbox,
slot: "selection"
})
]
})
}),
/*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Collection), {
items: columns,
dependencies: dependencies,
children: children
})
]
});
});
function $0fcd5fb617970a1d$var$VisuallyHiddenSelectAllLabel() {
let checkboxProps = (0, $auVFN$useSlottedContext)((0, $auVFN$CheckboxContext), 'selection');
return /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$VisuallyHidden), {
children: checkboxProps?.['aria-label']
});
}
const $0fcd5fb617970a1d$var$commonCellStyles = {
borderColor: 'transparent',
borderBottomWidth: 1,
borderTopWidth: 0,
borderXWidth: 0,
borderStyle: 'solid',
position: 'relative',
color: {
default: 'gray-800',
forcedColors: 'ButtonText'
},
outlineStyle: 'none',
paddingX: 16 // table-edge-to-content
};
const $0fcd5fb617970a1d$var$cell = function anonymous(props) {
let rules = " ";
rules += ' iq91';
rules += ' ila91';
rules += ' hXMFGYc91';
rules += ' _kJ8iPYd91';
rules += ' ma91';
if (props.isDivider) rules += ' lb91';
else rules += ' la91';
if (props.isDivider) rules += ' _jf91';
else rules += ' _je91';
rules += ' _Pc91';
if (props.isPressed) rules += ' po91';
else if (props.isFocusVisible) rules += ' po91';
else if (props.isHovered) rules += ' po91';
else rules += ' pt91';
rules += ' _Le91';
rules += ' Sf91';
rules += ' Rf91';
rules += ' Tu7Fubd91';
rules += ' Qu7Fubd91';
rules += ' MAyFGYc91';
rules += ' _oa91';
rules += ' Fb91';
rules += ' Za91';
if (props.size === "XL") {
rules += ' vg91';
rules += ' vsj91';
} else if (props.size === "L") {
rules += ' vp91';
rules += ' vsh91';
} else if (props.size === "S") {
rules += ' vb91';
rules += ' vse91';
} else if (props.size === "XS") {
rules += ' va91';
rules += ' vsc91';
} else {
rules += ' vd91';
rules += ' vsf91';
}
rules += ' eb91';
rules += ' sd91';
if (props.density === "spacious") rules += ' -M_-Mk91';
else if (props.density === "compact") rules += ' -M_-Mi91';
else rules += ' -M_-Mh91';
rules += ' -_k_-_ka91';
rules += ' -h_-hb91';
return rules;
};
const $0fcd5fb617970a1d$var$stickyCell = {
backgroundColor: 'gray-25'
};
const $0fcd5fb617970a1d$var$checkboxCellStyle = " iA91 ha91 _ka91 ma91 la91 _jf91 _Pc91 pt91 plb91 _Le91 Sf91 Rf91 gs9yXOb91 _cb91 FBJsHLe91";
const $0fcd5fb617970a1d$var$cellContent = function anonymous(props) {
let rules = " ";
rules += ' _Nc91';
rules += ' Pc91';
rules += ' _Yb91';
if (props.overflowMode === "wrap") rules += ' _7b91';
else rules += ' _7c91';
if (props.align === "end") rules += ' _Wb91';
else if (props.align === "center") rules += ' _Wa91';
else if (props.align === "start") rules += ' _Wd91';
rules += ' Za91';
rules += ' _Bb91';
if (props.isSticky) rules += ' Td91';
else rules += ' Tp91';
if (props.isSticky) rules += ' Qd91';
else rules += ' Qp91';
if (props.isSticky) rules += ' Sd91';
else rules += ' Sp91';
if (props.isSticky) rules += ' Rd91';
else rules += ' Rp91';
if (props.isSticky) rules += ' Jy91';
else rules += ' Jb91';
if (props.isSticky) rules += ' Gy91';
else rules += ' Gb91';
if (props.isSticky) rules += ' Iy91';
else rules += ' Ib91';
if (props.isSticky) rules += ' Hy91';
else rules += ' Hb91';
if (props.isSticky) rules += ' gs9yXOb91';
else rules += ' g991';
return rules;
};
const $0fcd5fb617970a1d$export$f6f0c3fe4ec306ea = /*#__PURE__*/ (0, $auVFN$forwardRef)(function Cell(props, ref) {
let { children: children, isSticky: isSticky, showDivider: showDivider = false, align: align, textValue: textValue, ...otherProps } = props;
let domRef = (0, $auVFN$useDOMRef)(ref);
let tableVisualOptions = (0, $auVFN$useContext)($0fcd5fb617970a1d$var$InternalTableContext);
textValue ||= typeof children === 'string' ? children : undefined;
return /*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Cell), {
ref: domRef,
// Also isSticky prop is applied just for the layout, will decide what the RAC api should be later
// @ts-ignore
isSticky: isSticky,
className: (renderProps)=>$0fcd5fb617970a1d$var$cell({
...renderProps,
...tableVisualOptions,
isDivider: showDivider
}),
textValue: textValue,
...otherProps,
children: ({ isFocusVisible: isFocusVisible })=>/*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Fragment), {
children: [
isFocusVisible && /*#__PURE__*/ (0, $auVFN$jsx)($0fcd5fb617970a1d$var$CellFocusRing, {}),
/*#__PURE__*/ (0, $auVFN$jsx)("span", {
className: $0fcd5fb617970a1d$var$cellContent({
...tableVisualOptions,
isSticky: isSticky,
align: align || 'start'
}),
children: children
})
]
})
});
});
// Use color-mix instead of transparency so sticky cells work correctly.
const $0fcd5fb617970a1d$var$selectedBackground = "[light-dark(color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(59, 99, 251), rgb(86, 129, 255)) 10%), color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(93, 137, 255), rgb(52, 91, 248)) 10%))]";
const $0fcd5fb617970a1d$var$selectedActiveBackground = "[light-dark(color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(59, 99, 251), rgb(86, 129, 255)) 15%), color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(93, 137, 255), rgb(52, 91, 248)) 15%))]";
const $0fcd5fb617970a1d$var$rowBackgroundColor = {
default: {
default: 'gray-25',
isQuiet: '--s2-container-bg'
},
isFocusVisibleWithin: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 7%)]",
isHovered: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 7%)]",
isPressed: "[color-mix(in srgb, light-dark(rgb(255, 255, 255), rgb(17, 17, 17)), light-dark(rgb(19, 19, 19), rgb(242, 242, 242)) 10%)]",
isSelected: {
default: $0fcd5fb617970a1d$var$selectedBackground,
isFocusVisibleWithin: $0fcd5fb617970a1d$var$selectedActiveBackground,
isHovered: $0fcd5fb617970a1d$var$selectedActiveBackground,
isPressed: $0fcd5fb617970a1d$var$selectedActiveBackground // table-selected-row-background-color, opacity /15
},
forcedColors: {
default: 'Background'
}
};
const $0fcd5fb617970a1d$var$row = function anonymous(props) {
let rules = " ";
rules += ' Fb91';
rules += ' _Pc91';
rules += ' _oa91';
rules += ' gs9yXOb91';
if (props.isSelected) {
if (props.isPressed) rules += ' -qH4xad-gT9rOHd91';
else if (props.isHovered) rules += ' -qH4xad-gT9rOHd91';
else if (props.isFocusVisibleWithin) rules += ' -qH4xad-gT9rOHd91';
else rules += ' -qH4xad-gJpow3b91';
} else if (props.isPressed) rules += ' -qH4xad-gRfT7e91';
else if (props.isHovered) rules += ' -qH4xad-gj1B7i91';
else if (props.isFocusVisibleWithin) rules += ' -qH4xad-gj1B7i91';
else if (props.isQuiet) rules += ' -qH4xad-gEzkoQe91';
else rules += ' -qH4xad-gX91';
rules += ' -qH4xad-lga91';
rules += ' -_34HbNb-Oh91';
rules += ' -_34HbNb-lOc91';
rules += ' _Le91';
rules += ' _ka91';
rules += ' hb91';
rules += ' ma91';
rules += ' la91';
rules += ' _jf91';
rules += ' iq91';
rules += ' ila91';
rules += ' _yb91';
return rules;
};
const $0fcd5fb617970a1d$export$b59bdbef9ce70de2 = /*#__PURE__*/ (0, $auVFN$forwardRef)(function Row({ id: id, columns: columns, children: children, dependencies: dependencies = [], ...otherProps }, ref) {
let { selectionBehavior: selectionBehavior, selectionMode: selectionMode } = (0, $auVFN$useTableOptions)();
let tableVisualOptions = (0, $auVFN$useContext)($0fcd5fb617970a1d$var$InternalTableContext);
let domRef = (0, $auVFN$useDOMRef)(ref);
return /*#__PURE__*/ (0, $auVFN$jsxs)((0, $auVFN$Row), {
// @ts-ignore
ref: domRef,
id: id,
dependencies: [
...dependencies,
columns
],
className: (renderProps)=>$0fcd5fb617970a1d$var$row({
...renderProps,
...tableVisualOptions
}) + (renderProps.isFocusVisible && " hFh6wc"),
...otherProps,
children: [
selectionMode !== 'none' && selectionBehavior === 'toggle' && /*#__PURE__*/ (0, $auVFN$jsx)($0fcd5fb617970a1d$export$f6f0c3fe4ec306ea, {
isSticky: true,
className: $0fcd5fb617970a1d$var$checkboxCellStyle,
children: /*#__PURE__*/ (0, $auVFN$jsx)((0, $9b405e0f8095dce0$export$48513f6b9f8ce62d), {
isEmphasized: true,
slot: "selection"
})
}),
/*#__PURE__*/ (0, $auVFN$jsx)((0, $auVFN$Collection), {
items: columns,
dependencies: [
...dependencies,
columns
],
children: children
})
]
});
});
export {$0fcd5fb617970a1d$export$4e03bdf0174fd602 as S2TableLayout, $0fcd5fb617970a1d$export$93e4b0b2cc49b648 as TableContext, $0fcd5fb617970a1d$export$b3c27e869d856b7 as TableView, $0fcd5fb617970a1d$export$76ccd210b9029917 as TableBody, $0fcd5fb617970a1d$export$816b5d811295e6bc as Column, $0fcd5fb617970a1d$export$f850895b287ef28e as TableHeader, $0fcd5fb617970a1d$export$f6f0c3fe4ec306ea as Cell, $0fcd5fb617970a1d$export$b59bdbef9ce70de2 as Row};
//# sourceMappingURL=TableView.mjs.map