@react-spectrum/s2
Version:
Spectrum 2 UI components in React
1,067 lines (1,042 loc) • 47.5 kB
JavaScript
require("./TableView.css");
var $af04e099a53d3e85$exports = require("./Checkbox.cjs");
var $1df9f1c9262ce5df$exports = require("./Chevron.cjs");
var $bde97c91243ed164$exports = require("../icons/Icon.cjs");
var $4526404114e78c80$exports = require("./intlStrings.cjs");
var $e741ea6b88ce4866$exports = require("./Menu.cjs");
var $308b180f49d82d28$exports = require("../icons/runtime.cjs");
var $23350f45c699333e$exports = require("./S2_MoveHorizontalTableWidget.cjs");
var $1c116ea4b0d2d023$exports = require("./ProgressCircle.cjs");
var $22bf2407c3628a21$exports = require("../icons/SortDown.cjs");
var $2197830b90e71c31$exports = require("../icons/SortUp.cjs");
var $85bf454149fe9ddc$exports = require("./ActionBar.cjs");
var $ee7b4c497f520c08$exports = require("./utils.cjs");
var $ac757a4c2bd72aee$exports = require("../icons/useSpectrumContextProps.cjs");
var $iLVc8$reactjsxruntime = require("react/jsx-runtime");
var $iLVc8$reactariacomponents = require("react-aria-components");
var $iLVc8$react = require("react");
var $iLVc8$reactspectrumutils = require("@react-spectrum/utils");
var $iLVc8$reactariai18n = require("@react-aria/i18n");
var $iLVc8$reactaria = require("react-aria");
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "TableContext", () => $bed37377ec7a3a9e$export$93e4b0b2cc49b648);
$parcel$export(module.exports, "TableView", () => $bed37377ec7a3a9e$export$b3c27e869d856b7);
$parcel$export(module.exports, "TableBody", () => $bed37377ec7a3a9e$export$76ccd210b9029917);
$parcel$export(module.exports, "Column", () => $bed37377ec7a3a9e$export$816b5d811295e6bc);
$parcel$export(module.exports, "TableHeader", () => $bed37377ec7a3a9e$export$f850895b287ef28e);
$parcel$export(module.exports, "Cell", () => $bed37377ec7a3a9e$export$f6f0c3fe4ec306ea);
$parcel$export(module.exports, "Row", () => $bed37377ec7a3a9e$export$b59bdbef9ce70de2);
/*
* 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 $bed37377ec7a3a9e$var$InternalTableContext = /*#__PURE__*/ (0, $iLVc8$react.createContext)({});
const $bed37377ec7a3a9e$var$tableWrapper = " Ma91 Na91 sd91 _Bb91 __ca91 _Pc91 _Nb91 Pb91";
const $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$var$DEFAULT_HEADER_HEIGHT = {
medium: 32,
large: 40
};
const $bed37377ec7a3a9e$var$ROW_HEIGHTS = {
compact: {
medium: 32,
large: 40
},
regular: {
medium: 40,
large: 50
},
spacious: {
medium: 48,
large: 60
}
};
class $bed37377ec7a3a9e$export$4e03bdf0174fd602 extends (0, $iLVc8$reactariacomponents.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, $iLVc8$reactariacomponents.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 $bed37377ec7a3a9e$export$93e4b0b2cc49b648 = /*#__PURE__*/ (0, $iLVc8$react.createContext)(null);
const $bed37377ec7a3a9e$export$b3c27e869d856b7 = /*#__PURE__*/ (0, $iLVc8$react.forwardRef)(function TableView(props, ref) {
[props, ref] = (0, $ac757a4c2bd72aee$exports.useSpectrumContextProps)(props, ref, $bed37377ec7a3a9e$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, $iLVc8$reactspectrumutils.useDOMRef)(ref);
let scale = (0, $ee7b4c497f520c08$exports.useScale)();
// 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, $iLVc8$react.useState)(false);
let onResizeStart = (0, $iLVc8$react.useCallback)((widths)=>{
propsOnResizeStart?.(widths);
}, [
propsOnResizeStart
]);
let onResizeEnd = (0, $iLVc8$react.useCallback)((widths)=>{
setIsInResizeMode(false);
propsOnResizeEnd?.(widths);
}, [
propsOnResizeEnd,
setIsInResizeMode
]);
let context = (0, $iLVc8$react.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, $iLVc8$react.useRef)(null);
let isCheckboxSelection = props.selectionMode === 'multiple' || props.selectionMode === 'single';
let { selectedKeys: selectedKeys, onSelectionChange: onSelectionChange, actionBar: actionBar, actionBarHeight: actionBarHeight } = (0, $85bf454149fe9ddc$exports.useActionBarContainer)({
...props,
scrollRef: scrollRef
});
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactariacomponents.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, $308b180f49d82d28$exports.mergeStyles)($bed37377ec7a3a9e$var$tableWrapper, styles),
style: UNSAFE_style,
children: [
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.Virtualizer), {
layout: $bed37377ec7a3a9e$export$4e03bdf0174fd602,
layoutOptions: {
rowHeight: overflowMode === 'wrap' ? undefined : $bed37377ec7a3a9e$var$ROW_HEIGHTS[density][scale],
estimatedRowHeight: overflowMode === 'wrap' ? $bed37377ec7a3a9e$var$ROW_HEIGHTS[density][scale] : undefined,
// No need for estimated headingHeight since the headers aren't affected by overflow mode: wrap
headingHeight: $bed37377ec7a3a9e$var$DEFAULT_HEADER_HEIGHT[scale],
loaderHeight: 60
},
children: /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)($bed37377ec7a3a9e$var$InternalTableContext.Provider, {
value: context,
children: /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.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)=>$bed37377ec7a3a9e$var$table({
...renderProps,
isCheckboxSelection: isCheckboxSelection,
isQuiet: isQuiet
}),
selectionBehavior: "toggle",
onRowAction: onAction,
...otherProps,
selectedKeys: selectedKeys,
defaultSelectedKeys: undefined,
onSelectionChange: onSelectionChange
})
})
}),
actionBar
]
});
});
const $bed37377ec7a3a9e$var$centeredWrapper = " sd91 eb91 _Ca91 Za91 Fb91";
const $bed37377ec7a3a9e$export$76ccd210b9029917 = /*#__PURE__*/ (0, $iLVc8$react.forwardRef)(function TableBody(props, ref) {
let { items: items, renderEmptyState: renderEmptyState, children: children, dependencies: dependencies = [] } = props;
let domRef = (0, $iLVc8$reactspectrumutils.useDOMRef)(ref);
let { loadingState: loadingState, onLoadMore: onLoadMore } = (0, $iLVc8$react.useContext)($bed37377ec7a3a9e$var$InternalTableContext);
let isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
let emptyRender;
let renderer = children;
let stringFormatter = (0, $iLVc8$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($4526404114e78c80$exports))), '-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, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.UNSTABLE_TableLoadingSentinel), {
isLoading: loadingState === 'loadingMore',
onLoadMore: onLoadMore,
className: " Fb91 Za91",
children: /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)("div", {
className: $bed37377ec7a3a9e$var$centeredWrapper,
children: /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $1c116ea4b0d2d023$exports.ProgressCircle), {
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, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactjsxruntime.Fragment), {
children: [
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.Collection), {
items: items,
dependencies: dependencies,
children: children
}),
loadMoreSpinner
]
});
else renderer = /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactjsxruntime.Fragment), {
children: [
children,
loadMoreSpinner
]
});
if (renderEmptyState != null && !isLoading) emptyRender = (props)=>/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)("div", {
className: $bed37377ec7a3a9e$var$centeredWrapper,
children: renderEmptyState(props)
});
else if (loadingState === 'loading') emptyRender = ()=>/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)("div", {
className: $bed37377ec7a3a9e$var$centeredWrapper,
children: /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $1c116ea4b0d2d023$exports.ProgressCircle), {
isIndeterminate: true,
"aria-label": stringFormatter.format('table.loading')
})
});
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.TableBody), {
// @ts-ignore
ref: domRef,
className: " Fb91",
...props,
renderEmptyState: emptyRender,
dependencies: [
loadingState
],
children: renderer
});
});
const $bed37377ec7a3a9e$var$cellFocus = {
outlineStyle: {
default: 'none',
isFocusVisible: 'solid'
},
outlineOffset: -2,
outlineWidth: 2,
outlineColor: 'focus-ring',
borderRadius: '[6px]'
};
function $bed37377ec7a3a9e$var$CellFocusRing() {
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.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 $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$export$816b5d811295e6bc = /*#__PURE__*/ (0, $iLVc8$react.forwardRef)(function Column(props, ref) {
let { isQuiet: isQuiet } = (0, $iLVc8$react.useContext)($bed37377ec7a3a9e$var$InternalTableContext);
let { allowsResizing: allowsResizing, children: children, align: align = 'start' } = props;
let domRef = (0, $iLVc8$reactspectrumutils.useDOMRef)(ref);
let isMenu = allowsResizing || !!props.menuItems;
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.Column), {
...props,
ref: domRef,
style: {
borderInlineEndColor: 'transparent'
},
className: (renderProps)=>$bed37377ec7a3a9e$var$columnStyles({
...renderProps,
isMenu: isMenu,
align: align,
isQuiet: isQuiet
}),
children: ({ allowsSorting: allowsSorting, sortDirection: sortDirection, isFocusVisible: isFocusVisible, sort: sort, startResize: startResize })=>/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactjsxruntime.Fragment), {
children: [
isFocusVisible && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)($bed37377ec7a3a9e$var$CellFocusRing, {}),
isMenu ? /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)($bed37377ec7a3a9e$var$ColumnWithMenu, {
isColumnResizable: allowsResizing,
menuItems: props.menuItems,
allowsSorting: allowsSorting,
sortDirection: sortDirection,
sort: sort,
startResize: startResize,
align: align,
children: children
}) : /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)($bed37377ec7a3a9e$var$ColumnContents, {
allowsSorting: allowsSorting,
sortDirection: sortDirection,
children: children
})
]
})
});
});
const $bed37377ec7a3a9e$var$columnContentWrapper = " Na91 sd91 eb91 Za91";
const $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$var$ColumnContents(props) {
let { allowsSorting: allowsSorting, sortDirection: sortDirection, children: children } = props;
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)("div", {
className: $bed37377ec7a3a9e$var$columnContentWrapper,
children: [
allowsSorting && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.Provider), {
values: [
[
(0, $bde97c91243ed164$exports.IconContext),
{
styles: $bed37377ec7a3a9e$var$sortIcon({})
}
]
],
children: sortDirection != null && (sortDirection === 'ascending' ? /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $2197830b90e71c31$exports.default), {}) : /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $22bf2407c3628a21$exports.default), {}))
}),
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)("span", {
className: " _Nc91 Pc91 _Yb91 _7c91 Za91",
children: children
})
]
});
}
const $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$var$columnHeaderText = " _Nc91 Pc91 _Yb91 _7c91 NXJkxGe91 _ua91 _vb91 _sd91";
const $bed37377ec7a3a9e$var$chevronIcon = " _Sd91 It91 Isu91 NXJkxGe91 _va91 -_8sjo0b-t5ZbAob91";
const $bed37377ec7a3a9e$var$nubbin = " _Pa91 Wr91 _AlhfIS91 ZXJkxGe91 FXJkxGe91 t5qAiPc91 tla91 -_8sjo0b-tw91 -_8sjo0b-lt8pvGJ91";
function $bed37377ec7a3a9e$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, $iLVc8$react.useContext)($bed37377ec7a3a9e$var$InternalTableContext);
let stringFormatter = (0, $iLVc8$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($4526404114e78c80$exports))), '-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, $iLVc8$react.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, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactjsxruntime.Fragment), {
children: [
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $e741ea6b88ce4866$exports.MenuTrigger), {
align: menuAlign,
children: [
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactariacomponents.Button), {
className: (renderProps)=>$bed37377ec7a3a9e$var$resizableMenuButtonWrapper({
...renderProps,
align: buttonAlignment
}),
children: [
allowsSorting && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.Provider), {
values: [
[
(0, $bde97c91243ed164$exports.IconContext),
{
styles: $bed37377ec7a3a9e$var$sortIcon({
isButton: true
})
}
]
],
children: sortDirection != null && (sortDirection === 'ascending' ? /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $2197830b90e71c31$exports.default), {}) : /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $22bf2407c3628a21$exports.default), {}))
}),
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)("div", {
className: $bed37377ec7a3a9e$var$columnHeaderText,
children: children
}),
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $1df9f1c9262ce5df$exports.default), {
size: "M",
className: $bed37377ec7a3a9e$var$chevronIcon
})
]
}),
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $e741ea6b88ce4866$exports.Menu), {
onAction: onMenuSelect,
styles: " Nn91",
children: [
items.length > 0 && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $e741ea6b88ce4866$exports.MenuSection), {
children: /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.Collection), {
items: items,
children: (item)=>/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $e741ea6b88ce4866$exports.MenuItem), {
children: item?.label
})
})
}),
menuItems
]
})
]
}),
isColumnResizable && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)("div", {
"data-react-aria-prevent-focus": "true",
children: /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.ColumnResizer), {
"data-react-aria-prevent-focus": "true",
className: ({ resizableDirection: resizableDirection, isResizing: isResizing })=>$bed37377ec7a3a9e$var$resizerHandleContainer({
resizableDirection: resizableDirection,
isResizing: isResizing,
isInResizeMode: isInResizeMode
}),
children: ({ isFocusVisible: isFocusVisible, isResizing: isResizing })=>/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactjsxruntime.Fragment), {
children: [
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)($bed37377ec7a3a9e$var$ResizerIndicator, {
isFocusVisible: isFocusVisible,
isResizing: isResizing
}),
(isFocusVisible || isInResizeMode) && isResizing && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)("div", {
className: $bed37377ec7a3a9e$var$nubbin,
children: /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $23350f45c699333e$exports.default), {})
})
]
})
})
})
]
});
}
function $bed37377ec7a3a9e$var$ResizerIndicator({ isFocusVisible: isFocusVisible, isResizing: isResizing }) {
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)("div", {
className: $bed37377ec7a3a9e$var$resizerHandle({
isFocusVisible: isFocusVisible,
isResizing: isResizing
})
});
}
const $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$var$selectAllCheckbox = " IC91";
const $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$export$f850895b287ef28e = /*#__PURE__*/ (0, $iLVc8$react.forwardRef)(function TableHeader({ columns: columns, dependencies: dependencies, children: children }, ref) {
let scale = (0, $ee7b4c497f520c08$exports.useScale)();
let { selectionBehavior: selectionBehavior, selectionMode: selectionMode } = (0, $iLVc8$reactariacomponents.useTableOptions)();
let { isQuiet: isQuiet } = (0, $iLVc8$react.useContext)($bed37377ec7a3a9e$var$InternalTableContext);
let domRef = (0, $iLVc8$reactspectrumutils.useDOMRef)(ref);
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactariacomponents.TableHeader), {
// @ts-ignore
ref: domRef,
className: $bed37377ec7a3a9e$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, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.Column), {
isSticky: true,
width: scale === 'medium' ? 40 : 52,
minWidth: scale === 'medium' ? 40 : 52,
className: $bed37377ec7a3a9e$var$selectAllCheckboxColumn({
isQuiet: isQuiet
}),
children: ({ isFocusVisible: isFocusVisible })=>/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactjsxruntime.Fragment), {
children: [
selectionMode === 'single' && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactjsxruntime.Fragment), {
children: [
isFocusVisible && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)($bed37377ec7a3a9e$var$CellFocusRing, {}),
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)($bed37377ec7a3a9e$var$VisuallyHiddenSelectAllLabel, {})
]
}),
selectionMode === 'multiple' && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $af04e099a53d3e85$exports.Checkbox), {
isEmphasized: true,
styles: $bed37377ec7a3a9e$var$selectAllCheckbox,
slot: "selection"
})
]
})
}),
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.Collection), {
items: columns,
dependencies: dependencies,
children: children
})
]
});
});
function $bed37377ec7a3a9e$var$VisuallyHiddenSelectAllLabel() {
let checkboxProps = (0, $iLVc8$reactariacomponents.useSlottedContext)((0, $iLVc8$reactariacomponents.CheckboxContext), 'selection');
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactaria.VisuallyHidden), {
children: checkboxProps?.['aria-label']
});
}
const $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$var$stickyCell = {
backgroundColor: 'gray-25'
};
const $bed37377ec7a3a9e$var$checkboxCellStyle = " iA91 ha91 _ka91 ma91 la91 _jf91 _Pc91 pt91 plb91 _Le91 Sf91 Rf91 gs9yXOb91 _cb91 FBJsHLe91";
const $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$export$f6f0c3fe4ec306ea = /*#__PURE__*/ (0, $iLVc8$react.forwardRef)(function Cell(props, ref) {
let { children: children, isSticky: isSticky, showDivider: showDivider = false, align: align, textValue: textValue, ...otherProps } = props;
let domRef = (0, $iLVc8$reactspectrumutils.useDOMRef)(ref);
let tableVisualOptions = (0, $iLVc8$react.useContext)($bed37377ec7a3a9e$var$InternalTableContext);
textValue ||= typeof children === 'string' ? children : undefined;
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.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)=>$bed37377ec7a3a9e$var$cell({
...renderProps,
...tableVisualOptions,
isDivider: showDivider
}),
textValue: textValue,
...otherProps,
children: ({ isFocusVisible: isFocusVisible })=>/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactjsxruntime.Fragment), {
children: [
isFocusVisible && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)($bed37377ec7a3a9e$var$CellFocusRing, {}),
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)("span", {
className: $bed37377ec7a3a9e$var$cellContent({
...tableVisualOptions,
isSticky: isSticky,
align: align || 'start'
}),
children: children
})
]
})
});
});
// Use color-mix instead of transparency so sticky cells work correctly.
const $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$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: $bed37377ec7a3a9e$var$selectedBackground,
isFocusVisibleWithin: $bed37377ec7a3a9e$var$selectedActiveBackground,
isHovered: $bed37377ec7a3a9e$var$selectedActiveBackground,
isPressed: $bed37377ec7a3a9e$var$selectedActiveBackground // table-selected-row-background-color, opacity /15
},
forcedColors: {
default: 'Background'
}
};
const $bed37377ec7a3a9e$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 $bed37377ec7a3a9e$export$b59bdbef9ce70de2 = /*#__PURE__*/ (0, $iLVc8$react.forwardRef)(function Row({ id: id, columns: columns, children: children, dependencies: dependencies = [], ...otherProps }, ref) {
let { selectionBehavior: selectionBehavior, selectionMode: selectionMode } = (0, $iLVc8$reactariacomponents.useTableOptions)();
let tableVisualOptions = (0, $iLVc8$react.useContext)($bed37377ec7a3a9e$var$InternalTableContext);
let domRef = (0, $iLVc8$reactspectrumutils.useDOMRef)(ref);
return /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsxs)((0, $iLVc8$reactariacomponents.Row), {
// @ts-ignore
ref: domRef,
id: id,
dependencies: [
...dependencies,
columns
],
className: (renderProps)=>$bed37377ec7a3a9e$var$row({
...renderProps,
...tableVisualOptions
}) + (renderProps.isFocusVisible && " hFh6wc"),
...otherProps,
children: [
selectionMode !== 'none' && selectionBehavior === 'toggle' && /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)($bed37377ec7a3a9e$export$f6f0c3fe4ec306ea, {
isSticky: true,
className: $bed37377ec7a3a9e$var$checkboxCellStyle,
children: /*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $af04e099a53d3e85$exports.Checkbox), {
isEmphasized: true,
slot: "selection"
})
}),
/*#__PURE__*/ (0, $iLVc8$reactjsxruntime.jsx)((0, $iLVc8$reactariacomponents.Collection), {
items: columns,
dependencies: [
...dependencies,
columns
],
children: children
})
]
});
});
//# sourceMappingURL=TableView.cjs.map