diff --git a/package-lock.json b/package-lock.json index 9104539a..ba66de41 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@oaknational/oak-components", - "version": "1.11.0", + "version": "1.12.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@oaknational/oak-components", - "version": "1.11.0", + "version": "1.12.2", "dependencies": { "@storybook/test": "^8.1.0" }, diff --git a/package.json b/package.json index 477c3601..60408c76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oaknational/oak-components", - "version": "1.11.0", + "version": "1.12.2", "licence": "MIT", "description": "Shared components for Oak applications", "main": "dist/cjs/index.js", diff --git a/src/components/organisms/pupil/OakLessonLayout/OakLessonLayout.stories.tsx b/src/components/organisms/pupil/OakLessonLayout/OakLessonLayout.stories.tsx index f2fda86a..5de7a634 100644 --- a/src/components/organisms/pupil/OakLessonLayout/OakLessonLayout.stories.tsx +++ b/src/components/organisms/pupil/OakLessonLayout/OakLessonLayout.stories.tsx @@ -5,7 +5,11 @@ import { OakLessonTopNav } from "../OakLessonTopNav"; import { OakLessonBottomNav } from "../OakLessonBottomNav"; import { OakQuizCounter } from "../OakQuizCounter"; -import { OakLessonLayout, OakLessonLayoutProps } from "./OakLessonLayout"; +import { + OakLessonLayout, + OakLessonLayoutProps, + lessonSectionNames, +} from "./OakLessonLayout"; import { OakBackLink, OakPrimaryButton } from "@/components/molecules"; import { OakBox } from "@/components/atoms"; @@ -15,14 +19,28 @@ const meta: Meta = { tags: ["autodocs"], title: "components/organisms/pupil/OakLessonLayout", decorators: [(Story) => ], + argTypes: { + lessonSectionName: { + options: [...lessonSectionNames], + control: { type: "radio" }, + }, + phase: { + options: ["primary", "secondary"], + control: { type: "radio" }, + }, + celebrate: { + control: { type: "boolean" }, + }, + }, parameters: { controls: { - include: ["lessonSectionName"], + include: ["lessonSectionName", "celebrate", "phase"], }, layout: "fullscreen", }, args: { - lessonSectionName: "intro", + lessonSectionName: lessonSectionNames[0], + celebrate: false, }, }; export default meta; diff --git a/src/components/organisms/pupil/OakLessonLayout/OakLessonLayout.tsx b/src/components/organisms/pupil/OakLessonLayout/OakLessonLayout.tsx index 2ecb158e..44b71dcf 100644 --- a/src/components/organisms/pupil/OakLessonLayout/OakLessonLayout.tsx +++ b/src/components/organisms/pupil/OakLessonLayout/OakLessonLayout.tsx @@ -1,22 +1,30 @@ import React, { ReactNode } from "react"; -import styled from "styled-components"; +import styled, { css } from "styled-components"; import { OakBox, OakFlex } from "@/components/atoms"; import { parseSpacing } from "@/styles/helpers/parseSpacing"; import { getBreakpoint } from "@/styles/utils/responsiveStyle"; import { OakCombinedColorToken, oakDefaultTheme } from "@/styles"; +import { backgrounds } from "@/image-map"; import { parseColor } from "@/styles/helpers/parseColor"; -type LessonSectionName = - | "overview" - | "intro" - | "starter-quiz" - | "video" - | "exit-quiz" - | "review"; +export const lessonSectionNames: string[] = [ + "overview", + "intro", + "starter-quiz", + "video", + "exit-quiz", + "review", +]; + +export type LessonSectionName = (typeof lessonSectionNames)[number]; + +type Phase = "primary" | "secondary"; export type OakLessonLayoutProps = { lessonSectionName: LessonSectionName; + phase?: Phase; + celebrate?: boolean; topNavSlot: ReactNode; bottomNavSlot: ReactNode; children: ReactNode; @@ -26,10 +34,26 @@ export type OakLessonLayoutProps = { * `OakBox` does not support space-between tokens on `padding` only `margin`, so we need to * set it here to apply appropriate padding to the top of the content. */ -const StyledLayoutBox = styled(OakBox)` +const StyledLayoutBox = styled(OakBox)<{ + sectionName: LessonSectionName; + phase: Phase; + celebrate: boolean; +}>` @media (min-width: ${getBreakpoint("small")}px) { padding-top: ${parseSpacing("space-between-xl")}; } + @media (min-width: ${getBreakpoint("large")}px) { + ${(props) => css` + ${getBackgroundUrlForLesson( + props.sectionName, + props.phase, + props.celebrate, + )} + `} + background-repeat: no-repeat; + background-position-x: center; + background-size: 100%; + } `; const StickyFooter = styled(OakBox)` @@ -43,6 +67,8 @@ const StickyFooter = styled(OakBox)` */ export const OakLessonLayout = ({ lessonSectionName, + phase = "primary", + celebrate = false, topNavSlot, bottomNavSlot, children, @@ -52,7 +78,7 @@ export const OakLessonLayout = ({ contentBackgroundColor, contentBorderColor, mobileContentBackgroundColor, - ] = pickSectionColours(lessonSectionName); + ] = pickSectionColours(lessonSectionName, phase); return ( ; const StyledMobileSummary = styled(OakSpan)` @media (min-width: ${getBreakpoint("small")}px) { @@ -20,7 +22,7 @@ const StyledMobileSummary = styled(OakSpan)` `; export type OakLessonTopNavProps = { - lessonSectionName: LessonSectionName; + lessonSectionName: LessonTopNavSectionName; /** * Slot to render `OakBackLink` or similar */ @@ -75,7 +77,7 @@ export const OakLessonTopNav = ({ }; function pickSectionIcon( - sectionName: LessonSectionName, + sectionName: LessonTopNavSectionName, ): Pick { switch (sectionName) { case "intro": @@ -98,5 +100,10 @@ function pickSectionIcon( iconName: "quiz", $background: "lemon110", }; + default: + return { + iconName: "intro", + $background: "aqua110", + }; } } diff --git a/src/image-map.ts b/src/image-map.ts index e1b895a3..c8aa1373 100644 --- a/src/image-map.ts +++ b/src/image-map.ts @@ -120,6 +120,13 @@ export const backgrounds = { "confetti-pink": "pupil-journey/confetti-pink.svg", "confetti-lavender": "pupil-journey/confetti-lavender.svg", "confetti-mint": "pupil-journey/confetti-mint.svg", + "lesson-confetti-green": "pupil-journey/lesson/lesson-confetti-green.svg", + "lesson-confetti-mint": "pupil-journey/lesson/lesson-confetti-mint.svg", + "lesson-confetti-pink": "pupil-journey/lesson/lesson-confetti-pink.svg", + "lesson-confetti-green-lemon": + "pupil-journey/lesson/lesson-confetti-green-lemon.svg", + "lesson-confetti-lavender": + "pupil-journey/lesson/lesson-confetti-lavender.svg", "line-pink": "pupil-journey/line-pink.svg", "line-lavender": "pupil-journey/line-lavender.svg", "line-mint": "pupil-journey/line-mint.svg",