jsx-slack
Version:
Build JSON object for Slack Block Kit surfaces from JSX
2 lines (1 loc) • 1.29 kB
JavaScript
import{JSXSlackError as d}from"../../error.mjs";import{createComponent as f,isValidElementFromComponent as u,createElementInternal as _}from"../../jsx-internals.mjs";import{coerceToInteger as h}from"../../utils.mjs";import{plainText as g}from"../composition/utils.mjs";import{wrapInInput as S}from"../layout/Input.mjs";import{SelectFragmentInternal as c,selectFragmentSelectedOptionsSymbol as v}from"../other/SelectFragment.mjs";import{focusOnLoadFromProps as m}from"./utils.mjs";const i=f("Select",o=>{const t=u(o.children,c)?o.children:_(c,{from:i,children:o.children});if(t.options&&t.options.length===0)throw new d("<Select> must contain least of one <Option> or <Optgroup>.",o.__source);const e=o.value===void 0?t[v]||[]:(a=>{const p=t.options||[].concat(...t.option_groups.map(n=>n.options)),s=[].concat(a);return p.filter(n=>s.includes(n.value))})(o.value),r=o.actionId||o.name,l=o.placeholder!==void 0?g(o.placeholder):void 0;return S(o.multiple?{type:"multi_static_select",action_id:r,placeholder:l,...t,initial_options:e.length>0?e:void 0,max_selected_items:h(o.maxSelectedItems),confirm:o.confirm,focus_on_load:m(o)}:{type:"static_select",action_id:r,placeholder:l,...t,initial_option:e.length>0?e[e.length-1]:void 0,confirm:o.confirm,focus_on_load:m(o)},o,i)});export{i as Select};