UNPKG

jsx-slack

Version:

Build JSON object for Slack Block Kit surfaces from JSX

2 lines (1 loc) 2.34 kB
import{JSXSlackError as c}from"../../error.mjs";import{createComponent as h,cleanMeta as l,createElementInternal as n}from"../../jsx-internals.mjs";import{coerceToString as o,coerceToInteger as r}from"../../utils.mjs";import{inputDispatchActionConfig as _,plainText as m}from"../composition/utils.mjs";import{EmailTextInput as f}from"../elements/EmailTextInput.mjs";import{NumberTextInput as v}from"../elements/NumberTextInput.mjs";import{PlainTextInput as b}from"../elements/PlainTextInput.mjs";import{UrlTextInput as x}from"../elements/UrlTextInput.mjs";import{focusOnLoadFromProps as I}from"../elements/utils.mjs";import{resolveTagName as y}from"../utils.mjs";const p=["channels_select","checkboxes","conversations_select","datepicker","datetimepicker","email_text_input","external_select","multi_channels_select","multi_conversations_select","multi_external_select","multi_static_select","multi_users_select","number_input","plain_text_input","radio_buttons","static_select","timepicker","url_text_input","users_select"],k=({element:e,from:t})=>{if(typeof e!="object")throw new c(`${t} has invalid value as an element of input layout block.`);if(!p.includes(e.type)){const i=y(e);throw new c(`${t} has detected an invalid type as the element of input layout block: "${e.type}"${i?` (Provided by ${i})`:""}`,e)}return l(e)},u=(e,t,i)=>{const d=l(n(k,{element:e,from:i?`<${i.$$jsxslackComponent.name}>`:"Input layout block"}));if(t.label){const a=t.hint||t.title;return{type:"input",block_id:t.blockId||t.id,label:m(t.label),hint:a?m(a):void 0,optional:!t.required,dispatch_action:t.dispatchAction!==void 0?!!t.dispatchAction:void 0,element:d}}return e},s=h("Input",e=>e.type==="hidden"||e.type==="submit"?{}:u(e.children||l((()=>{const t={actionId:e.actionId||e.name,placeholder:e.placeholder,dispatchActionConfig:_(e),focusOnLoad:I(e)};return e.type==="url"?n(x,{...t,initialValue:o(e.value)||void 0}):e.type==="email"?n(f,{...t,initialValue:o(e.value)||void 0}):e.type==="number"?n(v,{...t,initialValue:o(e.value)||void 0,isDecimalAllowed:e.decimal===void 0?void 0:!!e.decimal,maxValue:o(e.max),minValue:o(e.min)}):n(b,{...t,initialValue:e.value,maxLength:r(e.maxLength),minLength:r(e.minLength)})})()),{...e,dispatchAction:e.dispatchAction===void 0?void 0:!!e.dispatchAction},s));export{s as Input,p as knownInputs,u as wrapInInput};