@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 862 B
JavaScript
"use client";
;Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=tslib_1.__importDefault(require("react")),Parent_1=tslib_1.__importDefault(require("./Parent")),BaseSelect=(props,ref)=>{const{options=[],children,placeholder={label:"Select an option",value:""},value="",...p}=props;placeholder!=null&&(options.some(option=>option.value===placeholder.value)||options.unshift(placeholder));const Options=options.map((o,k)=>{const{label,...option}=o;return(0,jsx_runtime_1.jsx)("option",{...option,children:label},k)}),parentProps={options,ref,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("select",{ref,defaultValue:value,...p,children:Options})};exports.default=react_1.default.forwardRef(BaseSelect);