import type { Meta, StoryObj } from "@storybook/react-native-web-vite";
import React from "react";
import { View } from "react-native";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { PortalHost } from "@rn-primitives/portal";
import { useRootContext } from "@rn-primitives/select";
import { SelectPrimitive } from "./SelectPrimitive";
import { Text } from "../../Text";
import { Icon } from "../../Icon";
const meta = {
title: "Components/Primitives/SelectPrimitive",
component: SelectPrimitive.Root,
parameters: {
viewport: { defaultViewport: "mobile1" },
},
decorators: [
(Story: React.ComponentType) => (
<>
>
),
],
} satisfies Meta;
export default meta;
type Story = StoryObj;
const CITIES = [
{ value: "tor", label: "Toronto" },
{ value: "van", label: "Vancouver" },
{ value: "edm", label: "Edmonton" },
{ value: "wpg", label: "Winnipeg" },
{ value: "hal", label: "Halifax" },
];
/** Composes an option row from the styled `ItemText` + `ItemIndicator` parts. */
function Option({
value,
label,
disabled,
}: {
readonly value: string;
readonly label: string;
readonly disabled?: boolean;
}) {
return (
);
}
function CityItems() {
return (
<>
{CITIES.map(city => (
))}
>
);
}
/** Composes the raw overlay parts (`Portal > Overlay + Content > Viewport`). */
function Dropdown({ children }: { readonly children: React.ReactNode }) {
return (
{children}
);
}
/**
* A trailing chevron composed onto the trigger. The primitive owns no chevron —
* the icon and its open-state rotation are composed here (this is what the
* sugared `Select` will do), reading `open` from the primitive root context.
*/
function Chevron() {
const { open } = useRootContext();
return (
);
}
/** Composes the trigger: the value plus a composed, rotating chevron. */
function TriggerField({
placeholder,
invalid,
}: {
readonly placeholder: string;
readonly invalid?: boolean;
}) {
return (
);
}
function StateRow({
caption,
children,
}: {
readonly caption: string;
readonly children: React.ReactNode;
}) {
return (
{caption}
{children}
);
}
export const Basic: Story = {
render: () => (
),
};
export const WithSelection: Story = {
render: () => (
),
};
export const GroupsAndSeparator: Story = {
render: () => (
West
East
),
};
export const DisabledOption: Story = {
render: () => (
),
};
export const TriggerStates: Story = {
render: () => (
),
};