Skip to content

Commit 5bb307f

Browse files
committed
docs(inputs): add comprehensive JSDoc comments
This commit adds detailed JSDoc comments to the inputs components, enhancing code readability and developer understanding. These comments describe the purpose of components, types, interfaces, props, methods, and provide information on styling and behavior. By including this documentation, the codebase becomes more maintainable and easier for new developers to understand, facilitating a better development workflow and more efficient onboarding.
1 parent 214f04f commit 5bb307f

File tree

18 files changed

+637
-37
lines changed

18 files changed

+637
-37
lines changed

npm-packages/src/packages/components/ra-inputs/src/check-list/index.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @ Author: Redon Alla
3+
* @ Modified by: Redon Alla
4+
* @ Description: React component that allows users to select items from a list. Component extending React.PureComponent, which is optimized for performance by implementing a shallow prop and state comparison. It supports both single and multiple selection modes based on the 'multipleSelect' prop. The component maintains its selected items in the state and updates the selection when an item is pressed. It also provides styling options through various props and handles rendering of labels and helper text conditionally.
5+
*/
6+
17
import React from "react";
28
import { View, Text } from "react-native";
39
import ThemeContext from "@flexnative/theme-context";
@@ -8,11 +14,32 @@ import FalsyComponent from "../components/falsy-component";
814
import { includes, isEqual, isObject } from "../input.utilities";
915

1016

17+
/**
18+
* This defines a generic type alias StateProps that takes a type parameter T.
19+
* This allows us to create flexible and reusable types.
20+
*/
1121
type StateProps<T> = {
22+
/**
23+
* An optional property `selectedItem` of type `T`
24+
*/
1225
selectedItem?: T;
26+
27+
/**
28+
* An optional property `selectedItems` which is an array of items of type `T`
29+
*/
1330
selectedItems?: Array<T>;
1431
}
1532

33+
/**
34+
* React component that allows users to select items from a list.
35+
* Component extending React.PureComponent, which is optimized for performance by implementing a shallow prop and state comparison.
36+
* It supports both single and multiple selection modes based on the 'multipleSelect' prop.
37+
* The component maintains its selected items in the state and updates the selection when an item is pressed.
38+
* It also provides styling options through various props and handles rendering of labels and helper text conditionally.
39+
*
40+
* @class CheckList<T>
41+
* @extends {React.PureComponent<CheckListProps<T>, StateProps<T>>}
42+
*/
1643
export default class CheckList<T> extends React.PureComponent<CheckListProps<T>, StateProps<T>> {
1744
static contextType = ThemeContext;
1845
declare context: React.ContextType<typeof ThemeContext>;

npm-packages/src/packages/components/ra-inputs/src/check-list/props.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1+
/**
2+
* @ Author: Redon Alla
3+
* @ Modified by: Redon Alla
4+
* @ Description: Interface defines the properties for a CheckList component. It allows for single or multiple selections of items, supports custom styling options, and provides callbacks for handling changes in selection. The interface is generic, enabling it to work with various types of selected values.
5+
*/
6+
17
import { ReactElement, SyntheticEvent } from "react";
28
import { ColorValue, NativeSyntheticEvent, StyleProp, TextStyle, ViewProps } from "react-native";
39
import { BorderRadius, BorderWidth, Color, Sizes } from "@flexnative/theme-context";
410

511
import { InputType } from "../input.props";
612
import { CheckProps, CheckboxEvent } from "../check/props";
713

8-
14+
/**
15+
* Interface defines the properties for a CheckList component.
16+
* It allows for single or multiple selections of items, supports custom styling options,
17+
* and provides callbacks for handling changes in selection. The interface is generic,
18+
* enabling it to work with various types of selected values.
19+
*/
920
export interface CheckListProps<T> extends ViewProps {
1021
/**
1122
* @template T representing selected value from the available list.

npm-packages/src/packages/components/ra-inputs/src/check-list/styles.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @ Author: Redon Alla
3+
* @ Modified by: Redon Alla
4+
* @ Description: This code defines a function `createStyles` that generates a set of styles for a component based on the provided `StyleProps`. It utilizes theme properties such as font size, colors, and border radius to create responsive and consistent styles. The function returns a StyleSheet object containing styles for various elements like the container, label, and help text, adjusting properties based on the input props.
5+
*/
6+
17
import { ColorValue, StyleSheet } from 'react-native';
28

39
import { BaseTheme, BorderRadius, BorderWidth, Color, Sizes } from '@flexnative/theme-context';
@@ -7,20 +13,77 @@ import { getBorders } from '../input.utilities';
713
import { PADDING_HORIZONTAL_MULTIPLIER, PADDING_VERTICAL_MULTIPLIER, TEXT_HELPER_MULTIPLIER } from '../input.constants';
814

915

16+
/**
17+
* This TypeScript code defines a type named `StyleProps` which is used to specify the properties for styling components.
18+
* It includes various attributes such as `type`, `color`, `size`, `radius`, and optional properties like `borderWidth`,
19+
* `disabled`, `borderColor`, `backgroundColor`, `material`, `direction`, and `theme`.
20+
*
21+
* This type can be useful for ensuring consistent styling across different components in a TypeScript-based application.
22+
*/
1023
type StyleProps = {
24+
/**
25+
* Specifies the appearance style of the input component.
26+
*/
1127
type: InputType;
28+
29+
/**
30+
* Determines the color theme of the input, which can be a predefined theme color or a custom value.
31+
*/
1232
color: Color;
33+
34+
/**
35+
* Defines the size of the input component, affecting dimensions such as height and width.
36+
*/
1337
size: Sizes;
38+
39+
/**
40+
* Sets the border radius for the input, influencing how rounded the corners are.
41+
*/
1442
radius: BorderRadius;
43+
44+
/**
45+
* (Optional) Determines the width of the input's border.
46+
*/
1547
borderWidth?: BorderWidth;
48+
49+
/**
50+
* (Optional) A boolean indicating whether the input is disabled, meaning it cannot be interacted with by the user.
51+
*/
1652
disabled?: boolean;
53+
54+
/**
55+
* (Optional) Specifies the color of the border using `react-native` ColorValue definitions.
56+
*/
1757
borderColor?: ColorValue;
58+
59+
/**
60+
* (Optional) Sets the background color of the input using `react-native` ColorValue definitions.
61+
*/
1862
backgroundColor?: ColorValue;
63+
64+
/**
65+
* (Optional) Indicates whether to apply Material design characteristics to the input.
66+
*/
1967
material?: boolean;
68+
69+
/**
70+
* (Optional) Specifies the layout direction of elements within the input, either in a 'row' or 'column'.
71+
*/
2072
direction?: 'row' | 'column';
73+
74+
/**
75+
* The base theme object used for styling, which contains theme-related properties and values.
76+
*/
2177
theme: BaseTheme<any>;
2278
}
23-
79+
80+
/**
81+
* This code defines a function `createStyles` that generates a set of styles for a component based on the provided `StyleProps`.
82+
* It utilizes theme properties such as font size, colors, and border radius to create responsive and consistent styles.
83+
* The function returns a StyleSheet object containing styles for various elements like the container, label, and help text, adjusting properties based on the input props.
84+
* @param {StyleProps} props - `StyleProps` which is used to specify the properties for styling components.
85+
* @returns {StyleSheet} StyleSheet object containing styles for various elements like the container, label, and help text, adjusting properties based on the input props.
86+
*/
2487
export const createStyles = (props: StyleProps) => {
2588
const fontSize = props.theme.fontSize[props.size!] ?? props.theme.fontSize.default;
2689
const themeColor = props.theme.colors[props.color] ?? props.color;

npm-packages/src/packages/components/ra-inputs/src/check/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @ Author: Redon Alla
3+
* @ Modified by: Redon Alla
4+
* @ Description: This code defines a generic React component called Check, which represents a checkbox element. Component extending React.PureComponent, which is optimized for performance by implementing a shallow prop and state comparison. The component accepts various props for customization, such as value, type, size, colors, and label. It handles changes via the handleChange method, which triggers an onValueChange callback when the checkbox is pressed. The component renders a Pressable element that toggles between checked and unchecked states, displaying appropriate check and label elements based on the current state.
5+
*/
6+
17
import React from "react";
28
import { Pressable, Text, TextStyle, View } from "react-native";
39

@@ -10,6 +16,16 @@ import FalsyComponent from "../components/falsy-component";
1016
import { getStyle } from "../input.utilities";
1117

1218

19+
/**
20+
* This code defines a generic React component called Check, which represents a checkbox element.
21+
* Component extending React.PureComponent, which is optimized for performance by implementing a shallow prop and state comparison.
22+
* The component accepts various props for customization, such as value, type, size, colors, and label.
23+
* It handles changes via the handleChange method, which triggers an onValueChange callback when the checkbox is pressed.
24+
* The component renders a Pressable element that toggles between checked and unchecked states, displaying appropriate check and label elements based on the current state.
25+
*
26+
* @class Check<T>
27+
* @extends {React.PureComponent<CheckProps<T>>}
28+
*/
1329
export default class Check<T> extends React.PureComponent<CheckProps<T>> {
1430
static contextType = ThemeContext;
1531
declare context: React.ContextType<typeof ThemeContext>;

npm-packages/src/packages/components/ra-inputs/src/check/props.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { BorderRadius, BorderWidth, Color, Sizes } from "@flexnative/theme-conte
77

88
export type CheckType = 'outlined' | 'solid' | 'inverse' | 'ghost';
99

10+
/**
11+
* PRops that specifies the properties needed for styling CheckBox components.
12+
*/
1013
export interface CheckProps<T> extends PressableProps {
1114
/**
1215
* @template T representing checkbox selected value.

npm-packages/src/packages/components/ra-inputs/src/check/styles.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @ Author: Redon Alla
3+
* @ Modified by: Redon Alla
4+
* @ Description: Functions for creating styles for CheckBox component.
5+
*/
6+
17
import { ColorValue, StyleSheet } from 'react-native';
28

39
import { BaseTheme, BorderRadius, BorderWidth, Color, Sizes } from '@flexnative/theme-context';
@@ -6,26 +12,102 @@ import { CheckType } from './props';
612
import { CHECK_CONTAINER_SIZE_MULTIPLIER, PADDING_VERTICAL_MULTIPLIER, WHITE_TEXT_COLOR } from '../input.constants';
713

814

15+
/**
16+
* Props that specifies the properties needed for styling CheckBox components.
17+
*/
918
type StyleProps = {
19+
/**
20+
* The type of check, which influences the visual style ( "outlined" | "solid" | "inverse" | "ghost").
21+
*/
1022
type: CheckType;
23+
24+
/**
25+
* The primary color used for styling different elements of the component.
26+
*/
1127
color: Color;
28+
29+
/**
30+
* The size of the component, which can affect dimensions and font size.
31+
*/
1232
size: Sizes;
33+
34+
/**
35+
* Specifies the border radius, influencing the roundness of component corners.
36+
*/
1337
radius: BorderRadius;
38+
39+
/**
40+
* Specifies the border width. It is optional and may have a default value if not provided.
41+
*/
1442
borderWidth?: BorderWidth;
43+
44+
/**
45+
* A boolean indicating whether the component is disabled, impacting its interaction and appearance.
46+
*/
1547
disabled?: boolean;
48+
49+
/**
50+
* The color of the border when the component is in an unchecked state. This property is optional.
51+
*/
1652
borderColor?: ColorValue;
53+
54+
/**
55+
* The color of the border when the component is in a checked state.
56+
*/
1757
checkedBorderColor: ColorValue;
58+
59+
/**
60+
* The background color when the component is in an unchecked state. This property is optional.
61+
*/
1862
backgroundColor?: ColorValue;
63+
64+
/**
65+
* The background color when the component is in an unchecked state. This property is optional.
66+
*/
1967
checkedBackgroundColor?: ColorValue;
68+
69+
/**
70+
* The theme object containing various design tokens utilized for styling, such as colors, fonts, metrics, etc.
71+
*/
2072
theme: BaseTheme<any>;
2173
}
2274

75+
/**
76+
* This module defines a function `createStyles` that generates a set of styles for a UI component based on the provided properties and a theme.
77+
* It calculates various style attributes such as font size, colors, padding, border width, and radius, and returns a StyleSheet object containing styles for different states of the component.
78+
*
79+
* @param {StyleProps} props
80+
* @returns {StyleSheet} - StyleSheet object containing styles for different states of the component
81+
*/
2382
export const createStyles = (props: StyleProps) => {
83+
/**
84+
* Determine the font size based on the provided size or default value from the theme.
85+
*/
2486
const fontSize = props.theme.fontSize[props.size] ?? props.theme.fontSize.default;
87+
88+
/**
89+
* Determine the theme color based on the provided color or use a default color value.
90+
*/
2591
const themeColor = props.theme.colors[props.color] ?? props.color as ColorValue;
92+
93+
/**
94+
* Calculate vertical padding using a predefined multiplier and the determined font size.
95+
*/
2696
const paddingVertical = PADDING_VERTICAL_MULTIPLIER * fontSize;
97+
98+
/**
99+
* Set the border width either from the theme or directly from the provided property.
100+
*/
27101
const borderWidth = props.theme.borderWidth[props.borderWidth!] ?? props.borderWidth as number;
102+
103+
/**
104+
* Set the border radius either from the theme or directly from the provided property.
105+
*/
28106
const borderRadius = props.theme.borderRadius[props.radius] ?? props.radius as number;
107+
108+
/**
109+
* Calculate container size for check elements using a multiplier and font size.
110+
*/
29111
const checkContainerSize = fontSize * CHECK_CONTAINER_SIZE_MULTIPLIER;
30112

31113
return StyleSheet.create({
@@ -76,6 +158,16 @@ export const createStyles = (props: StyleProps) => {
76158
});
77159
}
78160

161+
/**
162+
* Determines the appropriate check color based on various conditions.
163+
*
164+
* @param {boolean} isLight - Indicates if the theme is light.
165+
* @param {ColorValue} colorValue - The color value to be used.
166+
* @param {Color} color - The color type.
167+
* @param {CheckType} type - The type of check.
168+
* @param {ColorValue} [blackColor='black'] - The default black color value.
169+
* @returns {ColorValue} - The determined check color.
170+
*/
79171
function getCheckColor(isLight: boolean, colorValue: ColorValue, color: Color, type: CheckType, blackColor: ColorValue = 'black') {
80172
if(type === 'outlined' || type === 'ghost')
81173
return colorValue;

npm-packages/src/packages/components/ra-inputs/src/components/falsy-component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @ Author: Redon Alla
3+
* @ Modified by: Redon Alla
4+
* @ Description: Helper component for conditionally render a component.
5+
*/
6+
17
import React from 'react';
28

39
export type RenderFCProp<Props> = (props?: Props) => React.ReactElement;

npm-packages/src/packages/components/ra-inputs/src/components/input-container.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,48 @@
1+
/**
2+
* @ Author: Redon Alla
3+
* @ Modified by: Redon Alla
4+
* @ Description: Component for Wrapper Input Component. It renders also the label for material design style.
5+
*/
6+
17
import React from "react";
28
import { StyleProp, TextStyle, View, Text } from "react-native";
39

410
import FalsyComponent from "./falsy-component";
511
import { materialStyle } from "../input.styles";
612

713

14+
/**
15+
* Type definition for InputContainer component props.
16+
*/
817
type InputContainerProps = {
18+
/**
19+
* Determines if the material design style should be applied.
20+
*/
921
material?: boolean;
22+
23+
/**
24+
* The children elements to be rendered inside the container.
25+
*/
1026
children: React.ReactNode;
27+
28+
/**
29+
* The label to be displayed. It can be a string or a React element.
30+
*/
1131
label?: string | React.ReactElement;
32+
33+
/**
34+
* Style to be applied to the label.
35+
*/
1236
labelStyle?: StyleProp<TextStyle>;
1337
}
1438

39+
/**
40+
* InputContainer component that conditionally applies material design styles.
41+
* It extends React.PureComponent to optimize performance by implementing a shallow prop and state comparison.
42+
*
43+
* @class InputContainer
44+
* @extends {React.PureComponent<InputContainerProps, {}>}
45+
*/
1546
export default class InputContainer extends React.PureComponent<InputContainerProps, {}> {
1647
static displayName = 'InputContainer';
1748

@@ -24,10 +55,7 @@ export default class InputContainer extends React.PureComponent<InputContainerPr
2455
if (!material) {
2556
return children;
2657
}
27-
28-
/**
29-
* Memoize styles if they are costly to compute.
30-
*/
58+
3159
const styles = materialStyle();
3260

3361
return (

0 commit comments

Comments
 (0)