Skip to content

Commit 4720587

Browse files
committed
chore: proofreading JSDoc and improve documentation for AddButton, FancyMultiSelect, FancySelect, and FieldTemplate components
1 parent 97df1cb commit 4720587

File tree

6 files changed

+86
-41
lines changed

6 files changed

+86
-41
lines changed

packages/shadcn/README.md

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
·
2020
<a href="https://github.com/rjsf-team/react-jsonschema-form/issues">Request Feature</a>
2121
</p>
22-
</p>
2322

2423
<!-- TABLE OF CONTENTS -->
2524

2625
## Table of Contents
2726

2827
- [Table of Contents](#table-of-contents)
2928
- [About The Project](#about-the-project)
30-
- [Built With](#built-with)
29+
- [Built With](#built-with)
3130
- [Getting Started](#getting-started)
32-
- [Prerequisites](#prerequisites)
33-
- [Installation](#installation)
31+
- [Prerequisites](#prerequisites)
32+
- [Installation](#installation)
3433
- [Usage](#usage)
3534
- [Contributing](#contributing)
3635
- [Contact](#contact)
@@ -77,29 +76,36 @@ import Form from '@rjsf/shadcn';
7776
or
7877

7978
```js
80-
import { withTheme } from '@rjsf/core';
81-
import { Theme as shadcnTheme } from '@rjsf/shadcn';
79+
import {withTheme} from '@rjsf/core';
80+
import {Theme as shadcnTheme} from '@rjsf/shadcn';
8281

8382
const Form = withTheme(shadcnTheme);
8483
```
84+
8585
<!-- THEMING -->
86-
## Theming
8786

87+
## Theming
8888

8989
### Using Tailwind
90+
9091
Follow shadCN installation guide [here](https://ui.shadcn.com/docs/installation) for your application
9192

9293
The color of the RJSF will automatically apply with your shadCN config.
9394

9495
### Not using Tailwind
96+
9597
#### Use the theme on demo site
98+
9699
All shadcn's default color theme are included in the npm packages. Simply do
100+
97101
```
98102
import '@rjsf/shadcn/dist/[color].css';
99103
e.g:
100104
import '@rjsf/shadcn/dist/zinc.css';
101105
```
106+
102107
Supported colors are:
108+
103109
- default
104110
- zinc
105111
- red
@@ -109,56 +115,77 @@ Supported colors are:
109115
- blue
110116
- yellow
111117
- violet
118+
112119
#### Coloring
113-
- Generate a theme from [official shadCN site](https://ui.shadcn.com/themes) or [zippy starter's shadcn/ui theme generator](https://zippystarter.com/tools/shadcn-ui-theme-generator) or [Railly](https://customizer.railly.dev/)
120+
121+
- Generate a theme from [official shadCN site](https://ui.shadcn.com/themes)
122+
or [zippy starter's shadcn/ui theme generator](https://zippystarter.com/tools/shadcn-ui-theme-generator)
123+
or [Railly](https://customizer.railly.dev/)
114124
- Navigate to shadcn/css, create a new file called [your-theme].css
115125
- Replace the base layer code with your new color
116126
- Follow the next section to build your CSS file
127+
117128
#### Build your CSS file
129+
118130
If you are not using tailwind but still wants to use this theme, you can follow these steps:
131+
119132
- Clone the repository
133+
120134
```
121135
cd packages/shadcn
122136
npm i
123137
npm run build:css
124138
```
139+
125140
- Include the built file in /dist/rjsf-shadcn.css in your application
126141

127142
## Dark mode (Tailwind only)
143+
128144
Check out this section by [shadCN](https://ui.shadcn.com/docs/dark-mode)
129145

130146
## RTL (Tailwind only)
147+
131148
### Installation
149+
132150
```bash
133151
npm install @radix-ui/react-direction --save
134152
```
135153

136154
### Implementation
137155

138156
1. Wrap your layout with DirectionProvider:
139-
```tsx
140-
import { DirectionProvider as RadixDirectionProvider } from '@radix-ui/react-direction;
141-
142-
function Layout({ children, direction }) {
143-
return (
144-
<RadixDirectionProvider dir={direction}>
145-
{children}
146-
</RadixDirectionProvider>
147-
);
148-
}
149-
```
157+
158+
```tsx
159+
import {DirectionProvider as RadixDirectionProvider} from '@radix-ui/react-direction;
160+
161+
function Layout({children, direction}) {
162+
return (
163+
<RadixDirectionProvider dir={direction}>
164+
{children}
165+
</RadixDirectionProvider>
166+
);
167+
}
168+
```
150169

151170
2. Set HTML direction attribute:
152-
```html
153-
<html dir="rtl">
154-
```
155-
3. You can refer to `direction-context.tsx`, `direction-provider.tsx` and `rtl-toggle.tsx` from demo repository for implementation.
171+
172+
```html
173+
<html dir="rtl" lang="en">
174+
```
175+
176+
3. You can refer to `direction-context.tsx`, `direction-provider.tsx` and `rtl-toggle.tsx` from demo repository for
177+
implementation.
156178

157179
## Updating to latest shadCN version
158-
- Simply copy the shadcn components into shadcn/src/components/ui and rebuilt the packages or using the shadcn CLI at the root level with the components.json
159-
- For RTL version, you might need component from [here](https://github.com/shadcn-ui/ui/pull/1638) by [nahasco](https://github.com/nahasco)
180+
181+
- Simply copy the shadcn components into shadcn/src/components/ui and rebuilt the packages or using the shadcn CLI at
182+
the root level with the components.json
183+
- For RTL version, you might need component from [here](https://github.com/shadcn-ui/ui/pull/1638)
184+
by [nahasco](https://github.com/nahasco)
160185
- [Fancy multi-select](https://craft.mxkaske.dev/post/fancy-multi-select)
186+
161187
<!-- CONTRIBUTING -->
188+
162189
## Contributing
163190

164191
Read our [contributors' guide](https://rjsf-team.github.io/react-jsonschema-form/docs/contributing/) to get started.
@@ -169,19 +196,30 @@ Read our [contributors' guide](https://rjsf-team.github.io/react-jsonschema-form
169196

170197
rjsf team: [https://github.com/orgs/rjsf-team/people](https://github.com/orgs/rjsf-team/people)
171198

172-
GitHub repository: [https://github.com/rjsf-team/react-jsonschema-form](https://github.com/rjsf-team/react-jsonschema-form)
199+
GitHub
200+
repository: [https://github.com/rjsf-team/react-jsonschema-form](https://github.com/rjsf-team/react-jsonschema-form)
173201

174202
<!-- MARKDOWN LINKS & IMAGES -->
175203
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
176204

177205
[build-shield]: https://github.com/rjsf-team/react-jsonschema-form/workflows/CI/badge.svg
206+
178207
[build-url]: https://github.com/rjsf-team/react-jsonschema-form/actions
208+
179209
[contributors-shield]: https://img.shields.io/github/contributors/rjsf-team/react-jsonschema-form.svg
210+
180211
[contributors-url]: https://github.com/rjsf-team/react-jsonschema-form/graphs/contributors
212+
181213
[license-shield]: https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square
214+
182215
[license-url]: https://choosealicense.com/licenses/apache-2.0/
216+
183217
[npm-shield]: https://img.shields.io/npm/v/@rjsf/shadcn/latest.svg?style=flat-square
218+
184219
[npm-url]: https://www.npmjs.com/package/@rjsf/shadcn
220+
185221
[npm-dl-shield]: https://img.shields.io/npm/dm/@rjsf/shadcn.svg?style=flat-square
222+
186223
[npm-dl-url]: https://www.npmjs.com/package/@rjsf/shadcn
224+
187225
[product-screenshot]: https://raw.githubusercontent.com/rjsf-team/react-jsonschema-form/59a8206e148474bea854bbb004f624143fbcbac8/packages/shadcn/screenshot.png

packages/shadcn/src/AddButton/AddButton.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { PlusCircle } from 'lucide-react';
44
import { Button } from '../components/ui/button';
55

66
/**
7-
* AddButton component for adding new items in a form
8-
* @template T - The type of data being handled
9-
* @template S - The JSON Schema type, extending StrictRJSFSchema
10-
* @template F - The form context type
11-
* @component
12-
* @param props - The component props
13-
* @returns - A button component with a plus icon
7+
* A button component for adding new items in a form
8+
* @param props - The component properties
9+
* @param props.uiSchema - The UI Schema for the form
10+
* @param props.registry - The registry object containing shared utilities
11+
* @param props.registry.translateString - Function to translate strings
1412
*/
1513
export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
1614
uiSchema,

packages/shadcn/src/FieldTemplate/FieldTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { cn } from '../lib/utils';
1111

1212
/** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field
13-
* content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component.
13+
* content, (label, description, children, errors and help) inside a `WrapIfAdditional` component.
1414
*
1515
* @param props - The `FieldTemplateProps` for this component
1616
*/

packages/shadcn/src/components/ui/fancy-multi-select.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
import { Command as CommandPrimitive } from 'cmdk';
44
import { isEqual } from 'lodash';
55
import { X } from 'lucide-react';
6-
import { FocusEvent, FocusEventHandler, KeyboardEvent, useCallback, useMemo, useRef, useState } from 'react';
6+
import {
7+
FocusEvent,
8+
FocusEventHandler,
9+
KeyboardEvent,
10+
ReactElement,
11+
useCallback,
12+
useMemo,
13+
useRef,
14+
useState,
15+
} from 'react';
716

817
import { cn } from '../../lib/utils';
918
import { Badge } from './badge';
@@ -35,7 +44,7 @@ interface FancyMultiSelectProps {
3544
selected: string[];
3645
/** Callback function when value changes */
3746
onValueChange?: (value: number[]) => void;
38-
/** Whether the component should auto-focus */
47+
/** Whether the component should autofocus */
3948
autoFocus?: boolean;
4049
/** ID of the element that describes this select */
4150
ariaDescribedby?: string;
@@ -71,7 +80,7 @@ export function FancyMultiSelect({
7180
onBlur,
7281
className,
7382
id,
74-
}: Readonly<FancyMultiSelectProps>): JSX.Element {
83+
}: Readonly<FancyMultiSelectProps>): ReactElement {
7584
const inputRef = useRef<HTMLInputElement>(null);
7685
const [open, setOpen] = useState(false);
7786
const [inputValue, setInputValue] = useState('');

packages/shadcn/src/components/ui/fancy-select.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { Check, ChevronDown } from 'lucide-react';
4-
import { FocusEvent, FocusEventHandler, useEffect, useRef, useState } from 'react';
4+
import { FocusEvent, FocusEventHandler, ReactElement, useEffect, useRef, useState } from 'react';
55
import { cn } from '../../lib/utils';
66
import { Command, CommandGroup, CommandItem, CommandList } from './command';
77

@@ -29,7 +29,7 @@ interface FancySelectInterface {
2929
selected: string;
3030
/** Callback function when value changes */
3131
onValueChange?: (value: any) => void;
32-
/** Whether the component should auto-focus */
32+
/** Whether the component should autofocus */
3333
autoFocus?: boolean;
3434
/** ID of the element that describes this select */
3535
ariaDescribedby?: string;
@@ -67,7 +67,7 @@ export function FancySelect({
6767
onFocus,
6868
onBlur,
6969
className,
70-
}: Readonly<FancySelectInterface>): JSX.Element {
70+
}: Readonly<FancySelectInterface>): ReactElement {
7171
const [open, setOpen] = useState(false);
7272
const selectedItem = items?.find((item) => item.value === selected);
7373
const selectedRef = useRef<HTMLDivElement>(null);

packages/shadcn/src/components/ui/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { cn } from '../../lib/utils';
88
export type InputProps = InputHTMLAttributes<HTMLInputElement>;
99

1010
/**
11-
* A input component with styling and focus states
11+
* An input component with styling and focus states
1212
*
1313
* @param props - The props for the Input component
1414
* @param props.className - Additional CSS classes to apply to the input

0 commit comments

Comments
 (0)