-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b99f5b6
commit 1fe5fcd
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |