Skip to content

Commit

Permalink
fix(footer): set max-toolbar-items when mini table is used
Browse files Browse the repository at this point in the history
  • Loading branch information
micaelagoffe committed Dec 9, 2024
1 parent 4158e70 commit b3b3b01
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 69 deletions.
109 changes: 52 additions & 57 deletions lib/render-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,56 @@ export const renderFooter = ({
csvFilename,
xlsxFilename,
xlsxSheetname,
topPlacement
}) => {
return html`
<cosmoz-bottom-bar
id="bottomBar"
?active=${!isEmpty(selectedItems.length)}
>
<slot name="info" slot="info">
${ngettext(
'{0} selected item',
'{0} selected items',
selectedItems.length
)}
</slot>
<slot name="actions" id="actions"></slot>
<!-- These slots are needed by cosmoz-bottom-bar
topPlacement,
maxToolbarItems,
}) =>
html`<cosmoz-bottom-bar
id="bottomBar"
?active=${!isEmpty(selectedItems.length)}
?max-toolbar-items=${!isEmpty(maxToolbarItems)}
>
<slot name="info" slot="info">
${ngettext(
'{0} selected item',
'{0} selected items',
selectedItems.length,
)}
</slot>
<slot name="actions" id="actions"></slot>
<!-- These slots are needed by cosmoz-bottom-bar
as it might change the slot of the actions to distribute them in the menu -->
<slot name="bottom-bar-toolbar" slot="bottom-bar-toolbar"></slot>
<slot name="bottom-bar-menu" slot="bottom-bar-menu"></slot>
<cosmoz-dropdown-menu slot="extra" .placement=${topPlacement}>
<svg
slot="button"
width="14"
height="18"
viewBox="0 0 14 18"
fill="none"
stroke="currentColor"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 8.5L7.00024 14.5L13 8.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path d="M13 17L1 17" stroke-width="2" stroke-linecap="round" />
<path d="M7 1V13" stroke-width="2" stroke-linecap="round" />
</svg>
<button
@click=${() => saveAsCsvAction(columns, selectedItems, csvFilename)}
>
${_('Save as CSV')}
</button>
<button
@click=${() =>
saveAsXlsxAction(
columns,
selectedItems,
xlsxFilename,
xlsxSheetname
)}
>
${_('Save as XLSX')}
</button>
<slot name="download-menu"></slot>
</cosmoz-dropdown-menu>
</cosmoz-bottom-bar>`;
};
<slot name="bottom-bar-toolbar" slot="bottom-bar-toolbar"></slot>
<slot name="bottom-bar-menu" slot="bottom-bar-menu"></slot>
<cosmoz-dropdown-menu slot="extra" .placement=${topPlacement}>
<svg
slot="button"
width="14"
height="18"
viewBox="0 0 14 18"
fill="none"
stroke="currentColor"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M1 8.5L7.00024 14.5L13 8.5"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path d="M13 17L1 17" stroke-width="2" stroke-linecap="round" />
<path d="M7 1V13" stroke-width="2" stroke-linecap="round" />
</svg>
<button
@click=${() => saveAsCsvAction(columns, selectedItems, csvFilename)}
>
${_('Save as CSV')}
</button>
<button
@click=${() =>
saveAsXlsxAction(columns, selectedItems, xlsxFilename, xlsxSheetname)}
>
${_('Save as XLSX')}
</button>
<slot name="download-menu"></slot>
</cosmoz-dropdown-menu>
</cosmoz-bottom-bar>`;
8 changes: 6 additions & 2 deletions lib/use-fast-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export const useFastLayout = ({
sortAndGroupOptions,
}) => {
const canvasWidth = useCanvasWidth(host),
{ miniColumn, miniColumns } = useMini({ host, canvasWidth, columns }),
{ isMiniSize, miniColumn, miniColumns } = useMini({
host,
canvasWidth,
columns,
}),
{ groupOnColumn } = sortAndGroupOptions,
layout = useLayout({
canvasWidth,
Expand Down Expand Up @@ -52,5 +56,5 @@ export const useFastLayout = ({

useStyleSheet(layoutCss);

return { collapsedColumns, miniColumns };
return { isMiniSize, collapsedColumns, miniColumns };
};
17 changes: 8 additions & 9 deletions lib/use-footer.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { defaultPlacement } from '@neovici/cosmoz-dropdown';
const _defaultPlacement = ['top-right', ...defaultPlacement];

export const useFooter = ({
host,
...rest
}) => {
export const useFooter = ({ host, ...rest }) => {
const {
csvFilename = 'omnitable.csv',
xlsxFilename = 'omnitable.xlsx',
xlsxSheetname = 'Omnitable',
topPlacement = _defaultPlacement,
} = host;
csvFilename = 'omnitable.csv',
xlsxFilename = 'omnitable.xlsx',
xlsxSheetname = 'Omnitable',
topPlacement = _defaultPlacement,
maxToolbarItems,
} = host;

return {
csvFilename,
xlsxFilename,
xlsxSheetname,
topPlacement,
maxToolbarItems,
...rest,
};
};
1 change: 1 addition & 0 deletions lib/use-mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const useMini = ({ host, canvasWidth, columns: _columns }) => {
}, [miniColumn]);

return {
isMiniSize,
miniColumn,
miniColumns,
};
Expand Down
4 changes: 3 additions & 1 deletion lib/use-omnitable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ export const useOmnitable = (host) => {
noLocalSort,
noLocalFilter,
}),
{ collapsedColumns, miniColumns } = useFastLayout({
{ isMiniSize, collapsedColumns, miniColumns } = useFastLayout({
host,
columns,
settings,
setSettings,
resizeSpeedFactor,
sortAndGroupOptions,
}),
maxToolbarItems = host.hasAttribute('mini') && isMiniSize ? '0' : '',
dataIsValid = data && Array.isArray(data) && data.length > 0,
[selectedItems, setSelectedItems] = useState([]);

Expand Down Expand Up @@ -94,6 +95,7 @@ export const useOmnitable = (host) => {
host,
selectedItems,
columns,
maxToolbarItems,
}),
};
};

0 comments on commit b3b3b01

Please sign in to comment.