import { useStore } from '@o/use-store'
import { selectDefined } from '@o/utils'
import { gloss, Theme } from 'gloss'
import React, { memo, useLayoutEffect, useState } from 'react'
import { Arrow } from './Arrow'
import { Button, ButtonProps } from './buttons/Button'
import { DockButtonPropsContext, DockStore, DockStoreContext } from './DockStore'
import { Tag, TagProps } from './Tag'
import { Stack, StackProps } from './View/Stack'
import { View } from './View/View'
// Dock
export type DockProps = StackProps
export const Dock = (props: DockProps) => {
const dockStore = useStore(DockStore)
return (
)
}
// DockButton
export type DockButtonProps = ButtonProps & {
label?: string
labelProps?: Partial
visible?: boolean
id: string
showLabelOnHover?: boolean
}
export const DockButton = (props: DockButtonProps) => {
const {
visible = true,
id,
label,
showLabelOnHover,
labelProps,
space = 12,
...buttonProps
} = DockButtonPropsContext.useProps(props)
const dockStore = DockStoreContext.useStore()
const show = selectDefined(dockStore.items[id], visible)
const [hovering, setHovering] = useState(false)
useLayoutEffect(() => {
dockStore.next[id] = visible
dockStore.rerender()
}, [visible])
return (
{!!props.label && (
{props.label}
)}
)
}
export type TagLabelProps = TagProps & {
arrowSize?: number
towards?: 'left' | 'right' | 'top' | 'bottom'
}
const TagLabel = ({
// arrow props
arrowSize = 12,
towards,
background,
// chrome props
maxWidth,
position,
top,
left,
bottom,
right,
display,
opacity,
transform,
transition,
hoverStyle,
focusStyle,
disabled,
disabledStyle,
active,
activeStyle,
hover,
// tag props
...props
}: TagLabelProps) => {
13
return (
{/* TODO do other directions */}
{towards === 'right' && (
)}
)
}
const TagLabelChrome = gloss(View, {
position: 'relative',
maxWidth: 'min-content',
})