Skip to content

Commit

Permalink
fix(Typography): 调整Typography明暗主题
Browse files Browse the repository at this point in the history
  • Loading branch information
panbibi authored and hy committed Apr 8, 2023
1 parent e9aa004 commit 127a548
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 44 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/Typography/Div.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React, { Fragment } from 'react';
import { Text, TextProps, ViewProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

interface DivProps {
children?: React.ReactNode;
}

export default function Div<T>({ children, ...otherProps }: DivProps & TextProps & ViewProps): JSX.Element | null {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';
if (!children) {
return null;
}
Expand All @@ -14,7 +18,7 @@ export default function Div<T>({ children, ...otherProps }: DivProps & TextProps
return typeof item === 'string' || (item && (item as any).type && (item as any).type.displayName === 'Text');
});
if (someStr) {
return <Text {...otherProps} children={children} />;
return <Text {...otherProps} children={children} style={{ color: textColor }} />;
}
return (
<Fragment>
Expand Down
23 changes: 18 additions & 5 deletions packages/core/src/Typography/Em.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
fontStyle: 'italic',
},
});
type CreStyle = {
textColor: string;
};

function createStyles({ textColor }: CreStyle) {
return StyleSheet.create({
default: {
fontStyle: 'italic',
color: textColor,
},
});
}

export interface EmProps extends TextProps {
children?: React.ReactNode;
}

export default function Em(props: EmProps) {
const theme = useTheme<Theme>();
const styles = createStyles({
textColor: theme.colors.primary_text || '#ccc',
});
return React.cloneElement(<Text />, {
...props,
style: [styles.default, props.style],
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/Typography/H1.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -15,8 +17,11 @@ export interface H1Props extends TextProps {
}

export default function H1(props: H1Props) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';

return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/Typography/H2.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -15,8 +17,11 @@ export interface H2Props extends TextProps {
}

export default function H2(props: H2Props) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';

return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/Typography/H3.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -15,8 +17,11 @@ export interface H3Props extends TextProps {
}

export default function H3(props: H3Props) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';

return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/Typography/H4.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -15,8 +17,11 @@ export interface H4Props extends TextProps {
}

export default function H4(props: H4Props) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';

return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/Typography/H5.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -15,8 +17,11 @@ export interface H5Props extends TextProps {
}

export default function H5(props: H5Props) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';

return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/Typography/H6.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -15,8 +17,10 @@ export interface H6Props extends TextProps {
}

export default function H6(props: H6Props) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';
return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down
32 changes: 23 additions & 9 deletions packages/core/src/Typography/Hr.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import React from 'react';
import { StyleSheet, View, ViewProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
height: 1,
flexDirection: 'row',
borderBottomWidth: StyleSheet.hairlineWidth,
borderColor: '#CDCDCD',
marginVertical: 10,
},
});
type CreStyle = {
textColor: string;
};

function createStyles({ textColor }: CreStyle) {
return StyleSheet.create({
default: {
height: 1,
flexDirection: 'row',
borderBottomWidth: StyleSheet.hairlineWidth,
borderColor: '#CDCDCD',
marginVertical: 10,
color: textColor,
},
});
}

export interface HrProps extends ViewProps {}

export default function Hr(props: HrProps) {
const theme = useTheme<Theme>();
const styles = createStyles({
textColor: theme.colors.primary_text || '#ccc',
});
const textColor = theme.colors.primary_text || '#ccc';
return <View {...props} style={[styles.default, props.style]} />;
}
6 changes: 5 additions & 1 deletion packages/core/src/Typography/P.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -15,8 +17,10 @@ export interface PProps extends TextProps {
}

export default function P(props: PProps) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';
return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down
51 changes: 32 additions & 19 deletions packages/core/src/Typography/RnText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Text as RNText, StyleSheet, TextProps as RNTextProps, TextStyle, Animat
import _ from 'lodash';
import Tooltip from '../Tooltip';
import { rnTextType, getTextPartsByHighlight, sliceText } from '../utils/rn-text';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

export type RnTextProps = RNTextProps & {
// header:Header标题 | title:列表/From标题 | label:正文,说明,备注label | subLabel:辅助性文字
Expand Down Expand Up @@ -37,6 +39,10 @@ const TooltipContainer = ({ content, children }: { content?: string; children?:
};

export default (props: RnTextProps) => {
const theme = useTheme<Theme>();
const styles = createStyles({
textColor: theme.colors.primary_text || '#ccc',
});
const {
type,
color,
Expand Down Expand Up @@ -107,22 +113,29 @@ export default (props: RnTextProps) => {
);
};

const styles = StyleSheet.create({
container: {
backgroundColor: 'transparent',
textAlign: 'left',
},
centered: {
textAlign: 'center',
},
uppercase: {
textTransform: 'uppercase',
},
highlight: {
color: '#333333',
fontSize: 14,
},
notHighlight: {
color: undefined,
},
});
const styles = StyleSheet.create({});
type CreStyle = {
textColor: string;
};

function createStyles({ textColor }: CreStyle) {
return StyleSheet.create({
container: {
backgroundColor: 'transparent',
textAlign: 'left',
},
centered: {
textAlign: 'center',
},
uppercase: {
textTransform: 'uppercase',
},
highlight: {
color: textColor,
fontSize: 14,
},
notHighlight: {
color: undefined,
},
});
}
6 changes: 5 additions & 1 deletion packages/core/src/Typography/S.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -13,8 +15,10 @@ export interface SProps extends TextProps {
}

export default function S(props: SProps) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';
return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/Typography/Strong.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -13,8 +15,10 @@ export interface StrongProps extends TextProps {
}

export default function Strong(props: StrongProps) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';
return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/Typography/U.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, TextProps } from 'react-native';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';

const styles = StyleSheet.create({
default: {
Expand All @@ -13,8 +15,10 @@ export interface UProps extends TextProps {
}

export default function U(props: UProps) {
const theme = useTheme<Theme>();
const textColor = theme.colors.primary_text || '#ccc';
return (
<Text {...props} style={[styles.default, props.style]}>
<Text {...props} style={[styles.default, props.style, { color: textColor }]}>
{props.children}
</Text>
);
Expand Down

0 comments on commit 127a548

Please sign in to comment.