|
|
@@ -3,13 +3,12 @@ import { Button as BS3Button } from 'react-bootstrap'
|
|
|
import type { ButtonProps } from '@/features/ui/components/types/button-props'
|
|
|
import type { ButtonProps as BS3ButtonPropsBase } from 'react-bootstrap'
|
|
|
import Button from '../bootstrap-5/button'
|
|
|
+import classnames from 'classnames'
|
|
|
|
|
|
export type BS3ButtonSize = 'xsmall' | 'sm' | 'medium' | 'lg'
|
|
|
|
|
|
export type OLButtonProps = ButtonProps & {
|
|
|
bs3Props?: {
|
|
|
- bsStyle?: string | null
|
|
|
- className?: string
|
|
|
loading?: React.ReactNode
|
|
|
bsSize?: BS3ButtonSize
|
|
|
}
|
|
|
@@ -20,6 +19,20 @@ export type BS3ButtonProps = Omit<BS3ButtonPropsBase, 'onClick'> & {
|
|
|
onClick?: React.MouseEventHandler<any>
|
|
|
}
|
|
|
|
|
|
+export function bs3ButtonProps(props: ButtonProps) {
|
|
|
+ const bs3ButtonProps: BS3ButtonProps = {
|
|
|
+ bsStyle: null,
|
|
|
+ bsSize: mapBsButtonSizes(props.size),
|
|
|
+ className: classnames(`btn-${props.variant || 'primary'}`, props.className),
|
|
|
+ disabled: props.isLoading || props.disabled,
|
|
|
+ form: props.form,
|
|
|
+ href: props.href,
|
|
|
+ onClick: props.onClick,
|
|
|
+ type: props.type,
|
|
|
+ }
|
|
|
+ return bs3ButtonProps
|
|
|
+}
|
|
|
+
|
|
|
// maps Bootstrap 5 sizes to Bootstrap 3 sizes
|
|
|
export const mapBsButtonSizes = (
|
|
|
size: ButtonProps['size']
|
|
|
@@ -29,22 +42,10 @@ export const mapBsButtonSizes = (
|
|
|
export default function OLButton(props: OLButtonProps) {
|
|
|
const { bs3Props, ...rest } = props
|
|
|
|
|
|
- const bs3ButtonProps: BS3ButtonProps = {
|
|
|
- bsStyle: rest.variant === 'secondary' ? 'default' : rest.variant,
|
|
|
- bsSize: mapBsButtonSizes(rest.size),
|
|
|
- className: rest.className,
|
|
|
- disabled: rest.isLoading || rest.disabled,
|
|
|
- form: rest.form,
|
|
|
- href: rest.href,
|
|
|
- onClick: rest.onClick,
|
|
|
- type: rest.type,
|
|
|
- ...bs3Props,
|
|
|
- }
|
|
|
-
|
|
|
return (
|
|
|
<BootstrapVersionSwitcher
|
|
|
bs3={
|
|
|
- <BS3Button {...bs3ButtonProps}>
|
|
|
+ <BS3Button {...bs3ButtonProps(rest)} {...bs3Props}>
|
|
|
{bs3Props?.loading || rest.children}
|
|
|
</BS3Button>
|
|
|
}
|