Skip to content

Commit 4aba135

Browse files
committed
feat: make shared styles (borders and text) work with themes
1 parent 7bc3ecb commit 4aba135

File tree

10 files changed

+145
-139
lines changed

10 files changed

+145
-139
lines changed

src/Button/Button.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from 'react-native';
1212

1313
import { ThemeContext } from '../common/theming/Theme';
14-
import { border, text, blockSizes } from '../common/styles';
14+
import { blockSizes } from '../common/styles';
1515

1616
export const testId = 'button';
1717

@@ -44,6 +44,7 @@ const Button = ({
4444
active = false,
4545
accessibilityLabel,
4646
}: ButtonProps) => {
47+
const theme = useContext(ThemeContext);
4748
const [isPressed, setIsPressed] = useState(false);
4849

4950
const getWidth = () => {
@@ -81,7 +82,7 @@ const Button = ({
8182
accessibilityRole='button'
8283
accessibilityLabel={accessibilityLabel}
8384
>
84-
<Text style={[disabled ? text.disabled : text.default]}>
85+
<Text style={[disabled ? theme.text.disabled : theme.text.default]}>
8586
{children}
8687
</Text>
8788
</TouchableHighlight>
@@ -127,17 +128,17 @@ const Borders = ({
127128
let focus;
128129

129130
if (variant === 'default') {
130-
wrapper = primary ? [border.outline] : [];
131-
outer = [border.defaultOuter];
132-
inner = [border.defaultInner];
133-
focus = isPressed ? [border.focusOutline] : [];
131+
wrapper = primary ? [theme.border.outline] : [];
132+
outer = [theme.border.defaultOuter];
133+
inner = [theme.border.defaultInner];
134+
focus = isPressed ? [theme.border.focusOutline] : [];
134135
} else if (variant === 'outside') {
135-
wrapper = primary ? [border.outline] : [];
136-
outer = [border.outsideOuter];
137-
inner = [border.outsideInner];
138-
focus = isPressed ? [border.focusOutline] : [];
136+
wrapper = primary ? [theme.border.outline] : [];
137+
outer = [theme.border.outsideOuter];
138+
inner = [theme.border.outsideInner];
139+
focus = isPressed ? [theme.border.focusOutline] : [];
139140
} else if (variant === 'menu' && (active || isPressed)) {
140-
wrapper = [border.well];
141+
wrapper = [theme.border.well];
141142
}
142143

143144
return (

src/Menu/MenuItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useContext, useState } from 'react';
22
import { StyleSheet, View, TouchableHighlight } from 'react-native';
33

44
import { ThemeContext } from '../common/theming/Theme';
5-
import { text, blockSizes } from '../common/styles';
5+
import { blockSizes } from '../common/styles';
66

77
import { Text } from '..';
88

@@ -52,7 +52,7 @@ export const Item = ({
5252
<View pointerEvents='none' style={[styles.content]}>
5353
<Text
5454
style={[
55-
disabled ? text.disabled : text.default,
55+
disabled ? theme.text.disabled : theme.text.default,
5656
!disabled && {
5757
color: isPressed
5858
? theme.materialTextInvert

src/Select/Select.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'react-native';
99

1010
import { ThemeContext } from '../common/theming/Theme';
11-
import { blockSizes, text, border } from '../common/styles';
11+
import { blockSizes } from '../common/styles';
1212
import { Border } from '../common/styleElements';
1313

1414
import getSelectOptions, { Option } from './SelectBase';
@@ -93,13 +93,13 @@ const Select = ({
9393
: theme.canvas,
9494
},
9595

96-
isPressed && border.focusSecondaryOutline,
96+
isPressed && theme.border.focusSecondaryOutline,
9797
]}
9898
>
9999
<Text
100100
style={[
101101
styles.textValue,
102-
disabled ? text.disabled : text.default,
102+
disabled ? theme.text.disabled : theme.text.default,
103103
!disabled &&
104104
isPressed && {
105105
color: isPressed

src/SwitchBase/SwitchBase.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010

1111
import { Border } from '../common/styleElements';
1212
import { ThemeContext } from '../common/theming/Theme';
13-
import { border } from '../common/styles';
1413

1514
import { Text } from '..';
1615

@@ -135,7 +134,7 @@ const SwitchBase = ({
135134
<View
136135
style={[
137136
!disabled && isPressed
138-
? border.focusOutline
137+
? theme.border.focusOutline
139138
: { borderWidth: 2, borderColor: 'transparent' },
140139
]}
141140
>

src/Tabs/Tabs.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'react-native';
99

1010
import { ThemeContext } from '../common/theming/Theme';
11-
import { border, padding, margin, blockSizes } from '../common/styles';
11+
import { padding, margin, blockSizes } from '../common/styles';
1212
import { Border } from '../common/styleElements';
1313
import { Text, Panel } from '..';
1414

@@ -130,7 +130,9 @@ const Tab = ({
130130
/>
131131
<Text>{children}</Text>
132132
<View style={[styles.mask, { backgroundColor: theme.material }]} />
133-
{isPressed && <View style={[styles.focusOutline]} />}
133+
{isPressed && (
134+
<View style={[styles.focusOutline, theme.border.focusOutline]} />
135+
)}
134136
</View>
135137
</TouchableHighlight>
136138
);
@@ -177,7 +179,6 @@ const styles = StyleSheet.create({
177179
top: 6,
178180
bottom: 4,
179181
right: 6,
180-
...border.focusOutline,
181182
},
182183
});
183184

src/Text/Text.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
} from 'react-native';
99

1010
import { ThemeContext } from '../common/theming/Theme';
11-
import { text } from '../common/styles';
1211

1312
type Props = React.ComponentProps<typeof NativeText> & {
1413
children: React.ReactNode;
@@ -39,7 +38,11 @@ const Text = ({
3938
return (
4039
<NativeText
4140
style={[
42-
disabled ? text.disabled : secondary ? text.secondary : text.default,
41+
disabled
42+
? theme.text.disabled
43+
: secondary
44+
? theme.text.secondary
45+
: theme.text.default,
4346
linkUrl ? { ...styles.link, color: theme.anchor } : {},
4447
{
4548
fontWeight: bold ? 'bold' : 'normal',

src/TextInput/TextInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'react-native';
99

1010
import { ThemeContext } from '../common/theming/Theme';
11-
import { blockSizes, text } from '../common/styles';
11+
import { blockSizes } from '../common/styles';
1212
import { Border } from '../common/styleElements';
1313

1414
type Props = {
@@ -43,7 +43,7 @@ const TextInput = ({
4343
{
4444
backgroundColor: disabled ? theme.material : theme.canvas,
4545
},
46-
disabled && hasValue ? text.disabled : text.default,
46+
disabled && hasValue ? theme.text.disabled : theme.text.default,
4747
]}
4848
placeholderTextColor={theme.materialTextDisabled}
4949
defaultValue={defaultValue}

src/common/styleElements.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable import/prefer-default-export */
2-
import React from 'react';
2+
import React, { useContext } from 'react';
33
import { StyleSheet, View, StyleProp, ViewStyle } from 'react-native';
4-
import { border } from './styles';
4+
5+
import { ThemeContext } from './theming/Theme';
56

67
// Borders acts like a pseudo element that
78
// will be positioned absolutely in it's parent element
@@ -22,21 +23,23 @@ export const Border = ({
2223
radius = 0,
2324
children,
2425
}: BorderProps) => {
26+
const theme = useContext(ThemeContext);
27+
2528
const wrapper: StyleProp<ViewStyle> = [];
2629
let outer;
2730
let inner;
2831

2932
if (variant === 'default') {
30-
outer = [border.defaultOuter];
31-
inner = [border.defaultInner];
33+
outer = [theme.border.defaultOuter];
34+
inner = [theme.border.defaultInner];
3235
} else if (variant === 'outside') {
33-
outer = [border.outsideOuter];
34-
inner = [border.outsideInner];
36+
outer = [theme.border.outsideOuter];
37+
inner = [theme.border.outsideInner];
3538
} else if (variant === 'well') {
36-
outer = [border.well, borderStyles.invert];
39+
outer = [theme.border.well, borderStyles.invert];
3740
} else if (variant === 'cutout') {
38-
outer = [border.cutoutOuter];
39-
inner = [border.cutoutInner];
41+
outer = [theme.border.cutoutOuter];
42+
inner = [theme.border.cutoutInner];
4043
}
4144

4245
const getSharedStyles = (() => {

0 commit comments

Comments
 (0)