Skip to content

Commit

Permalink
Merge pull request #158 from oaknational/feat/pupil-687/oak-pupil-jou…
Browse files Browse the repository at this point in the history
…rney-subject-button

Feat/pupil 687/oak pupil journey subject button
  • Loading branch information
kimon-satan authored May 7, 2024
2 parents 79326e7 + ec7fddf commit 7511bf3
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export type InternalShadowRectButtonProps = Omit<
| "$pa"
| "$ph"
| "$pv"
| "$pt"
| "$pb"
| "$ba"
| "$borderRadius"
| "$borderColor"
Expand Down Expand Up @@ -61,6 +63,8 @@ export type InternalShadowRectButtonProps = Omit<
pv?: SpacingStyleProps["$pv"];
ph?: SpacingStyleProps["$ph"];
font?: TypographyStyleProps["$font"];
innerWidth?: SizeStyleProps["$width"];
textAlign?: TypographyStyleProps["$textAlign"];
} & PositionStyleProps;

const StyledInternalButton = styled(InternalButton)<
Expand Down Expand Up @@ -151,6 +155,7 @@ export const InternalShadowRectButton = <C extends ElementType = "button">(
disabled,
width = "max-content",
maxWidth,
innerWidth,
defaultBackground,
defaultBorderColor,
defaultTextColor,
Expand All @@ -164,10 +169,13 @@ export const InternalShadowRectButton = <C extends ElementType = "button">(
hoverShadow = "drop-shadow-lemon",
pv = "inner-padding-s",
ph = "inner-padding-m",
pt,
pb,
iconLayout = "row",
iconGap = "space-between-ssx",
iconOverride,
font = "heading-7",
textAlign = "left",
...rest
} = props;

Expand Down Expand Up @@ -227,6 +235,8 @@ export const InternalShadowRectButton = <C extends ElementType = "button">(
$color={defaultTextColor}
$pv={pv}
$ph={ph}
$pt={pt}
$pb={pb}
$borderRadius={"border-radius-s"}
$position={"relative"}
disabled={disabled || isLoading}
Expand All @@ -248,9 +258,12 @@ export const InternalShadowRectButton = <C extends ElementType = "button">(
$alignItems={"center"}
$gap={iconGap}
$justifyContent="center"
$width={innerWidth}
>
{!isTrailingIcon && iconLogic}
<OakSpan $font={font}>{children}</OakSpan>
<OakSpan $font={font} $textAlign={textAlign}>
{children}
</OakSpan>
{isTrailingIcon && iconLogic}
</OakFlex>
</StyledInternalButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ exports[`InternalShadowRectButton matches snapshot 1`] = `
-moz-letter-spacing: 0.0115rem;
-ms-letter-spacing: 0.0115rem;
letter-spacing: 0.0115rem;
text-align: left;
}
.c8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ exports[`OakPrimaryButton matches snapshot 1`] = `
-moz-letter-spacing: 0.0115rem;
-ms-letter-spacing: 0.0115rem;
letter-spacing: 0.0115rem;
text-align: left;
}
.c8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ exports[`OakPrimaryInvertedButton matches snapshot 1`] = `
-moz-letter-spacing: 0.0115rem;
-ms-letter-spacing: 0.0115rem;
letter-spacing: 0.0115rem;
text-align: left;
}
.c8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ exports[`OakSecondaryButton matches snapshot 1`] = `
-moz-letter-spacing: 0.0115rem;
-ms-letter-spacing: 0.0115rem;
letter-spacing: 0.0115rem;
text-align: left;
}
.c8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ exports[`OakCookieBanner matches snapshot 1`] = `
-moz-letter-spacing: 0.0115rem;
-ms-letter-spacing: 0.0115rem;
letter-spacing: 0.0115rem;
text-align: left;
}
.c15 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ exports[`OakCookieConsent matches snapshot 1`] = `
-moz-letter-spacing: 0.0115rem;
-ms-letter-spacing: 0.0115rem;
letter-spacing: 0.0115rem;
text-align: left;
}
.c15 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ exports[`OakPrimaryNav matches snapshot 1`] = `
-moz-letter-spacing: 0.0115rem;
-ms-letter-spacing: 0.0115rem;
letter-spacing: 0.0115rem;
text-align: left;
}
.c2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ exports[`OakPrimaryNavItem matches snapshot 1`] = `
-moz-letter-spacing: 0.0115rem;
-ms-letter-spacing: 0.0115rem;
letter-spacing: 0.0115rem;
text-align: left;
}
.c3 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from "react";
import { StoryObj, Meta } from "@storybook/react";

import { OakPupilJourneySubjectButton } from "./OakPupilJourneySubjectButton";

const meta: Meta<typeof OakPupilJourneySubjectButton> = {
component: OakPupilJourneySubjectButton,
tags: ["autodocs"],
argTypes: {
phase: { control: { type: "radio" }, options: ["primary", "secondary"] },
subjectIconName: { control: { type: "text" } },
disabled: { control: { type: "boolean" } },
subjectText: { control: { type: "text" } },
},
parameters: {
controls: {
include: ["phase", "subjectIconName", "disabled", "subjectText"],
},
},
};

export default meta;

type Story = StoryObj<typeof OakPupilJourneySubjectButton>;

export const Default: Story = {
render: (args) => (
<OakPupilJourneySubjectButton {...args}>
{args.subjectText}
</OakPupilJourneySubjectButton>
),
args: {
phase: "primary",
subjectIconName: "subject-english",
disabled: false,
subjectText: "English",
},
};

export const Disabled: Story = {
render: (args) => (
<OakPupilJourneySubjectButton {...args}>
{args.subjectText}
</OakPupilJourneySubjectButton>
),
args: {
disabled: true,
subjectIconName: "subject-english",
phase: "primary",
subjectText: "English",
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from "react";
import "@testing-library/jest-dom";
import { create } from "react-test-renderer";

import { OakPupilJourneySubjectButton } from "./OakPupilJourneySubjectButton";

import renderWithTheme from "@/test-helpers/renderWithTheme";
import { OakThemeProvider } from "@/components/atoms";
import { oakDefaultTheme } from "@/styles";

describe("OakPupilJourneySubjectButton", () => {
it("renders", () => {
const { getByRole } = renderWithTheme(
<OakPupilJourneySubjectButton
phase="primary"
subjectIconName="subject-english"
>
English
</OakPupilJourneySubjectButton>,
);
expect(getByRole("button", { name: /English/ })).toBeInTheDocument();
});

it("matches snapshot", () => {
const tree = create(
<OakThemeProvider theme={oakDefaultTheme}>
<OakPupilJourneySubjectButton
phase="primary"
subjectIconName="subject-english"
>
English
</OakPupilJourneySubjectButton>
</OakThemeProvider>,
).toJSON();
expect(tree).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React, { ElementType } from "react";

import {
InternalShadowRectButton,
InternalShadowRectButtonProps,
} from "@/components/molecules/InternalShadowRectButton";
import { PolymorphicPropsWithoutRef } from "@/components/polymorphic";
import { OakIcon, OakIconName } from "@/components/atoms";

export type OakPupilJourneySubjectButtonProps = {
phase: "primary" | "secondary";
subjectIconName: OakIconName;
} & Omit<
InternalShadowRectButtonProps,
| "defaultBorderColor"
| "defaultBackground"
| "defaultTextColor"
| "hoverBackground"
| "hoverBorderColor"
| "hoverTextColor"
| "disabledBackground"
| "disabledBorderColor"
| "disabledTextColor"
| "pv"
| "ph"
| "font"
>;

/**
*
* A specific implementation of InternalRectButton
*
* Changes colour according to the phase prop. Can be used as a link or a button.
* The following callbacks are available for tracking focus events:
*
* ### onClick
* `onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;`
*
* ### onHovered
* `onHovered?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>, duration: number) => void;`<br>
* called after a mouseEnter and mouseLeave event has happened
*/

export const OakPupilJourneySubjectButton = <C extends ElementType = "button">({
phase,
element,
subjectIconName,
...rest
}: OakPupilJourneySubjectButtonProps & PolymorphicPropsWithoutRef<C>) => {
const defaultBackground =
phase === "primary"
? "bg-decorative4-very-subdued"
: "bg-decorative3-very-subdued";
const hoverBackground =
phase === "primary" ? "bg-decorative4-main" : "bg-decorative3-main";
const borderColor =
phase === "primary"
? "border-decorative4-stronger"
: "border-decorative3-stronger";

const iconOverride = (
<OakIcon
iconName={subjectIconName}
$minWidth={"all-spacing-12"}
$minHeight={"all-spacing-12"}
/>
);

return (
<InternalShadowRectButton
element={element ?? "button"}
iconOverride={iconOverride}
iconLayout="column"
iconGap={"space-between-sssx"}
pv={null}
pt={"inner-padding-s"}
pb={"inner-padding-xl"}
ph={"inner-padding-s"}
font={"heading-7"}
defaultBorderColor={borderColor}
defaultBackground={defaultBackground}
defaultTextColor="text-primary"
hoverBackground={hoverBackground}
hoverBorderColor={borderColor}
hoverTextColor="text-primary"
disabledBackground="bg-btn-secondary-disabled"
disabledBorderColor="border-neutral-lighter"
disabledTextColor="text-subdued"
textAlign={"center"}
innerWidth={"all-spacing-16"}
{...rest}
/>
);
};
Loading

0 comments on commit 7511bf3

Please sign in to comment.