Skip to content

Commit 96c6c72

Browse files
authored
Merge pull request #100 from adaptui/refactoring-components
2 parents d058a56 + f5bdf17 commit 96c6c72

File tree

20 files changed

+251
-127
lines changed

20 files changed

+251
-127
lines changed

src/components/badge/Badge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const RNBadge: React.FC<Partial<BadgeProps>> = forwardRef<
7676
})
7777
) : (
7878
<Box style={tailwind.style(cx(badgeStyles.size[size]?.prefix))}>
79-
{prefix}
79+
{prefix as React.ReactNode}
8080
</Box>
8181
);
8282

src/components/button/ButtonSpinner.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { isValidElement } from "react";
33
import { Box } from "../../primitives";
44
import { useTheme } from "../../theme";
55
import { cx } from "../../utils";
6-
import { Spinner } from "../spinner";
6+
import { Spinner, SpinnerSizes } from "../spinner";
77

88
import { ButtonProps } from "./Button";
99

@@ -47,13 +47,13 @@ export const ButtonSpinner: React.FC<ButtonSpinnerProps> = ({
4747
prefix,
4848
suffix,
4949
}) => {
50-
const tailwind = useTheme();
5150
const buttonTheme = useTheme("button");
5251

53-
const spinnerSize =
52+
const spinnerSize = (
5453
prefix || suffix
5554
? spinnerSizes[size]?.spinner
56-
: spinnerSizes[size]?.iconOnly;
55+
: spinnerSizes[size]?.iconOnly
56+
) as SpinnerSizes;
5757

5858
return isValidElement(spinner) ? (
5959
React.cloneElement(spinner, {
@@ -63,9 +63,7 @@ export const ButtonSpinner: React.FC<ButtonSpinnerProps> = ({
6363
) : (
6464
<Spinner
6565
size={spinnerSize}
66-
style={tailwind.style(
67-
cx(buttonTheme.themeColor[themeColor]?.[variant]?.spinner?.disabled),
68-
)}
66+
stroke={buttonTheme.themeColor[themeColor]?.[variant]?.spinner?.disabled}
6967
/>
7068
);
7169
};

src/components/checkbox/Checkbox.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const RNCheckbox: React.FC<Partial<CheckboxProps>> = forwardRef<
113113
isIndeterminate,
114114
isDisabled,
115115
style,
116+
index,
116117
} = props;
117118

118119
const hasOnlyLabel = label && !description;
@@ -351,6 +352,9 @@ const RNCheckbox: React.FC<Partial<CheckboxProps>> = forwardRef<
351352
tailwind.style(
352353
cx(
353354
checkboxTheme?.label?.common,
355+
index !== 0
356+
? checkboxTheme?.group[checkboxGroupState.orientation]?.spacing
357+
: "",
354358
description ? checkboxTheme?.label?.withDescription : "",
355359
checkboxTheme.size[size]?.label?.wrapper,
356360
touchState.pressed

src/components/checkbox/CheckboxGroup.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import {
1212
createContext,
1313
cx,
1414
getValidChildren,
15+
passProps,
1516
styleAdapter,
1617
} from "../../utils";
1718

1819
import { CheckboxSizes, CheckboxTheme } from "./Checkbox";
1920

2021
interface CheckboxGroupContext
21-
extends Pick<CheckboxGroupProps, "size" | "themeColor">,
22+
extends Pick<CheckboxGroupProps, "size" | "themeColor" | "orientation">,
2223
CheckboxGroupState {}
2324

2425
const [CheckboxGroupProvider, useCheckboxGroupContext] =
@@ -98,17 +99,14 @@ const RNCheckboxGroup: React.FC<Partial<CheckboxGroupProps>> = forwardRef<
9899
accessibilityRole={Platform.OS === "web" ? "group" : undefined}
99100
ref={ref}
100101
>
101-
<CheckboxGroupProvider value={{ ...state, size, themeColor }}>
102-
{validChildren.map((renderElement, index) => (
103-
<Box
104-
key={index}
105-
style={tailwind.style(
106-
cx(checkboxGroupTheme.group[orientation]?.spacing),
107-
)}
108-
>
109-
{renderElement}
110-
</Box>
111-
))}
102+
<CheckboxGroupProvider
103+
value={{ ...state, size, themeColor, orientation }}
104+
>
105+
{validChildren.map((renderElement, index) =>
106+
passProps(renderElement, {
107+
index,
108+
}),
109+
)}
112110
</CheckboxGroupProvider>
113111
</Box>
114112
);

src/components/circular-progress/CircularProgress.tsx

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { forwardRef } from "react";
22
import { StyleSheet } from "react-native";
33
import Animated, {
4+
cancelAnimation,
45
Easing,
56
interpolate,
67
useAnimatedProps,
@@ -128,9 +129,10 @@ const RNCircularProgress: React.FC<Partial<CircularProgressProps>> = forwardRef<
128129
};
129130
});
130131

131-
// Indeterminate Progress
132+
// Indeterminate Progress Code
132133
const progress = useSharedValue(0);
133134
const rotate = useSharedValue(0);
135+
134136
const animatedSvgStyle = useAnimatedStyle(() => {
135137
const rotateValue = interpolate(rotate.value, [0, 1], [0, 360]);
136138
return {
@@ -141,6 +143,7 @@ const RNCircularProgress: React.FC<Partial<CircularProgressProps>> = forwardRef<
141143
],
142144
};
143145
});
146+
144147
const indeterminateAnimatedCircularProgress = useAnimatedProps(() => {
145148
return {
146149
strokeDashoffset: interpolate(
@@ -152,23 +155,40 @@ const RNCircularProgress: React.FC<Partial<CircularProgressProps>> = forwardRef<
152155
});
153156

154157
React.useEffect(() => {
155-
progress.value = withRepeat(
156-
withTiming(1, {
157-
duration: 1500,
158-
easing: Easing.linear,
159-
}),
160-
-1,
161-
false,
162-
);
163-
rotate.value = withRepeat(
164-
withTiming(1, {
165-
duration: 1000,
166-
easing: Easing.bezier(0.4, 0, 0.2, 1),
167-
}),
168-
-1,
169-
false,
170-
);
171-
}, [progress, rotate]);
158+
if (isIndeterminate) {
159+
progress.value = withRepeat(
160+
withTiming(1, {
161+
duration: 1500,
162+
easing: Easing.linear,
163+
}),
164+
-1,
165+
false,
166+
finished => {
167+
if (!finished) {
168+
progress.value = 0;
169+
}
170+
},
171+
);
172+
rotate.value = withRepeat(
173+
withTiming(1, {
174+
duration: 1000,
175+
easing: Easing.bezier(0.4, 0, 0.2, 1),
176+
}),
177+
-1,
178+
false,
179+
finished => {
180+
if (!finished) {
181+
rotate.value = 0;
182+
}
183+
},
184+
);
185+
} else {
186+
cancelAnimation(progress);
187+
cancelAnimation(rotate);
188+
}
189+
}, [isIndeterminate, progress, rotate]);
190+
191+
// Indeterminate Progress Code
172192

173193
const circularProgressBoxDimensions = {
174194
width: hint
@@ -185,7 +205,7 @@ const RNCircularProgress: React.FC<Partial<CircularProgressProps>> = forwardRef<
185205
style={[
186206
circularProgressBoxDimensions,
187207
styleAdapter(style),
188-
isIndeterminate && animatedSvgStyle,
208+
isIndeterminate ? animatedSvgStyle : {},
189209
]}
190210
{...otherProps}
191211
>

src/components/input/Input.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { forwardRef, ReactNode, useMemo, useRef, useState } from "react";
2-
import { Platform, TextInputProps, ViewStyle } from "react-native";
2+
import { Platform, TextInputProps } from "react-native";
33

44
import { Box, BoxProps, RNTextInput, TouchableProps } from "../../primitives";
55
import { useTheme } from "../../theme";
@@ -71,14 +71,14 @@ export interface InputProps extends TextInputProps {
7171
}
7272

7373
interface DefaultInputSpinnerProps extends Pick<InputProps, "size"> {
74-
spinnerStroke: ViewStyle;
74+
spinnerStroke: string;
7575
}
7676

7777
export const DefaultInputSpinner = (
7878
state: DefaultInputSpinnerProps,
7979
): JSX.Element => {
8080
const { size, spinnerStroke } = state;
81-
return <Spinner size={size !== "xl" ? "xs" : "md"} style={spinnerStroke} />;
81+
return <Spinner size={size !== "xl" ? "xs" : "md"} stroke={spinnerStroke} />;
8282
};
8383

8484
const RNInput: React.FC<Partial<InputProps>> = forwardRef<
@@ -212,13 +212,13 @@ const RNInput: React.FC<Partial<InputProps>> = forwardRef<
212212
})
213213
: suffix;
214214

215-
const spinnerStroke = tailwind.style(
215+
const spinnerStroke = tailwind.getColor(
216216
cx(
217217
editable
218218
? inputTheme.variant[variant]?.default?.suffix
219219
: inputTheme.variant[variant]?.disabled?.suffix,
220220
),
221-
);
221+
) as string;
222222
const inputLoading = runIfFn(DefaultInputSpinner, {
223223
size,
224224
spinnerStroke,

src/components/select/SelectPrefix.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const SelectPrefix: React.FC<SelectPrefixProps> = ({
6464
)}
6565
{...props}
6666
>
67-
{_prefix}
67+
{_prefix as React.ReactNode}
6868
</Box>
6969
);
7070
};

src/components/select/SelectSuffix.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const SelectSuffix: React.FC<SelectSuffixProps> = ({
5252
iconFill: tailwind.getColor(iconColor),
5353
})
5454
: suffix;
55-
return selectSuffix;
55+
return selectSuffix as React.ReactNode;
5656
// eslint-disable-next-line react-hooks/exhaustive-deps
5757
}, [disabled, invalid, suffix, isPressedOrHovered]);
5858

src/components/slider/SliderTooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const RNSliderTooltip: React.FC<Partial<SliderTooltipProps>> = props => {
118118
getContainerStyle,
119119
]}
120120
>
121-
{content}
121+
{content as React.ReactNode}
122122
</Box>
123123
<AnimatedBox
124124
style={[

0 commit comments

Comments
 (0)