1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/dashboard/users/SelectElement.tsx

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-01-30 00:27:26 +03:00
import escapeHtml from 'escape-html';
2021-10-15 23:38:03 +03:00
import React, { FunctionComponent } from 'react';
import globalize from '../../../scripts/globalize';
2022-02-18 14:27:39 +03:00
const createSelectElement = ({ className, label, option }: { className?: string, label: string, option: string[] }) => ({
2021-10-15 23:38:03 +03:00
__html: `<select
class="${className}"
is="emby-select"
label="${label}"
>
${option}
</select>`
});
2021-11-20 16:15:42 +03:00
type ProvidersArr = {
Name?: string;
Id?: string;
}
2021-10-15 23:38:03 +03:00
type IProps = {
className?: string;
label?: string;
currentProviderId: string;
2021-11-20 16:15:42 +03:00
providers: ProvidersArr[]
2021-10-15 23:38:03 +03:00
}
const SelectElement: FunctionComponent<IProps> = ({ className, label, currentProviderId, providers }: IProps) => {
const renderOption = providers.map((provider) => {
const selected = provider.Id === currentProviderId || providers.length < 2 ? ' selected' : '';
2022-01-30 00:27:26 +03:00
return '<option value="' + provider.Id + '"' + selected + '>' + escapeHtml(provider.Name) + '</option>';
2021-10-15 23:38:03 +03:00
});
return (
<div
dangerouslySetInnerHTML={createSelectElement({
className: className,
label: globalize.translate(label),
option: renderOption
})}
/>
);
};
export default SelectElement;