Skip to content

Commit

Permalink
fix styling in filter combobox, editable label
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Dec 3, 2024
1 parent 9e88e30 commit 175c33a
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 39 deletions.
34 changes: 21 additions & 13 deletions vuu-ui/packages/vuu-filters/src/filter-clause/ColumnPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ColumnDescriptor } from "@finos/vuu-table-types";
import { ExpandoCombobox } from "./ExpandoCombobox";
import { ComboBoxProps, Option } from "@salt-ds/core";
import { ForwardedRef, SyntheticEvent, forwardRef } from "react";
import { useExpandoComboBox } from "./useExpandoCombobox";

export type ColumnPickerProps = Pick<
ComboBoxProps,
Expand All @@ -12,29 +13,36 @@ export type ColumnPickerProps = Pick<
};

export const ColumnPicker = forwardRef(function ColumnPicker(
{ className, columns, inputProps, onSelect, value }: ColumnPickerProps,
forwardedRef: ForwardedRef<HTMLDivElement>
{
className,
columns,
inputProps,
onSelect,
value: valueProp,
}: ColumnPickerProps,
forwardedRef: ForwardedRef<HTMLDivElement>,
) {
const handleSelectionChange = (
evt: SyntheticEvent,
newSelected: string[]
) => {
onSelect(evt, newSelected[0]);
};
const comboProps = useExpandoComboBox({
onSelect,
value: valueProp?.toString() ?? "",
});

return (
<ExpandoCombobox
{...comboProps}
inputProps={inputProps}
className={className}
data-field="column"
onSelectionChange={handleSelectionChange}
ref={forwardedRef}
title="column"
value={value}
>
{columns.map(({ name }) => (
<Option value={name} key={name} />
))}
{columns
.filter(({ name }) =>
name.toLowerCase().includes(comboProps.value.toLowerCase()),
)
.map(({ name, label = name }) => (
<Option value={label} key={name} />
))}
</ExpandoCombobox>
);
});
1 change: 1 addition & 0 deletions vuu-ui/packages/vuu-filters/src/filter-clause/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./ColumnPicker";
export * from "./ExpandoCombobox";
export * from "./FilterClause";
export * from "./value-editors/FilterClauseValueEditorText";
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ChangeEvent, SyntheticEvent, useState } from "react";

export const useExpandoComboBox = ({
onSelect,
value: valueProp,
}: {
onSelect: (evt: SyntheticEvent, columnName: string) => void;
value: string;
}) => {
const [value, setValue] = useState(valueProp);
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
const value = event.target.value;
setValue(value);
};

// const handleSelectionChange = (
// _evt: SyntheticEvent,
// newSelected: string[],
// ) => {
// if (newSelected.length === 1) {
// setValue(newSelected[0]);
// } else {
// setValue("");
// }
// };

const handleSelectionChange = (
evt: SyntheticEvent,
newSelected: string[],
) => {
onSelect?.(evt, newSelected[0]);
};

return {
onChange: handleChange,
onSelectionChange: handleSelectionChange,
value: value.toString().trim(),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

color: inherit;
cursor: default;
display: flex;
display: inline-flex;
flex-direction: column;
font-size: var(--salt-text-fontSize);
height: 100%;
justify-content: center;
letter-spacing: normal;

/* max-width: 170px; */
overflow: hidden;
padding-right: var(--editableLabel-padding);
position: relative;
Expand All @@ -25,6 +24,16 @@
&[data-embedded] {
outline: none;
}

.saltInput-activationIndicator {
display: none;
}

.saltInput-focused {
background-color: inherit;
outline: none;
}

}

.vuuEditableLabel:before {
Expand All @@ -46,9 +55,6 @@
width: calc(100% - 4px);
}

.vuuEditableLabel .saltInput-activationIndicator {
display: none;
}

.vuuEditableLabel-input {
background-color: transparent;
Expand All @@ -63,6 +69,7 @@
min-width: 0;
outline: none;
padding: 0;
width:0;
}

.vuuEditableLabel-label {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { LocalDataSourceProvider, getSchema } from "@finos/vuu-data-test";
import { SchemaColumn, TableSchema } from "@finos/vuu-data-types";
import { ColumnDescriptorsByName } from "@finos/vuu-filter-types";
import { FilterClause, FilterClauseModel } from "@finos/vuu-filters";
import { useMemo } from "react";
import { ReactNode, useMemo } from "react";
import { ColumnPicker } from "@finos/vuu-filters/src/filter-clause/ColumnPicker";

import "./FilterClause.examples.css";
import { Input } from "@salt-ds/core";

const FilterClauseTemplate = ({
filterClauseModel = new FilterClauseModel({}),
Expand All @@ -27,6 +29,36 @@ const FilterClauseTemplate = ({
);
};

const ExpandoContainer = ({ children }: { children: ReactNode }) => (
<div
style={{
alignItems: "center",
border: "solid 1px black",
display: "flex",
flexDirection: "column",
gap: 12,
padding: 12,
width: 300,
}}
>
<Input />
{children}
<Input />
</div>
);

export const DefaultColumnPicker = () => {
const columns = useMemo(() => getSchema("instruments").columns, []);
return (
<ExpandoContainer>
<ColumnPicker
columns={columns}
onSelect={(e, val) => console.log(`select ${val}`)}
/>
</ExpandoContainer>
);
};

export const NewFilterClause = () => {
return (
<LocalDataSourceProvider modules={["SIMUL"]}>
Expand Down
89 changes: 69 additions & 20 deletions vuu-ui/showcase/src/examples/UiControls/EditableLabel.examples.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,85 @@
import { EditableLabel } from "@finos/vuu-ui-controls";
import { useState } from "react";
import {
EditableLabel,
ExitEditModeHandler,
Icon,
} from "@finos/vuu-ui-controls";
import { Button, Input } from "@salt-ds/core";
import { ReactNode, useRef, useState } from "react";

const ExpandoContainer = ({ children }: { children: ReactNode }) => (
<div
style={{
alignItems: "center",
border: "solid 1px black",
display: "flex",
flexDirection: "column",
gap: 12,
padding: 12,
width: 300,
}}
>
<Input />
{children}
<Input />
</div>
);

export const EditableLabelControlledValueUncontrolledEditing = () => {
const [value, setValue] = useState<string>("Initial value");
const [editing, setEditing] = useState(false);
const editButtonRef = useRef<HTMLButtonElement>(null);

const handleEnterEditMode = () => {
console.log("handleEnterEditMode");
};

const handleExitEditMode = (finalValue = "") => {
console.log(`handleExitEditMode '${value}'`);
const handleExitEditMode: ExitEditModeHandler = (
originalValue,
finalValue = "",
) => {
console.log(`handleExitEditMode finalValue ${finalValue} value '${value}'`);
if (finalValue !== value) {
setValue(finalValue);
}
setEditing(false);
requestAnimationFrame(() => {
editButtonRef.current?.focus();
});
};

const beginEdit = () => {
requestAnimationFrame(() => {
setEditing(true);
});
};

return (
<div
style={{
display: "inline-block",
border: "solid 1px #ccc",
position: "absolute",
top: 100,
left: 100,
}}
>
<EditableLabel
value={value}
onChange={setValue}
onEnterEditMode={handleEnterEditMode}
onExitEditMode={handleExitEditMode}
/>
</div>
<ExpandoContainer>
<div
style={{
alignItems: "center",
display: "flex",
padding: 4,
flex: "0 0 40px",
}}
>
<EditableLabel
editing={editing}
value={value}
onChange={setValue}
onEnterEditMode={handleEnterEditMode}
onExitEditMode={handleExitEditMode}
/>

<Button
className="vuuIconButton"
disabled={editing}
ref={editButtonRef}
onClick={beginEdit}
>
<Icon name="edit" />
</Button>
</div>
</ExpandoContainer>
);
};

0 comments on commit 175c33a

Please sign in to comment.