Merge pull request #18882 from drodil/catalog_filter_breakpoint

feat: allow specifying breakpoint for catalog filters
This commit is contained in:
Fredrik Adelöw
2023-08-07 15:18:25 +02:00
committed by GitHub
4 changed files with 39 additions and 7 deletions
+7 -1
View File
@@ -63,7 +63,13 @@ export const catalogApiRef: ApiRef<CatalogApi>;
// @public (undocumented)
export const CatalogFilterLayout: {
(props: { children: React_2.ReactNode }): JSX.Element;
Filters: (props: { children: React_2.ReactNode }) => JSX.Element;
Filters: (props: {
children: React_2.ReactNode;
options?: {
drawerBreakpoint?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | number;
drawerAnchor?: 'left' | 'right' | 'top' | 'bottom';
};
}) => JSX.Element;
Content: (props: { children: React_2.ReactNode }) => JSX.Element;
};
@@ -28,14 +28,20 @@ import FilterListIcon from '@material-ui/icons/FilterList';
import { BackstageTheme } from '@backstage/theme';
/** @public */
export const Filters = (props: { children: React.ReactNode }) => {
const isMidSizeScreen = useMediaQuery<BackstageTheme>(theme =>
theme.breakpoints.down('md'),
export const Filters = (props: {
children: React.ReactNode;
options?: {
drawerBreakpoint?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | number;
drawerAnchor?: 'left' | 'right' | 'top' | 'bottom';
};
}) => {
const isScreenSmallerThanBreakpoint = useMediaQuery<BackstageTheme>(theme =>
theme.breakpoints.down(props.options?.drawerBreakpoint ?? 'md'),
);
const theme = useTheme<BackstageTheme>();
const [filterDrawerOpen, setFilterDrawerOpen] = useState<boolean>(false);
return isMidSizeScreen ? (
return isScreenSmallerThanBreakpoint ? (
<>
<Button
style={{ marginTop: theme.spacing(1), marginLeft: theme.spacing(1) }}
@@ -47,7 +53,7 @@ export const Filters = (props: { children: React.ReactNode }) => {
<Drawer
open={filterDrawerOpen}
onClose={() => setFilterDrawerOpen(false)}
anchor="left"
anchor={props.options?.drawerAnchor ?? 'left'}
disableAutoFocus
keepMounted
variant="temporary"
+16 -1
View File
@@ -413,7 +413,22 @@ export interface EntitySwitchProps {
}
// @public @deprecated (undocumented)
export const FilterContainer: (props: { children: ReactNode }) => JSX.Element;
export const FilterContainer: (props: {
children: ReactNode;
options?:
| {
drawerBreakpoint?:
| number
| 'xs'
| 'sm'
| 'md'
| 'lg'
| 'xl'
| undefined;
drawerAnchor?: 'left' | 'top' | 'bottom' | 'right' | undefined;
}
| undefined;
}) => JSX.Element;
// @public @deprecated (undocumented)
export const FilteredEntityLayout: (props: {