import type { DropdownMenuProps } from '@planview/pv-uikit' import { DropdownMenu } from '@planview/pv-uikit' import React from 'react' import styled, { css } from 'styled-components' import { text, theme, useIsFocusVisible, states, spacing, useMergeRefs, } from '@planview/pv-utilities' export type NaturalLanguageDropdownMenuProps = { /** When no triggerValue is provided, render this text as a placeholder */ placeholder?: string /** Text to render as part of the natural language form. This will be the trigger for the dropdown menu. */ triggerValue?: string } & Omit const InlineComponent = styled.div<{ $placeholder: boolean $activated: boolean $focusVisible: boolean }>` cursor: pointer; width: min-content; min-width: ${spacing.small * 2}px; white-space: nowrap; ${text.semibold}; color: ${(props) => props.$placeholder ? theme.textPlaceholder : theme.textPrimary}; font-size: inherit; line-height: inherit; display: inline-block; border-bottom: dashed 1px ${theme.borderNormal}; ${(props) => states.focus({ focusVisible: props.$focusVisible })} &:hover, &:focus { color: ${theme.textPrimary}; border-color: ${theme.borderHover}; } ${(props) => props.$activated && css` color: ${theme.textPrimary}; border-bottom: solid 1px ${theme.borderActive}; `} ` export const NaturalLanguageDropdownMenu = ({ label, placeholder = ' ', triggerValue, children, ...props }: NaturalLanguageDropdownMenuProps) => { const { innerRef: _innerRef, ref, focusVisible, ...rest } = useIsFocusVisible() return ( { // Even though this is a callback, it is called on every single render and will // therefore be consistent, not in violation of the rules of hooks // eslint-disable-next-line react-hooks/rules-of-hooks const mergedRef = useMergeRefs([triggerProps.ref, ref]) return ( {triggerValue || placeholder} ) }} role="listbox" {...props} > {children} ) }