mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-27 08:50:56 +01:00
* feat: add bookmark widget * fix: item component type issue, widget-ordered-object-list-input item component issue * feat: add button in items list * wip * wip: bookmark options dnd * wip: improve widget sortable item list * feat: add sortable item list input to widget edit modal * feat: implement bookmark widget * chore: address pull request feedback * fix: format issues * fix: lockfile not up to date * fix: import configuration missing and apps not imported * fix: bookmark items not sorted * feat: add flex layouts to bookmark widget * fix: deepsource issue * fix: add missing layout bookmarks old-import options mapping --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
30 lines
1.9 KiB
TypeScript
30 lines
1.9 KiB
TypeScript
import type { WidgetKind } from "@homarr/definitions";
|
|
import { useScopedI18n } from "@homarr/translation/client";
|
|
|
|
import type { WidgetOptionOfType, WidgetOptionType } from "../options";
|
|
|
|
export interface CommonWidgetInputProps<TKey extends WidgetOptionType> {
|
|
kind: WidgetKind;
|
|
property: string;
|
|
options: Omit<WidgetOptionOfType<TKey>, "defaultValue" | "type">;
|
|
initialOptions: Record<string, unknown>;
|
|
}
|
|
|
|
type UseWidgetInputTranslationReturnType = (key: "label" | "description") => string;
|
|
|
|
/**
|
|
* Short description why as and unknown convertions are used below:
|
|
* Typescript was not smart enought to work with the generic of the WidgetKind to only allow properties that are relying within that specified kind.
|
|
* This does not mean, that the function useWidgetInputTranslation can be called with invalid arguments without type errors and rather means that the above widget.<kind>.option.<property> string
|
|
* is not recognized as valid argument for the scoped i18n hook. Because the typesafety should remain outside the usage of those methods I (Meierschlumpf) decided to provide this fully typesafe useWidgetInputTranslation method.
|
|
*
|
|
* Some notes about it:
|
|
* - The label translation can be used for every input, especially considering that all options should have defined a label for themself. The description translation should only be used when withDescription
|
|
* is defined for the option. The method does sadly not reconize issues with those definitions. So it does not yell at you when you somewhere show the label without having it defined in the translations.
|
|
*/
|
|
export const useWidgetInputTranslation = (kind: WidgetKind, property: string): UseWidgetInputTranslationReturnType => {
|
|
return useScopedI18n(
|
|
`widget.${kind}.option.${property}` as never, // Because the type is complex and not recognized by typescript, we need to cast it to never to make it work.
|
|
) as unknown as UseWidgetInputTranslationReturnType;
|
|
};
|