-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from oaknational/feat/pupil-687/oak-pupil-jou…
…rney-subject-button Feat/pupil 687/oak pupil journey subject button
- Loading branch information
Showing
16 changed files
with
411 additions
and
1 deletion.
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
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
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
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
52 changes: 52 additions & 0 deletions
52
...nts/organisms/pupil/OakPupilJourneySubjectButton/OakPupilJourneySubjectButton.stories.tsx
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,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", | ||
}, | ||
}; |
37 changes: 37 additions & 0 deletions
37
...onents/organisms/pupil/OakPupilJourneySubjectButton/OakPupilJourneySubjectButton.test.tsx
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,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(); | ||
}); | ||
}); |
94 changes: 94 additions & 0 deletions
94
src/components/organisms/pupil/OakPupilJourneySubjectButton/OakPupilJourneySubjectButton.tsx
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,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} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.