@commercelayer/react-components
Version:
The Official Commerce Layer React Components
2 lines • 648 B
JavaScript
"use client";
import{jsx as _jsx}from"react/jsx-runtime";import React from"react";import Parent from"./Parent";const 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 _jsx("option",{...option,children:label},k)}),parentProps={options,ref,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("select",{ref,defaultValue:value,...p,children:Options})};export default React.forwardRef(BaseSelect);