-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theme UI #2
Open
taggartbg
wants to merge
5
commits into
master
Choose a base branch
from
theme-ui-update
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Theme UI #2
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6252a70
Integrate styled-system, add variants
taggartbg 03b6976
Update Storybook to use Type definition, filter styled-system args fr…
taggartbg cbbcb8e
Add Button with multiple variants
taggartbg 2ae2646
Theme-UI building with Text and Buttons
taggartbg d63ce54
Remove defaultProps
taggartbg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** @jsxImportSource theme-ui */ | ||
import { ReactChild } from 'react' | ||
import { Button as _Button, useThemeUI, get } from 'theme-ui' | ||
|
||
type Kind = "primary" | "secondary" | ||
type Size = "sm" | "md" | "lg" | ||
interface ButtonProps { | ||
kind?: Kind, | ||
size?: Size, | ||
children: ReactChild | ||
} | ||
|
||
const Button = ({ size = "md", kind = "primary", children }: ButtonProps) => { | ||
const context = useThemeUI() | ||
const sizes = get(context.theme, `button.${size}`) | ||
const kinds = get(context.theme, `button.${kind}`) | ||
|
||
return <_Button sx={{ ...sizes, ...kinds }}>{ children }</_Button> | ||
} | ||
|
||
export default Button | ||
export type { ButtonProps } |
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,45 +1,19 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
/** @jsxImportSource theme-ui */ | ||
import { ReactChild } from 'react' | ||
import { Text as _Text, useThemeUI, get } from 'theme-ui' | ||
|
||
import React, { ReactElement } from "react" | ||
import styled from "styled-components" | ||
|
||
type StyledProps = { | ||
// TODO: Why doesn't this enum work? "no overload matches this call" | ||
// size?: ".75em" | "1em" | "1.25em" | ||
size?: string | ||
} | ||
const TextComponent = styled.span<StyledProps>` | ||
font-family: "Source Code Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", | ||
"Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", | ||
"Helvetica Neue", sans-serif; | ||
font-size: ${(props) => props.size}; | ||
line-height: ${(props) => props.size}; | ||
size: unset; | ||
` | ||
|
||
type Props = { | ||
size?: "sm" | "md" | "lg" | ||
// TODO: Import Typography props as well? Or merge sx object? | ||
interface TextProps { | ||
size?: "sm" | "md" | "lg", | ||
children: ReactChild | ||
} | ||
export default function Text( | ||
props: React.PropsWithChildren<Props>, | ||
): ReactElement { | ||
const { size = "md", children } = props | ||
|
||
let sizeVal | ||
switch (size) { | ||
case "sm": | ||
sizeVal = ".75em" | ||
break | ||
case "md": | ||
sizeVal = "1em" | ||
break | ||
case "lg": | ||
sizeVal = "1.25em" | ||
break | ||
} | ||
const Text = ({ size = "md", children }: TextProps) => { | ||
const context = useThemeUI() | ||
const styles = get(context.theme, `text.${size}`) | ||
|
||
return <TextComponent size={sizeVal}>{children}</TextComponent> | ||
return <_Text sx={styles}>{ children }</_Text> | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** @jsxImportSource theme-ui */ | ||
import { Story, Meta } from "@storybook/react" | ||
|
||
import Button, { ButtonProps } from "../components/Button" | ||
|
||
export default { | ||
title: "Button", | ||
component: Button, | ||
parameters: { controls: { include: ['size', 'kind']}} | ||
} as Meta | ||
|
||
const Template: Story<ButtonProps> = (args) => ( | ||
<Button {...args}>Hello, World!</Button> | ||
) | ||
|
||
export const Default = Template.bind({}) | ||
|
||
export const Large = Template.bind({}) | ||
Large.args = { | ||
size: "lg" | ||
} | ||
|
||
export const Medium = Template.bind({}) | ||
Medium.args = { | ||
size: "md" | ||
} | ||
|
||
export const Small = Template.bind({}) | ||
Small.args = { | ||
size: "sm" | ||
} | ||
|
||
export const Primary = Template.bind({}) | ||
Primary.args = { | ||
kind: "primary" | ||
} | ||
|
||
export const Secondary = Template.bind({}) | ||
Secondary.args = { | ||
kind: "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 |
---|---|---|
@@ -1,25 +1,31 @@ | ||
// TODO: replace with styled-components | ||
// import "../styles/global.scss" | ||
/** @jsxImportSource theme-ui */ | ||
import { Story, Meta } from "@storybook/react" | ||
|
||
import React, { ReactElement } from "react" | ||
import Text, { TextProps } from "../components/Text" | ||
|
||
import Text from "../components/Text" | ||
export default { | ||
title: "Text", | ||
component: Text, | ||
parameters: { controls: { include: ['size']}} | ||
} as Meta | ||
|
||
export const TextStory = (): ReactElement => ( | ||
<> | ||
<div> | ||
<Text size="lg">Large Text</Text> | ||
</div> | ||
<div> | ||
<Text size="md">Medium Text (default)</Text> | ||
</div> | ||
<div> | ||
<Text size="sm">Small Text</Text> | ||
</div> | ||
</> | ||
const Template: Story<TextProps> = (args) => ( | ||
<Text {...args}>Hello, World!</Text> | ||
) | ||
|
||
export default { | ||
title: "Text", | ||
component: TextStory, | ||
export const Default = Template.bind({}) | ||
|
||
export const Large = Template.bind({}) | ||
Large.args = { | ||
size: "lg" | ||
} | ||
|
||
export const Medium = Template.bind({}) | ||
Medium.args = { | ||
size: "md" | ||
} | ||
|
||
export const Small = Template.bind({}) | ||
Small.args = { | ||
size: "sm" | ||
} |
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,12 @@ | ||
export default { | ||
fontSizes: [14, 18, 22], | ||
lineHeights: ['14px', '18px', '22px'], | ||
fonts: { | ||
serif: "serif", | ||
sansSerif: "sans-serif" | ||
}, | ||
colors: { | ||
primary: '#07c', | ||
secondary: '#0fa', | ||
} | ||
} |
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at chakra for some API inspiration https://chakra-ui.com/docs/theming/component-style#styling-single-part-components (scroll down a little for the button implementation)