UNPKG

@cerberus-design/react

Version:

The Cerberus Design React component library.

1 lines 1.71 kB
{"version":3,"sources":["../../../../src/components/cta-dialog/utils.ts"],"sourcesContent":["import type { MouseEventHandler, ReactNode } from 'react'\n\n/**\n * This module provide utility functions for the cta modal.\n * @module 'react/cta-modal/utils'\n */\n\nexport type CTAButtonAction = {\n /**\n * The text of the button.\n */\n text: string\n /**\n * The onClick handler for the button.\n */\n handleClick: MouseEventHandler<HTMLButtonElement>\n}\n\nexport type CTAModalAction = (CTAButtonAction | ReactNode)[]\n\nexport interface CTAModalActionReturn {\n /**\n * The type of the action content.\n */\n type: 'reactNode' | 'btnAction'\n /**\n * The actions for the cta modal. Max of 2 actions.\n */\n _actions: CTAModalAction\n}\n\n/**\n * Creates the action data to pass to the cta modal `show` method.\n */\nexport function createCTAModalActions(\n providedActions: CTAModalAction,\n): CTAModalActionReturn {\n if (providedActions.length !== 2) {\n throw new Error('CTAModal must include 2 actions')\n }\n\n if (\n providedActions.every(\n (action) => (action as unknown as CTAButtonAction)?.handleClick,\n )\n ) {\n return {\n type: 'btnAction',\n _actions: providedActions as CTAButtonAction[],\n }\n }\n\n return {\n type: 'reactNode',\n _actions: providedActions as ReactNode[],\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCO,SAAS,sBACd,iBACsB;AACtB,MAAI,gBAAgB,WAAW,GAAG;AAChC,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,MACE,gBAAgB;AAAA,IACd,CAAC,WAAY,iCAAuC;AAAA,EACtD,GACA;AACA,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA,EACZ;AACF;","names":[]}