carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 2.06 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import t,{useRef as r,useContext as n}from"react";import o from"../../../__internal__/utils/helpers/guid/index.js";import i from"./option-row.style.js";import l from"../__internal__/select-list/select-list.context.js";function c(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const s=t.forwardRef(((t,s)=>{var{id:u,text:a,children:p,disabled:d,onSelect:f,value:b,index:O,hidden:y,style:m}=t,j=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,["id","text","children","disabled","onSelect","value","index","hidden","style"]);const g=r(u||o()),h=n(l);let w=h.currentOptionsListIndex===O;return h.multiselectValues&&(w=h.multiselectValues.includes(b)),e(i,(v=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){c(e,t,r[t])}))}return e}({id:g.current,ref:s,"aria-selected":w,"aria-disabled":d,isDisabled:d,onClick:()=>{d||null==f||f({text:a,value:b,id:g.current})},isHighlighted:h.currentOptionsListIndex===O,role:"option",hidden:y,style:m},j),x=null!=(x={"data-component":"option-row",children:p})?x:{},Object.getOwnPropertyDescriptors?Object.defineProperties(v,Object.getOwnPropertyDescriptors(x)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(x)).forEach((function(e){Object.defineProperty(v,e,Object.getOwnPropertyDescriptor(x,e))})),v));var v,x}));s.displayName="OptionRow";export{s as default};