Skip to content
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

[UI lib] Button, Link & ButtonLink components #7438

Merged
merged 38 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d72276d
migrate Link to use chakra
pettinarip Aug 1, 2022
e82c63d
fix footer link
pettinarip Aug 1, 2022
d40a004
remove active styles as we are not using them
pettinarip Aug 2, 2022
80ef4d0
fix typing issues
pettinarip Aug 2, 2022
ed06eb8
fix styles on wrapped Links
pettinarip Aug 11, 2022
e3f03e2
initial refactor of Buttons and ButtonLinks
pettinarip Aug 13, 2022
89dd33f
Merge branch 'dev' into chakra-buttonlink-component
pettinarip Aug 14, 2022
032a1bc
fix button styles
pettinarip Aug 15, 2022
321e53d
fix types
pettinarip Aug 15, 2022
bb06888
revert dir prop
pettinarip Aug 15, 2022
72b33f5
remove old comments
pettinarip Aug 15, 2022
416ee6a
remove constants file since it was causing an error in the build
pettinarip Aug 15, 2022
08bf701
enable chakra resetCSS flag
pettinarip Aug 15, 2022
4a473d2
implement button outline-color variant
pettinarip Aug 15, 2022
c23aa97
adopt design system colors
pettinarip Aug 15, 2022
575f4f2
Merge branch 'dev' into chakra-buttonlink-component
pettinarip Aug 16, 2022
8f8ae9b
fix intl links
pettinarip Aug 16, 2022
963a128
use existing variants
pettinarip Aug 16, 2022
11176a0
cleanup
pettinarip Aug 16, 2022
fbfe7a6
fix bad use of ButtonLink
pettinarip Aug 18, 2022
9fb65ff
use primaryHover color on primary shadow
pettinarip Aug 22, 2022
bffac7b
fix outline size as defined in the design sys
pettinarip Aug 22, 2022
017479c
more adjustments on button styles
pettinarip Aug 22, 2022
921889c
fix social buttons in footer
pettinarip Aug 22, 2022
7911694
use new chakra button in buttondropdown
pettinarip Aug 22, 2022
0c96ebb
refactor comments
pettinarip Aug 23, 2022
07ccf07
update migration guide
pettinarip Aug 23, 2022
e81291e
change outline bg color to transparent
pettinarip Aug 25, 2022
da1e20c
fix red color name
pettinarip Aug 29, 2022
0d718ea
add margins on the arrow icon for external links
pettinarip Aug 29, 2022
9365546
add scale animation on glossary icon
pettinarip Aug 29, 2022
23d6bf1
change focus styles on Links
pettinarip Aug 30, 2022
8102b6e
fix action card outline on focus
pettinarip Aug 30, 2022
32b69e4
Merge branch 'dev' into chakra-buttonlink-component
pettinarip Aug 30, 2022
6008fbe
fix old style prop name
pettinarip Aug 30, 2022
5a40de1
set link outline styles as auto
pettinarip Aug 31, 2022
3372f93
tmp fix on header anchors styles
pettinarip Aug 31, 2022
d1855b4
revert hidden outline in ActionCard
pettinarip Aug 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gatsby-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const config: GatsbyConfig = {
{
resolve: "@chakra-ui/gatsby-plugin",
options: {
resetCSS: false,
resetCSS: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have enabled the reset from Chakra. It does seem to be working fine so far. I haven't seen any conflict yet.

isUsingColorMode: true,
},
},
Expand Down
46 changes: 46 additions & 0 deletions src/@chakra-ui/gatsby-plugin/components/Button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { ComponentStyleConfig } from "@chakra-ui/theme"

export const Button: ComponentStyleConfig = {
baseStyle: {
fontWeight: "normal",
borderRadius: "base",
_hover: {
textDecoration: "none",
boxShadow: "primary",
},
},
sizes: {
md: {
h: 42,
},
},
variants: {
// solid is the default variant used by chakra
solid: {
color: "buttonColor",
bg: "primary",
border: 0,
_hover: {
bg: "primary",
opacity: 0.8,
},
_active: {
bg: "primaryActive",
},
},
outline: {
color: "text",
bg: "transparent",
borderColor: "text",
_hover: {
color: "primary",
bg: "transparent",
border: "1px",
borderColor: "primary",
},
_active: {
bg: "secondaryButtonBackgroundActive",
},
},
},
}
8 changes: 8 additions & 0 deletions src/@chakra-ui/gatsby-plugin/components/Link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { ComponentStyleConfig } from "@chakra-ui/theme"

export const Link: ComponentStyleConfig = {
baseStyle: {
color: "primary",
textDecoration: "underline",
},
}
2 changes: 2 additions & 0 deletions src/@chakra-ui/gatsby-plugin/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Link"
export * from "./Button"
11 changes: 11 additions & 0 deletions src/@chakra-ui/gatsby-plugin/foundations/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import colors from "./colors"
import shadows from "./shadows"

const foundations = {
// breakpoints,
// zIndices,
// radii,
// blur,
colors,
// ...typography,
// sizes,
shadows,
// space: spacing,
// borders,
// transition,
}

export default foundations
6 changes: 6 additions & 0 deletions src/@chakra-ui/gatsby-plugin/foundations/shadows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const shadows = {
// using css variables bc shadows do not support color tokens yet
primary: `4px 4px 0px 0px var(--eth-colors-primaryLight)`,
}

export default shadows
2 changes: 1 addition & 1 deletion src/@chakra-ui/gatsby-plugin/semanticTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const semanticTokens = {

// Design System colors
primary: { _light: "blue.500", _dark: "orange.500" },
primaryLight: { _light: "blue.100", _dark: "orange.100" },
primaryDark: { _light: "blue.700", _dark: "orange.800" },
primaryHover: { _light: "blue.300", _dark: "orange.300" },
primaryLight: { _light: "blue.100", _dark: "orange.100"},
body: { _light: "grey.700", _dark: "grey.100" },
bodyLight: { _light: "grey.500", _dark: "grey.100" },
disabled: { _light: "grey.300", _dark: "grey.500" },
Expand Down
4 changes: 4 additions & 0 deletions src/@chakra-ui/gatsby-plugin/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import styles from "./styles"
// Foundational style overrides
import foundations from "./foundations"

// Component style overrides
import * as components from "./components"

import semanticTokens from "./semanticTokens"

const config: ThemeConfig = {
Expand All @@ -23,6 +26,7 @@ const theme: ThemeOverride = {
styles,
...foundations,
semanticTokens,
components,
}

export default extendTheme(theme)
1 change: 1 addition & 0 deletions src/components/ActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const Card = styled(Link)`

&:hover,
&:focus {
text-decoration: none;
border-radius: 4px;
box-shadow: 0px 8px 17px rgba(0, 0, 0, 0.15);
background: ${(props) => props.theme.colors.tableBackgroundHover};
Expand Down
4 changes: 2 additions & 2 deletions src/components/BeaconChainActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const BeaconChainActions: React.FC = () => {
<StyledButtonLink to="https://launchpad.ethereum.org">
<Translation id="get-started" />
</StyledButtonLink>
<ButtonLink isSecondary to="/staking/">
<ButtonLink variant="outline" to="/staking/">
<Translation id="page-upgrades-index-staking-learn" />
</ButtonLink>
</StyledCardLeft>
Expand All @@ -168,7 +168,7 @@ const BeaconChainActions: React.FC = () => {
intl
)}
>
<ButtonLink isSecondary to="/upgrades/get-involved/">
<ButtonLink variant="outline" to="/upgrades/get-involved/">
<Translation id="consensus-run-beacon-chain" />
</ButtonLink>
</StyledCardRight>
Expand Down
1 change: 1 addition & 0 deletions src/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const CrumbLink = styled(Link)`
color: ${(props) => props.theme.colors.textTableOfContents};

&:hover {
text-decoration: none;
color: ${(props) => props.theme.colors.primary};
}

Expand Down
26 changes: 26 additions & 0 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react"
import { Button as ChakraButton, ButtonProps } from "@chakra-ui/react"

import { scrollIntoView } from "../utils/scrollIntoView"

export interface IProps extends ButtonProps {
toId?: string
}

const Button: React.FC<IProps> = ({ toId, children, ...props }) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm calling this component Button bc it is the same Chakra button but with the scrolling feature. This way, you will just use this button component in the codebase.

import Button from 'components/Button'

On the other hand, we could break them out by calling this component ButtonScroll and using it only where we need to use the auto-scrolling.

import ButtonScroll from 'components/ButtonScroll'

// for the rest, we use the native chakra button
import Button from 'chakra/Button'

I just wanted to check if you have a preference.

const handleOnClick = () => {
if (!toId) {
return
}

scrollIntoView(toId)
}

return (
<ChakraButton onClick={handleOnClick} {...props}>
{children}
</ChakraButton>
)
}

export default Button
1 change: 1 addition & 0 deletions src/components/ButtonDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const NavLink = styled(Link)`
padding: 0.5rem;
color: ${(props) => props.theme.colors.text};
&:hover {
text-decoration: none;
color: ${(props) => props.theme.colors.primary};
}
`
Expand Down
122 changes: 7 additions & 115 deletions src/components/ButtonLink.tsx
Original file line number Diff line number Diff line change
@@ -1,123 +1,15 @@
import React from "react"
import styled from "@emotion/styled"
import { margin, MarginProps } from "styled-system"
import { Button, ButtonProps } from "@chakra-ui/react"

import { scrollIntoView } from "../utils/scrollIntoView"
import Link, { IBaseProps as ILinkProps } from "./Link"

import Link, { IProps as ILinkProps } from "./Link"
export interface IProps extends ILinkProps, ButtonProps {}

const buttonStyling = `
text-decoration: none;
display: inline-block;
padding: 0.5rem 0.75rem;
font-size: 1rem;
border-radius: 0.25em;
text-align: center;
cursor: pointer;
${margin}
`

const StyledLinkButton = styled(Link)`
${buttonStyling}
`

const StyledScrollButton = styled.button`
${buttonStyling}
`

const PrimaryLink = styled(StyledLinkButton)`
background-color: ${(props) => props.theme.colors.primary};
color: ${(props) => props.theme.colors.buttonColor} !important;
border: 1px solid transparent;

&:hover {
background-color: ${(props) => props.theme.colors.primaryHover};
box-shadow: ${(props) => props.theme.colors.cardBoxShadow};
}
&:active {
background-color: ${(props) => props.theme.colors.primaryActive};
}
`

const SecondaryLink = styled(StyledLinkButton)`
color: ${(props) => props.theme.colors.text};
border: 1px solid ${(props) => props.theme.colors.text};
background-color: transparent;

&:hover {
color: ${(props) => props.theme.colors.primary};
border: 1px solid ${(props) => props.theme.colors.primary};
box-shadow: ${(props) => props.theme.colors.cardBoxShadow};
}
&:active {
background-color: ${(props) =>
props.theme.colors.secondaryButtonBackgroundActive};
}
`

const PrimaryScrollLink = styled(StyledScrollButton)`
color: ${(props) => props.theme.colors.buttonColor} !important;
background-color: ${(props) => props.theme.colors.primary};
border: 1px solid transparent;

&:hover {
background-color: ${(props) => props.theme.colors.primaryHover};
box-shadow: ${(props) => props.theme.colors.cardBoxShadow};
}
&:active {
background-color: ${(props) => props.theme.colors.primaryActive};
}
`

const SecondaryScrollLink = styled(StyledScrollButton)`
color: ${(props) => props.theme.colors.text};
border: 1px solid ${(props) => props.theme.colors.text};
background-color: transparent;

&:hover {
color: ${(props) => props.theme.colors.primary};
border: 1px solid ${(props) => props.theme.colors.primary};
box-shadow: ${(props) => props.theme.colors.cardBoxShadow};
}
&:active {
background-color: ${(props) =>
props.theme.colors.secondaryButtonBackgroundActive};
}
`

export interface IProps extends ILinkProps, MarginProps {
toId?: string
isSecondary?: boolean
}

const ButtonLink: React.FC<IProps> = ({
to,
toId,
isSecondary,
children,
className,
hideArrow = false,
...props
}) => {
const handleOnClick = () => {
if (!toId) {
return
}

scrollIntoView(toId)
}

const Link = isSecondary ? SecondaryLink : PrimaryLink
const ScrollLink = isSecondary ? SecondaryScrollLink : PrimaryScrollLink

return to ? (
<Link to={to} hideArrow={hideArrow} className={className} {...props}>
{children}
</Link>
) : (
<ScrollLink onClick={handleOnClick} className={className} {...props}>
const ButtonLink: React.FC<IProps> = ({ children, ...props }) => {
return (
<Button as={Link} textDecoration="none" {...props}>
{children}
</ScrollLink>
</Button>
)
}

Expand Down
1 change: 1 addition & 0 deletions src/components/CardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const ItemLink = styled(Link)`
width: 100%;
color: #000000;
&:hover {
text-decoration: none;
border-radius: 4px;
box-shadow: 0 0 1px ${(props) => props.theme.colors.primary};
background: ${(props) => props.theme.colors.tableBackgroundHover};
Expand Down
1 change: 1 addition & 0 deletions src/components/DataProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Card = styled(Link)`
border: 1px solid ${(props) => props.theme.colors.lightBorder};
text-decoration: none;
&:hover {
text-decoration: none;
box-shadow: ${(props) => props.theme.colors.tableBoxShadow};
background: ${(props) => props.theme.colors.tableBackgroundHover};
transition: transform 0.1s;
Expand Down
1 change: 1 addition & 0 deletions src/components/DocLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Container = styled(Link)<{ isExternal: boolean }>`
color: ${({ theme }) => theme.colors.text};
border: 1px solid ${({ theme }) => theme.colors.border};
&:hover {
text-decoration: none;
box-shadow: 0 0 1px ${({ theme }) => theme.colors.primary};
background: ${({ theme }) => theme.colors.tableBackgroundHover};
border-radius: 4px;
Expand Down
Loading