Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added custom toolbar element to ultimate table toolbar #414

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/components/basic/Table/Table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { Story, Meta } from '@storybook/blocks'
import { SharedThemeProvider } from '../SharedThemeProvider'
import { SharedCssBaseline } from '../SharedCssBaseline'
import { Box, Typography, Button } from '@mui/material'
import { Table } from '.'
import TestRows from '../../../../src/assets/data/TableRows.json'

Expand Down Expand Up @@ -133,7 +134,7 @@ Make sure that search, filter, and action buttons are accessible and labeled cor
}]}
rows={TestRows}
title={'Table with toolbar'}
toolbarVariant={'premium'}
toolbarVariant={'ultimate'}
toolbar={{
buttonLabel: 'Add user',
onButtonClick: () => console.log('on button click'),
Expand All @@ -153,6 +154,29 @@ Make sure that search, filter, and action buttons are accessible and labeled cor
],
},
],
customToolbarContent: (
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: 2,
padding: 0,
margin: 0,
maxHeight: '50px',
boxSizing: 'border-box',
overflow: 'hidden',
}}
>
<Button variant="contained" onClick={() => console.log('Custom filter applied')}
sx={{
lineHeight: '1',
fontSize: '14px',
}}>
Apply Filter
</Button>
</Box>
),
}}
/>

Expand Down
58 changes: 42 additions & 16 deletions src/components/basic/Table/components/Toolbar/UltimateToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface UltimateToolbarProps extends ToolbarProps {
searchDebounce?: number
searchExpr?: string
autoFocus?: boolean
customToolbarContent?: React.ReactNode
}

export const UltimateToolbar = ({
Expand All @@ -46,6 +47,7 @@ export const UltimateToolbar = ({
onClearSearch,
searchDebounce = 500,
autoFocus,
customToolbarContent,
}: UltimateToolbarProps) => {
const { spacing } = useTheme()
const [searchInput, setSearchInput] = useState<string>(
Expand Down Expand Up @@ -111,27 +113,51 @@ export const UltimateToolbar = ({
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
flexWrap: 'wrap',
}}
>
{onSearch != null && (
<Box sx={{ display: 'flex', alignItems: 'center', height: '50px' }}>
<SearchInput
autoFocus={autoFocus}
endAdornment={endAdornment}
value={searchInput}
onChange={onSearchChange}
onKeyPress={onSearchInputKeyPress}
placeholder={searchPlaceholder}
sx={{
'.MuiInputBase-input': {
{(onSearch != null || customToolbarContent) && (
<Box
sx={{
display: 'flex',
justifyContent: 'flex-start',
alignItems: 'center',
gap: '1',
maxHeight: '50px',
}}
>
{onSearch !== null && (
<SearchInput
autoFocus={autoFocus}
endAdornment={endAdornment}
value={searchInput}
onChange={onSearchChange}
onKeyPress={onSearchInputKeyPress}
placeholder={searchPlaceholder}
sx={{
'.MuiInputBase-input': {
padding: '4px 10px',
width: '300px',
},
}}
/>
)}
{customToolbarContent &&
React.cloneElement(customToolbarContent as React.ReactElement, {
style: {
padding: '4px 10px',
width: '300px',
display: 'flex',
maxHeight: '50px',
alignItems: 'center',
justifyContent: 'center',
},
}}
/>
})}
</Box>
)}
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>

<Box
sx={{ display: 'flex', justifyContent: 'flex-end', flexWrap: 'wrap' }}
>
{onFilter != null &&
filter?.map(({ name, values }) => (
<Box
Expand All @@ -142,7 +168,7 @@ export const UltimateToolbar = ({
}}
>
{values?.map(({ value, label }) => (
<Box component="span" sx={{ marginLeft: 3 }} key={value}>
<Box component="span" key={value}>
<Button
id={`${name}${value}`}
name={name}
Expand Down
Loading