Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/table-filter-trigger-iconbutton.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astryxdesign/core': patch
---

[fix] Table: the column filter trigger in a header cell is now Core's ghost `IconButton` at size `sm`, so it takes Button's own hover, focus, press and touch target instead of a hand-styled button. Its name, popover and accent color when a filter is set are unchanged.
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
46 changes: 46 additions & 0 deletions apps/storybook/stories/TableFiltering.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,49 @@ export const EmptyState: Story = {
);
},
};

/**
* Sortable and filterable header cells at each density, so the header's
* controls can be compared side by side.
*/
export const HeaderDensities: Story = {
render: () => {
const {config, applyFilters} = usePowerSearchConfig(fieldDefs);
const {filters, onFilterChange} = useTableFilterState();
const {sortConfig, applySort} = useTableSortableState<Employee>({
data: employees,
});
const columns: TableColumn<Employee>[] = [
{key: 'name', header: 'Name', sortable: true, filter: 'name'},
{key: 'role', header: 'Role', sortable: true, filter: 'role'},
{key: 'level', header: 'Level', sortable: true},
{key: 'department', header: 'Department'},
];
const filterPlugin = useTableFiltering<Employee>({
filters,
onFilterChange,
searchConfig: config,
});
const sortPlugin = useTableSortable<Employee>(sortConfig);
const data = applySort(
applyFilters(
toSearchFilters(filters, columns, config) as PowerSearchFilter[],
employees,
),
).slice(0, 2);
return (
<div style={{maxWidth: 640, display: 'grid', gap: 16}}>
{(['compact', 'balanced', 'spacious'] as const).map(density => (
<Table
key={density}
data={data}
columns={columns}
idKey="name"
density={density}
plugins={{sort: sortPlugin, filter: filterPlugin}}
/>
))}
</div>
);
},
};
46 changes: 9 additions & 37 deletions packages/core/src/Table/plugins/filtering/useTableFiltering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import {
type ReactNode,
} from 'react';
import * as stylex from '@stylexjs/stylex';
import {spacingVars, radiusVars} from '../../../theme/tokens.stylex';
import {spacingVars} from '../../../theme/tokens.stylex';
import {Icon} from '../../../Icon';
import {Button} from '../../../Button';
import {IconButton} from '../../../IconButton/IconButton';
import {Popover} from '../../../Popover';
import {TextInput} from '../../../TextInput';
import {NumberInput} from '../../../NumberInput';
Expand Down Expand Up @@ -381,36 +382,13 @@ const filterStyles = stylex.create({
marginTop: spacingVars['--spacing-1'],
minWidth: 0,
},
triggerButton: {
backgroundColor: 'transparent',
borderWidth: 0,
borderStyle: 'none',
cursor: {
default: 'pointer',
':is(:disabled,[aria-disabled="true"])': 'default',
},
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
padding: 0,
borderRadius: radiusVars['--radius-element'],
flexShrink: 0,
// Minimum 44px touch target on coarse pointer devices (iOS guideline).
'@media (pointer: coarse)': {
minWidth: '44px',
minHeight: '44px',
},
},
triggerInactive: {
opacity: {
default: 0.35,
':is(th:hover *)': 1,
':focus-visible': 1,
},
},
triggerActive: {
opacity: 1,
},
popoverContent: {
width: '240px',
},
Expand Down Expand Up @@ -1027,20 +1005,14 @@ function PopoverFilterTrigger({
</div>
</FilterStoreContext>
}>
<button
type="button"
aria-label={t('@astryx.tableFiltering.filterByColumn', {header})}
<IconButton
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
label={t('@astryx.tableFiltering.filterByColumn', {header})}
aria-haspopup="dialog"
{...stylex.props(
filterStyles.triggerButton,
hasValue ? filterStyles.triggerActive : filterStyles.triggerInactive,
)}>
<Icon
icon="funnel"
size="xsm"
color={hasValue ? 'accent' : 'secondary'}
/>
</button>
variant="ghost"
size="sm"
icon={<Icon icon="funnel" color={hasValue ? 'accent' : 'secondary'} />}
xstyle={hasValue ? undefined : filterStyles.triggerInactive}
/>
</Popover>
);
}
Expand Down
Loading