'use client'
import { type ButtonHTMLAttributes,ForwardedRef, forwardRef } from 'react'
import { PktIcon } from '../icon/Icon'
declare global {
interface Window {
pktAnimationPath?: string
}
}
window.pktAnimationPath = window.pktAnimationPath || 'https://punkt-cdn.oslo.kommune.no/latest/animations/'
export interface IPktButton extends ButtonHTMLAttributes {
iconName?: string
secondIconName?: string
iconPath?: string
secondIconPath?: string
mode?: 'light' | 'dark'
size?: 'small' | 'medium' | 'large'
fullWidth?: boolean
fullWidthOnMobile?: boolean
color?:
| 'blue'
| 'blue-outline'
| 'green'
| 'green-outline'
| 'green-dark'
| 'green-dark-outline'
| 'beige-light'
| 'beige-dark-outline'
| 'yellow'
| 'yellow-outline'
| 'red'
| 'red-outline'
skin?: 'primary' | 'secondary' | 'tertiary'
variant?: 'label-only' | 'icon-left' | 'icon-right' | 'icon-only' | 'icons-right-and-left'
state?: 'normal' | 'focus' | 'hover' | 'active'
type?: 'button' | 'submit' | 'reset'
isLoading?: boolean
loadingAnimationPath?: string
}
export const PktButton = forwardRef(
(
{
children,
className,
iconName = 'user',
secondIconName = 'user',
iconPath,
secondIconPath,
size = 'medium',
fullWidth = false,
fullWidthOnMobile = false,
skin = 'primary',
type = 'button',
variant = 'label-only',
state,
color,
isLoading = undefined,
disabled = undefined,
loadingAnimationPath = window.pktAnimationPath,
...props
}: IPktButton,
ref: ForwardedRef,
) => {
const classes = [
className,
'pkt-btn',
size && `pkt-btn--${size}`,
fullWidth && 'pkt-btn--full',
fullWidthOnMobile && 'pkt-btn--full-small',
skin && `pkt-btn--${skin}`,
variant && `pkt-btn--${variant}`,
color && `pkt-btn--${color}`,
state && `pkt-btn--${state}`,
isLoading && `pkt-btn--isLoading`,
]
.filter(Boolean)
.join(' ')
return (
)
},
)
PktButton.displayName = 'PktButton'