unit.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { NeoButton } from 'app/design/controls'
  2. import { components } from 'app/components/registry';
  3. import { useUnitActionHugs } from 'app/components/units/unit-action-width';
  4. export default function MenuItemSubmenu({ menuItem, isPrimary }) {
  5. // Profile rows on phones: a compact button on the right (unit-action-width.js).
  6. const hugs = useUnitActionHugs();
  7. if (!menuItem) return null;
  8. if (menuItem.data?.type) {
  9. const Element = components['molecule'][String(menuItem.data.type)]
  10. if (Element) {
  11. const oElementParams = {
  12. ...menuItem.data,
  13. primary: isPrimary,
  14. params: {
  15. ...menuItem.data?.params,
  16. button_rounded: menuItem.data?.params?.button_rounded || false,
  17. button_full_width: hugs ? false : (menuItem.data?.params?.button_full_width ?? true),
  18. only_icon: menuItem.data?.params?.only_icon || false,
  19. on_done: (sAction, oData) => {
  20. // Handle action completion
  21. },
  22. },
  23. };
  24. return <Element key={menuItem.id || menuItem.name} {...oElementParams} />;
  25. }
  26. } else {
  27. return (
  28. <NeoButton
  29. style={isPrimary ? 'borderedProminent' : undefined}
  30. controlSize="small"
  31. width={hugs ? undefined : 'fill'}
  32. image={menuItem.icon || undefined}
  33. label={menuItem.title || undefined}
  34. classNames={{ root: 'my-auto' }}
  35. expoUI={false}
  36. onPress={menuItem.onPress}
  37. />
  38. );
  39. }
  40. return null;
  41. }