-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'FZ-88-FZ-89-select' into develop
- Loading branch information
Showing
24 changed files
with
888 additions
and
81 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,50 @@ | ||
import {A, AnchorProps} from "@solidjs/router"; | ||
import {ImInfo} from "solid-icons/im"; | ||
import {Match, Switch, VoidComponent} from "solid-js"; | ||
import {htmlAttributes, useLangFunc} from "../utils"; | ||
import {Button} from "./Button"; | ||
|
||
interface ButtonProps extends htmlAttributes.button { | ||
href?: undefined; | ||
} | ||
|
||
interface LinkProps extends AnchorProps { | ||
href: string; | ||
} | ||
|
||
type Props = ButtonProps | LinkProps; | ||
|
||
/** | ||
* A tiny blue (i) icon providing more information to a control it is next to. | ||
* It can be a button, or an internal or external link. | ||
*/ | ||
export const InfoIcon: VoidComponent<Props> = (props) => { | ||
const t = useLangFunc(); | ||
const icon = <ImInfo class="inlineIcon !mb-0.5 text-blue-500" size="16" />; | ||
return ( | ||
<Switch> | ||
<Match when={props.href && props}> | ||
{(linkProps) => ( | ||
<A | ||
title={t("more_info")} | ||
{...(linkProps() as AnchorProps)} | ||
onClick={(e) => { | ||
// If the info icon is on an active element, we generally don't want to pass the click. | ||
// TODO: Investigate why this doesn't work. | ||
e.stopPropagation(); | ||
}} | ||
> | ||
{icon} | ||
</A> | ||
)} | ||
</Match> | ||
<Match when={!props.href && props}> | ||
{(buttonProps) => ( | ||
<Button title={t("more_info")} {...buttonProps}> | ||
{icon} | ||
</Button> | ||
)} | ||
</Match> | ||
</Switch> | ||
); | ||
}; |
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
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
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,57 @@ | ||
import {NON_NULLABLE, htmlAttributes} from "components/utils"; | ||
import {Position, useDictionaries} from "data-access/memo-api/dictionaries"; | ||
import {VoidComponent, createMemo, mergeProps, splitProps} from "solid-js"; | ||
import {MultipleSelectPropsPart, Select, SelectBaseProps, SelectItem, SingleSelectPropsPart} from "./Select"; | ||
import {mergeSelectProps} from "./select_helper"; | ||
|
||
interface BaseProps | ||
extends htmlAttributes.div, | ||
Pick<SelectBaseProps, "name" | "label" | "disabled" | "placeholder" | "small"> { | ||
/** The id or name of the dictionary. */ | ||
dictionary: string; | ||
filterable?: boolean; | ||
/** What to do with disabled dictionary positions. Default: hide. */ | ||
disabledItemsMode?: "show" | "showAsActive" | "hide"; | ||
/** A function creating the items. It can make use of the default item properties provided. */ | ||
itemFunc?: (pos: Position, defItem: () => DefaultDictionarySelectItem) => SelectItem | undefined; | ||
} | ||
|
||
type DefaultDictionarySelectItem = Required<Pick<SelectItem, "value" | "text" | "disabled">>; | ||
|
||
type Props = BaseProps & (SingleSelectPropsPart | MultipleSelectPropsPart); | ||
|
||
const DEFAULT_PROPS = { | ||
filterable: true, | ||
disabledItemsMode: "hide", | ||
itemFunc: (pos: Position, defItem: () => DefaultDictionarySelectItem) => defItem(), | ||
} satisfies Partial<BaseProps>; | ||
|
||
export const DictionarySelect: VoidComponent<Props> = (allProps) => { | ||
const defProps = mergeProps(DEFAULT_PROPS, allProps); | ||
const [props, selectProps] = splitProps(defProps, ["dictionary", "filterable", "disabledItemsMode", "itemFunc"]); | ||
const dictionaries = useDictionaries(); | ||
const items = createMemo(() => { | ||
const dicts = dictionaries(); | ||
if (!dicts) { | ||
return undefined; | ||
} | ||
const dict = dicts.get(props.dictionary); | ||
const positions = props.disabledItemsMode === "hide" ? dict.activePositions : dict.allPositions; | ||
return positions | ||
.map<SelectItem | undefined>((pos) => { | ||
const defItem = (): DefaultDictionarySelectItem => ({ | ||
value: pos.id, | ||
text: pos.label, | ||
disabled: props.disabledItemsMode === "show" && pos.disabled, | ||
}); | ||
return props.itemFunc(pos, defItem); | ||
}) | ||
.filter(NON_NULLABLE); | ||
}); | ||
const mergedSelectProps = mergeSelectProps<"items" | "isLoading" | "onFilterChange">(selectProps, { | ||
items: () => items() || [], | ||
isLoading: () => !items(), | ||
onFilterChange: () => (props.filterable ? "internal" : undefined), | ||
}); | ||
return <Select {...mergedSelectProps} />; | ||
}; |
Oops, something went wrong.