-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
400 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
vuu-ui/packages/vuu-filters/src/inline-filter/useInlineFilter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useEditableCell, useHeaderProps } from "@finos/vuu-table"; | ||
import { | ||
CommitHandler, | ||
FilterAggregator, | ||
getFieldName, | ||
} from "@finos/vuu-utils"; | ||
import { useCallback, useMemo } from "react"; | ||
import { FilterValueChangeHandler } from "./InlineFilter"; | ||
|
||
export const useInlineFilter = ({ | ||
onChange, | ||
}: { | ||
onChange: FilterValueChangeHandler; | ||
}) => { | ||
const filterAggregator = useMemo(() => new FilterAggregator(), []); | ||
const { columns = [], virtualColSpan = 0 } = useHeaderProps(); | ||
|
||
const handleCommit = useCallback< | ||
CommitHandler<HTMLElement, string | number | undefined> | ||
>( | ||
(evt, value = "") => { | ||
const fieldName = getFieldName(evt.target); | ||
const column = columns.find((c) => c.name === fieldName); | ||
if (column) { | ||
if (value === "") { | ||
if (filterAggregator.removeFilter(column)) { | ||
onChange(filterAggregator.filter); | ||
} | ||
} else { | ||
filterAggregator.addFilter(column, value); | ||
onChange(filterAggregator.filter); | ||
} | ||
} | ||
}, | ||
[columns, filterAggregator, onChange], | ||
); | ||
|
||
const { onKeyDown } = useEditableCell(); | ||
|
||
return { | ||
columns, | ||
onCommit: handleCommit, | ||
onKeyDown, | ||
virtualColSpan, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { CellPos } from "@finos/vuu-table-types"; | ||
import { getAriaCellPos } from "./table-dom-utils"; | ||
|
||
/** | ||
* Used to track the Table cell (if any) with focus. | ||
*/ | ||
export interface ICellFocusState { | ||
el: HTMLElement | null; | ||
outsideViewport: "above" | "below" | false; | ||
placeholderEl: HTMLDivElement | null; | ||
pos: { top: number } | undefined; | ||
cellPos: CellPos | undefined; | ||
} | ||
|
||
export class CellFocusState implements ICellFocusState { | ||
#cellPos: CellPos | undefined = undefined; | ||
#el: HTMLElement | null = null; | ||
outsideViewport: "above" | "below" | false = false; | ||
placeholderEl: HTMLDivElement | null = null; | ||
pos: { top: number } | undefined = undefined; | ||
|
||
set cell(cell: HTMLDivElement) { | ||
this.#el = cell; | ||
this.#cellPos = getAriaCellPos(cell); | ||
} | ||
|
||
get cellPos() { | ||
return this.#cellPos; | ||
} | ||
set cellPos(cellPos) { | ||
this.#cellPos = cellPos; | ||
} | ||
|
||
get el() { | ||
return this.#el; | ||
} | ||
set el(el) { | ||
this.#el = el; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.