mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 21:29:08 +03:00
## Problem Now that we migrated old components to their new shadcn alternatives, we don't need the `_Shadcn_` suffix anymore. ## Solution Remove it <img width="659" height="609" alt="image" src="https://github.com/user-attachments/assets/2d7271a9-066a-4dcc-92fe-729b106d2c2f" />
115 lines
2.9 KiB
TypeScript
115 lines
2.9 KiB
TypeScript
import { Copy } from 'lucide-react'
|
|
import React, {
|
|
ComponentProps,
|
|
ComponentPropsWithoutRef,
|
|
ElementRef,
|
|
forwardRef,
|
|
useState,
|
|
} from 'react'
|
|
import {
|
|
Input as BaseInput,
|
|
cn,
|
|
copyToClipboard,
|
|
InputGroup,
|
|
InputGroupAddon,
|
|
InputGroupButton,
|
|
InputGroupInput,
|
|
} from 'ui'
|
|
|
|
export interface Props extends Omit<ComponentProps<typeof BaseInput>, 'onCopy'> {
|
|
copy?: boolean
|
|
showCopyOnHover?: boolean
|
|
onCopy?: () => void
|
|
icon?: any
|
|
reveal?: boolean
|
|
actions?: React.ReactNode
|
|
iconContainerClassName?: string
|
|
containerClassName?: string
|
|
}
|
|
|
|
const Input = forwardRef<
|
|
ElementRef<typeof BaseInput>,
|
|
ComponentPropsWithoutRef<typeof BaseInput> & Props
|
|
>(
|
|
(
|
|
{
|
|
copy,
|
|
showCopyOnHover = false,
|
|
icon,
|
|
reveal = false,
|
|
actions,
|
|
onCopy,
|
|
iconContainerClassName,
|
|
containerClassName,
|
|
size = 'small',
|
|
...props
|
|
}: Props,
|
|
ref
|
|
) => {
|
|
const [copyLabel, setCopyLabel] = useState('Copy')
|
|
const [hidden, setHidden] = useState(true)
|
|
|
|
function _onCopy(value: any) {
|
|
copyToClipboard(value, () => {
|
|
/* clipboard successfully set */
|
|
setCopyLabel('Copied')
|
|
setTimeout(function () {
|
|
setCopyLabel('Copy')
|
|
}, 3000)
|
|
onCopy?.()
|
|
})
|
|
}
|
|
|
|
function onReveal() {
|
|
setHidden(false)
|
|
}
|
|
|
|
return (
|
|
<InputGroup className={containerClassName}>
|
|
<InputGroupInput
|
|
ref={ref}
|
|
onFocus={(event) => event.target.select()}
|
|
{...props}
|
|
size={size}
|
|
onCopy={onCopy}
|
|
type={reveal && hidden ? 'password' : props.type}
|
|
disabled={props.disabled}
|
|
className={props.className}
|
|
data-1p-ignore // 1Password
|
|
data-lpignore="true" // LastPass
|
|
data-form-type="other" // Dashlane
|
|
data-bwignore // Bitwarden
|
|
/>
|
|
{icon && <InputGroupAddon align="inline-start">{icon}</InputGroupAddon>}
|
|
{copy || actions ? (
|
|
<InputGroupAddon
|
|
align="inline-end"
|
|
// Override defaults
|
|
className="pr-1 has-[>button]:mr-0 has-[>kbd]:mr-0"
|
|
>
|
|
{copy && !(reveal && hidden) ? (
|
|
<InputGroupButton
|
|
size="tiny"
|
|
type="default"
|
|
className={cn(showCopyOnHover && 'opacity-0 group-hover:opacity-100 transition')}
|
|
icon={<Copy size={16} className="text-foreground-muted" />}
|
|
onClick={() => _onCopy(props.value)}
|
|
>
|
|
{copyLabel}
|
|
</InputGroupButton>
|
|
) : null}
|
|
{reveal && hidden ? (
|
|
<InputGroupButton size="tiny" type="default" onClick={onReveal}>
|
|
Reveal
|
|
</InputGroupButton>
|
|
) : null}
|
|
{actions && actions}
|
|
</InputGroupAddon>
|
|
) : null}
|
|
</InputGroup>
|
|
)
|
|
}
|
|
)
|
|
|
|
export { Input }
|