Skip to content

Commit 28e88ad

Browse files
authored
fix: divider theme props accepted (#108)
1 parent 89bb56f commit 28e88ad

File tree

1 file changed

+46
-42
lines changed
  • packages/react-native-ficus-ui/src/components/divider

1 file changed

+46
-42
lines changed
Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { useMemo } from 'react';
22

33
import { useColorMode } from '../../hooks';
4-
import { type NativeFicusProps, ficus, forwardRef } from '../system';
4+
import { ThemingProps, omitThemingProps } from '../../style-system';
5+
import {
6+
type NativeFicusProps,
7+
ficus,
8+
forwardRef,
9+
useMultiStyleConfig,
10+
} from '../system';
511

612
interface DividerOptions {
713
color?: string;
@@ -10,49 +16,47 @@ interface DividerOptions {
1016

1117
export interface DividerProps
1218
extends NativeFicusProps<'View'>,
13-
DividerOptions {}
19+
DividerOptions,
20+
ThemingProps<'Divider'> {}
1421

1522
/**
1623
* Layout component used to visually separate content in a list or group.
1724
* It displays a thin horizontal or vertical line
1825
*/
19-
export const Divider = forwardRef<DividerProps, 'View'>(
20-
function Divider(props, ref) {
21-
const { colorMode } = useColorMode();
22-
23-
const {
24-
orientation = 'horizontal',
25-
color = colorMode === 'dark' ? 'white' : 'black',
26-
__styles,
27-
...rest
28-
} = props;
29-
30-
const dividerStyles = useMemo(() => {
31-
const bg = color;
32-
33-
return {
34-
vertical: {
35-
w: 1,
36-
h: '100%',
37-
bg,
38-
},
39-
horizontal: {
40-
h: 1,
41-
w: '100%',
42-
bg,
43-
},
44-
};
45-
}, [color]);
46-
47-
return (
48-
<ficus.View
49-
ref={ref}
50-
{...rest}
51-
__styles={{
52-
...dividerStyles[orientation],
53-
...__styles,
54-
}}
55-
/>
56-
);
57-
}
58-
);
26+
export const Divider = forwardRef<DividerProps, 'View'>((props, ref) => {
27+
const { colorMode } = useColorMode();
28+
const themingProps = omitThemingProps(props);
29+
30+
const {
31+
orientation = 'horizontal',
32+
__styles,
33+
color: colorProp,
34+
...rest
35+
} = themingProps;
36+
37+
const styles = useMultiStyleConfig('Divider', props);
38+
39+
const color =
40+
colorProp ??
41+
(styles.color as string) ??
42+
(colorMode === 'dark' ? 'white' : 'black');
43+
44+
const dividerStyles = useMemo(() => {
45+
const base = { ...styles, bg: color };
46+
return {
47+
vertical: { w: 1, h: '100%', ...base },
48+
horizontal: { h: 1, w: '100%', ...base },
49+
};
50+
}, [color, styles]);
51+
52+
return (
53+
<ficus.View
54+
ref={ref}
55+
{...rest}
56+
__styles={{
57+
...dividerStyles[orientation],
58+
...__styles,
59+
}}
60+
/>
61+
);
62+
});

0 commit comments

Comments
 (0)