Skip to content

Commit

Permalink
post rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Jul 19, 2024
1 parent 648530b commit be85633
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/dataviews/src/components/dataviews-context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type DataViewsContextType< Item > = {
openedFilter: string | null;
setOpenedFilter: ( openedFilter: string | null ) => void;
getItemId: ( item: Item ) => string;
density: number;
};

const DataViewsContext = createContext< DataViewsContextType< any > >( {
Expand All @@ -42,6 +43,7 @@ const DataViewsContext = createContext< DataViewsContextType< any > >( {
setOpenedFilter: () => {},
openedFilter: null,
getItemId: ( item ) => item.id,
density: 0,
} );

export default DataViewsContext;
2 changes: 2 additions & 0 deletions packages/dataviews/src/components/dataviews-layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function DataViewsLayout() {
selection,
onChangeSelection,
setOpenedFilter,
density,
} = useContext( DataViewsContext );

const ViewComponent = VIEW_LAYOUTS.find( ( v ) => v.type === view.type )
Expand All @@ -44,6 +45,7 @@ export default function DataViewsLayout() {
selection={ selection }
setOpenedFilter={ setOpenedFilter }
view={ view }
density={ density }
/>
);
}
10 changes: 10 additions & 0 deletions packages/dataviews/src/components/dataviews/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import DataViewsViewConfig from '../dataviews-view-config';
import { normalizeFields } from '../../normalize-fields';
import type { Action, Field, View, SupportedLayouts } from '../../types';
import type { SelectionOrUpdater } from '../../private-types';
import DensityPicker from '../../layouts/grid/density-picker';
import { LAYOUT_GRID } from '../../constants';

type ItemWithId = { id: string };

Expand Down Expand Up @@ -59,6 +61,7 @@ export default function DataViews< Item >( {
onChangeSelection,
}: DataViewsProps< Item > ) {
const [ selectionState, setSelectionState ] = useState< string[] >( [] );
const [ density, setDensity ] = useState< number >( 0 );
const isUncontrolled =
selectionProperty === undefined || onChangeSelection === undefined;
const selection = isUncontrolled ? selectionState : selectionProperty;
Expand Down Expand Up @@ -95,6 +98,7 @@ export default function DataViews< Item >( {
openedFilter,
setOpenedFilter,
getItemId,
density,
} }
>
<div className="dataviews-wrapper">
Expand All @@ -111,6 +115,12 @@ export default function DataViews< Item >( {
{ search && <DataViewsSearch label={ searchLabel } /> }
<DataViewsFilters />
</HStack>
{ view.type === LAYOUT_GRID && (
<DensityPicker
density={ density }
setDensity={ setDensity }
/>
) }
<DataViewsBulkActions />
<DataViewsViewConfig defaultLayouts={ defaultLayouts } />
</HStack>
Expand Down
9 changes: 6 additions & 3 deletions packages/dataviews/src/layouts/grid/density-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ export default function DensityPicker( {
return 0;
}
const breakValues = viewportBreaks[ viewport ];
if ( _density >= breakValues.min && _density <= breakValues.max ) {
return _density;
if ( _density < breakValues.min ) {
return breakValues.min;
}
return breakValues.default;
if ( _density > breakValues.max ) {
return breakValues.max;
}
return _density;
} );
}, [ setDensity, viewport ] );
if ( ! viewport ) {
Expand Down
36 changes: 24 additions & 12 deletions packages/dataviews/src/layouts/grid/style.scss
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
.dataviews-view-grid {
margin-bottom: auto;
grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
grid-template-rows: max-content;
padding: 0 $grid-unit-60 $grid-unit-30;
transition: padding ease-out 0.1s;
@include reduce-motion("transition");

@include break-mobile() {
grid-template-columns: repeat(2, minmax(0, 1fr)) !important; // Todo: eliminate !important dependency
}

@include break-xlarge() {
grid-template-columns: repeat(3, minmax(0, 1fr)) !important; // Todo: eliminate !important dependency
}

@include break-huge() {
grid-template-columns: repeat(4, minmax(0, 1fr)) !important; // Todo: eliminate !important dependency
}

.dataviews-view-grid__card {
height: 100%;
Expand Down Expand Up @@ -122,6 +110,30 @@
}
}

.dataviews-view-grid.dataviews-view-grid {
grid-template-columns: repeat(1, minmax(0, 1fr));

@include break-mobile() {
grid-template-columns: repeat(2, minmax(0, 1fr));
}

@include break-xlarge() {
grid-template-columns: repeat(3, minmax(0, 1fr));
}

@include break-huge() {
grid-template-columns: repeat(4, minmax(0, 1fr));
}

@include break-xhuge() {
grid-template-columns: repeat(5, minmax(0, 1fr));
}
}

.dataviews-density-picker__range-control {
width: 200px;
}

.dataviews-view-grid__field-value:empty,
.dataviews-view-grid__field:empty {
display: none;
Expand Down

0 comments on commit be85633

Please sign in to comment.