diff --git a/src/vs/base/browser/ui/positronComponents/button/button.css b/src/vs/base/browser/ui/positronComponents/button/button.css index 415d1e04d62..3fc256a2d0b 100644 --- a/src/vs/base/browser/ui/positronComponents/button/button.css +++ b/src/vs/base/browser/ui/positronComponents/button/button.css @@ -6,7 +6,10 @@ border: none; cursor: pointer; background-color: transparent; + + /* Unset user agent stylesheet styles. */ font-family: unset !important; + text-align: unset !important; } .positron-button:focus { diff --git a/src/vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox.css b/src/vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox.css index fbca2b23cd7..53c9eea95c3 100644 --- a/src/vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox.css +++ b/src/vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox.css @@ -18,9 +18,7 @@ .drop-down-list-box .title { - display: flex; padding-left: 6px; - align-items: center; grid-column: title / chevron; color: var(--vscode-positronContextMenu-foreground); } @@ -33,10 +31,6 @@ grid-column: chevron / end; } -.drop-down-list-box -.chevron.disabled { -} - .drop-down-list-box-items { width: 100%; margin: 4px; diff --git a/src/vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox.tsx b/src/vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox.tsx index 95702891a0b..1a6ec30cefd 100644 --- a/src/vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox.tsx +++ b/src/vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox.tsx @@ -20,29 +20,35 @@ import { PositronModalPopup } from 'vs/workbench/browser/positronComponents/posi import { PositronModalReactRenderer } from 'vs/workbench/browser/positronModalReactRenderer/positronModalReactRenderer'; import { DropDownListBoxSeparator } from 'vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBoxSeparator'; +/** + * DropDownListBoxEntry type. + */ +export type DropDownListBoxEntry, V extends NonNullable> = DropDownListBoxItem | DropDownListBoxSeparator; + /** * DropDownListBoxProps interface. */ -interface DropDownListBoxProps { +interface DropDownListBoxProps, V extends NonNullable> { keybindingService: IKeybindingService; layoutService: ILayoutService; className?: string; disabled?: boolean; title: string; - entries: (DropDownListBoxItem | DropDownListBoxSeparator)[]; - selectedIdentifier?: string; - onSelectionChanged: (identifier: string) => void; + entries: DropDownListBoxEntry[]; + createItem?: (dropDownListBoxItem: DropDownListBoxItem) => JSX.Element; + selectedIdentifier?: T; + onSelectionChanged: (dropDownListBoxItem: DropDownListBoxItem) => void; } /** * Finds a drop down list box item by identifier. - * @param identifier The identifier of the drop down list box item to find. * @param entries The set of drop down list box entries. + * @param identifier The identifier of the drop down list box item to find. * @returns The drop down list box item, if it was found; otherwise, undefined. */ -const findDropDownListBoxItem = ( - identifier: string | undefined, - entries: (DropDownListBoxItem | DropDownListBoxSeparator)[] +const findDropDownListBoxItem = , V>( + entries: DropDownListBoxEntry[], + identifier?: T | undefined ) => { // Find the drop down list box item. for (let i = 0; i < entries.length; i++) { @@ -61,23 +67,23 @@ const findDropDownListBoxItem = ( * @param props The component properties. * @returns The rendered component. */ -export const DropDownListBox = (props: DropDownListBoxProps) => { +export const DropDownListBox = , V,>(props: DropDownListBoxProps) => { // Reference hooks. const ref = useRef(undefined!); // State hooks. const [selectedDropDownListBoxItem, setSelectedDropDownListBoxItem] = - useState( - findDropDownListBoxItem(props.selectedIdentifier, props.entries) + useState | undefined>( + findDropDownListBoxItem(props.entries, props.selectedIdentifier) ); const [highlightedDropDownListBoxItem, setHighlightedDropDownListBoxItem] = - useState(undefined); + useState | undefined>(undefined); // Updates the selected drop down list box item. useEffect(() => { setSelectedDropDownListBoxItem(findDropDownListBoxItem( + props.entries, props.selectedIdentifier, - props.entries )); }, [props.entries, props.selectedIdentifier]); @@ -85,14 +91,22 @@ export const DropDownListBox = (props: DropDownListBoxProps) => { * Gets the title to display. * @returns The title to display. */ - const titleToDisplay = () => { - if (highlightedDropDownListBoxItem) { - return highlightedDropDownListBoxItem.options.title; - } else if (selectedDropDownListBoxItem) { - return selectedDropDownListBoxItem.options.title; + const Title = () => { + if (!props.createItem) { + if (highlightedDropDownListBoxItem) { + return {highlightedDropDownListBoxItem.options.title}; + } else if (selectedDropDownListBoxItem) { + return {selectedDropDownListBoxItem.options.title}; + } } else { - return props.title; + if (highlightedDropDownListBoxItem) { + return props.createItem(highlightedDropDownListBoxItem); + } else if (selectedDropDownListBoxItem) { + return props.createItem(selectedDropDownListBoxItem); + } } + + return {props.title}; }; // Render. @@ -115,23 +129,26 @@ export const DropDownListBox = (props: DropDownListBoxProps) => { // Show the drop down list box modal popup. renderer.render( - renderer={renderer} anchor={ref.current} entries={props.entries} + createItem={props.createItem} onItemHighlighted={dropDownListBoxItem => setHighlightedDropDownListBoxItem(dropDownListBoxItem) } onItemSelected={dropDownListBoxItem => { setSelectedDropDownListBoxItem(dropDownListBoxItem); - props.onSelectionChanged(dropDownListBoxItem.options.identifier); + props.onSelectionChanged(dropDownListBoxItem); }} /> ); }} > -
{titleToDisplay()}
-