From 022b61961474f27065c2c843c263d4106bf433f6 Mon Sep 17 00:00:00 2001 From: Anika Churilova Date: Tue, 9 Apr 2024 11:46:57 +0200 Subject: [PATCH] utils: add dropdown options generator * closes https://github.com/inveniosoftware/invenio-app-rdm/issues/2593 --- src/lib/utils/dropdownOptionsGenerator.js | 25 +++++++++++++++++++++++ src/lib/utils/index.js | 1 + 2 files changed, 26 insertions(+) create mode 100644 src/lib/utils/dropdownOptionsGenerator.js diff --git a/src/lib/utils/dropdownOptionsGenerator.js b/src/lib/utils/dropdownOptionsGenerator.js new file mode 100644 index 00000000..c719fac9 --- /dev/null +++ b/src/lib/utils/dropdownOptionsGenerator.js @@ -0,0 +1,25 @@ +// This file is part of React-Invenio-Forms +// Copyright (C) 2024 CERN. +// +// React-Invenio-Forms is free software; you can redistribute it and/or modify it +// under the terms of the MIT License; see LICENSE file for more details. + +import React from "react"; + +export function dropdownOptionsGenerator(dropdownOptions) { + return dropdownOptions.map((options) => { + return { + key: options.key, + text: options.text, + value: options.key, + content: ( + <> +
{options.text}
+
+ {options.description} +
+ + ), + }; + }); +} diff --git a/src/lib/utils/index.js b/src/lib/utils/index.js index 1d5cc688..9f213050 100644 --- a/src/lib/utils/index.js +++ b/src/lib/utils/index.js @@ -1 +1,2 @@ export { humanReadableBytes } from "./humanReadableBytes"; +export { dropdownOptionsGenerator } from "./dropdownOptionsGenerator";