MCPcopy Create free account
hub / github.com/adobe/react-spectrum / ColumnWithMenu

Function ColumnWithMenu

packages/@react-spectrum/s2/src/TableView.tsx:998–1132  ·  view source on GitHub ↗
(props: ColumnWithMenuProps)

Source from the content-addressed store, hash-verified

996}
997
998function ColumnWithMenu(props: ColumnWithMenuProps) {
999 let {
1000 allowsSorting,
1001 sortDirection,
1002 sort,
1003 startResize,
1004 children,
1005 align,
1006 isColumnResizable,
1007 menuItems
1008 } = props;
1009 let {setIsInResizeMode, isInResizeMode} = useContext(InternalTableContext);
1010 let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/s2');
1011 const onMenuSelect = key => {
1012 switch (key) {
1013 case 'sort-asc':
1014 sort('ascending');
1015 break;
1016 case 'sort-desc':
1017 sort('descending');
1018 break;
1019 case 'resize':
1020 setIsInResizeMode?.(true);
1021 startResize();
1022 break;
1023 }
1024 };
1025
1026 let items = useMemo(() => {
1027 let options: Array<{label: string; id: string}> = [];
1028 if (isColumnResizable) {
1029 options = [
1030 {
1031 // oxlint-disable-next-line react/react-compiler
1032 label: stringFormatter.format('table.resizeColumn'),
1033 id: 'resize'
1034 }
1035 ];
1036 }
1037 if (allowsSorting) {
1038 options = [
1039 {
1040 label: stringFormatter.format('table.sortAscending'),
1041 id: 'sort-asc'
1042 },
1043 {
1044 label: stringFormatter.format('table.sortDescending'),
1045 id: 'sort-desc'
1046 },
1047 ...options
1048 ];
1049 }
1050 return options;
1051 // eslint-disable-next-line react-hooks/exhaustive-deps
1052 }, [allowsSorting, isColumnResizable]);
1053
1054 let buttonAlignment = 'start';
1055 let menuAlign = 'start' as 'start' | 'end';

Callers

nothing calls this directly

Calls 2

formatMethod · 0.45

Tested by

no test coverage detected