import * as InputSelectPrimitive from "@radix-ui/react-select"; import React from "react"; import styled from "styled-components"; import { depths, s } from "@shared/styles"; import { Props as ButtonProps } from "~/components/Button"; import Separator from "~/components/ContextMenu/Separator"; import { fadeAndSlideDown, fadeAndSlideUp } from "~/styles/animations"; import { SelectItemIndicator, SelectItem as SelectItemWrapper, SelectButton, } from "./components/InputSelect"; /** Root InputSelect component - all the other components are rendered inside it. */ const InputSelectRoot = InputSelectPrimitive.Root; /** InputSelect's trigger. */ export type TriggerButtonProps = { /** When true, "nude" variant of Button is rendered. */ nude?: boolean; /** Optional css class names to pass to the trigger. */ className?: string; } & Pick, "borderOnHover">; type InputSelectTriggerProps = { placeholder: string } & TriggerButtonProps & React.ComponentPropsWithoutRef; const InputSelectTrigger = React.forwardRef< React.ElementRef, InputSelectTriggerProps >((props, ref) => { const { placeholder, children, ...buttonProps } = props; return ( ); }); InputSelectTrigger.displayName = InputSelectPrimitive.Trigger.displayName; /** InputSelect's content - renders the options in a scrollable element. */ type ContentProps = Omit< React.ComponentPropsWithoutRef, "position" >; const InputSelectContent = React.forwardRef< React.ElementRef, ContentProps >((props, ref) => { const { children, ...rest } = props; return ( {children} ); }); InputSelectContent.displayName = InputSelectPrimitive.Content.displayName; /** Individual InputSelect option rendered in the menu. */ const InputSelectItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => { const { children, ...rest } = props; return ( {children} ); }); InputSelectItem.displayName = InputSelectPrimitive.Item.displayName; /** Horizontal separator rendered between the options. */ const InputSelectSeparator = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >((props, ref) => ( )); InputSelectSeparator.displayName = InputSelectPrimitive.Separator.displayName; /** Styled components. */ const StyledContent = styled(InputSelectPrimitive.Content)` z-index: ${depths.menu}; min-width: var(--radix-select-trigger-width); max-width: 400px; min-height: 44px; max-height: 350px; padding: 4px; border-radius: 6px; background: ${s("menuBackground")}; box-shadow: ${s("menuShadow")}; transform-origin: 50% 0; &[data-side="bottom"] { animation: ${fadeAndSlideDown} 200ms ease; } &[data-side="top"] { animation: ${fadeAndSlideUp} 200ms ease; } @media print { display: none; } `; export { InputSelectRoot, InputSelectTrigger, InputSelectContent, InputSelectItem, InputSelectSeparator, };