update version to 1.0.1 with minor fixes.
This commit is contained in:
@@ -2,32 +2,42 @@ import React from 'react';
|
||||
|
||||
import clsx from 'clsx';
|
||||
|
||||
export interface KintonePluginSelectOptionData {
|
||||
key: string;
|
||||
export type KintonePluginSelectOptionData = {
|
||||
value: string;
|
||||
label: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
interface KintonePluginSelectProps {
|
||||
export type KintonePluginSelectProps = {
|
||||
className?: string;
|
||||
defaultValue?: string;
|
||||
onChange?: (e: React.ChangeEvent<HTMLSelectElement>) => void;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
options: KintonePluginSelectOptionData[];
|
||||
}
|
||||
};
|
||||
|
||||
const KintonePluginSelect: React.FC<KintonePluginSelectProps> = (props) => {
|
||||
const { className, defaultValue, onChange, options } = props;
|
||||
if (!options || options.length === 0) {
|
||||
return null; // Return null if no options are provided
|
||||
const { className, value, onChange, options } = props;
|
||||
const optionWithKeys = React.useMemo(
|
||||
() =>
|
||||
options.map((option) => ({
|
||||
...option,
|
||||
key: crypto.randomUUID(),
|
||||
})),
|
||||
[options],
|
||||
);
|
||||
if (options.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const handleOnChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||
onChange(e.target.value);
|
||||
};
|
||||
return (
|
||||
<div className={clsx('kintoneplugin-select-outer', className)}>
|
||||
<div className="kintoneplugin-select">
|
||||
<select defaultValue={defaultValue} onChange={onChange}>
|
||||
{options.map((option) => (
|
||||
<option key={option.key} value={option.value} disabled={option.disabled}>
|
||||
{option.label}
|
||||
<select value={value} onChange={handleOnChange}>
|
||||
{optionWithKeys.map(({ key, value: itemValue, label, disabled }) => (
|
||||
<option key={key} value={itemValue} disabled={disabled}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
Reference in New Issue
Block a user