Skip to content

Commit 22dc93c

Browse files
committed
refactor(checkbox): ♻️ remove additional wrapper around checkbox in checkboxGroup,
moved orientation based spacing to Touchable component in Checkbox, fix border radius in checkbox & fix full width tappable when in CheckboxGroup
1 parent 8c957d9 commit 22dc93c

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

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/theme/defaultTheme/checkbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const checkbox = {
22
group: {
33
vertical: {
4-
common: "flex flex-col items-start",
4+
common: "flex flex-col",
55
spacing: "mt-1",
66
},
77
horizontal: {
@@ -67,7 +67,7 @@ export const checkbox = {
6767
wrapper: "min-h-9 px-3 py-2 rounded-[10px]",
6868
},
6969
icon: {
70-
wrapper: "w-5 h-5 text-base rounded",
70+
wrapper: "w-5 h-5 text-base rounded-md",
7171
iconSize: "w-4 h-4",
7272
},
7373
text: {

0 commit comments

Comments
 (0)