Skip to content

Commit

Permalink
feat: Add color theme support in text props (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbitDoge authored Nov 17, 2020
1 parent 7efc22b commit 2bbc200
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ResetCSS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ResetCSS = createGlobalStyle`
box-sizing: border-box;
}
* {
font-family: 'Noto Sans', "Helvetica Neue", Arial, sans-serif;
font-family: 'Kanit', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Text/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const Default: React.FC = () => {
<Text bold>Bold text</Text>
<Text fontSize="24px">Custom fontsize</Text>
<Text color="red">Custom color</Text>
<Text color="primary">Custom color from theme</Text>
</div>
);
};
7 changes: 6 additions & 1 deletion src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled, { DefaultTheme } from "styled-components";
import { space, SpaceProps } from "styled-system";
import getThemeValue from "../../util/getThemeValue";

export interface Props extends SpaceProps {
color?: string;
Expand All @@ -12,7 +13,7 @@ interface ThemedProps extends Props {
}

const getColor = ({ color, theme }: ThemedProps) => {
return color || theme.colors.text;
return getThemeValue(`colors.${color}`, color)(theme);
};

const getFontSize = ({ fontSize }: Props) => {
Expand All @@ -27,4 +28,8 @@ const Text = styled.div<Props>`
${space}
`;

Text.defaultProps = {
color: "text",
};

export default Text;

0 comments on commit 2bbc200

Please sign in to comment.