1- 'use client' ;
2-
1+ import { forwardRef , RefObject } from 'react' ;
32import type { CollectionItem } from '@chakra-ui/react' ;
43import { Select as ChakraSelect , Portal } from '@chakra-ui/react' ;
54import { CloseButton } from './close-button' ;
6- import * as React from 'react' ;
75
86interface SelectTriggerProps extends ChakraSelect . ControlProps {
97 clearable ?: boolean ;
108}
119
12- export const SelectTrigger = React . forwardRef < HTMLButtonElement , SelectTriggerProps > ( function SelectTrigger (
13- props ,
14- ref
15- ) {
10+ /**
11+ * SelectTrigger component that renders a trigger for the select component.
12+ *
13+ * @param {SelectTriggerProps } props - The properties for the select trigger component.
14+ * @param {boolean } [props.clearable] - Whether the trigger is clearable.
15+ * @param {ReactNode } [props.children] - The content to display inside the trigger.
16+ * @returns {JSX.Element } The rendered select trigger component.
17+ */
18+ export const SelectTrigger = forwardRef < HTMLButtonElement , SelectTriggerProps > ( function SelectTrigger ( props , ref ) {
1619 const { children, clearable, ...rest } = props ;
1720 return (
1821 < ChakraSelect . Control { ...rest } >
@@ -25,22 +28,36 @@ export const SelectTrigger = React.forwardRef<HTMLButtonElement, SelectTriggerPr
2528 ) ;
2629} ) ;
2730
28- const SelectClearTrigger = React . forwardRef < HTMLButtonElement , ChakraSelect . ClearTriggerProps > (
31+ /**
32+ * SelectClearTrigger component that renders a clear button for the select component.
33+ *
34+ * @param {ChakraSelect.ClearTriggerProps } props - The properties for the clear trigger component.
35+ * @returns {JSX.Element } The rendered select clear trigger component.
36+ */
37+ const SelectClearTrigger = forwardRef < HTMLButtonElement , ChakraSelect . ClearTriggerProps > (
2938 function SelectClearTrigger ( props , ref ) {
3039 return (
3140 < ChakraSelect . ClearTrigger asChild { ...props } ref = { ref } >
3241 < CloseButton size = 'xs' variant = 'plain' focusVisibleRing = 'inside' focusRingWidth = '2px' pointerEvents = 'auto' />
3342 </ ChakraSelect . ClearTrigger >
3443 ) ;
35- }
44+ } ,
3645) ;
3746
3847interface SelectContentProps extends ChakraSelect . ContentProps {
3948 portalled ?: boolean ;
40- portalRef ?: React . RefObject < HTMLElement > ;
49+ portalRef ?: RefObject < HTMLElement > ;
4150}
4251
43- export const SelectContent = React . forwardRef < HTMLDivElement , SelectContentProps > ( function SelectContent ( props , ref ) {
52+ /**
53+ * SelectContent component that renders the content of the select component.
54+ *
55+ * @param {SelectContentProps } props - The properties for the select content component.
56+ * @param {boolean } [props.portalled] - Whether to use a portal for rendering the content.
57+ * @param {RefObject<HTMLElement> } [props.portalRef] - The ref for the portal container.
58+ * @returns {JSX.Element } The rendered select content component.
59+ */
60+ export const SelectContent = forwardRef < HTMLDivElement , SelectContentProps > ( function SelectContent ( props , ref ) {
4461 const { portalled = true , portalRef, ...rest } = props ;
4562 return (
4663 < Portal disabled = { ! portalled } container = { portalRef } >
@@ -51,7 +68,15 @@ export const SelectContent = React.forwardRef<HTMLDivElement, SelectContentProps
5168 ) ;
5269} ) ;
5370
54- export const SelectItem = React . forwardRef < HTMLDivElement , ChakraSelect . ItemProps > ( function SelectItem ( props , ref ) {
71+ /**
72+ * SelectItem component that represents an item in the select component.
73+ *
74+ * @param {SelectItemProps } props - The properties for the select item component.
75+ * @param {CollectionItem } [props.item] - The item to display in the select.
76+ * @param {ReactNode } [props.children] - The content to display inside the item.
77+ * @returns {JSX.Element } The rendered select item component.
78+ */
79+ export const SelectItem = forwardRef < HTMLDivElement , ChakraSelect . ItemProps > ( function SelectItem ( props , ref ) {
5580 const { item, children, ...rest } = props ;
5681 return (
5782 < ChakraSelect . Item key = { item . value } item = { item } { ...rest } ref = { ref } >
@@ -65,10 +90,15 @@ interface SelectValueTextProps extends Omit<ChakraSelect.ValueTextProps, 'childr
6590 children ?( items : CollectionItem [ ] ) : React . ReactNode ;
6691}
6792
68- export const SelectValueText = React . forwardRef < HTMLSpanElement , SelectValueTextProps > ( function SelectValueText (
69- props ,
70- ref
71- ) {
93+ /**
94+ * SelectValueText component that displays the selected value in the select component.
95+ *
96+ * @param {SelectValueTextProps } props - The properties for the select value text component.
97+ * @param {function } [props.children] - A function that receives the selected items and returns the content to display.
98+ * @param {ReactNode } [props.placeholder] - The placeholder text to display when no items are selected.
99+ * @returns {JSX.Element } The rendered select value text component.
100+ */
101+ export const SelectValueText = forwardRef < HTMLSpanElement , SelectValueTextProps > ( function SelectValueText ( props , ref ) {
72102 const { children, ...rest } = props ;
73103 return (
74104 < ChakraSelect . ValueText { ...rest } ref = { ref } >
@@ -91,7 +121,15 @@ export const SelectValueText = React.forwardRef<HTMLSpanElement, SelectValueText
91121 ) ;
92122} ) ;
93123
94- export const SelectRoot = React . forwardRef < HTMLDivElement , ChakraSelect . RootProps > ( function SelectRoot ( props , ref ) {
124+ /**
125+ * SelectRoot component that serves as the root element for the select component.
126+ *
127+ * @param {SelectRootProps } props - The properties for the select root component.
128+ * @param {ChakraSelect.PositioningProps } [props.positioning] - The positioning properties for the select component.
129+ * @param {ReactNode } [props.children] - The content to display inside the select root.
130+ * @returns {JSX.Element } The rendered select root component.
131+ */
132+ export const SelectRoot = forwardRef < HTMLDivElement , ChakraSelect . RootProps > ( function SelectRoot ( props , ref ) {
95133 return (
96134 < ChakraSelect . Root { ...props } ref = { ref } positioning = { { sameWidth : true , ...props . positioning } } >
97135 { props . asChild ? (
@@ -110,10 +148,15 @@ interface SelectItemGroupProps extends ChakraSelect.ItemGroupProps {
110148 label : React . ReactNode ;
111149}
112150
113- export const SelectItemGroup = React . forwardRef < HTMLDivElement , SelectItemGroupProps > ( function SelectItemGroup (
114- props ,
115- ref
116- ) {
151+ /**
152+ * SelectItemGroup component that groups select items together.
153+ *
154+ * @param {SelectItemGroupProps } props - The properties for the select item group component.
155+ * @param {React.ReactNode } [props.label] - The label for the item group.
156+ * @param {ReactNode } [props.children] - The content to display inside the item group.
157+ * @returns {JSX.Element } The rendered select item group component.
158+ */
159+ export const SelectItemGroup = forwardRef < HTMLDivElement , SelectItemGroupProps > ( function SelectItemGroup ( props , ref ) {
117160 const { children, label, ...rest } = props ;
118161 return (
119162 < ChakraSelect . ItemGroup { ...rest } ref = { ref } >
0 commit comments