Skip to content

Commit 6522577

Browse files
committed
add js docs to the slider components
1 parent dd9b65a commit 6522577

File tree

11 files changed

+183
-57
lines changed

11 files changed

+183
-57
lines changed

packages/chakra-ui/src/CheckboxesWidget/CheckboxesWidget.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ export default function CheckboxesWidget<
4343
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, true) as string[];
4444

4545
return (
46-
<FieldsetRoot
47-
mb={1}
48-
disabled={disabled || readonly}
49-
invalid={rawErrors && rawErrors.length > 0}
50-
>
46+
<FieldsetRoot mb={1} disabled={disabled || readonly} invalid={rawErrors && rawErrors.length > 0}>
5147
<CheckboxGroup
5248
onValueChange={(option) => onChange(enumOptionsValueForIndex<S>(option, enumOptions, emptyValue))}
5349
value={selectedIndexes}

packages/chakra-ui/src/RangeWidget/RangeWidget.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default function RangeWidget<T = any, S extends StrictRJSFSchema = RJSFSc
2525
hideLabel,
2626
id,
2727
}: WidgetProps<T, S, F>) {
28-
2928
const sliderWidgetProps = { value, label, id, ...rangeSpec<S>(schema) };
3029

3130
const _onChange = ({ value }: SliderValueChangeDetails) => onChange(value === undefined ? options.emptyValue : value);

packages/chakra-ui/src/SelectNativeWidget/NativeSelectWidget.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ChangeEvent, FocusEvent, useMemo } from 'react';
2-
32
import {
43
ariaDescribedByIds,
54
EnumOptionsType,
@@ -16,10 +15,21 @@ import { OptionsOrGroups } from 'chakra-react-select';
1615
import { createListCollection } from '@chakra-ui/react';
1716
import { NativeSelect as ChakraSelect } from '@chakra-ui/react';
1817

18+
/**
19+
* NativeSelectWidget is a React component that renders a native select input.
20+
*
21+
* @param {T} T - The type of the value.
22+
* @param {S} S - The type of the schema.
23+
* @param {F} F - The type of the form context.
24+
* @param {WidgetProps<T, S, F>} props - The props for the component.
25+
*
26+
* @returns {JSX.Element} - The rendered component.
27+
*/
28+
1929
export default function NativeSelectWidget<
2030
T = any,
2131
S extends StrictRJSFSchema = RJSFSchema,
22-
F extends FormContextType = any
32+
F extends FormContextType = any,
2333
>(props: WidgetProps<T, S, F>) {
2434
const {
2535
id,

packages/chakra-ui/src/components/ui/alert.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1+
import { forwardRef, ReactElement, ReactNode } from 'react';
12
import { Alert as ChakraAlert } from '@chakra-ui/react';
23
import { CloseButton } from './close-button';
3-
import * as React from 'react';
44

5+
/**
6+
* Alert component that displays a message with an optional icon and close button.
7+
*
8+
* @param {AlertProps} props - The properties for the alert component.
9+
* @param {ReactNode} [props.startElement] - The element to display at the start of the alert.
10+
* @param {ReactNode} [props.endElement] - The element to display at the end of the alert.
11+
* @param {ReactNode} [props.title] - The title of the alert.
12+
* @param {ReactElement} [props.icon] - The icon to display in the alert.
13+
* @param {boolean} [props.closable] - Whether to show the close button.
14+
* @param {function} [props.onClose] - The function to call when the close button is clicked.
15+
*
16+
* @returns {JSX.Element} The rendered alert component.
17+
*/
518
export interface AlertProps extends Omit<ChakraAlert.RootProps, 'title'> {
6-
startElement?: React.ReactNode;
7-
endElement?: React.ReactNode;
8-
title?: React.ReactNode;
9-
icon?: React.ReactElement;
19+
startElement?: ReactNode;
20+
endElement?: ReactNode;
21+
title?: ReactNode;
22+
icon?: ReactElement;
1023
closable?: boolean;
1124
onClose?: () => void;
1225
}
1326

14-
export const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(props, ref) {
27+
export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(props, ref) {
1528
const { title, children, icon, closable, onClose, startElement, endElement, ...rest } = props;
1629
return (
1730
<ChakraAlert.Root ref={ref} {...rest}>

packages/chakra-ui/src/components/ui/checkbox.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
import { forwardRef, InputHTMLAttributes, ReactNode, Ref } from 'react';
12
import { Checkbox as ChakraCheckbox } from '@chakra-ui/react';
2-
import * as React from 'react';
33

44
export interface CheckboxProps extends ChakraCheckbox.RootProps {
5-
icon?: React.ReactNode;
6-
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
7-
rootRef?: React.Ref<HTMLLabelElement>;
5+
icon?: ReactNode;
6+
inputProps?: InputHTMLAttributes<HTMLInputElement>;
7+
rootRef?: Ref<HTMLLabelElement>;
88
}
99

10-
export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(props, ref) {
10+
/**
11+
* Checkbox component that allows users to select or deselect an option.
12+
*
13+
* @param {CheckboxProps} props - The properties for the checkbox component.
14+
* @param {ReactNode} [props.icon] - The icon to display in the checkbox.
15+
* @param {InputHTMLAttributes<HTMLInputElement>} [props.inputProps] - Additional props for the input element.
16+
* @param {Ref<HTMLLabelElement>} [props.rootRef] - Ref for the root element of the checkbox.
17+
* @returns {JSX.Element} The rendered checkbox component.
18+
*/
19+
export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(props, ref) {
1120
const { icon, children, inputProps, rootRef, ...rest } = props;
1221
return (
1322
<ChakraCheckbox.Root ref={rootRef} {...rest}>

packages/chakra-ui/src/components/ui/close-button.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
import { forwardRef } from 'react';
12
import type { ButtonProps } from '@chakra-ui/react';
23
import { IconButton as ChakraIconButton } from '@chakra-ui/react';
3-
import * as React from 'react';
44
import { LuX } from 'react-icons/lu';
55

66
export type CloseButtonProps = ButtonProps;
77

8-
export const CloseButton = React.forwardRef<HTMLButtonElement, CloseButtonProps>(function CloseButton(props, ref) {
8+
/**
9+
* CloseButton component that renders a button with a close icon.
10+
*
11+
* @param {CloseButtonProps} props - The properties for the close button component.
12+
* @param {ReactNode} [props.children] - The content to display inside the button.
13+
* @returns {JSX.Element} The rendered close button component.
14+
*/
15+
export const CloseButton = forwardRef<HTMLButtonElement, CloseButtonProps>(function CloseButton(props, ref) {
916
return (
1017
<ChakraIconButton variant='ghost' aria-label='Close' ref={ref} {...props}>
1118
{props.children ?? <LuX />}

packages/chakra-ui/src/components/ui/field.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
import { forwardRef, ReactNode } from 'react';
12
import { Field as ChakraField } from '@chakra-ui/react';
2-
import * as React from 'react';
33

44
export interface FieldProps extends Omit<ChakraField.RootProps, 'label'> {
5-
label?: React.ReactNode;
6-
helperText?: React.ReactNode;
7-
errorText?: React.ReactNode;
8-
optionalText?: React.ReactNode;
5+
label?: ReactNode;
6+
helperText?: ReactNode;
7+
errorText?: ReactNode;
8+
optionalText?: ReactNode;
99
}
1010

11-
export const Field = React.forwardRef<HTMLDivElement, FieldProps>(function Field(props, ref) {
11+
/**
12+
* Field component that serves as a wrapper for form fields, providing
13+
* additional functionality such as labels, helper text, and error messages.
14+
*
15+
* @param {FieldProps} props - The properties for the field component.
16+
* @param {ReactNode} [props.label] - The label for the field.
17+
* @param {ReactNode} [props.helperText] - Helper text to display below the field.
18+
* @param {ReactNode} [props.errorText] - Error message to display below the field.
19+
* @param {ReactNode} [props.optionalText] - Text to indicate that the field is optional.
20+
* @returns {JSX.Element} The rendered field component.
21+
*/
22+
export const Field = forwardRef<HTMLDivElement, FieldProps>(function Field(props, ref) {
1223
const { label, children, helperText, errorText, optionalText, ...rest } = props;
1324
return (
1425
<ChakraField.Root ref={ref} {...rest}>

packages/chakra-ui/src/components/ui/number-input.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
import { forwardRef } from 'react';
12
import { NumberInput as ChakraNumberInput } from '@chakra-ui/react';
2-
import * as React from 'react';
33

44
export type NumberInputProps = ChakraNumberInput.RootProps;
55

6-
export const NumberInputRoot = React.forwardRef<HTMLDivElement, NumberInputProps>(function NumberInput(props, ref) {
6+
/**
7+
* NumberInput component that allows users to input numeric values.
8+
*
9+
* @param {NumberInputProps} props - The properties for the number input component.
10+
* @param {ReactNode} [props.children] - The content to display inside the number input.
11+
* @returns {JSX.Element} The rendered number input component.
12+
*/
13+
export const NumberInputRoot = forwardRef<HTMLDivElement, NumberInputProps>(function NumberInput(props, ref) {
714
const { children, ...rest } = props;
815
return (
916
<ChakraNumberInput.Root ref={ref} variant='outline' {...rest}>

packages/chakra-ui/src/components/ui/radio.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
import { forwardRef, InputHTMLAttributes, Ref } from 'react';
12
import { RadioGroup as ChakraRadioGroup } from '@chakra-ui/react';
2-
import * as React from 'react';
33

44
export interface RadioProps extends ChakraRadioGroup.ItemProps {
5-
rootRef?: React.Ref<HTMLDivElement>;
6-
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
5+
rootRef?: Ref<HTMLDivElement>;
6+
inputProps?: InputHTMLAttributes<HTMLInputElement>;
77
}
88

9-
export const Radio = React.forwardRef<HTMLInputElement, RadioProps>(function Radio(props, ref) {
9+
/**
10+
* Radio component that allows users to select a single option from a set.
11+
*
12+
* @param {RadioProps} props - The properties for the radio component.
13+
* @param {InputHTMLAttributes<HTMLInputElement>} [props.inputProps] - Additional props for the input element.
14+
* @param {Ref<HTMLDivElement>} [props.rootRef] - Ref for the root element of the radio.
15+
* @returns {JSX.Element} The rendered radio component.
16+
*/
17+
export const Radio = forwardRef<HTMLInputElement, RadioProps>(function Radio(props, ref) {
1018
const { children, inputProps, rootRef, ...rest } = props;
1119
return (
1220
<ChakraRadioGroup.Item ref={rootRef} {...rest}>

packages/chakra-ui/src/components/ui/select.tsx

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
'use client';
2-
1+
import { forwardRef, RefObject } from 'react';
32
import type { CollectionItem } from '@chakra-ui/react';
43
import { Select as ChakraSelect, Portal } from '@chakra-ui/react';
54
import { CloseButton } from './close-button';
6-
import * as React from 'react';
75

86
interface 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

3847
interface 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

Comments
 (0)