Skip to content

Commit a99f5bd

Browse files
committed
fix: style and overrides
1 parent 4e399bb commit a99f5bd

3 files changed

Lines changed: 45 additions & 52 deletions

File tree

src/components/Inputs/TextInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ const StyledInput = (props: InputProps) => {
235235
width: '100%',
236236
...textSize,
237237
...(isDisabled
238-
? { backgroundColor: theme.colors.background.greyDark }
238+
? { backgroundColor: theme.colors.background.greyLight }
239239
: {}),
240240
...(isInvalid ? { borderColor: theme.colors.border.danger } : {}),
241241
...(numberOfLines

src/utils/overrides.test.tsx

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
11
import * as React from 'react';
2-
import { TextStyle, View, ViewProps } from 'react-native';
2+
import { Text, TextProps, View, ViewProps } from 'react-native';
33
import { render } from 'react-native-testing-library';
44

55
import { getOverrides, WithOverrides } from './overrides';
66

7-
interface ComponentTwoProps {
8-
two?: string;
9-
style?: TextStyle;
7+
interface CommonComponentProps extends TextProps {
8+
isDisabled: boolean;
109
}
1110

12-
const ComponentTwo = (props: ComponentTwoProps) => {
13-
return <></>;
11+
const CommonComponent = (props: CommonComponentProps) => {
12+
const { isDisabled, ...textProps } = props;
13+
14+
return <Text {...textProps} />;
1415
};
1516

16-
interface ComponentOneBaseProps {
17-
one?: string;
17+
interface RootProps extends ViewProps {
18+
children?: React.ReactNode;
1819
}
1920

20-
interface ComponentOneOverrides {
21-
Root: ViewProps;
22-
ComponentTwo: ComponentTwoProps;
23-
}
21+
const StyledRoot = (props: RootProps) => {
22+
const { children, ...viewProps } = props;
2423

25-
type ComponentOneProps = WithOverrides<
26-
ComponentOneBaseProps,
27-
ComponentOneOverrides
28-
>;
29-
30-
const ComponentOne = (props: ComponentOneProps) => {
31-
return <></>;
24+
return <View {...viewProps}>{children}</View>;
3225
};
3326

3427
interface TestComponentBaseProps {
35-
zero?: string;
28+
isDisabled: boolean;
3629
}
3730

3831
interface TestComponentOverrides {
39-
Root: ViewProps;
40-
ComponentOne: ComponentOneProps;
41-
ComponentTwo: ComponentTwoProps;
32+
Root: RootProps;
33+
ComponentOne: CommonComponentProps;
34+
ComponentTwo: CommonComponentProps;
4235
}
4336

4437
type TestComponentProps = WithOverrides<
@@ -47,71 +40,68 @@ type TestComponentProps = WithOverrides<
4740
>;
4841

4942
const TestComponent = (props: TestComponentProps) => {
50-
const { overrides = {}, zero } = props;
43+
const { overrides = {}, isDisabled } = props;
5144

5245
const [RootR, rootProps] = getOverrides(
53-
View,
46+
StyledRoot,
5447
props,
5548
overrides.Root,
5649
overrides.Root,
5750
);
5851
const [ComponentOneR, componentOneProps] = getOverrides(
59-
ComponentOne,
52+
CommonComponent,
6053
props,
6154
overrides.ComponentOne,
6255
overrides.ComponentOne,
6356
);
6457
const [ComponentTwoR, componentTwoProps] = getOverrides(
65-
ComponentTwo,
58+
CommonComponent,
6659
props,
6760
overrides.ComponentTwo,
6861
overrides.ComponentTwo,
6962
);
7063

7164
return (
7265
<RootR {...rootProps}>
73-
<ComponentOneR one={zero} {...componentOneProps} />
74-
<ComponentTwoR two={zero} {...componentTwoProps} />
66+
<ComponentOneR isDisabled={isDisabled} {...componentOneProps} />
67+
<ComponentTwoR isDisabled={isDisabled} {...componentTwoProps} />
7568
</RootR>
7669
);
7770
};
7871

79-
const ReplaceComponentTwo = (props: ComponentTwoProps) => <></>;
72+
const ReplaceComponentTwo = (props: CommonComponentProps) => <></>;
8073

8174
describe('Overrides', () => {
8275
test('Component is correctly type-checked and can render', () => {
83-
render(
76+
const { getByTestId } = render(
8477
<TestComponent
78+
isDisabled={true}
8579
overrides={{
8680
Root: {
87-
props: props => ({
88-
testID: props.zero,
89-
}),
90-
style: props => ({
91-
height: 1,
92-
}),
93-
},
94-
ComponentOne: {
9581
props: {
96-
one: '1',
97-
overrides: {
98-
Root: {
99-
style: {
100-
height: 1,
101-
},
102-
},
103-
},
82+
testID: 'ROOT',
10483
},
105-
},
106-
ComponentTwo: {
10784
style: {
108-
fontSize: 1,
85+
backgroundColor: 'blue',
10986
},
87+
},
88+
ComponentOne: {
89+
props: ({ isDisabled }) => ({
90+
testID: isDisabled ? 'COMPONENT_ONE' : 'INVALID_COMPONENT',
91+
}),
92+
style: ({ isDisabled }) => ({
93+
backgroundColor: isDisabled ? 'blue' : 'green',
94+
}),
95+
},
96+
ComponentTwo: {
11097
component: ReplaceComponentTwo,
11198
},
11299
}}
113100
/>,
114101
);
102+
103+
const componentOne = getByTestId('COMPONENT_ONE');
104+
expect(componentOne.props.style.backgroundColor).toBe('blue');
115105
});
116106
});
117107

src/utils/overrides.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ const applyOverrides = <TProps = any, TChildProps = any>(
9494
}
9595

9696
if (override.style) {
97-
style = getStyle<Partial<TChildProps>>(overrideProps, override.style);
97+
style = getStyle<Partial<TChildProps>>(
98+
{ ...parentProps, ...overrideProps },
99+
override.style,
100+
);
98101
}
99102

100103
return { ...overrideProps, ...(style ? { style } : {}) };

0 commit comments

Comments
 (0)