2021-03-09 12:39:13 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2021 lingdocs.com
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import classNames from "classnames";
|
|
|
|
|
2021-11-03 21:57:13 +00:00
|
|
|
type PickerProps<T extends string> = {
|
|
|
|
options: { label: any, value: T, color?: string }[],
|
|
|
|
value: T,
|
|
|
|
handleChange: (payload: T) => void,
|
2021-03-09 12:39:13 +00:00
|
|
|
small?: boolean,
|
|
|
|
xSmall?: boolean,
|
|
|
|
}
|
|
|
|
|
2021-11-03 21:57:13 +00:00
|
|
|
function ButtonSelect<L extends string>(props: PickerProps<L>) {
|
2022-04-04 19:22:47 +00:00
|
|
|
return <div className="btn-group">
|
|
|
|
{props.options.map((option) => (
|
|
|
|
<button
|
|
|
|
key={option.value}
|
|
|
|
type="button"
|
|
|
|
className={classNames(
|
|
|
|
"btn",
|
|
|
|
"btn-outline-secondary",
|
|
|
|
{ active: props.value === option.value },
|
2022-04-13 14:10:54 +00:00
|
|
|
{ "btn-sm": props.small || props.xSmall },
|
2022-04-04 19:22:47 +00:00
|
|
|
)}
|
|
|
|
onClick={() => props.handleChange(option.value)}
|
|
|
|
style={{
|
|
|
|
...props.xSmall ?
|
|
|
|
{ fontSize: "small" }: {},
|
|
|
|
...(option.color && (props.value === option.value)) ?
|
|
|
|
{ backgroundColor: option.color } : {},
|
|
|
|
}}
|
|
|
|
>
|
2022-04-13 14:10:54 +00:00
|
|
|
<span className={classNames([{ "text-on-gender-color": option.color && (props.value === option.value) }])}>
|
|
|
|
{option.label}
|
|
|
|
</span>
|
2022-04-04 19:22:47 +00:00
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</div>
|
2021-03-09 12:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ButtonSelect;
|