-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Theme-UI building with Text and Buttons
- Loading branch information
Showing
12 changed files
with
1,121 additions
and
417 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,49 +1,23 @@ | ||
import styled from "styled-components" | ||
import { variant, compose, typography, TypographyProps } from "styled-system" | ||
/** @jsxImportSource theme-ui */ | ||
import { ReactChild } from 'react' | ||
import { Text as _Text, useThemeUI, get } from 'theme-ui' | ||
|
||
// NB: We can include all Typography props if we prefer | ||
// interface TextProps extends TypographyProps { | ||
// size?: "sm" | "md" | "lg" | ||
// } | ||
// TODO: Import Typography props as well? Or merge sx object? | ||
interface TextProps { | ||
size?: "sm" | "md" | "lg" | ||
size?: "sm" | "md" | "lg", | ||
children: ReactChild | ||
} | ||
|
||
const sizes = variant({ | ||
prop: "size", | ||
variants: { | ||
sm: { | ||
fontSize: 0, | ||
lineHeight: 0 | ||
}, | ||
md: { | ||
fontSize: 1, | ||
lineHeight: 1 | ||
}, | ||
lg: { | ||
fontSize: 2, | ||
lineHeight: 2 | ||
}, | ||
} | ||
}) | ||
const Text = ({ size, children }: TextProps) => { | ||
const context = useThemeUI() | ||
const styles = get(context.theme, `text.${size}`) | ||
|
||
// Compose all typography styles w/ our variants if we prefer | ||
// const textStyles = compose(typography, sizes) | ||
// const Text = styled.span<TextProps>(textStyles) | ||
const Text = styled.span<TextProps>(sizes) | ||
return <_Text sx={styles}>{ children }</_Text> | ||
} | ||
|
||
Text.defaultProps = { | ||
size: "md" | ||
} | ||
|
||
// NB: OR we can also forgo the "variants" like so: | ||
// const Text = styled.span<TypographyProps>` | ||
// ${typography} | ||
// ` | ||
// Text.defaultProps = { | ||
// fontFamily: "sansSerif", | ||
// fontSize: 1 | ||
// } | ||
|
||
export default Text | ||
export type { TextProps } |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import Text from "./components/Text" | ||
// import Text from "./components/Text" | ||
import { Text } from "theme-ui" | ||
|
||
export { Text } |
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
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
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,21 @@ | ||
export default { | ||
button: { | ||
// size | ||
sm: { | ||
fontSize: 0 | ||
}, | ||
md: { | ||
fontSize: 1 | ||
}, | ||
lg: { | ||
fontSize: 2 | ||
}, | ||
// kind | ||
primary: { | ||
bg: 'primary' | ||
}, | ||
secondary: { | ||
bg: 'secondary' | ||
} | ||
} | ||
} |
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,16 @@ | ||
export default { | ||
text: { | ||
sm: { | ||
fontSize: 0, | ||
lineHeight: 0 | ||
}, | ||
md: { | ||
fontSize: 1, | ||
lineHeight: 1 | ||
}, | ||
lg: { | ||
fontSize: 2, | ||
lineHeight: 2 | ||
}, | ||
} | ||
} |
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,13 @@ | ||
import { Theme } from 'theme-ui' | ||
|
||
import base from './base' | ||
import text from './text' | ||
import button from './button' | ||
|
||
const theme: Theme = { | ||
...base, | ||
...text, | ||
...button | ||
} | ||
|
||
export default theme |