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

[SCSE-187] Override Chakra UI Button base styles #76

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
63 changes: 24 additions & 39 deletions apps/web/__tests__/__snapshots__/index.snapshot.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,26 @@ exports[`renders homepage unchanged 1`] = `
<div
class="chakra-stack css-md5zo3"
>
<button
class="chakra-button css-ik4ihr"
type="button"
<a
class="chakra-button css-jd3l4b"
href="/events"
>
<a
class="chakra-link css-13jvj27"
href="/events"
<p
class="chakra-text css-0"
>
<p
class="chakra-text css-0"
>
LEARN MORE
</p>
</a>
</button>
<button
class="chakra-button css-1bittrd"
type="button"
LEARN MORE
</p>
</a>
<a
class="chakra-button css-jd3l4b"
href="/contact"
>
<a
class="chakra-link css-13jvj27"
href="/contact"
<p
class="chakra-text css-0"
>
<p
class="chakra-text css-0"
>
CONTACT US
</p>
</a>
</button>
CONTACT US
</p>
</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -162,21 +152,16 @@ exports[`renders homepage unchanged 1`] = `
>
Let’s work together
</h2>
<button
class="chakra-button css-2nck4"
type="button"
<a
class="chakra-button css-qklkzv"
href="./contact"
>
<a
class="chakra-link css-13jvj27"
href="./contact"
<p
class="chakra-text css-0"
>
<p
class="chakra-text css-0"
>
Contact Us
</p>
</a>
</button>
Contact Us
</p>
</a>
</div>
<span
hidden=""
Expand Down
2 changes: 1 addition & 1 deletion apps/web/cypress/e2e/app.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Navigation", () => {
cy.get('[role="heading"]').contains("WELCOME TO SCSE CLUB");

// Find a button with a href attribute containing "contact" and click it
cy.get('button a[href*="contact"]').first().click();
cy.get('a[class*="chakra-button"][href*="contact"]').first().click();

// The new url should include "/contact"
cy.url().should("include", "/contact");
Expand Down
10 changes: 6 additions & 4 deletions apps/web/pages/academics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, FooterContentText, FooterContentTextProps, Hero } from "ui";
import { ButtonLink, FooterContentText, FooterContentTextProps, Hero } from "ui";
import { Box, Heading, Text, VStack, Grid, GridItem } from "@chakra-ui/react";
import Image from "next/image";

Expand Down Expand Up @@ -44,17 +44,19 @@ const Academics = () => {
width={{ base: "100%", md: "auto" }}
>
<GridItem>
<Button
<ButtonLink
label="PYP QUESTIONS"
href="https://ts.ntu.edu.sg/sites/lib-repository/exam-question-papers/_layouts/15/start.aspx#/Shared%20Documents/Forms/AllItems.aspx"
width={{ base: "100%", md: "auto" }}
size="lg"
/>
</GridItem>
<GridItem>
<Button
<ButtonLink
label="PYP SOLUTIONS"
href="https://bit.ly/3CDVXlf"
buttonType="primary.black"
variant="primary-black"
size="lg"
width={{ base: "100%", md: "auto" }}
/>
</GridItem>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const Home = ({ posts }: HomeProps) => {
{
label: "LEARN MORE",
href: "/events",
buttonType: "primary.blue",
variant: "primary-blue",
},
{
label: "CONTACT US",
href: "/contact",
buttonType: "primary.black",
variant: "primary-black",
},
],
};
Expand Down
64 changes: 0 additions & 64 deletions packages/ui/components/button/Button.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import React from "react";
import { ComponentStory, ComponentMeta } from "@storybook/react";

import { Button } from "./Button";
import { ButtonLink } from "./ButtonLink";

export default {
title: "Components/Button",
component: Button,
title: "Components/ButtonLink",
component: ButtonLink,
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {},
} as ComponentMeta<typeof Button>;
} as ComponentMeta<typeof ButtonLink>;

const Template: ComponentStory<typeof Button> = (args) => <Button {...args} />;
const Template: ComponentStory<typeof ButtonLink> = (args) => <ButtonLink {...args} />;

export const PrimaryBlue = Template.bind({});
PrimaryBlue.args = {
label: "CLICK ME",
href: "#",
size: "lg",
buttonType: "primary.blue",
variant: "primary-blue",
};

export const PrimaryBlack = Template.bind({});
PrimaryBlack.args = {
label: "CLICK ME",
href: "#",
size: "lg",
buttonType: "primary.black",
variant: "primary-black",
};
21 changes: 21 additions & 0 deletions packages/ui/components/button/ButtonLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Button, Text } from "@chakra-ui/react";
import { HTMLChakraProps, ThemingProps } from "@chakra-ui/system";
import { ButtonOptions } from "@chakra-ui/button";

export interface ButtonLinkProps
extends HTMLChakraProps<"button">,
ButtonOptions,
ThemingProps<"Button"> {
label: string;
href: string;
variant?: "primary-blue" | "primary-black";
}

export const ButtonLink = (props: ButtonLinkProps) => {
const { label, href, variant='primary-blue', ...buttonProps } = props
return (
<Button as='a' variant={variant} href={href} {...buttonProps}>
<Text>{ label }</Text>
</Button>
)
}
4 changes: 2 additions & 2 deletions packages/ui/components/button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Button } from "./Button";
export type { ButtonProps } from "./Button";
export { ButtonLink } from "./ButtonLink";
export type { ButtonLinkProps } from "./ButtonLink";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { VStack, Heading } from "@chakra-ui/react";
import { Button } from "ui";
import { ButtonLink } from "ui";

export interface FooterContentButtonProps {
href: string;
Expand All @@ -26,7 +26,7 @@ export const FooterContentButton = ({
>
{title}
</Heading>
<Button textTransform="uppercase" label={label} href={href} />
<ButtonLink textTransform="uppercase" label={label} href={href} />
</VStack>
);
};
10 changes: 5 additions & 5 deletions packages/ui/components/hero/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
FlexProps,
TextProps,
} from "@chakra-ui/react";
import { Button, ButtonProps } from "ui";
import { ButtonLink, ButtonLinkProps } from "ui";

export interface HeroProps extends FlexProps {
backgroundImage: string;
backgroundGradient?: string;
buttons?: Array<ButtonProps>;
buttons?: Array<ButtonLinkProps>;
text?: string;
textProps?: TextProps;
}
Expand Down Expand Up @@ -70,13 +70,13 @@ export const Hero = ({
justify="center"
>
{buttons?.map((button) => {
const { label, href, buttonType, ...buttonProps } = button;
const { label, href, variant, ...buttonProps } = button;
return (
<Button
<ButtonLink
key={label}
label={label}
href={href}
buttonType={buttonType}
variant={variant}
size="lg"
width={{ base: "100%", md: "auto" }}
{...buttonProps}
Expand Down
33 changes: 29 additions & 4 deletions packages/ui/theme/components/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,41 @@ import { defineStyleConfig } from "@chakra-ui/react";

const Button = defineStyleConfig({
// Styles for the base style
baseStyle: {},
baseStyle: {
fontWeight: 'bold',
rounded: 'none',
textColor: 'white',
_hover:
{
bg: 'white',
color: 'black',
textDecoration: 'none'
}
},

// Styles for the size variations
sizes: {},
sizes: {
lg: {
px: '58px',
py: '32px',
}
},

// Styles for the visual style variations
variants: {},
variants: {
'primary-blue': {
bg: 'brand.blue',
},
'primary-black': {
bg: 'black',
}
},

// The default `size` or `variant` values
defaultProps: {},
defaultProps: {
variant: 'primary-blue',
size: 'lg'
},
});

export default Button;