@loadsmart/miranda-react 3.0.0-beta.6 → 3.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import type { ReactNode, ComponentProps } from 'react';
2
- import type { WebComponentProps } from '@lit/react';
3
1
  import { Tooltip as WCTooltip } from '@loadsmart/miranda-wc';
2
+ import type { ReactElement, ReactNode, ComponentProps } from 'react';
3
+ import type { WebComponentProps } from '@lit/react';
4
4
  import type { TooltipPlacement, TooltipTrigger } from '@loadsmart/miranda-wc';
5
5
  declare global {
6
6
  namespace JSX {
@@ -11,7 +11,14 @@ declare global {
11
11
  }
12
12
  declare const WiredTooltip: import("@lit/react").ReactWebComponent<WCTooltip, {}>;
13
13
  export type TooltipProps = ComponentProps<typeof WiredTooltip> & {
14
- message?: ReactNode;
14
+ message: ReactNode;
15
+ children: ReactElement;
15
16
  };
16
- export declare function Tooltip(props: TooltipProps): import("react/jsx-runtime").JSX.Element;
17
+ /**
18
+ * Render the tooltip component.
19
+ *
20
+ * **Warning**: This component will throw if the provided `children` is not a single child,
21
+ * and will not render if the children is not valid or is a fragment.
22
+ */
23
+ export declare function Tooltip(props: TooltipProps): import("react/jsx-runtime").JSX.Element | null;
17
24
  export type { TooltipPlacement, TooltipTrigger };
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { AccordionTitle as AccordionTitle$1, AccordionContent as AccordionContent$1, Accordion as Accordion$1, Badge as Badge$1, BannerActionPrimary as BannerActionPrimary$1, BannerActions as BannerActions$1, BannerActionSecondary as BannerActionSecondary$1, BannerDescription as BannerDescription$1, BannerIcon as BannerIcon$1, BannerTitle as BannerTitle$1, Banner as Banner$1, Button as Button$1, CardTitle as CardTitle$1, CardSubtitle as CardSubtitle$1, CardBody as CardBody$1, CardDivider as CardDivider$1, CardActionPrimary as CardActionPrimary$1, CardActionSecondary as CardActionSecondary$1, CardActionTertiary as CardActionTertiary$1, CardFooter as CardFooter$1, Card as Card$1, Checkbox as Checkbox$1, DialogActionPrimary as DialogActionPrimary$1, DialogActionSecondary as DialogActionSecondary$1, DialogActionTertiary as DialogActionTertiary$1, DialogActions as DialogActions$1, DialogBody as DialogBody$1, DialogClose as DialogClose$1, DialogFooter as DialogFooter$1, DialogHeader as DialogHeader$1, Dialog as Dialog$1, Divider as Divider$1, DrawerActionPrimary as DrawerActionPrimary$1, DrawerActionSecondary as DrawerActionSecondary$1, DrawerActionTertiary as DrawerActionTertiary$1, DrawerActions as DrawerActions$1, DrawerBody as DrawerBody$1, DrawerClose as DrawerClose$1, DrawerHeader as DrawerHeader$1, Drawer as Drawer$1, DropdownItem as DropdownItem$1, DropdownMenu as DropdownMenu$1, DropdownTrigger as DropdownTrigger$1, Dropdown as Dropdown$1, EmptyStateIllustration as EmptyStateIllustration$1, EmptyStateHeader as EmptyStateHeader$1, EmptyStateMessage as EmptyStateMessage$1, EmptyStateAction as EmptyStateAction$1, EmptyState as EmptyState$1, FieldLabel as FieldLabel$1, FieldHint as FieldHint$1, Field as Field$1, HeaderActions as HeaderActions$1, HeaderContent as HeaderContent$1, HeaderTitle as HeaderTitle$1, SubHeader as SubHeader$1, BackButton, Header as Header$1, Icon as Icon$1, LabeledValueLabel as LabeledValueLabel$1, LabeledValueValue as LabeledValueValue$1, LabeledValue as LabeledValue$1, Box as Box$1, Group as Group$1, Stack as Stack$1, Grid as Grid$1, Sidebar as Sidebar$1, Switcher as Switcher$1, Container as Container$1, Row as Row$1, Column as Column$1, Link as Link$1, Body as Body$1, PageContent as PageContent$1, Pagination as Pagination$1, ProgressBar as ProgressBar$1, ProgressBarCountdown as ProgressBarCountdown$1, Radio as Radio$1, RadioGroup as RadioGroup$1, SectionTitle as SectionTitle$1, Section as Section$1, SelectOption as SelectOption$1, Select as Select$1, SpinnerWheel as SpinnerWheel$1, Step as Step$1, Steps as Steps$1, Switch as Switch$1, TableHead as TableHead$1, TableBody as TableBody$1, TableFoot as TableFoot$1, TableRow as TableRow$1, TableCell as TableCell$1, TableToolbar as TableToolbar$1, TableHeadCell as TableHeadCell$1, TableFeedback as TableFeedback$1, TableActions as TableActions$1, Table as Table$1, Tab as Tab$1, TabPanel as TabPanel$1, Tabs as Tabs$1, Tag as Tag$1, ActionableTag as ActionableTag$1, Text as Text$1, TextArea as TextArea$1, TextField as TextField$1, TimelineItem as TimelineItem$1, TimelineExpandableItem as TimelineExpandableItem$1, TimelineItemBody as TimelineItemBody$1, TimelineItemFooter as TimelineItemFooter$1, TimelineItemHeader as TimelineItemHeader$1, TimelineItemHeaderSubtitle as TimelineItemHeaderSubtitle$1, TimelineItemHeaderTitle as TimelineItemHeaderTitle$1, TimelineItemIcon as TimelineItemIcon$1, Timeline as Timeline$1, Toggle as Toggle$1, ToggleGroup as ToggleGroup$1, Tooltip as Tooltip$1, LogoLoader as LogoLoader$1 } from '@loadsmart/miranda-wc';
2
2
  export { DIALOG_SIZES, DIALOG_VARIANTS, DRAWER_SIZES, EMPTY_STATE_VARIANTS, Accordion as WCAccordion, AccordionContent as WCAccordionContent, AccordionTitle as WCAccordionTitle, ActionableTag as WCActionableTag, Badge as WCBadge, Banner as WCBanner, BannerActionPrimary as WCBannerActionPrimary, BannerActionSecondary as WCBannerActionSecondary, BannerActions as WCBannerActions, BannerDescription as WCBannerDescription, BannerIcon as WCBannerIcon, BannerTitle as WCBannerTitle, Box as WCBox, Button as WCButton, Card as WCCard, CardActionPrimary as WCCardActionPrimary, CardActionSecondary as WCCardActionSecondary, CardActionTertiary as WCCardActionTertiary, CardBody as WCCardBody, CardDivider as WCCardDivider, CardFooter as WCCardFooter, CardSubtitle as WCCardSubtitle, CardTitle as WCCardTitle, Checkbox as WCCheckbox, Column as WCColumn, Container as WCContainer, Dialog as WCDialog, DialogActionPrimary as WCDialogActionPrimary, DialogActionSecondary as WCDialogActionSecondary, DialogActionTertiary as WCDialogActionTertiary, DialogActions as WCDialogActions, DialogBody as WCDialogBody, DialogClose as WCDialogClose, DialogFooter as WCDialogFooter, DialogHeader as WCDialogHeader, Divider as WCDivider, Drawer as WCDrawer, DrawerActionPrimary as WCDrawerActionPrimary, DrawerActionSecondary as WCDrawerActionSecondary, DrawerActionTertiary as WCDrawerActionTertiary, DrawerActions as WCDrawerActions, DrawerBody as WCDrawerBody, DrawerClose as WCDrawerClose, DrawerHeader as WCDrawerHeader, Dropdown as WCDropdown, DropdownItem as WCDropdownItem, DropdownMenu as WCDropdownMenu, DropdownTrigger as WCDropdownTrigger, EmptyState as WCEmptyState, EmptyStateAction as WCEmptyStateAction, EmptyStateHeader as WCEmptyStateHeader, EmptyStateIllustration as WCEmptyStateIllustration, EmptyStateMessage as WCEmptyStateMessage, Field as WCField, FieldHint as WCFieldHint, FieldLabel as WCFieldLabel, Grid as WCGrid, Group as WCGroup, Header as WCHeader, HeaderActions as WCHeaderActions, HeaderContent as WCHeaderContent, HeaderTitle as WCHeaderTitle, Icon as WCIcon, LabeledValue as WCLabeledValue, LabeledValueLabel as WCLabeledValueLabel, LabeledValueValue as WCLabeledValueValue, Link as WCLink, LogoLoader as WCLogoLoader, PageContent as WCPageContent, Pagination as WCPagination, ProgressBar as WCProgressBar, ProgressBarCountdown as WCProgressBarCountdown, Radio as WCRadio, RadioGroup as WCRadioGroup, Row as WCRow, Section as WCSection, SectionTitle as WCSectionTitle, Sidebar as WCSidebar, SpinnerWheel as WCSpinnerWheel, Stack as WCStack, Step as WCStep, Steps as WCSteps, SubHeader as WCSubHeader, Switch as WCSwitch, Switcher as WCSwitcher, Tab as WCTab, TabPanel as WCTabPanel, Table as WCTable, TableActions as WCTableActions, TableBody as WCTableBody, TableCell as WCTableCell, TableFeedback as WCTableFeedback, TableFoot as WCTableFoot, TableHead as WCTableHead, TableHeadCell as WCTableHeadCell, TableRow as WCTableRow, TableToolbar as WCTableToolbar, Tabs as WCTabs, Tag as WCTag, Text as WCText, TextArea as WCTextArea, TextField as WCTextField, Timeline as WCTimeline, TimelineExpandableItem as WCTimelineExpandableItem, TimelineItem as WCTimelineItem, TimelineItemBody as WCTimelineItemBody, TimelineItemFooter as WCTimelineItemFooter, TimelineItemHeader as WCTimelineItemHeader, TimelineItemHeaderSubtitle as WCTimelineItemHeaderSubtitle, TimelineItemHeaderTitle as WCTimelineItemHeaderTitle, TimelineItemIcon as WCTimelineItemIcon, Toggle as WCToggle, ToggleGroup as WCToggleGroup, Tooltip as WCTooltip } from '@loadsmart/miranda-wc';
3
3
  import * as React from 'react';
4
- import { forwardRef, useState, useCallback } from 'react';
5
- import { jsxs, jsx } from 'react/jsx-runtime';
4
+ import { forwardRef, useState, useCallback, Children, isValidElement, cloneElement } from 'react';
5
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
+ import { isFragment } from 'react-is';
6
7
 
7
8
  function _extends() {
8
9
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -1223,9 +1224,55 @@ const WiredTooltip = createComponent({
1223
1224
  elementClass: Tooltip$1,
1224
1225
  displayName: 'Tooltip',
1225
1226
  });
1227
+ let counter = 0;
1228
+ /**
1229
+ * Generates a unique id for our elements, prepending the given `prefix`.
1230
+ * @param prefix - Id prefix. Defaults to 'm-tt-anchor'
1231
+ */
1232
+ function generateId(prefix = 'tt-anchor') {
1233
+ counter += 1;
1234
+ /**
1235
+ * prefixing with 'm' to ensure we always start with a letter.
1236
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id
1237
+ */
1238
+ const id = `m-${prefix}-${counter}`;
1239
+ /**
1240
+ * Embracing the unlikelyhood of having 9007199254740991 elements we id-d with this approach
1241
+ * at the same time in the document (in which case we would have a collision).
1242
+ */
1243
+ if (counter === Number.MAX_SAFE_INTEGER) {
1244
+ counter = 0;
1245
+ }
1246
+ return id;
1247
+ }
1248
+ /**
1249
+ * Render the tooltip component.
1250
+ *
1251
+ * **Warning**: This component will throw if the provided `children` is not a single child,
1252
+ * and will not render if the children is not valid or is a fragment.
1253
+ */
1226
1254
  function Tooltip(props) {
1227
1255
  const { children, message, ...rest } = props;
1228
- return jsx(WiredTooltip, { ...rest, children: message !== null && message !== void 0 ? message : children });
1256
+ const child = Children.only(children);
1257
+ if (isFragment(child) || !isValidElement(child)) {
1258
+ console.error('Tooltip must wrap a single and valid child element (Fragment is not accepted).');
1259
+ return null; // do not render the tooltip if the children are not valid or a fragment
1260
+ }
1261
+ const [anchorId, childWithId] = (() => {
1262
+ const elementWithID = child;
1263
+ const { id } = elementWithID.props;
1264
+ if (id) {
1265
+ return [id, elementWithID];
1266
+ }
1267
+ const generatedAnchorId = generateId();
1268
+ return [
1269
+ generatedAnchorId,
1270
+ cloneElement(elementWithID, {
1271
+ id: generatedAnchorId,
1272
+ }),
1273
+ ];
1274
+ })();
1275
+ return (jsxs(Fragment, { children: [jsx(WiredTooltip, { anchor: anchorId, ...rest, children: message }), childWithId] }));
1229
1276
  }
1230
1277
 
1231
1278
  const LogoLoader = createComponent({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadsmart/miranda-react",
3
- "version": "3.0.0-beta.6",
3
+ "version": "3.0.0-beta.7",
4
4
  "description": "React component library based on Miranda Web Components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,6 +26,7 @@
26
26
  "@testing-library/cypress": "^10.0.1",
27
27
  "@types/react": "^17.0.79",
28
28
  "@types/react-dom": "^17.0.25",
29
+ "@types/react-is": "^18.3.0",
29
30
  "cypress": "^13.2.0",
30
31
  "cypress-plugin-tab": "^1.0.5",
31
32
  "react": "^17.0.2",
@@ -40,9 +41,10 @@
40
41
  "access": "public"
41
42
  },
42
43
  "dependencies": {
43
- "@loadsmart/miranda-tokens": "4.0.0-beta.6",
44
- "@loadsmart/miranda-wc": "3.0.0-beta.6",
45
- "@lit/react": "^1.0.5"
44
+ "@loadsmart/miranda-tokens": "4.0.0-beta.7",
45
+ "@loadsmart/miranda-wc": "3.0.0-beta.7",
46
+ "@lit/react": "^1.0.5",
47
+ "react-is": "^18.3.1"
46
48
  },
47
49
  "directories": {
48
50
  "test": "tests"