mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
* React 19 upgrade Bumps react and react-dom to 19.2.8, with the dependency changes React 19 requires: react-is 19, @types/react 19, @types/react-dom 19, react-helmet-async 3 and react-avatar-editor 15 (which now ships its own types). framer-motion moves to 13 — its v6 types reference React.ReactHTML, removed from @types/react 19. The type changes fall into a few classes: - The global JSX namespace is gone, so JSX.Element becomes React.JSX.Element and the custom element declarations move into a module augmentation. - useRef() now requires an initial value. - A ref created with a null initial value is typed nullable, so consumers that accept one are widened to RefObject<T | null>. - React.ReactChild was removed; tooltips take React.ReactNode. - Ref callbacks may only return a cleanup function. react-dnd connectors return the connected node, so useDragRef and useDropRef wrap useDrag and useDrop and hand back a ref callback. react-i18next stays on v12: i18next 23 drops compatibilityJSON "v3", which would rewrite all 64 _plural keys across every locale. outline-icons, oy-vey and react-waypoint have no release that lists React 19 as a peer. All three render correctly under it; the install reports them as unmet peers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Remove react-helmet and forwardRef --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
182 lines
5.1 KiB
TypeScript
182 lines
5.1 KiB
TypeScript
import * as InputSelectPrimitive from "@radix-ui/react-select";
|
|
import * as React from "react";
|
|
import styled from "styled-components";
|
|
import Text from "@shared/components/Text";
|
|
import { depths, s, borderRadius } from "@shared/styles";
|
|
import type { Props as ButtonProps } from "~/components/Button";
|
|
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<ButtonProps<unknown>, "borderOnHover">;
|
|
|
|
type InputSelectTriggerProps = {
|
|
placeholder: string;
|
|
/** When provided, overrides the selected value rendered inside the trigger. */
|
|
displayValue?: React.ReactNode;
|
|
ref?: React.Ref<React.ComponentRef<typeof InputSelectPrimitive.Trigger>>;
|
|
} & TriggerButtonProps &
|
|
React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Trigger>;
|
|
|
|
function InputSelectTrigger(props: InputSelectTriggerProps) {
|
|
const { ref, placeholder, children, nude, displayValue, ...buttonProps } =
|
|
props;
|
|
|
|
return (
|
|
<InputSelectPrimitive.Trigger ref={ref} asChild>
|
|
<SelectButton neutral disclosure $nude={nude} {...buttonProps}>
|
|
{displayValue !== undefined ? (
|
|
<>{displayValue}</>
|
|
) : (
|
|
<InputSelectPrimitive.Value placeholder={placeholder} />
|
|
)}
|
|
</SelectButton>
|
|
</InputSelectPrimitive.Trigger>
|
|
);
|
|
}
|
|
InputSelectTrigger.displayName = InputSelectPrimitive.Trigger.displayName;
|
|
|
|
/** InputSelect's content - renders the options in a scrollable element. */
|
|
type ContentProps = Omit<
|
|
React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Content>,
|
|
"position"
|
|
> & {
|
|
ref?: React.Ref<React.ComponentRef<typeof InputSelectPrimitive.Content>>;
|
|
};
|
|
|
|
function InputSelectContent(props: ContentProps) {
|
|
const { ref, children, ...rest } = props;
|
|
|
|
return (
|
|
<InputSelectPrimitive.Portal>
|
|
<StyledContent ref={ref} position={"popper"} {...rest}>
|
|
<InputSelectPrimitive.Viewport style={{ overscrollBehavior: "none" }}>
|
|
{children}
|
|
</InputSelectPrimitive.Viewport>
|
|
</StyledContent>
|
|
</InputSelectPrimitive.Portal>
|
|
);
|
|
}
|
|
InputSelectContent.displayName = InputSelectPrimitive.Content.displayName;
|
|
|
|
/** Individual InputSelect option rendered in the menu. */
|
|
function InputSelectItem(
|
|
props: React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Item> & {
|
|
ref?: React.Ref<React.ComponentRef<typeof InputSelectPrimitive.Item>>;
|
|
}
|
|
) {
|
|
const { ref, children, ...rest } = props;
|
|
|
|
return (
|
|
<InputSelectPrimitive.Item ref={ref} {...rest} asChild>
|
|
<SelectItemWrapper>
|
|
<InputSelectPrimitive.ItemText>
|
|
{children}
|
|
</InputSelectPrimitive.ItemText>
|
|
<InputSelectPrimitive.ItemIndicator asChild>
|
|
<SelectItemIndicator />
|
|
</InputSelectPrimitive.ItemIndicator>
|
|
</SelectItemWrapper>
|
|
</InputSelectPrimitive.Item>
|
|
);
|
|
}
|
|
InputSelectItem.displayName = InputSelectPrimitive.Item.displayName;
|
|
|
|
/** Horizontal separator rendered between the options. */
|
|
function InputSelectSeparator({
|
|
ref,
|
|
...props
|
|
}: React.ComponentPropsWithoutRef<typeof InputSelectPrimitive.Separator> & {
|
|
ref?: React.Ref<React.ComponentRef<typeof InputSelectPrimitive.Separator>>;
|
|
}) {
|
|
return (
|
|
<InputSelectPrimitive.Separator ref={ref} asChild>
|
|
<Separator {...props} />
|
|
</InputSelectPrimitive.Separator>
|
|
);
|
|
}
|
|
InputSelectSeparator.displayName = InputSelectPrimitive.Separator.displayName;
|
|
|
|
const Separator = styled.hr`
|
|
margin: 6px 0;
|
|
`;
|
|
|
|
/** Non-selectable heading rendered to group options in the menu. */
|
|
function InputSelectHeading({
|
|
ref,
|
|
children,
|
|
}: {
|
|
children?: React.ReactNode;
|
|
ref?: React.Ref<HTMLSpanElement>;
|
|
}) {
|
|
return (
|
|
<InputSelectPrimitive.Group>
|
|
<InputSelectPrimitive.Label asChild>
|
|
<Heading ref={ref}>{children}</Heading>
|
|
</InputSelectPrimitive.Label>
|
|
</InputSelectPrimitive.Group>
|
|
);
|
|
}
|
|
InputSelectHeading.displayName = "InputSelectHeading";
|
|
|
|
const Heading = styled(Text).attrs({
|
|
type: "tertiary",
|
|
size: "xsmall",
|
|
weight: "bold",
|
|
})`
|
|
display: block;
|
|
padding-block: 8px 4px;
|
|
padding-inline: 8px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.04em;
|
|
`;
|
|
|
|
/** 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;
|
|
${borderRadius(8)}
|
|
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,
|
|
InputSelectHeading,
|
|
};
|