UNPKG

jsx-slack

Version:

Build JSON object for Slack Block Kit surfaces from JSX

2 lines (1 loc) 925 B
import{JSXSlackError as t}from"../../error.mjs";import{JSXSlack as l}from"../../jsx.mjs";import{createComponent as i}from"../../jsx-internals.mjs";import{plainText as f}from"../composition/utils.mjs";import{resolveTagName as a}from"../utils.mjs";const m=i("OverflowItem",({children:e,url:r,value:o})=>({text:f(e),url:r,value:o})),c=i("Overflow",e=>{const r=l.Children.toArray(e.children).filter(o=>{if(!l.isValidElement(o))return!1;if(o.$$jsxslack.type!==m){const n=a(o);throw new t(`<Overflow> must contain only <OverflowItem>${n?` but it is included ${n}`:""}.`,o)}return!0});if(r.length<1)throw new t("<Overflow> must contain least of 1 <OverflowItem>.",e.__source);if(r.length>5)throw new t(`<Overflow> must contain up to 5 <OverflowItem> elements but there are ${r.length} elements.`,e.__source);return{type:"overflow",action_id:e.actionId||e.name,options:r,confirm:e.confirm}});export{c as Overflow,m as OverflowItem};