Files
react-test/docs/data/joy/components/select/SelectCustomOption.tsx
how2ice 005cf56baf
Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
init project
2025-12-12 14:26:25 +09:00

57 lines
1.6 KiB
TypeScript

import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import ListDivider from '@mui/joy/ListDivider';
import Select, { SelectOption } from '@mui/joy/Select';
import Option from '@mui/joy/Option';
const options = [
{ value: '1', label: 'Eric', src: '/static/images/avatar/1.jpg' },
{ value: '2', label: 'Smith', src: '/static/images/avatar/2.jpg' },
{ value: '3', label: 'Erika', src: '/static/images/avatar/3.jpg' },
];
function renderValue(option: SelectOption<string> | null) {
if (!option) {
return null;
}
return (
<React.Fragment>
<ListItemDecorator>
<Avatar size="sm" src={options.find((o) => o.value === option.value)?.src} />
</ListItemDecorator>
{option.label}
</React.Fragment>
);
}
export default function SelectCustomOption() {
return (
<Select
defaultValue="1"
slotProps={{
listbox: {
sx: {
'--ListItemDecorator-size': '44px',
},
},
}}
sx={{ '--ListItemDecorator-size': '44px', minWidth: 240 }}
renderValue={renderValue}
>
{options.map((option, index) => (
<React.Fragment key={option.value}>
{index !== 0 ? <ListDivider role="none" inset="startContent" /> : null}
<Option value={option.value} label={option.label}>
<ListItemDecorator>
<Avatar size="sm" src={option.src} />
</ListItemDecorator>
{option.label}
</Option>
</React.Fragment>
))}
</Select>
);
}