generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #832 from trey-wallis/dev
8.10.0 Former-commit-id: 4c1dd37
- Loading branch information
Showing
12 changed files
with
274 additions
and
90 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
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
2 changes: 1 addition & 1 deletion
2
src/react/loom-app/header-cell-edit/number-format-submenu/styles.css
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.dataloom-number-format-submenu { | ||
width: 100%; | ||
height: 240px; | ||
overflow-y: scroll; | ||
overflow-x: auto; | ||
overflow-y: scroll; | ||
} |
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
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 |
---|---|---|
@@ -1,43 +1,67 @@ | ||
import Stack from "../stack"; | ||
import Text from "../text"; | ||
import Icon from "../icon"; | ||
|
||
import MultiSelectMenu from "./multi-select-menu"; | ||
import { useMenu } from "../menu-provider/hooks"; | ||
import { LoomMenuLevel } from "../menu-provider/types"; | ||
import MenuTrigger from "../menu-trigger"; | ||
import { MultiSelectOptionType } from "./types"; | ||
|
||
import "./styles.css"; | ||
|
||
interface Props { | ||
className?: string; | ||
value: string[]; | ||
onKeyDown?: (e: React.KeyboardEvent<HTMLSelectElement>) => void; | ||
onChange: (value: string[]) => void; | ||
children: React.ReactNode; | ||
id: string; | ||
title: string; | ||
selectedOptionIds: string[]; | ||
options: MultiSelectOptionType[]; | ||
onChange: (keys: string[]) => void; | ||
} | ||
|
||
export default function MultiSelect({ | ||
className: customClassName, | ||
value, | ||
id, | ||
title, | ||
selectedOptionIds, | ||
options, | ||
onChange, | ||
onKeyDown, | ||
children, | ||
}: Props) { | ||
function handleChange(e: React.ChangeEvent<HTMLSelectElement>) { | ||
const selectedValues = Array.from( | ||
e.target.selectedOptions, | ||
(option) => option.value | ||
); | ||
onChange(selectedValues); | ||
} | ||
const COMPONENT_ID = `multi-select-${id}`; | ||
const menu = useMenu(COMPONENT_ID); | ||
|
||
let className = "dataloom-multi-select dataloom-focusable"; | ||
if (customClassName) { | ||
className += " " + customClassName; | ||
function openMenu() { | ||
menu.onOpen(LoomMenuLevel.TWO); | ||
} | ||
|
||
return ( | ||
<select | ||
tabIndex={0} | ||
multiple={true} | ||
className={className} | ||
value={value} | ||
onChange={handleChange} | ||
onKeyDown={onKeyDown} | ||
> | ||
{children} | ||
</select> | ||
<> | ||
<MenuTrigger | ||
ref={menu.triggerRef} | ||
variant="cell" | ||
menuId={menu.id} | ||
level={LoomMenuLevel.TWO} | ||
isFocused={menu.isTriggerFocused} | ||
onOpen={() => openMenu()} | ||
> | ||
<div className="dataloom-multi-select"> | ||
<Stack | ||
isHorizontal | ||
justify="space-between" | ||
align="center" | ||
height="100%" | ||
> | ||
<Text value={`${selectedOptionIds.length} ${title}`} /> | ||
<Icon lucideId="chevron-down" /> | ||
</Stack> | ||
</div> | ||
</MenuTrigger> | ||
<MultiSelectMenu | ||
id={menu.id} | ||
isOpen={menu.isOpen} | ||
position={menu.position} | ||
options={options} | ||
selectedOptionIds={selectedOptionIds} | ||
onChange={onChange} | ||
/> | ||
</> | ||
); | ||
} |
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,86 @@ | ||
import Stack from "../stack"; | ||
import Text from "../text"; | ||
import Menu from "../menu"; | ||
import { LoomMenuPosition } from "../menu/types"; | ||
import MultiSelectOption from "./multi-select-option"; | ||
import { MultiSelectOptionType } from "./types"; | ||
import Input from "../input"; | ||
import React from "react"; | ||
import Padding from "../padding"; | ||
|
||
interface Props { | ||
id: string; | ||
isOpen: boolean; | ||
position: LoomMenuPosition; | ||
options: MultiSelectOptionType[]; | ||
selectedOptionIds: string[]; | ||
onChange: (keys: string[]) => void; | ||
} | ||
|
||
export default function MultiSelectMenu({ | ||
id, | ||
isOpen, | ||
position, | ||
options, | ||
selectedOptionIds, | ||
onChange, | ||
}: Props) { | ||
const [inputValue, setInputValue] = React.useState(""); | ||
|
||
React.useEffect(() => { | ||
if (!isOpen) { | ||
setInputValue(""); | ||
} | ||
}, [isOpen]); | ||
|
||
function handleOptionClick(id: string) { | ||
const isSelected = selectedOptionIds.includes(id); | ||
if (isSelected) { | ||
const filteredOptionIds = selectedOptionIds.filter( | ||
(selected) => selected !== id | ||
); | ||
onChange(filteredOptionIds); | ||
} else { | ||
onChange([...selectedOptionIds, id]); | ||
} | ||
} | ||
|
||
const filteredOptions = options.filter((option) => | ||
option.name.toLowerCase().includes(inputValue.toLocaleLowerCase()) | ||
); | ||
return ( | ||
<Menu id={id} isOpen={isOpen} position={position} topOffset={35}> | ||
<div className="dataloom-multi-select-menu"> | ||
<Stack spacing="md"> | ||
<Padding px="md" pt="sm"> | ||
<Input | ||
value={inputValue} | ||
placeholder="Type to filter..." | ||
onChange={setInputValue} | ||
/> | ||
</Padding> | ||
<div className="dataloom-multi-select__options"> | ||
{filteredOptions.map((option) => { | ||
const { id, component } = option; | ||
const isChecked = selectedOptionIds.includes(id); | ||
return ( | ||
<MultiSelectOption | ||
key={id} | ||
id={id} | ||
isChecked={isChecked} | ||
component={component} | ||
handleOptionClick={handleOptionClick} | ||
/> | ||
); | ||
})} | ||
{options.length === 0 && ( | ||
<Padding px="md" pb="sm"> | ||
<Text value="No options to select" /> | ||
</Padding> | ||
)} | ||
</div> | ||
</Stack> | ||
</div> | ||
</Menu> | ||
); | ||
} |
Oops, something went wrong.