@stratakit/react
Version:
A React component library for StrataKit
58 lines (57 loc) • 1.58 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import * as React from "react";
import { Field, Select as SkSelect } from "@stratakit/bricks";
import { useEventHandlers } from "@stratakit/foundations/secret-internals";
const Select = React.forwardRef((props, forwardedRef) => {
const {
id,
disabled,
value,
onChange: onChangeProp,
options,
defaultValue,
triggerProps,
required,
// biome-ignore lint/correctness/noUnusedVariables: NO-OP
native,
// biome-ignore-start lint/correctness/noUnusedVariables: NOT IMPLEMENTED
size,
status,
multiple,
styleType,
placeholder,
// biome-ignore-end lint/correctness/noUnusedVariables: NOT IMPLEMENTED
...rest
} = props;
const mergedOnChange = useEventHandlers(triggerProps?.onChange, (event) => {
onChangeProp?.(event.target.value, event);
});
const renderedOptions = React.useMemo(() => {
return options.map((option) => {
return /* @__PURE__ */ jsx("option", { ...option, children: option.label }, option.value);
});
}, [options]);
return /* @__PURE__ */ jsx(
Field.Control,
{
id,
render: (controlProps) => /* @__PURE__ */ jsx(SkSelect.Root, { ...rest, children: /* @__PURE__ */ jsx(
SkSelect.HtmlSelect,
{
...controlProps,
...triggerProps,
required,
disabled,
value: value ?? void 0,
defaultValue,
onChange: mergedOnChange,
children: renderedOptions
}
) }),
ref: forwardedRef
}
);
});
export {
Select
};