Skip to content

Commit

Permalink
feat: Add text component (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbitDoge committed Oct 19, 2020
1 parent b99f5b6 commit 1fe5fcd
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/components/Text/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";
import Text from "./index";

export default {
title: "Text",
component: Text,
argTypes: {
bold: {
name: "bold",
table: {
type: { summary: "bool", detail: "Bold the text" },
defaultValue: { summary: false },
},
control: {
type: null,
},
},
fontSize: {
name: "fontSize",
table: {
type: { summary: "string", detail: "Fontsize in px or em" },
defaultValue: { summary: "16px" },
},
control: {
type: null,
},
},
color: {
name: "color",
table: {
type: { summary: "string", detail: "Color from the theme, or CSS color" },
defaultValue: { summary: "theme.colors.text" },
},
control: {
type: null,
},
},
},
};

export const Default: React.FC = () => {
return (
<div>
<Text>Default</Text>
<Text bold>Bold text</Text>
<Text fontSize="24px">Custom fontsize</Text>
<Text color="red">Custom color</Text>
</div>
);
};
28 changes: 28 additions & 0 deletions src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import styled, { DefaultTheme } from "styled-components";

export interface Props {
color?: string;
fontSize?: string;
bold?: boolean;
}

interface ThemedProps extends Props {
theme: DefaultTheme;
}

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

const getFontSize = ({ fontSize }: Props) => {
return fontSize || "16px";
};

const Text = styled.div<Props>`
color: ${getColor};
font-size: ${getFontSize};
font-weight: ${({ bold }) => (bold ? 600 : 400)};
line-height: 1.4;
`;

export default Text;

0 comments on commit 1fe5fcd

Please sign in to comment.