Skip to content

Commit ace64e2

Browse files
committed
chore: add docs and fix some pr review issues
1 parent 240cc0b commit ace64e2

File tree

22 files changed

+107
-19
lines changed

22 files changed

+107
-19
lines changed

packages/carbon/src/AddButton/AddButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Add } from '@carbon/icons-react';
22
import { Button } from '@carbon/react';
33
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
44

5+
/** The `AddButton` renders a button that represent the `Add` action on a form
6+
*/
57
export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
68
uiSchema,
79
registry,

packages/carbon/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { useMemo } from 'react';
22
import { ArrayFieldTemplateItemType, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
33

4+
/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
5+
*
6+
* @param props - The `ArrayFieldTemplateItemType` props for the component
7+
*/
48
export default function ArrayFieldItemTemplate<
59
T = any,
610
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import {
1111
} from '@rjsf/utils';
1212
import { Layer, LayerBackground } from '../components/Layer';
1313

14+
/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
15+
*
16+
* @param props - The `ArrayFieldTemplateItemType` props for the component
17+
*/
1418
export default function ArrayFieldTemplate<
1519
T = any,
1620
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/BaseInputTemplate/BaseInputTemplate.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import {
1111
import { TextInput } from '@carbon/react';
1212
import { ConditionLabel } from '../components/ConditionLabel';
1313

14+
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
15+
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
16+
* It can be customized/overridden for other themes or individual implementations as needed.
17+
*
18+
* @param props - The `WidgetProps` for this template
19+
*/
1420
export default function BaseInputTemplate<
1521
T = any,
1622
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/CheckboxWidget/CheckboxWidget.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import {
1212
import { Checkbox } from '@carbon/react';
1313
import { ConditionLabel } from '../components/ConditionLabel';
1414

15+
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
16+
* It is typically used to represent a boolean.
17+
*
18+
* @param props - The `WidgetProps` for this component
19+
*/
1520
export default function CheckboxWidget<
1621
T = any,
1722
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/CheckboxesWidget/CheckboxesWidget.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import {
1414
} from '@rjsf/utils';
1515
import { ConditionLabel } from '../components/ConditionLabel';
1616

17+
/** The `CheckboxesWidget` is a widget for rendering checkbox groups.
18+
* It is typically used to represent an array of enums.
19+
*
20+
* @param props - The `WidgetProps` for this component
21+
*/
1722
export default function CheckboxesWidget<
1823
T = any,
1924
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/DescriptionField/DescriptionField.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
22

3+
/** The `DescriptionField` is the template to use to render the description of a field
4+
*
5+
* @param props - The `DescriptionFieldProps` for this component
6+
*/
37
export default function DescriptionField<
48
T = any,
59
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/FieldErrorTemplate/FieldErrorTemplate.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default function FieldErrorTemplate<
1010
F extends FormContextType = any
1111
>(props: FieldErrorProps<T, S, F>) {
1212
const { errors = [], idSchema } = props;
13-
console.log('FieldErrorTemplate errors', errors);
1413
if (errors.length === 0) {
1514
return null;
1615
}

packages/carbon/src/FieldTemplate/FieldTemplate.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import {
77
StrictRJSFSchema,
88
} from '@rjsf/utils';
99

10+
/** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field
11+
* content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component.
12+
*
13+
* @param props - The `FieldTemplateProps` for this component
14+
*/
1015
export default function FieldTemplate<
1116
T = any,
1217
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/Form/Form.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { withTheme, FormProps } from '@rjsf/core';
33
import { generateTheme } from '../Theme';
44
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
55

6+
/** Generate a `Form` component that is customized with the `carbon` theme.
7+
*
8+
*/
69
export function generateForm<
710
T = any,
811
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/IconButton/IconButton.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, Transla
33
import { Button } from '@carbon/react';
44
import { Copy, ArrowDown, ArrowUp, TrashCan } from '@carbon/icons-react';
55

6+
/** The `CopyButton` is used to render a copy action on a `Form` for elements in an array.
7+
* @param props - The `IconButtonProps` props
8+
*/
69
export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
710
props: IconButtonProps<T, S, F>
811
) {
@@ -21,6 +24,9 @@ export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
2124
);
2225
}
2326

27+
/** The `MoveDownButton` is used to render a move down action on a `Form` for elements in an array.
28+
* @param props - The `IconButtonProps` props
29+
*/
2430
export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
2531
props: IconButtonProps<T, S, F>
2632
) {
@@ -39,6 +45,9 @@ export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema,
3945
);
4046
}
4147

48+
/** The `MoveUpButton` is used to render a move up action on a `Form` for elements in an array.
49+
* @param props - The `IconButtonProps` props
50+
*/
4251
export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
4352
props: IconButtonProps<T, S, F>
4453
) {
@@ -57,6 +66,9 @@ export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F
5766
);
5867
}
5968

69+
/** The `RemoveButton` is used to render a remove action on a `Form` for both a existing `additionalProperties` element for an object or an existing element in an array.
70+
* @param props - The `IconButtonProps` props
71+
*/
6072
export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
6173
props: IconButtonProps<T, S, F>
6274
) {

packages/carbon/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-expect-error there's no type definition for Stack
2-
import { Button, Stack } from '@carbon/react';
2+
import { Stack } from '@carbon/react';
33
import {
44
canExpand,
55
descriptionId,
@@ -10,12 +10,16 @@ import {
1010
RJSFSchema,
1111
StrictRJSFSchema,
1212
titleId,
13-
TranslatableString,
1413
} from '@rjsf/utils';
1514
import { useCarbonOptions } from '../contexts';
1615
import { Layer, LayerBackground } from '../components/Layer';
17-
import { Add } from '@carbon/icons-react';
1816

17+
/** The `ObjectFieldTemplate` is the template to use to render all the inner properties of an object along with the
18+
* title and description if available. If the object is expandable, then an `AddButton` is also rendered after all
19+
* the properties.
20+
*
21+
* @param props - The `ObjectFieldTemplateProps` for this component
22+
*/
1923
export default function ObjectFieldTemplate<
2024
T = any,
2125
S extends StrictRJSFSchema = RJSFSchema,
@@ -37,17 +41,16 @@ export default function ObjectFieldTemplate<
3741
} = props;
3842
const uiOptions = getUiOptions<T, S, F>(uiSchema);
3943
const carbonOptions = useCarbonOptions();
40-
const { translateString } = registry;
4144
const TitleFieldTemplate = getTemplate<'TitleFieldTemplate', T, S, F>('TitleFieldTemplate', registry, uiOptions);
4245
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
4346
'DescriptionFieldTemplate',
4447
registry,
4548
uiOptions
4649
);
4750
// Button templates are not overridden in the uiSchema
48-
// const {
49-
// ButtonTemplates: { AddButton },
50-
// } = registry.templates;
51+
const {
52+
ButtonTemplates: { AddButton },
53+
} = registry.templates;
5154

5255
return (
5356
<>
@@ -80,17 +83,13 @@ export default function ObjectFieldTemplate<
8083
</Layer>
8184
)}
8285
{canExpand(schema, uiSchema, formData) && (
83-
<Button
84-
size='sm'
85-
kind='tertiary'
86-
renderIcon={Add}
87-
disabled={disabled || readonly}
86+
<AddButton
8887
onClick={onAddClick(schema)}
88+
disabled={disabled || readonly}
89+
className='object-property-expand'
8990
uiSchema={uiSchema}
9091
registry={registry}
91-
>
92-
{translateString(TranslatableString.AddItemButton)}
93-
</Button>
92+
/>
9493
)}
9594
</Stack>
9695
</LayerBackground>

packages/carbon/src/SubmitButton/SubmitButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Button } from '@carbon/react';
22
import { FormContextType, getSubmitButtonOptions, RJSFSchema, StrictRJSFSchema, SubmitButtonProps } from '@rjsf/utils';
33

4+
/** The `SubmitButton` renders a button that represent the `Submit` action on a form
5+
*/
46
export default function SubmitButton<
57
T = any,
68
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/Templates/Templates.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import TitleField from '../TitleField';
1212
import ArrayFieldTemplate from '../ArrayFieldTemplate';
1313
import ArrayFieldItemTemplate from '../ArrayFieldItemTemplate';
1414

15+
/** Generates a set of templates `carbon` theme uses.
16+
*/
1517
export function generateTemplates<
1618
T = any,
1719
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/TextareaWidget/TextareaWidget.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { ariaDescribedByIds, FormContextType, RJSFSchema, StrictRJSFSchema, Widg
33
import { TextArea } from '@carbon/react';
44
import { ConditionLabel } from '../components/ConditionLabel';
55

6+
/** The `TextareaWidget` is a widget for rendering input fields as textarea.
7+
*
8+
* @param props - The `WidgetProps` for this component
9+
*/
610
export default function TextareaWidget<
711
T = any,
812
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/Theme/Theme.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
44
import { generateTemplates } from '../Templates';
55
import { generateWidgets } from '../Widgets';
66

7+
/** Generates a theme for the Carbon Design System
8+
*/
79
export function generateTheme<
810
T = any,
911
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/TitleField/TitleField.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { FormContextType, RJSFSchema, StrictRJSFSchema, TitleFieldProps } from '@rjsf/utils';
22
import { ConditionLabel } from '../components/ConditionLabel';
33

4+
/** The `TitleField` is the template to use to render the title of a field
5+
*
6+
* @param props - The `TitleFieldProps` for this component
7+
*/
48
export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
59
id,
610
title,

packages/carbon/src/Widgets/Widgets.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import TextareaWidget from '../TextareaWidget';
33
import CheckboxWidget from '../CheckboxWidget';
44
import CheckboxesWidget from '../CheckboxesWidget';
55

6+
/** Generates a set of widgets `carbon` theme uses.
7+
*/
68
export function generateWidgets<
79
T = any,
810
S extends StrictRJSFSchema = RJSFSchema,

packages/carbon/src/components/ConditionLabel.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { ReactNode } from 'react';
22
import { CarbonOptionsContextType, useCarbonOptions } from '../contexts';
33

4-
function getMark(required: boolean, labelMark: CarbonOptionsContextType['labelMark']) {
4+
/** Get the mark for the label, marking it as required or optional
5+
*
6+
* @param required - Whether the field is required
7+
* @param labelMark - The label mark type
8+
* @returns
9+
*/
10+
function getMark(required: boolean, labelMark: CarbonOptionsContextType['labelMark']): ReactNode {
511
if (required && labelMark === 'required') {
612
return ' (required)';
713
}
@@ -11,12 +17,22 @@ function getMark(required: boolean, labelMark: CarbonOptionsContextType['labelMa
1117
return null;
1218
}
1319

14-
export function ConditionLabel({ hide, required, label }: { label: ReactNode; hide?: boolean; required?: boolean }) {
20+
/** The `ConditionLabel` render a label conditionally and append a required or optional mark
21+
*/
22+
export function ConditionLabel({
23+
hide = false,
24+
required = false,
25+
label,
26+
}: {
27+
label: ReactNode;
28+
hide?: boolean;
29+
required?: boolean;
30+
}) {
1531
const carbonOptions = useCarbonOptions();
1632
if (hide) {
1733
return null;
1834
}
19-
const mark = getMark(required ?? false, carbonOptions.labelMark);
35+
const mark = getMark(required, carbonOptions.labelMark);
2036
return (
2137
<>
2238
{label}

packages/carbon/src/components/Layer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Layer as CarbonLayer } from '@carbon/react';
33
import { ReactNode } from 'react';
44
import { NestDepth, useNestDepth } from '../contexts';
55

6+
/** The `Layer` render [a carbon layer](https://carbondesignsystem.com/guidelines/color/usage#layering-tokens), in order to create a visual hierarchy
7+
*/
68
export function Layer({ children }: { children: ReactNode }) {
79
const nestDepth = useNestDepth();
810
return (
@@ -12,6 +14,8 @@ export function Layer({ children }: { children: ReactNode }) {
1214
);
1315
}
1416

17+
/** The `LayerBackground` render a background for [a carbon layer](https://carbondesignsystem.com/guidelines/color/usage#layering-tokens)
18+
*/
1519
export function LayerBackground({ children }: { children: ReactNode }) {
1620
const nestDepth = useNestDepth();
1721
return (

packages/carbon/src/contexts.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export function useCarbonOptions() {
2525

2626
export const NestDepthContext = createContext<number>(0);
2727

28+
/**
29+
* Get the current nest depth, used for rendering proper [carbon layers](https://carbondesignsystem.com/guidelines/color/usage#layering-tokens)
30+
*/
2831
export function useNestDepth() {
2932
return useContext(NestDepthContext);
3033
}

packages/carbon/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export { default as Form, generateForm } from './Form';
44
export { default as Templates, generateTemplates } from './Templates';
55
export { default as Theme, generateTheme } from './Theme';
66
export { default as Widgets, generateWidgets } from './Widgets';
7+
export { Layer, LayerBackground } from './components/Layer';
78

89
export { CarbonOptionsProvider, useCarbonOptions } from './contexts';
910
export type { CarbonOptionsContextType } from './contexts';

0 commit comments

Comments
 (0)