Skip to content

Commit b239136

Browse files
author
crstnmac
committed
fix: refactor divider component and add extra prop to style the divider line
1 parent 30ad937 commit b239136

File tree

3 files changed

+70
-30
lines changed

3 files changed

+70
-30
lines changed

example/src/modules/primitives/DividerScreen.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import { ScrollView } from "react-native-gesture-handler";
3-
import { Box, Divider, useTheme } from "@adaptui/react-native-tailwind";
3+
import { Box, Divider, Tag, useTheme } from "@adaptui/react-native-tailwind";
44

55
export const DividerScreen = () => {
66
const tailwind = useTheme();
@@ -28,14 +28,30 @@ export const DividerScreen = () => {
2828
label="Continue"
2929
/>
3030
</Box>
31+
<Box style={tailwind.style("h-15 px-2 justify-center")}>
32+
<Divider
33+
orientation="horizontal"
34+
labelPosition="center"
35+
slot={
36+
<Tag
37+
style={tailwind.style("rounded-full")}
38+
variant="subtle"
39+
themeColor="primary"
40+
>
41+
New Messages
42+
</Tag>
43+
}
44+
dividerStyle={tailwind.style(" border-blue-300")}
45+
/>
46+
</Box>
3147
<Box style={tailwind.style("h-50 py-4 justify-center")}>
3248
<Divider
3349
orientation="vertical"
3450
labelPosition="start"
3551
label="Continue"
3652
/>
3753
</Box>
38-
<Box style={tailwind.style("h-50 py-4 justify-center")}>
54+
<Box style={tailwind.style("h-50 py-4 w-full justify-center")}>
3955
<Divider
4056
orientation="vertical"
4157
labelPosition="center"

src/components/divider/Divider.tsx

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,67 @@
11
import { ReactElement } from "react";
2+
import { StyleProp, ViewStyle } from "react-native";
23
import { Box, useTheme } from "@adaptui/react-native-tailwind";
34

4-
import { createComponent, cx } from "../../utils";
5+
import { createComponent, cx, styleAdapter } from "../../utils";
56
import { Button, ButtonProps } from "../button";
67

78
interface DividerProps {
8-
label?: string;
9-
orientation?: "horizontal" | "vertical";
10-
slot?: ReactElement;
9+
/**
10+
* Label name
11+
*/
12+
label: string;
13+
/**
14+
* The orientation of the divider
15+
* @default horizontal
16+
*/
17+
orientation: "horizontal" | "vertical";
18+
/**
19+
* Pass custom component instead of deafult component.
20+
*/
21+
slot: ReactElement;
22+
/**
23+
* The position of the label/slot
24+
* @default start
25+
*/
1126
labelPosition: "start" | "center" | "end";
27+
/**
28+
* A prop that is passed for the button component
29+
*/
1230
buttonProps: ButtonProps;
31+
/**
32+
* A style prop that is passed for the divider line
33+
*/
34+
dividerStyle: StyleProp<ViewStyle>;
1335
}
1436

15-
const RNDivider = ({
16-
label,
17-
orientation = "horizontal",
18-
slot,
19-
labelPosition = "start",
20-
buttonProps,
21-
}: Partial<DividerProps>) => {
37+
const RNDivider = (props: Partial<DividerProps>) => {
38+
const {
39+
label,
40+
orientation = "horizontal",
41+
slot,
42+
labelPosition = "start",
43+
buttonProps,
44+
dividerStyle,
45+
} = props;
2246
const tailwind = useTheme();
2347
const dividerTheme = useTheme("divider");
2448
return (
2549
<Box
2650
style={tailwind.style(
27-
cx(dividerTheme.orientation[orientation]),
51+
cx(dividerTheme[orientation].orientaion),
2852
orientation === "vertical" ? "overflow-hidden" : {},
2953
)}
3054
>
31-
<Box style={tailwind.style(cx(dividerTheme.lines[orientation]))} />
55+
<Box
56+
style={[
57+
tailwind.style(cx(dividerTheme[orientation].lines)),
58+
styleAdapter(dividerStyle),
59+
]}
60+
/>
3261

3362
<Box
3463
style={tailwind.style(
35-
cx(dividerTheme.label[orientation]?.[labelPosition]),
64+
cx(dividerTheme[orientation]?.label[labelPosition]),
3665
)}
3766
>
3867
{label ? (
@@ -43,8 +72,6 @@ const RNDivider = ({
4372
slot
4473
) : null}
4574
</Box>
46-
47-
<Box style={tailwind.style(cx(dividerTheme.lines[orientation]))} />
4875
</Box>
4976
);
5077
};

src/theme/defaultTheme/divider.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
export const divider = {
2-
base: "border-gray-300",
3-
orientation: {
4-
horizontal: "w-full items-center justify-center",
5-
vertical: "justify-center h-full items-center",
6-
},
7-
lines: {
8-
horizontal: "border-b border-gray-400 w-full",
9-
vertical: "border-r border-gray-400 h-full",
10-
},
11-
label: {
12-
horizontal: {
2+
horizontal: {
3+
orientaion: "w-full items-center justify-center",
4+
lines: "border-b border-gray-400 w-full",
5+
label: {
136
start: "z-1 absolute left-4",
147
center: "z-1 absolute",
158
end: "z-1 absolute right-4",
169
},
17-
vertical: {
10+
},
11+
vertical: {
12+
orientaion: "h-full items-center justify-center",
13+
lines: "border-r border-gray-400 h-full",
14+
label: {
1815
start: "z-1 absolute top-4",
1916
center: "z-1 absolute",
2017
end: "z-1 absolute bottom-4",

0 commit comments

Comments
 (0)