From 9be25ce7f9a69c25e3c91e4604b7bbd74d814af3 Mon Sep 17 00:00:00 2001 From: Rodrigo Dias Date: Thu, 22 Aug 2024 09:33:54 -0300 Subject: [PATCH] feat: storybook / TSDocs - Select --- .../__tests__/Select.spec.tsx | 2 +- .../src/components/Select/Select.tsx | 47 +++++++- .../src/components/Select/index.ts | 5 +- packages/react-material-ui/src/index.ts | 2 +- .../CustomWidgets/CustomSelectWidget.tsx | 2 +- stories/Select.stories.tsx | 103 ++++++++++++++++++ 6 files changed, 150 insertions(+), 11 deletions(-) create mode 100644 stories/Select.stories.tsx diff --git a/packages/react-material-ui/__tests__/Select.spec.tsx b/packages/react-material-ui/__tests__/Select.spec.tsx index 05f1f728..707e3636 100644 --- a/packages/react-material-ui/__tests__/Select.spec.tsx +++ b/packages/react-material-ui/__tests__/Select.spec.tsx @@ -5,7 +5,7 @@ import '@testing-library/jest-dom'; import React from 'react'; import { render, fireEvent } from '@testing-library/react'; -import Select, { SelectOptions } from '../src/components/Select/Select'; +import { Select, SelectOptions } from '../src/components/Select/Select'; describe('Select Component', () => { const options: SelectOptions[] = [ diff --git a/packages/react-material-ui/src/components/Select/Select.tsx b/packages/react-material-ui/src/components/Select/Select.tsx index 2c25e175..f36d27a5 100644 --- a/packages/react-material-ui/src/components/Select/Select.tsx +++ b/packages/react-material-ui/src/components/Select/Select.tsx @@ -10,19 +10,60 @@ import { import { FormLabel } from '../FormLabel'; import { TextProps } from 'interfaces'; +/** + * Option type for the Select component. + */ export type SelectOptions = { + /** Display label for the option */ label: string; + /** Value associated with the option */ value: string | number; + /** Whether the option is disabled */ disabled?: boolean; }; -type Props = { +/** + * Props for the Select component. + */ +export type SelectProps = TextFieldProps & { + /** Props for the container `Box` element */ containerProps?: BoxProps; + /** Props for the label component */ labelProps?: TextProps; + /** Array of selectable options */ options: SelectOptions[]; }; -const Select = (props: Props & TextFieldProps) => { +/** + * The Select component is a custom dropdown that leverages Material-UI's + * `TextField` component with a `select` prop, allowing for a selection + * from a list of options. It supports custom labels, error handling, + * and can be styled using additional props for the container and label. + * It's props extend from [Material UI's TextField](https://mui.com/material-ui/api/text-field/#props) component props, so every + * prop is interchangeable between those two. + * + * @see [Storybook - Select](https://storybook.rockets.tools/?path=/docs/select) + * + * @example + * ```tsx + *