UNPKG

@nitrogenbuilder/core

Version:

CMS Agnostic Page Builder for React projects

1 lines 1.07 kB
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import React from"react";import"./CtrlEnum.scss";export default function CtrlEnum({currMod:e,updatePath:t,prop:o,value:l,inheritVal:n,deleteProp:r,updateProps:a}){if(!o.options)return _jsx("div",{children:"Missing options for enum"});const s=o.options.length&&"object"==typeof o.options[0]?o.options.findIndex((e=>e.value===l)):o.options.indexOf(l);return _jsxs(React.Fragment,{children:[!1!==o.clearable&&l&&!n&&_jsx("div",{className:"ctrl-enum__clear-btn",onClick:()=>r(t),children:"Clear"}),_jsxs("select",{className:"ctrl-enum__select-dropdown "+(n?"ctrl-enum__select-dropdown--inherit-val":""),value:!o.allowOther||s>-1?l:"other",onChange:o=>a(e.id,t,o.target.value),children:[o.options.map((e=>"object"==typeof e?_jsx("option",{value:e.value,children:e.label},e.value):_jsx("option",{value:e,children:e},e))),o.allowOther&&_jsx("option",{value:"other",children:"Other"})]}),o.allowOther&&-1===s&&_jsx("input",{className:"ctrl-enum__input",type:"text",value:l,onChange:o=>a(e.id,t,o.target.value)},e.id+t)]})}