diff --git a/.gitignore b/.gitignore index 354fe60fa..3bde20174 100644 --- a/.gitignore +++ b/.gitignore @@ -25,8 +25,11 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +checklist.md + .idea .vscode +.src-old # testing /coverage @@ -34,3 +37,4 @@ yarn-error.log* /test-results/ /playwright-report/ /playwright/.cache/ + diff --git a/.nvmrc b/.nvmrc index 9e15be387..6bb900519 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v16.20.0 +v22.22.3 diff --git a/README.md b/README.md index 4767a06ab..18922a478 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,22 @@ -Comic Relief React Component Library + +Comic Relief Component Library -------------- [![GitHub Actions](https://github.com/comicrelief/component-library/actions/workflows/main.yml/badge.svg)](https://github.com/comicrelief/component-library/actions) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) -React components to be shared across Comic Relief applications +### Recent Rebuild Notes (June 2026): +- No more markdown importing Javascript faff in example files, just simple React component examples. +- Only exception is the code examples visible below each of the components - they are built using a Vite-specific import feature: +```import buttonExampleSrc from '../components/Atoms/Button/ButtonExample.jsx?raw';``` +- Styled-Components 5 => Styled Components 6 - slight syntax change. Previously usage of nested selector / "&" usage in nested CSS was assumed. It now needs to be explicit (like normal native CSS). +- Removed _TriggerConfetti.js file. I couldn't find any usage, was likely a private helper no longer needed. -### Use -CR-CL has a dependency of Styled-components. +### General Usage +#### Main Dependencies +- Vite +- Styled Components #### Install the package ``` @@ -35,7 +43,7 @@ $ yarn install To start the dev build and server: ``` -$ yarn styleguide +$ yarn dev ``` To test: diff --git a/babel.config.js b/babel.config.js index 0f8518bde..befa8ee62 100644 --- a/babel.config.js +++ b/babel.config.js @@ -2,10 +2,12 @@ module.exports = function (api) { api.cache(true); - const presets = [['react-app', { absoluteRuntime: false }]]; + const presets = [ + ['@babel/preset-env', { targets: { node: 'current' } }], + ['@babel/preset-react', { runtime: 'automatic' }] + ]; const plugins = [ - ['babel-plugin-styled-components'], - ['import', { libraryName: 'lodash', libraryDirectory: '', camel2DashComponentName: false }] + ['babel-plugin-styled-components'] ]; return { diff --git a/docs/installation.md b/docs/installation.md deleted file mode 100644 index d7669703f..000000000 --- a/docs/installation.md +++ /dev/null @@ -1,12 +0,0 @@ -### How to use components - -CR-CL has a dependency of Styled-components. - -#### Install the package -`yarn add @comicrelief/component-library` - -#### Wrap your app with the ThemeProvider and crTheme -`import { ThemeProvider, crTheme } from '@comicrelief/component-library';` - -#### Import components -`import { HeroBanner } from '@comicrelief/component-library';` diff --git a/docs/introduction.md b/docs/introduction.md deleted file mode 100644 index 30fa5407e..000000000 --- a/docs/introduction.md +++ /dev/null @@ -1,3 +0,0 @@ -## Comic Relief React Component Library - -This component library is build using styleguidist, documenting the layouts, design patterns and components used across our sites and products. \ No newline at end of file diff --git a/docs/utils.md b/docs/utils.md deleted file mode 100644 index 28306c26c..000000000 --- a/docs/utils.md +++ /dev/null @@ -1,71 +0,0 @@ -## hideVisually - -`import { hideVisually } from '@comicrelief/component-library';` - -How to use in your styled component -`export const Component = styled.span'${hideVisually};';` - -## allowListed - -`import { allowListed } from '@comicrelief/component-library';` - -`allowListed(url)` - -Check if a url is allowListed. Used to check links and change link target. - -## zIndex - -`import { zIndex } from '@comicrelief/component-library';` - -How to use in your styled component -`export const Component = styled.span'${zIndex('high')};';` - -## spacing - -`import { spacing } from '@comicrelief/component-library';` - -Default spacing scale - -| Name | Size | -| :--- | :-----: | -| none | 0 | -| xsm | 0.25rem | -| sm | 0.25rem | -| md | 1rem | -| l | 2rem | -| xl | 4rem | -| xxl | 8rem | -| xxxl | 16rem | - -How to use in your styled component: - -`padding: ${spacing('md)'} ${spacing('l)'};';` - -## allBreakpoints, and { breakpointValues } within allBreakpoints - -| S | M | L | Nav | XL | -|:----:|------:| ------:| -----:| ------:| -| 0 | 740 | 1024 | 1150 | 1440 | - -## Usage within Component Library itself -#### media queries (no need to import): -`@media ${({ theme }) => theme.allBreakpoints('M')} {` - -### screen sizes: -`import { breakpointValues } from '../../../theme/shared/allBreakpoints';` - -`max-width: ${breakpointValues.M}px;` - -### Usage within Component Library: -`import { breakpointValues } from '@comicrelief/component-library/src/theme/shared/allBreakpoints';` - -`max-width: ${breakpointValues.M}px);` - - -## containers from containers.js -| small | medium | large | -|:-------:|--------:| ------:| -| 800px | 1200px | 1440px | - -### Note: These are used in a max-width context: -`max-width: ${containers.small}` diff --git a/index.html b/index.html new file mode 100644 index 000000000..9ffc7a842 --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + + + + + Component Library + + +
+ + + diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 000000000..5837d6ece --- /dev/null +++ b/netlify.toml @@ -0,0 +1,7 @@ +[build] + command = "yarn build:preview" + publish = "dist" + +[build.environment] + NODE_VERSION = "22" + diff --git a/package.json b/package.json index 29a983c99..282030a96 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,19 @@ "name": "@comicrelief/component-library", "author": "Comic Relief Engineering Team", "version": "0.0.0-see.readme.for.semantic.release.process", - "main": "dist/index.js", + "main": "dist/index.cjs.js", + "module": "dist/index.es.js", + "files": [ + "dist" + ], "license": "ISC", + "repository": { + "type": "git", + "url": "https://github.com/comicrelief/component-library.git" + }, "jest": { "verbose": true, + "testEnvironment": "jsdom", "testPathIgnorePatterns": [ "/playwright/", "/dist/", @@ -16,93 +25,76 @@ "^axios$": "axios/dist/node/axios.cjs" } }, - "module": "dist/index.js", - "repository": { - "type": "git", - "url": "https://github.com/comicrelief/component-library.git" + "scripts": { + "dev": "vite", + "build": "vite build", + "build:preview": "vite build --config vite.preview.config.mjs", + "preview": "vite preview", + "test:unit": "jest", + "test:unit:update": "jest -u", + "serve:preview": "vite preview --config vite.preview.config.mjs --port 4173", + "test:e2e": "playwright test --project=chromium", + "test:e2e--h": "playwright test --project=chromium --headed", + "test:e2e:ci": "playwright test --project=chromium", + "test:e2e:local": "playwright test --project=chromium; yarn playwright show-report", + "test:e2e:mac": "playwright test --project=chromium; yarn playwright show-report", + "test:e2e:mac:atoms": "playwright test playwright/components/atoms --project=chromium; yarn playwright show-report", + "test:e2e:mac:molecules": "playwright test playwright/components/molecules --project=chromium; yarn playwright show-report", + "test:e2e:mac:organisms": "playwright test playwright/components/organisms --project=chromium; yarn playwright show-report", + "test:e2e:mac:organisms:emailSignUpForm": "playwright test playwright/components/organisms/emailSignUpForm.spec.js --project=chromium; yarn playwright show-report", + "lint": "eslint src", + "lint-fix": "yarn lint --fix" + }, + "peerDependencies": { + "react": ">=18", + "react-dom": ">=18", + "styled-components": ">=6" }, "dependencies": { - "@babel/cli": "^7.21.5", "@hookform/resolvers": "^3.9.0", "@splidejs/react-splide": "^0.7.12", - "axios": "^1.7.2", - "babel-plugin-import": "^1.13.8", + "axios": "^1.7.7", "lazysizes": "^5.3.2", - "lodash": "^4.17.11", - "moment": "^2.29.4", + "lodash": "^4.17.21", + "moment": "^2.30.1", "prop-types": "^15.8.1", - "pure-react-carousel": "1.30.1", - "react": "^17.0.2", - "react-canvas-confetti": "^1.4.0", + "pure-react-carousel": "^1.30.1", + "react-canvas-confetti": "^2.0.7", "react-currency-format": "^1.1.0", - "react-dom": "^17.0.2", - "react-hook-form": "^7.52.1", + "react-hook-form": "^7.53.2", "react-modal": "^3.16.1", "react-range-slider-input": "^3.0.7", - "react-responsive": "^9.0.2", - "react-scripts": "4.0.3", - "react-spinners": "^0.11.0", + "react-responsive": "^10.0.0", + "react-spinners": "^0.14.1", "react-uid": "^2.3.3", - "styled-components": "^5.3.11", "youtube-player": "^5.6.0", "yup": "^1.4.0" }, - "resolutions": { - "react-scripts/workbox-webpack-plugin/workbox-build/@surma/rollup-plugin-off-main-thread/ejs": "3.1.10", - "loader-utils": "2.0.3", - "unset-value": "2.0.1", - "shell-quote": "1.7.3", - "ansi-html": "0.0.9", - "semver": "7.5.2", - "braces": "3.0.3", - "node-forge": "1.3.2", - "nth-check": "2.0.1" - }, - "scripts": { - "build": "rm -rf dist && NODE_ENV=production babel src --out-dir dist --copy-files --ignore __tests__,spec.js,test.js", - "test:unit": "yarn run jest", - "test:unit:update": "yarn jest -u", - "styleguide": "cross-env FAST_REFRESH=false styleguidist server", - "styleguide:build": "styleguidist build", - "test:e2e": "playwright test --project=chromium", - "test:e2e--h": "playwright test --project=chromium --headed", - "test:e2e:ci": "NODE_ENV=development; start-server-and-test styleguide http://localhost:6060 test:e2e", - "test:e2e:local": "export NODE_ENV=development; start-server-and-test styleguide http://localhost:6060 test:e2e", - "lint": "eslint src", - "lint-fix": "yarn lint --fix", - "build-pr": "rm -rf dist && NODE_ENV=development BABEL_ENV=development yarn babel src --out-dir dist --copy-files --ignore __tests__,spec.js,test.js", - "postinstall": "yarn build-pr" - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - }, "devDependencies": { - "@babel/plugin-proposal-private-property-in-object": "^7.21.11", + "@babel/core": "^7.24.0", + "@babel/preset-env": "^7.24.0", + "@babel/preset-react": "^7.24.0", "@playwright/test": "^1.38.1", - "cross-env": "^7.0.3", - "ejs": "^3.1.10", + "@vitejs/plugin-react": "^4.3.1", + "autoprefixer": "^10.5.0", + "babel-jest": "^29.7.0", + "babel-plugin-styled-components": "^2.1.4", + "dotenv": "^17.4.2", "eslint": "^7.32.0", "eslint-config-airbnb": "^18.2.0", "eslint-plugin-import": "^2.27.5", "eslint-plugin-jsx-a11y": "^6.7.1", "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", - "jest": "^26.1.0", - "jest-styled-components": "^7.1.1", - "npm-run-all": "^4.1.5", - "prettier": "^2.8.8", - "react-styleguidist": "^11.1.7", - "react-test-renderer": "^17.0.2", + "jest": "^29.7.0", + "jest-environment-jsdom": "^29.7.0", + "jest-styled-components": "^7.4.0", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "react-test-renderer": "^18.3.1", "semantic-release": "^17.4.6", - "start-server-and-test": "^2.0.4" + "styled-components": "^6.1.13", + "vite": "^5.4.10", + "vite-plugin-dts": "^4.3.0" } } diff --git a/playwright.config.js b/playwright.config.js index 7b157c890..666e6d9eb 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -23,9 +23,11 @@ module.exports = defineConfig({ }, reporter: [ ['list'], - ['html', { open: 'never' }] + ['html', { open: 'never' }], + ['json', { outputFile: '/tmp/pw-progress.json' }] ], use: { + baseURL: 'http://localhost:4173', actionTimeout: 0, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry' @@ -37,6 +39,7 @@ module.exports = defineConfig({ name: 'chromium', use: { ...devices['Desktop Chrome'], + channel: process.platform === 'darwin' ? 'chrome' : undefined, viewport: { // Match our widest nav: width: 1300, @@ -48,9 +51,9 @@ module.exports = defineConfig({ /* Run your local dev server before starting the tests */ webServer: { - command: 'yarn styleguide', - port: '6060', + command: 'yarn build:preview && yarn serve:preview', + url: 'http://localhost:4173', timeout: 120000, - reuseExistingServer: true + reuseExistingServer: !process.env.CI } }); diff --git a/playwright/components/atoms/input.spec.js b/playwright/components/atoms/input.spec.js index 1a4470017..e7398f73c 100644 --- a/playwright/components/atoms/input.spec.js +++ b/playwright/components/atoms/input.spec.js @@ -39,7 +39,7 @@ test.describe('input component', () => { await page.locator('#input-example-2').type('This is test input text'); // error message should be visible - await expect(page.locator('[data-preview="Input"] > div > label > span[data-test="error-message"]')).toBeVisible(); + await expect(page.locator('label[for="input-example-2"] span[data-test="error-message"]')).toBeVisible(); await page.close(); }); @@ -57,7 +57,7 @@ test.describe('input component', () => { const nameAttribute = await inputElement.getAttribute('name'); // Verify the 'name' attribute - expect(nameAttribute).toBe('fullname'); + expect(nameAttribute).toBe('fullname3'); await page.locator('#input-example-3').type('This is test input text'); @@ -77,7 +77,7 @@ test.describe('input component', () => { const nameAttribute = await inputElement.getAttribute('name'); // Verify the 'name' attribute - expect(nameAttribute).toBe('fullname'); + expect(nameAttribute).toBe('fullname4'); await page.locator('#input-example-4').type('This is test input text'); @@ -97,7 +97,7 @@ test.describe('input component', () => { const nameAttribute = await inputElement.getAttribute('name'); // Verify the 'name' attribute - expect(nameAttribute).toBe('fullname'); + expect(nameAttribute).toBe('fullname5'); await page.locator('#input-example-5').type('This is test input text'); diff --git a/playwright/components/atoms/label.spec.js b/playwright/components/atoms/label.spec.js index e86ad355e..a3d0f0066 100644 --- a/playwright/components/atoms/label.spec.js +++ b/playwright/components/atoms/label.spec.js @@ -6,7 +6,7 @@ test.describe('label component', () => { await page.goto('/#label'); // select dropdown menu component-1 should be visible - const specificElement = page.locator('[data-testid="Label-example-0"]'); + const specificElement = page.locator('[data-testid="label-basic"]'); await expect(specificElement).toBeVisible(); await page.locator('input[name="field-wrapper-test"]').type('This is test text'); @@ -19,7 +19,7 @@ test.describe('label component', () => { await page.goto('/#label'); // select dropdown menu component-1 should be visible - const specificElement = page.locator('[data-testid="Label-example-1"]'); + const specificElement = page.locator('[data-testid="label-styled"]'); await expect(specificElement).toBeVisible(); await page.locator('input[name="field-wrapper-test-1"]').type('This is test text'); diff --git a/playwright/components/atoms/link.spec.js b/playwright/components/atoms/link.spec.js index 3ca646526..9f7f980c9 100644 --- a/playwright/components/atoms/link.spec.js +++ b/playwright/components/atoms/link.spec.js @@ -6,12 +6,12 @@ test.describe('link component', () => { await page.goto('/#link'); // select dropdown menu component-1 should be visible - const specificElement = page.locator('[data-testid="Link-example-0"]'); + const specificElement = page.locator('[data-testid="Link-example-1"]'); await expect(specificElement).toBeVisible(); const [popup] = await Promise.all([ context.waitForEvent('page'), // Wait for a new page (popup) - page.click('[data-preview="Link"] div:nth-child(1) > a'), // Click the link + page.click('[data-testid="Link-example-1"] a[href="#anchor"]:first-of-type'), // Click the link ]); // Check if the popup is a new window @@ -27,15 +27,15 @@ test.describe('link component', () => { await page.goto('/#link'); // select dropdown menu component-1 should be visible - const specificElement = page.locator('[data-testid="Link-example-0"]'); + const specificElement = page.locator('[data-testid="Link-example-1"]'); await expect(specificElement).toBeVisible(); // link standard icon should be visible - await expect(page.locator('[data-preview="Link"] div:nth-child(2) > a > span[type="standard"]')).toBeVisible(); + await expect(page.locator('[data-testid="Link-example-1"] a span[type="standard"]')).toBeVisible(); const [popup] = await Promise.all([ context.waitForEvent('page'), // Wait for a new page (popup) - page.click('[data-preview="Link"] div:nth-child(2) > a'), // Click the link + page.click('[data-testid="Link-example-1"] a:has(span[type="standard"])'), // Click the link ]); // Check if the popup is a new window diff --git a/playwright/components/molecules/accordian.spec.js b/playwright/components/molecules/accordian.spec.js index 2ad3985f9..826c3463b 100644 --- a/playwright/components/molecules/accordian.spec.js +++ b/playwright/components/molecules/accordian.spec.js @@ -7,12 +7,12 @@ test.describe('accordian component', () => { // accordian elements should be visible await expect(page.locator('[data-testid="Accordion-example-1"]')).toBeVisible(); await expect(page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"]')).toBeVisible(); - // dropdown svg icon should be visible - await expect(page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"] img')).toBeVisible(); + // dropdown icon should be visible + await expect(page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"] img').first()).toBeVisible(); // clicking the accordian should show the paragraph - await page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"] img').click(); - await expect(page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"] p')).toBeVisible(); + await page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"] img').first().click(); + await expect(page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"] p').first()).toBeVisible(); await page.close(); }); diff --git a/playwright/components/molecules/searchInput.spec.js b/playwright/components/molecules/searchInput.spec.js index 3deb0dffa..dc8292baa 100644 --- a/playwright/components/molecules/searchInput.spec.js +++ b/playwright/components/molecules/searchInput.spec.js @@ -8,13 +8,13 @@ test.describe('search input component', () => { await expect(page.locator('[data-testid="SearchInput-example-1"]')).toBeVisible(); await expect(page.locator('[data-preview="SearchInput"]')).toBeVisible(); - const inputElement = page.locator('#school-lookup'); + const inputElement = page.locator('#search'); // Get the 'placeholder' attribute const placeholderAttribute = await inputElement.getAttribute('placeholder'); // Verify the 'placeholder' attribute - expect(placeholderAttribute).toBe('Type to start search'); + expect(placeholderAttribute).toBe('Search...'); await page.locator('#search').type('Red Nose Day'); diff --git a/playwright/components/molecules/shareButton.spec.js b/playwright/components/molecules/shareButton.spec.js index 433283ae5..59d0c206b 100644 --- a/playwright/components/molecules/shareButton.spec.js +++ b/playwright/components/molecules/shareButton.spec.js @@ -6,12 +6,12 @@ test.describe('share button component', () => { await page.goto('/#sharebutton'); // accordian elements should be visible - await expect(page.locator('[data-testid="ShareButton-example-0"]')).toBeVisible(); + await expect(page.locator('[data-testid="ShareButton-example-1"]')).toBeVisible(); await expect(page.locator('[data-preview="ShareButton"]')).toBeVisible(); - await expect(page.locator('[data-preview="ShareButton"] > div > div > div:nth-child(1) > ul > li:nth-child(1) > a > img')).toBeVisible(); + await expect(page.locator('[data-testid="ShareButton-example-1"] a[title="Share on Facebook"] img').first()).toBeVisible(); - const facebookShareButton = page.locator('[data-preview="ShareButton"] > div > div > div:nth-child(1) > ul > li:nth-child(1) > a'); + const facebookShareButton = page.locator('[data-testid="ShareButton-example-1"] a[title="Share on Facebook"]').first(); // Get the 'title' attribute const placeholderAttribute = await facebookShareButton.getAttribute('title'); @@ -19,7 +19,7 @@ test.describe('share button component', () => { // Verify the 'title' attribute expect(placeholderAttribute).toBe('Share on Facebook'); - const twitterShareButton = page.locator('[data-preview="ShareButton"] > div > div > div:nth-child(1) > ul > li:nth-child(2) > a'); + const twitterShareButton = page.locator('[data-testid="ShareButton-example-1"] a[title="Share on Twitter"]').first(); // Get the 'title' attribute const twiiterPlaceholderAttribute = await twitterShareButton.getAttribute('title'); diff --git a/playwright/components/molecules/simpleSchoolLookUp.spec.js b/playwright/components/molecules/simpleSchoolLookUp.spec.js index ec5ce2a32..a8c2226ff 100644 --- a/playwright/components/molecules/simpleSchoolLookUp.spec.js +++ b/playwright/components/molecules/simpleSchoolLookUp.spec.js @@ -2,10 +2,26 @@ const { test, expect } = require('@playwright/test'); test.describe('simple school lookup component', () => { test('simple school lookup', async ({ page, context }) => { + await page.route('**/schools/lookup**', route => { + route.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ + data: { + schools: [ + { name: "St Paul's School", post_code: 'SW13 9JT' }, + { name: "St Paul's Cathedral School", post_code: 'EC4M 8AD' }, + { name: 'EC4M 9AD School', post_code: 'EC4M 9AD' } + ] + } + }) + }); + }); + await page.goto('/#simpleschoollookup'); // simple school lookup elements should be visible - await expect(page.locator('[data-testid="SimpleSchoolLookup-example-0"]')).toBeVisible(); + await expect(page.locator('[data-testid="SimpleSchoolLookup-example-1"]')).toBeVisible(); await expect(page.locator('[data-preview="SimpleSchoolLookup"]')).toBeVisible(); const inputElement = page.locator('#school_lookup'); @@ -18,15 +34,15 @@ test.describe('simple school lookup component', () => { // enter school name and click find address button await page.locator('input#school_lookup').type('St Paul'); - await expect(page.locator('[data-preview="SimpleSchoolLookup"] > div > div > button[type="button"]')).toBeVisible(); - await page.locator('[data-preview="SimpleSchoolLookup"] > div > div > button[type="button"]').click(); + await expect(page.locator('[data-preview="SimpleSchoolLookup"] button[type="button"]')).toBeVisible(); + await page.locator('[data-preview="SimpleSchoolLookup"] button[type="button"]').click(); await expect(page.locator('label[for="school_lookup"] ~ div > ul[role="listbox"]')).toBeVisible(); // clear school name and enter school postcode await page.locator('input#school_lookup').fill(''); await page.locator('input#school_lookup').fill('EC4M 9AD'); - await expect(page.locator('[data-preview="SimpleSchoolLookup"] > div > div > button[type="button"]')).toBeVisible(); - await page.locator('[data-preview="SimpleSchoolLookup"] > div > div > button[type="button"]').click(); + await expect(page.locator('[data-preview="SimpleSchoolLookup"] button[type="button"]')).toBeVisible(); + await page.locator('[data-preview="SimpleSchoolLookup"] button[type="button"]').click(); await expect(page.locator('label[for="school_lookup"] ~ div > ul[role="listbox"]')).toBeVisible(); await page.close(); diff --git a/playwright/components/organisms/donate.spec.js b/playwright/components/organisms/donate.spec.js index 00d2ce72a..18c61840c 100644 --- a/playwright/components/organisms/donate.spec.js +++ b/playwright/components/organisms/donate.spec.js @@ -115,172 +115,172 @@ test.describe('donate component', () => { await page.close(); }); - test('Donate-example-3 - high value cart', async ({ page }) => { + test('Donate-example-1 - high value cart', async ({ page }) => { await page.goto('/#donate'); - await expect(page.locator('[data-testid="Donate-example-3"]')).toBeVisible(); + await expect(page.locator('[data-testid="Donate-example-2"]')).toBeVisible(); // moneybuy 1 - await page.locator('[data-testid="Donate-example-3"] input[id$="moneyBuy-box1"][aria-label="£7777"]').click(); - await expect(page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]')).toHaveValue('7777'); + await page.locator('[data-testid="Donate-example-2"] input[id$="moneyBuy-box1"][aria-label="£7777"]').click(); + await expect(page.locator('[data-testid="Donate-example-2"] input[name="membership_amount"]')).toHaveValue('7777'); - const moneybuyOneButtonText = await page.locator('[data-testid="Donate-example-3"] button[type="submit"]').textContent(); + const moneybuyOneButtonText = await page.locator('[data-testid="Donate-example-2"] button[type="submit"]').textContent(); console.log('buttonText:', moneybuyOneButtonText); - await expect(page.locator('[data-testid="Donate-example-3"] button[type="submit"]')).toContainText('Donate £7777 now'); + await expect(page.locator('[data-testid="Donate-example-2"] button[type="submit"]')).toContainText('Donate £7777 now'); // moneybuy 2 - await page.locator('[data-testid="Donate-example-3"] input[id$="moneyBuy-box2"][aria-label="£8888"]').click(); - await expect(page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]')).toHaveValue('8888'); + await page.locator('[data-testid="Donate-example-2"] input[id$="moneyBuy-box2"][aria-label="£8888"]').click(); + await expect(page.locator('[data-testid="Donate-example-2"] input[name="membership_amount"]')).toHaveValue('8888'); - const moneybuyTwoButtonText = await page.locator('[data-testid="Donate-example-3"] button[type="submit"]').textContent(); + const moneybuyTwoButtonText = await page.locator('[data-testid="Donate-example-2"] button[type="submit"]').textContent(); console.log('buttonText:', moneybuyTwoButtonText); - await expect(page.locator('[data-testid="Donate-example-3"] button[type="submit"]')).toContainText('Donate £8888 now'); + await expect(page.locator('[data-testid="Donate-example-2"] button[type="submit"]')).toContainText('Donate £8888 now'); // moneybuy 3 - await page.locator('[data-testid="Donate-example-3"] input[id$="moneyBuy-box3"][aria-label="£9999"]').click(); - await expect(page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]')).toHaveValue('9999'); + await page.locator('[data-testid="Donate-example-2"] input[id$="moneyBuy-box3"][aria-label="£9999"]').click(); + await expect(page.locator('[data-testid="Donate-example-2"] input[name="membership_amount"]')).toHaveValue('9999'); - const moneybuyThreeButtonText = await page.locator('[data-testid="Donate-example-3"] button[type="submit"]').textContent(); + const moneybuyThreeButtonText = await page.locator('[data-testid="Donate-example-2"] button[type="submit"]').textContent(); console.log('buttonText:', moneybuyThreeButtonText); - await expect(page.locator('[data-testid="Donate-example-3"] button[type="submit"]')).toContainText('Donate £9999 now'); + await expect(page.locator('[data-testid="Donate-example-2"] button[type="submit"]')).toContainText('Donate £9999 now'); // amount field validation - await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-2"] input[name="membership_amount"]').fill(''); // enter amount 0 should show error message - await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').type('0'); - await expect(page.locator('[data-testid="Donate-example-3"] p:nth-child(4)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); + await page.locator('[data-testid="Donate-example-2"] input[name="membership_amount"]').type('0'); + await expect(page.locator('[data-testid="Donate-example-2"] p:nth-child(4)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); // enter amount 25001 should show error message - await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').fill(''); - await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').type('25001'); - await expect(page.locator('[data-testid="Donate-example-3"] p:nth-child(4)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); + await page.locator('[data-testid="Donate-example-2"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-2"] input[name="membership_amount"]').type('25001'); + await expect(page.locator('[data-testid="Donate-example-2"] p:nth-child(4)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); // enter own amount in decimals should not show error message - await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').fill(''); - await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').type('22000'); - await expect(page.locator('[data-testid="Donate-example-3"] button[type="submit"]')).toContainText('Donate £22000 now'); + await page.locator('[data-testid="Donate-example-2"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-2"] input[name="membership_amount"]').type('22000'); + await expect(page.locator('[data-testid="Donate-example-2"] button[type="submit"]')).toContainText('Donate £22000 now'); // clicking the submit button should take to donate.comicrelief.com - await page.locator('[data-testid="Donate-example-3"] button[type="submit"]').click(); + await page.locator('[data-testid="Donate-example-2"] button[type="submit"]').click(); await page.close(); }); - test('Donate-example-5 - Single Giving', async ({ page }) => { + test('Donate-example-2 - Single Giving', async ({ page }) => { await page.goto('/#donate'); - await expect(page.locator('[data-testid="Donate-example-5"]')).toBeVisible(); + await expect(page.locator('[data-testid="Donate-example-3"]')).toBeVisible(); // moneybuy 1 - await page.locator('[data-testid="Donate-example-5"] input[id$="moneyBuy-box1"][aria-label="£10"]').click(); - await expect(page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]')).toHaveValue('10'); + await page.locator('[data-testid="Donate-example-3"] input[id$="moneyBuy-box1"][aria-label="£10"]').click(); + await expect(page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]')).toHaveValue('10'); - const moneybuyOneButtonText = await page.locator('[data-testid="Donate-example-5"] button[type="submit"]').textContent(); + const moneybuyOneButtonText = await page.locator('[data-testid="Donate-example-3"] button[type="submit"]').textContent(); console.log('buttonText:', moneybuyOneButtonText); - await expect(page.locator('[data-testid="Donate-example-5"] button[type="submit"]')).toContainText('Donate £10 now'); + await expect(page.locator('[data-testid="Donate-example-3"] button[type="submit"]')).toContainText('Donate £10 now'); // moneybuy 2 - await page.locator('[data-testid="Donate-example-5"] input[id$="moneyBuy-box2"][aria-label="£20"]').click(); - await expect(page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]')).toHaveValue('20'); + await page.locator('[data-testid="Donate-example-3"] input[id$="moneyBuy-box2"][aria-label="£20"]').click(); + await expect(page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]')).toHaveValue('20'); - const moneybuyTwoButtonText = await page.locator('[data-testid="Donate-example-5"] button[type="submit"]').textContent(); + const moneybuyTwoButtonText = await page.locator('[data-testid="Donate-example-3"] button[type="submit"]').textContent(); console.log('buttonText:', moneybuyTwoButtonText); - await expect(page.locator('[data-testid="Donate-example-5"] button[type="submit"]')).toContainText('Donate £20 now'); + await expect(page.locator('[data-testid="Donate-example-3"] button[type="submit"]')).toContainText('Donate £20 now'); // moneybuy 3 - await page.locator('[data-testid="Donate-example-5"] input[id$="moneyBuy-box3"][aria-label="£30"]').click(); - await expect(page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]')).toHaveValue('30'); + await page.locator('[data-testid="Donate-example-3"] input[id$="moneyBuy-box3"][aria-label="£30"]').click(); + await expect(page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]')).toHaveValue('30'); - const moneybuyThreeButtonText = await page.locator('[data-testid="Donate-example-5"] button[type="submit"]').textContent(); + const moneybuyThreeButtonText = await page.locator('[data-testid="Donate-example-3"] button[type="submit"]').textContent(); console.log('buttonText:', moneybuyThreeButtonText); - await expect(page.locator('[data-testid="Donate-example-5"] button[type="submit"]')).toContainText('Donate £30 now'); + await expect(page.locator('[data-testid="Donate-example-3"] button[type="submit"]')).toContainText('Donate £30 now'); // amount field validation - await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').fill(''); // enter amount 0 should show error message - await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').type('0'); - await expect(page.locator('[data-testid="Donate-example-5"] p:nth-child(4)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); + await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').type('0'); + await expect(page.locator('[data-testid="Donate-example-3"] p:nth-child(4)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); // enter amount 25001 should show error message - await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').fill(''); - await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').type('25001'); - await expect(page.locator('[data-testid="Donate-example-5"] p:nth-child(4)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); + await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').type('25001'); + await expect(page.locator('[data-testid="Donate-example-3"] p:nth-child(4)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); // enter own amount in decimals should not show error message - await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').fill(''); - await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').type('20.01'); - await expect(page.locator('[data-testid="Donate-example-5"] button[type="submit"]')).toContainText('Donate £20.01 now'); + await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-3"] input[name="membership_amount"]').type('20.01'); + await expect(page.locator('[data-testid="Donate-example-3"] button[type="submit"]')).toContainText('Donate £20.01 now'); // clicking the submit button should take to donate.comicrelief.com - await page.locator('[data-testid="Donate-example-5"] button[type="submit"]').click(); + await page.locator('[data-testid="Donate-example-3"] button[type="submit"]').click(); await page.close(); }); - test('Donate-example-7 - Single Giving "No Money Buys"', async ({ page }) => { + test('Donate-example-3 - Single Giving "No Money Buys"', async ({ page }) => { await page.goto('/#donate'); - await expect(page.locator('[data-testid="Donate-example-7"]')).toBeVisible(); + await expect(page.locator('[data-testid="Donate-example-4"]')).toBeVisible(); - await expect(page.locator('[data-testid="Donate-example-7"] button[type="submit"]')).toContainText('Donate £20'); + await expect(page.locator('[data-testid="Donate-example-4"] button[type="submit"]')).toContainText('Donate £20'); // amount field validation - await page.locator('[data-testid="Donate-example-7"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-4"] input[name="membership_amount"]').fill(''); // enter amount 0 should show error message - await page.locator('[data-testid="Donate-example-7"] input[name="membership_amount"]').type('0'); - await expect(page.locator('[data-testid="Donate-example-7"] p:nth-child(3)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); + await page.locator('[data-testid="Donate-example-4"] input[name="membership_amount"]').type('0'); + await expect(page.locator('[data-testid="Donate-example-4"] p:nth-child(3)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); // enter amount 25001 should show error message - await page.locator('[data-testid="Donate-example-7"] input[name="membership_amount"]').fill(''); - await page.locator('[data-testid="Donate-example-7"] input[name="membership_amount"]').type('25001'); - await expect(page.locator('[data-testid="Donate-example-7"] p:nth-child(3)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); + await page.locator('[data-testid="Donate-example-4"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-4"] input[name="membership_amount"]').type('25001'); + await expect(page.locator('[data-testid="Donate-example-4"] p:nth-child(3)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); // enter own amount in decimals should not show error message - await page.locator('[data-testid="Donate-example-7"] input[name="membership_amount"]').fill(''); - await page.locator('[data-testid="Donate-example-7"] input[name="membership_amount"]').type('20.01'); - await expect(page.locator('[data-testid="Donate-example-7"] button[type="submit"]')).toContainText('Donate £20.01'); + await page.locator('[data-testid="Donate-example-4"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-4"] input[name="membership_amount"]').type('20.01'); + await expect(page.locator('[data-testid="Donate-example-4"] button[type="submit"]')).toContainText('Donate £20.01'); // clicking the submit button should take to donate.comicrelief.com - await page.locator('[data-testid="Donate-example-7"] button[type="submit"]').click(); + await page.locator('[data-testid="Donate-example-4"] button[type="submit"]').click(); await page.close(); }); - test('Donate-example-9 - Single Giving "No Money Buys" with overridden manual input value', async ({ page }) => { + test('Donate-example-4 - Single Giving "No Money Buys" with overridden manual input value', async ({ page }) => { await page.goto('/#donate'); - await expect(page.locator('[data-testid="Donate-example-9"]')).toBeVisible(); + await expect(page.locator('[data-testid="Donate-example-5"]')).toBeVisible(); - await expect(page.locator('[data-testid="Donate-example-9"] button[type="submit"]')).toContainText('Donate £567.89'); + await expect(page.locator('[data-testid="Donate-example-5"] button[type="submit"]')).toContainText('Donate £567.89'); // amount field validation - await page.locator('[data-testid="Donate-example-9"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').fill(''); // enter amount 0 should show error message - await page.locator('[data-testid="Donate-example-9"] input[name="membership_amount"]').type('0'); - await expect(page.locator('[data-testid="Donate-example-9"] p:nth-child(3)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); + await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').type('0'); + await expect(page.locator('[data-testid="Donate-example-5"] p:nth-child(3)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); // enter amount 25001 should show error message - await page.locator('[data-testid="Donate-example-9"] input[name="membership_amount"]').fill(''); - await page.locator('[data-testid="Donate-example-9"] input[name="membership_amount"]').type('25001'); - await expect(page.locator('[data-testid="Donate-example-9"] p:nth-child(3)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); + await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').type('25001'); + await expect(page.locator('[data-testid="Donate-example-5"] p:nth-child(3)')).toContainText('Please enter an amount between £1 and £25000 and up to 2 decimal places'); // enter own amount in decimals should not show error message - await page.locator('[data-testid="Donate-example-9"] input[name="membership_amount"]').fill(''); - await page.locator('[data-testid="Donate-example-9"] input[name="membership_amount"]').type('20.01'); - await expect(page.locator('[data-testid="Donate-example-9"] button[type="submit"]')).toContainText('Donate £20.01'); + await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').fill(''); + await page.locator('[data-testid="Donate-example-5"] input[name="membership_amount"]').type('20.01'); + await expect(page.locator('[data-testid="Donate-example-5"] button[type="submit"]')).toContainText('Donate £20.01'); // clicking the submit button should take to donate.comicrelief.com - await page.locator('[data-testid="Donate-example-9"] button[type="submit"]').click(); + await page.locator('[data-testid="Donate-example-5"] button[type="submit"]').click(); await page.close(); }); diff --git a/playwright/components/organisms/dynamicGallery.spec.js b/playwright/components/organisms/dynamicGallery.spec.js index 2c0cd2fd2..35fc9b431 100644 --- a/playwright/components/organisms/dynamicGallery.spec.js +++ b/playwright/components/organisms/dynamicGallery.spec.js @@ -21,85 +21,95 @@ test.describe('dynamic gallery component', () => { }); test('gallery column props', async ({ page }) => { - await page.goto('/#!/DynamicGallery/5'); + await page.goto('/#dynamicgallery'); - // expect three gallery columns - await expect(page.locator('.gallery-column')).toHaveCount(4); + const gallery = page.locator('[data-testid="gallery-customised"]'); + + // expect four gallery columns + await expect(gallery.locator('.gallery-column')).toHaveCount(4); await page.close(); }); // MARK: responsive columns test('responsive gallery columns', async ({ page }) => { - await page.goto('/#!/DynamicGallery/3'); + await page.goto('/#dynamicgallery'); + + const gallery = page.locator('[data-testid="gallery-basic"]'); // expect three gallery columns - await expect(page.locator('.gallery-column')).toHaveCount(3); + await expect(gallery.locator('.gallery-column')).toHaveCount(3); // resize the page to a small width await page.setViewportSize({ width: 700, height: 1000 }); - // expect one gallery column - await expect(page.locator('.gallery-column')).toHaveCount(2); + // expect two gallery columns + await expect(gallery.locator('.gallery-column')).toHaveCount(2); // resize the page to a medium width await page.setViewportSize({ width: 320, height: 1000 }); // expect one gallery column - await expect(page.locator('.gallery-column')).toHaveCount(1); + await expect(gallery.locator('.gallery-column')).toHaveCount(1); await page.close(); }); // MARK: chunk mode test('chunk mode test', async ({ page }) => { - await page.goto('/#!/DynamicGallery/3'); + await page.goto('/#dynamicgallery'); + + const gallery = page.locator('[data-testid="gallery-basic"]'); // expect 25 images to be visible - await expect(page.locator('.gallery-node')).toHaveCount(25); + await expect(gallery.locator('.gallery-node')).toHaveCount(25); // find the "load more" button and click it - await page.locator('button:has-text("Show more")').click(); + await gallery.locator('button:has-text("Show more")').click(); // expect 50 images to be visible - await expect(page.locator('.gallery-node')).toHaveCount(50); + await expect(gallery.locator('.gallery-node')).toHaveCount(50); // expect the "load more" button to be hidden - await expect(page.locator('button:has-text("Show more")')).toBeHidden(); + await expect(gallery.locator('button:has-text("Show more")')).toBeHidden(); await page.close(); }); // MARK: non-chunk mode test('non-chunk mode test', async ({ page }) => { - await page.goto('/#!/DynamicGallery/5'); + await page.goto('/#dynamicgallery'); + + const gallery = page.locator('[data-testid="gallery-customised"]'); // expect all 30 images to be visible - await expect(page.locator('.gallery-node')).toHaveCount(30); + await expect(gallery.locator('.gallery-node')).toHaveCount(30); // expect the "load more" button to be hidden - await expect(page.locator('button:has-text("Show more")')).toBeHidden(); + await expect(gallery.locator('button:has-text("Show more")')).toBeHidden(); await page.close(); }); // MARK: tabbing test('gallery tabbing', async ({ page }) => { - await page.goto('/#!/DynamicGallery/3'); + await page.goto('/#dynamicgallery'); + + const gallery = page.locator('[data-testid="gallery-basic"]'); // focus the first gallery node - await page.locator('.gallery-node').first().focus(); + await gallery.locator('.gallery-node').first().focus(); await page.waitForTimeout(3000); // first tab should focus the first node in the first column - const firstNode = page.locator('.gallery-column').first().locator('.gallery-node').first(); + const firstNode = gallery.locator('.gallery-column').first().locator('.gallery-node').first(); await firstNode.focus(); await expect(firstNode).toBeFocused(); // tab to the first node in the second column await page.keyboard.press('Tab'); - const secondNode = page.locator('.gallery-column').nth(1).locator('.gallery-node').first(); + const secondNode = gallery.locator('.gallery-column').nth(1).locator('.gallery-node').first(); await expect(secondNode).toBeFocused(); // tab back to the first node in the first column @@ -111,19 +121,21 @@ test.describe('dynamic gallery component', () => { // MARK: tabbing out test('gallery tabbing should allow tabbing out of the gallery', async ({ page }) => { - await page.goto('/#!/DynamicGallery/5'); + await page.goto('/#dynamicgallery'); await page.waitForTimeout(3000); - // focus the first gallery node - const galleryNodes = await page.locator('.gallery-node').all(); - await page.locator(`[data-node-index="${galleryNodes.length - 1}"]`).focus(); + const gallery = page.locator('[data-testid="gallery-customised"]'); + + // focus the last gallery node + const galleryNodes = await gallery.locator('.gallery-node').all(); + await gallery.locator(`[data-node-index="${galleryNodes.length - 1}"]`).focus(); // press tab await page.keyboard.press('Tab'); - const galleryContainer = page.locator('.gallery-container'); + const galleryContainer = gallery.locator('.gallery-container'); - // asset that the focus has moved outside the gallery + // assert that the focus has moved outside the gallery expect( await galleryContainer.evaluate( el => !el.contains(document.activeElement) @@ -134,9 +146,9 @@ test.describe('dynamic gallery component', () => { // MARK: colours test('custom page background and text colour', async ({ page }) => { - await page.goto('/#!/DynamicGallery/5'); + await page.goto('/#dynamicgallery'); - const galleryContainer = page.locator('.gallery-container'); + const galleryContainer = page.locator('[data-testid="gallery-customised"] .gallery-container'); const backgroundColor = await galleryContainer.evaluate(el => window.getComputedStyle(el).getPropertyValue('background-color')); expect(backgroundColor).toBe(hexToRgb('#0565D1')); @@ -149,65 +161,71 @@ test.describe('dynamic gallery component', () => { // MARK: lightbox mode test('check lightbox mode', async ({ page }) => { - await page.goto('/#!/DynamicGallery/3'); + await page.goto('/#dynamicgallery'); + + const gallery = page.locator('[data-testid="gallery-basic"]'); // find the first gallery node - const galleryNode = page.locator('.gallery-node').first(); + const galleryNode = gallery.locator('.gallery-node').first(); // click it await galleryNode.click(); // expect the lightbox to be visible - await expect(page.locator('dialog')).toBeVisible(); + await expect(gallery.locator('dialog')).toBeVisible(); await page.waitForTimeout(1000); await page.keyboard.press('Escape'); - await expect(page.locator('dialog')).toBeHidden(); + await expect(gallery.locator('dialog')).toBeHidden(); // focus the gallery node and press enter await galleryNode.focus(); await page.keyboard.press('Enter'); // expect the lightbox to be visible - await expect(page.locator('dialog')).toBeVisible(); + await expect(gallery.locator('dialog')).toBeVisible(); await page.close(); }); // MARK: lightbox focus test('check lightbox auto-focus', async ({ page }) => { - await page.goto('/#!/DynamicGallery/3'); + await page.goto('/#dynamicgallery'); + + const gallery = page.locator('[data-testid="gallery-basic"]'); // find the first gallery node - const galleryNode = page.locator('.gallery-node').first(); + const galleryNode = gallery.locator('.gallery-node').first(); // click it await galleryNode.click(); // the close button should not be focused after opening the lightbox with the mouse - await expect(page.locator('.close-button')).not.toBeFocused(); + await expect(gallery.locator('.close-button')).not.toBeFocused(); await page.keyboard.press('Escape'); // the close button should be focused after opening the lightbox with the keyboard await galleryNode.focus(); await page.keyboard.press('Enter'); - await expect(page.locator('.close-button')).toBeFocused(); + await expect(gallery.locator('.close-button')).toBeFocused(); await page.close(); }); // MARK: lightbox navigation test('lightbox navigation', async ({ page }) => { - await page.goto('/#!/DynamicGallery/3'); + await page.goto('/#dynamicgallery'); + + const gallery = page.locator('[data-testid="gallery-basic"]'); // find the first gallery node - const galleryNode = page.locator('.gallery-node').first(); + const galleryNode = gallery.locator('.gallery-node').first(); // click it await galleryNode.click(); // expect the lightbox and caption to be visible - await expect(page.locator('dialog')).toBeVisible(); + await expect(gallery.locator('dialog')).toBeVisible(); await expect(page.getByText('Lightbox: This is the body for image 0')).toBeVisible(); await page.waitForTimeout(1000); @@ -221,42 +239,46 @@ test.describe('dynamic gallery component', () => { // MARK: lightbox pointer close test('lightbox pointer close', async ({ page }) => { - await page.goto('/#!/DynamicGallery/3'); + await page.goto('/#dynamicgallery'); + + const gallery = page.locator('[data-testid="gallery-basic"]'); // find the first gallery node - const galleryNode = page.locator('.gallery-node').first(); + const galleryNode = gallery.locator('.gallery-node').first(); // click it await galleryNode.click(); // click the close button - await page.locator('.close-button').click(); + await gallery.locator('.close-button').click(); // expect the lightbox to be hidden - await expect(page.locator('dialog')).toBeHidden(); + await expect(gallery.locator('dialog')).toBeHidden(); await page.close(); }); // MARK: non-lightbox mode test('check non-lightbox mode', async ({ page }) => { - await page.goto('/#!/DynamicGallery/5'); + await page.goto('/#dynamicgallery'); + + const gallery = page.locator('[data-testid="gallery-customised"]'); // find the first gallery node - const galleryNode = page.locator('.gallery-node').first(); + const galleryNode = gallery.locator('.gallery-node').first(); // click it await galleryNode.click(); // expect the lightbox to be hidden - await expect(page.locator('dialog')).toBeHidden(); + await expect(gallery.locator('dialog')).toBeHidden(); // focus the gallery node and press enter await galleryNode.focus(); await page.keyboard.press('Enter'); // expect the lightbox to be hidden - await expect(page.locator('dialog')).toBeHidden(); + await expect(gallery.locator('dialog')).toBeHidden(); await page.close(); }); diff --git a/playwright/components/organisms/emailSignUpForm.spec.js b/playwright/components/organisms/emailSignUpForm.spec.js index b0de6e675..d00c5e3fb 100644 --- a/playwright/components/organisms/emailSignUpForm.spec.js +++ b/playwright/components/organisms/emailSignUpForm.spec.js @@ -93,12 +93,19 @@ test.describe('Email Signup Form component', () => { // enter valid inputs should not show error messages await page.locator('[data-testid="EmailSignUpForm-example-1"] #first-name').fill(''); await page.locator('[data-testid="EmailSignUpForm-example-1"] #first-name').type('test firstname'); + // .blur() triggers a blur/ click / focus outside. + await page.locator('[data-testid="EmailSignUpForm-example-1"] #first-name').blur(); await page.locator('[data-testid="EmailSignUpForm-example-1"] #last-name').fill(''); await page.locator('[data-testid="EmailSignUpForm-example-1"] #last-name').type('test lastname'); + // .blur() triggers a blur/ click / focus outside. + await page.locator('[data-testid="EmailSignUpForm-example-1"] #last-name').blur(); await page.locator('[data-testid="EmailSignUpForm-example-1"] #email').fill(''); // clear the email field await page.locator('[data-testid="EmailSignUpForm-example-1"] #email').type('email-signup@email.sls.comicrelief.com'); + // Blur the final field too, so handleSubmit (EmailSignUpForm.js:24) sees a + // fully-validated, up-to-date form before we click submit. + await page.locator('[data-testid="EmailSignUpForm-example-1"] #email').blur(); // submit the ESU form await page.locator('[data-testid="EmailSignUpForm-example-1"] button[type="submit"]').click(); diff --git a/playwright/components/organisms/footer.spec.js b/playwright/components/organisms/footer.spec.js index 833b48031..aabad5502 100644 --- a/playwright/components/organisms/footer.spec.js +++ b/playwright/components/organisms/footer.spec.js @@ -6,16 +6,16 @@ test.describe('footer component', () => { await expect(page.locator('[data-testid="Footer-example-1"]')).toBeVisible(); // footer social icons should be visible - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(2) > footer[role="banner"] [title="Check out our Facebook page"]')).toBeVisible(); - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(2) > footer[role="banner"] [title="Check out our Instagram account"]')).toBeVisible(); - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(2) > footer[role="banner"] [title="Check out our Twitter account"]')).toBeVisible(); - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(2) > footer[role="banner"] [title="Check out our YouTube channel"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-1"] footer[role="banner"] [title="Check out our Facebook page"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-1"] footer[role="banner"] [title="Check out our Instagram account"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-1"] footer[role="banner"] [title="Check out our Twitter account"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-1"] footer[role="banner"] [title="Check out our YouTube channel"]')).toBeVisible(); // CR logo in the footer should be visible - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(2) > footer[role="banner"] [title="Go to Comic Relief homepage"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-1"] footer[role="banner"] [title="Go to Comic Relief homepage"]')).toBeVisible(); // footer menu should be visible - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(2) > footer[role="banner"] [aria-label="main-menu"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-1"] footer[role="banner"] [aria-label="main-menu"]')).toBeVisible(); await page.close(); }); @@ -23,18 +23,18 @@ test.describe('footer component', () => { test('Overrides allowList functionality', async ({ page }) => { await page.goto('/#footer'); - await expect(page.locator('[data-testid="Footer-example-1"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-2"]')).toBeVisible(); // footer social icons should be visible - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(4) > footer[role="banner"] [title="Check out our Facebook page"]')).toBeVisible(); - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(4) > footer[role="banner"] [title="Check out our Instagram account"]')).toBeVisible(); - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(4) > footer[role="banner"] [title="Check out our Twitter account"]')).toBeVisible(); - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(4) > footer[role="banner"] [title="Check out our YouTube channel"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-2"] footer[role="banner"] [title="Check out our Facebook page"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-2"] footer[role="banner"] [title="Check out our Instagram account"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-2"] footer[role="banner"] [title="Check out our Twitter account"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-2"] footer[role="banner"] [title="Check out our YouTube channel"]')).toBeVisible(); // CR logo in the footer should be visible - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(4) > footer[role="banner"] [title="Go to Comic Relief homepage"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-2"] footer[role="banner"] [title="Go to Comic Relief homepage"]')).toBeVisible(); // footer menu should be visible - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(4) > footer[role="banner"] [aria-label="main-menu"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-2"] footer[role="banner"] [aria-label="main-menu"]')).toBeVisible(); await page.close(); }); @@ -42,22 +42,22 @@ test.describe('footer component', () => { test('additional legal line footer', async ({ page }) => { await page.goto('/#footer'); - await expect(page.locator('[data-testid="Footer-example-1"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-3"]')).toBeVisible(); // legal line to the top of the footer should be present - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(6) > footer[role="banner"] > div > p')).toContainText('CHICKEN RUN: DAWN OF THE NUGGET ™/ © Aardman. Netflix ™/© Netflix. Used with permission/Wallace & Gromit Ltd. All rights reserved/ Shaun the Sheep © & TM /Morph ©/TM Aardman Animations Ltd. All rights reserved.'); + await expect(page.locator('[data-testid="Footer-example-3"] footer[role="banner"] > div > p')).toContainText('CHICKEN RUN: DAWN OF THE NUGGET ™/ © Aardman. Netflix ™/© Netflix. Used with permission/Wallace & Gromit Ltd. All rights reserved/ Shaun the Sheep © & TM /Morph ©/TM Aardman Animations Ltd. All rights reserved.'); // footer social icons should be visible - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(4) > footer[role="banner"] [title="Check out our Facebook page"]')).toBeVisible(); - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(6) > footer[role="banner"] [title="Check out our Instagram account"]')).toBeVisible(); - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(6) > footer[role="banner"] [title="Check out our Twitter account"]')).toBeVisible(); - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(6) > footer[role="banner"] [title="Check out our YouTube channel"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-3"] footer[role="banner"] [title="Check out our Facebook page"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-3"] footer[role="banner"] [title="Check out our Instagram account"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-3"] footer[role="banner"] [title="Check out our Twitter account"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-3"] footer[role="banner"] [title="Check out our YouTube channel"]')).toBeVisible(); // CR logo in the footer should be visible - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(6) > footer[role="banner"] [title="Go to Comic Relief homepage"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-3"] footer[role="banner"] [title="Go to Comic Relief homepage"]')).toBeVisible(); // footer menu should be visible - await expect(page.locator('[data-preview="Footer"] > div > div:nth-child(6) > footer[role="banner"] [aria-label="main-menu"]')).toBeVisible(); + await expect(page.locator('[data-testid="Footer-example-3"] footer[role="banner"] [aria-label="main-menu"]')).toBeVisible(); await page.close(); }); diff --git a/playwright/components/organisms/header.spec.js b/playwright/components/organisms/header.spec.js index e54ba90e7..2dc5765ef 100644 --- a/playwright/components/organisms/header.spec.js +++ b/playwright/components/organisms/header.spec.js @@ -20,13 +20,13 @@ test.describe('header component', () => { await page.goto('/#header'); - await expect(page.locator('[data-testid="Header-example-3"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-2"]')).toBeVisible(); // donate locator - await expect(page.locator('[data-testid="Header-example-3"] header[role="banner"] a[href="/donation"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-2"] header[role="banner"] a[href="/donation"]')).toBeVisible(); // SR logo - await expect(page.locator('[data-testid="Header-example-3"] header[role="banner"] a[href="/sportrelief"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-2"] header[role="banner"] a[href="/sportrelief"]')).toBeVisible(); // shop - await expect(page.locator('[data-testid="Header-example-3"] header[role="banner"] a[href*="/shop"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-2"] header[role="banner"] a[href*="/shop"]')).toBeVisible(); await page.close(); }); @@ -35,13 +35,13 @@ test.describe('header component', () => { await page.goto('/#header'); - await expect(page.locator('[data-testid="Header-example-5"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-3"]')).toBeVisible(); // donate locator - await expect(page.locator('[data-testid="Header-example-5"] header[role="banner"] a[href="/donation"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-3"] header[role="banner"] a[href="/donation"]')).toBeVisible(); // CR logo - await expect(page.locator('[data-testid="Header-example-5"] [title="Go to Comic Relief homepage"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-3"] [title="Go to Comic Relief homepage"]')).toBeVisible(); // shop - await expect(page.locator('[data-testid="Header-example-5"] header[role="banner"] a[href*="/shop"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-3"] header[role="banner"] a[href*="/shop"]')).toBeVisible(); await page.close(); }); @@ -50,15 +50,15 @@ test.describe('header component', () => { await page.goto('/#header'); - await expect(page.locator('[data-testid="Header-example-7"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-4"]')).toBeVisible(); // donate locator - await expect(page.locator('[data-testid="Header-example-7"] header[role="banner"] a[href="/donation"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-4"] header[role="banner"] a[href="/donation"]')).toBeVisible(); // CR logo - await expect(page.locator('[data-testid="Header-example-7"] [title="Go to Comic Relief homepage"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-4"] [title="Go to Comic Relief homepage"]')).toBeVisible(); // shop - await expect(page.locator('[data-testid="Header-example-7"] header[role="banner"] a[href*="/shop"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-4"] header[role="banner"] a[href*="/shop"]')).toBeVisible(); // search - await expect(page.locator('[data-testid="Header-example-7"] header[role="banner"] a[href="/search"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-4"] header[role="banner"] a[href="/search"]')).toBeVisible(); await page.close(); }); @@ -67,15 +67,15 @@ test.describe('header component', () => { await page.goto('/#header'); - await expect(page.locator('[data-testid="Header-example-9"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-5"]')).toBeVisible(); // donate locator - await expect(page.locator('[data-testid="Header-example-9"] header[role="banner"] a[href="/donation"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-5"] header[role="banner"] a[href="/donation"]')).toBeVisible(); // CR logo - await expect(page.locator('[data-testid="Header-example-9"] [title="Go to Comic Relief homepage"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-5"] [title="Go to Comic Relief homepage"]')).toBeVisible(); // shop icon - await expect(page.locator('[data-testid="Header-example-9"] header[role="banner"] [title="Shop"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-5"] header[role="banner"] [title="Shop"]')).toBeVisible(); // search - await expect(page.locator('[data-testid="Header-example-9"] header[role="banner"] a[href="/search"]')).toBeVisible(); + await expect(page.locator('[data-testid="Header-example-5"] header[role="banner"] a[href="/search"]')).toBeVisible(); await page.close(); }); diff --git a/playwright/components/organisms/impactSlider.spec.js b/playwright/components/organisms/impactSlider.spec.js index 015e5ab99..695d7897a 100644 --- a/playwright/components/organisms/impactSlider.spec.js +++ b/playwright/components/organisms/impactSlider.spec.js @@ -1,42 +1,47 @@ const { test, expect } = require('@playwright/test'); +// The range component is a "click anywhere on the track to jump to that value" slider, +// so the value at any point along its width maps linearly between these bounds. +const SLIDER_MIN = 5; +const SLIDER_MAX = 100; + +// On master, each test repeated ~25 lines of inline drag simulation: locate the slider, +// grab its bounding box, mouse.down(), then loop mouse.move() + re-read the bounding box +// until the displayed amount matched the target position. That loop was slow, flakey +// (it could spin indefinitely if the amount never landed exactly on targetPosition due to +// rounding), and duplicated across every test. Since the slider responds to a single click +// at the desired position, we can skip the drag entirely and click straight to the target - +// faster and far more reliable. This helper centralises that click-to-value logic so each +// test just calls `setSliderValue(page, testid, value)`. +async function setSliderValue(page, testid, value) { + const slider = page.locator(`[data-testid="${testid}"] #ImpactSlider`); + await slider.scrollIntoViewIfNeeded(); + + const box = await slider.boundingBox(); + if (box) { + // Map the requested £ value onto a 0-1 fraction of the track's width. Capped at 0.98 + // so we never click right at the track's edge, where the handle can be clipped/unreliable. + const fraction = Math.min((value - SLIDER_MIN) / (SLIDER_MAX - SLIDER_MIN), 0.98); + const clickX = box.x + box.width * fraction; + const clickY = box.y + box.height / 2; + await page.mouse.click(clickX, clickY); + } +} + test.describe('impact slider component - 1', () => { test('impact slider - sliding to £70', async ({ page }) => { - await page.goto('/#impactslider'); // Ensure that the slider and its handle are visible await expect(page.locator('[data-testid="ImpactSlider-example-1"]')).toBeVisible(); await expect(page.locator('[data-testid="ImpactSlider-example-1"] #ImpactSlider > div:nth-child(4)')).toBeVisible(); - // slider selector - const sliderSelector = '[data-testid="ImpactSlider-example-1"] #ImpactSlider'; - const slider = await page.$(sliderSelector); - const moneyBuyElement = page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-1"]'); - const moneyBuyText = await moneyBuyElement.innerText(); - console.log('Target initially: ', moneyBuyText); - - if (slider) { - // Get the bounding box of the slider - let sliderBound = await slider.boundingBox(); - - // Get the target position for the mouse move to a donation of £70 - const targetPosition = sliderBound.width * (70 / 100); + console.log('Target initially: ', await moneyBuyElement.innerText()); - // Perform mouse actions to simulate dragging the slider handle - await page.mouse.move(sliderBound.x, sliderBound.y + sliderBound.height / 2); - await page.mouse.down(); + await setSliderValue(page, 'ImpactSlider-example-1', 70); - while (sliderBound.width * (parseFloat(await moneyBuyElement.innerText()) / 100) !== targetPosition) { - await page.mouse.move(sliderBound.x + targetPosition, sliderBound.y + sliderBound.height / 2); - sliderBound = await slider.boundingBox(); - } - - await page.mouse.up(); - } - - await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > div > p')).toContainText('A donation of £70 could help pay for:'); + await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > p')).toContainText('A donation of £70 could help pay for:'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-1"] [data-testid="moneybuy-amount"]')).toContainText('70'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-2"] [data-testid="moneybuy-amount"]')).toContainText('7'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-3"] [data-testid="moneybuy-amount"]')).toContainText('4'); @@ -50,41 +55,18 @@ test.describe('impact slider component - 1', () => { }); test('impact slider - sliding to the maximum amount £100', async ({ page }) => { - await page.goto('/#impactslider'); // Ensure that the slider and its handle are visible await expect(page.locator('[data-testid="ImpactSlider-example-1"]')).toBeVisible(); await expect(page.locator('[data-testid="ImpactSlider-example-1"] #ImpactSlider > div:nth-child(4)')).toBeVisible(); - // slider selector - const sliderSelector = '[data-testid="ImpactSlider-example-1"] #ImpactSlider'; - const slider = await page.$(sliderSelector); - const moneyBuyElement = page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-1"]'); - const moneyBuyText = await moneyBuyElement.innerText(); - console.log('Target initially: ', moneyBuyText); - - if (slider) { - // Get the bounding box of the slider - let sliderBound = await slider.boundingBox(); + console.log('Target initially: ', await moneyBuyElement.innerText()); - // Get the target position for the mouse move to a donation of £100 - const targetPosition = sliderBound.width * (100 / 100); + await setSliderValue(page, 'ImpactSlider-example-1', 100); - // Perform mouse actions to simulate dragging the slider handle - await page.mouse.move(sliderBound.x, sliderBound.y + sliderBound.height / 2); - await page.mouse.down(); - - while (sliderBound.width * (parseFloat(await moneyBuyElement.innerText()) / 100) !== targetPosition) { - await page.mouse.move(sliderBound.x + targetPosition, sliderBound.y + sliderBound.height / 2); - sliderBound = await slider.boundingBox(); - } - - await page.mouse.up(); - } - - await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > div > p')).toContainText('A donation of £100 could help pay for:'); + await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > p')).toContainText('A donation of £100 could help pay for:'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-1"] [data-testid="moneybuy-amount"]')).toContainText('100'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-2"] [data-testid="moneybuy-amount"]')).toContainText('10'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-3"] [data-testid="moneybuy-amount"]')).toContainText('6'); @@ -98,41 +80,18 @@ test.describe('impact slider component - 1', () => { }); test('impact slider - sliding to the minimum amount £25', async ({ page }) => { - await page.goto('/#impactslider'); // Ensure that the slider and its handle are visible await expect(page.locator('[data-testid="ImpactSlider-example-1"]')).toBeVisible(); await expect(page.locator('[data-testid="ImpactSlider-example-1"] #ImpactSlider > div:nth-child(4)')).toBeVisible(); - // slider selector - const sliderSelector = '[data-testid="ImpactSlider-example-1"] #ImpactSlider'; - const slider = await page.$(sliderSelector); - const moneyBuyElement = page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-1"]'); - const moneyBuyText = await moneyBuyElement.innerText(); - console.log('Target initially: ', moneyBuyText); - - if (slider) { - // Get the bounding box of the slider - let sliderBound = await slider.boundingBox(); - - // Get the target position for the mouse move to a donation of £25 - const targetPosition = sliderBound.width * (25 / 100); - - // Perform mouse actions to simulate dragging the slider handle - await page.mouse.move(sliderBound.x, sliderBound.y + sliderBound.height / 2); - await page.mouse.down(); - - while (sliderBound.width * (parseFloat(await moneyBuyElement.innerText()) / 100) !== targetPosition) { - await page.mouse.move(sliderBound.x + targetPosition, sliderBound.y + sliderBound.height / 2); - sliderBound = await slider.boundingBox(); - } + console.log('Target initially: ', await moneyBuyElement.innerText()); - await page.mouse.up(); - } + await setSliderValue(page, 'ImpactSlider-example-1', 25); - await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > div > p')).toContainText('A donation of £25 could help pay for:'); + await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > p')).toContainText('A donation of £25 could help pay for:'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-1"] [data-testid="moneybuy-amount"]')).toContainText('25'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-2"] [data-testid="moneybuy-amount"]')).toContainText('2'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-3"] [data-testid="moneybuy-amount"]')).toContainText('1'); @@ -152,42 +111,14 @@ test.describe('impact slider component - 1', () => { await expect(page.locator('[data-testid="ImpactSlider-example-1"]')).toBeVisible(); await expect(page.locator('[data-testid="ImpactSlider-example-1"] #ImpactSlider > div:nth-child(4)')).toBeVisible(); - const sliderSelector = '[data-testid="ImpactSlider-example-1"] #ImpactSlider'; - const slider = await page.$(sliderSelector); - const moneyBuyElement = page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-1"]'); - const moneyBuyText = await moneyBuyElement.innerText(); - console.log('Target initially: ', moneyBuyText); - - let targetAmountBeforeMoving; - let sliderBound; + console.log('Target initially: ', await moneyBuyElement.innerText()); // drag the slider to the right to increase the amount to £80 - if (slider) { - // Get the bounding box of the slider - sliderBound = await slider.boundingBox(); - - // Get the target position for the mouse move to a donation of £80 - const targetPosition80 = sliderBound.width * (80 / 100); - - // Perform mouse actions to simulate dragging the slider handle to 80 - await page.mouse.move(sliderBound.x, sliderBound.y + sliderBound.height / 2); - await page.mouse.down(); - - while (sliderBound.width * (parseFloat(await moneyBuyElement.innerText()) / 100) !== targetPosition80) { - await page.mouse.move(sliderBound.x + targetPosition80, sliderBound.y + sliderBound.height / 2); - sliderBound = await slider.boundingBox(); - } + await setSliderValue(page, 'ImpactSlider-example-1', 80); + console.log('Slider increased to amount: ', await moneyBuyElement.innerText()); - await page.mouse.up(); - - // Update targetAmountBeforeMoving after the first slider move - targetAmountBeforeMoving = parseFloat(await moneyBuyElement.innerText()); - console.log('Slider increased to amount: ', targetAmountBeforeMoving); - } - - // Validate that the slider is at £80 - await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > div > p')).toContainText('A donation of £80 could help pay for:'); + await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > p')).toContainText('A donation of £80 could help pay for:'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-1"] [data-testid="moneybuy-amount"]')).toContainText('80'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-2"] [data-testid="moneybuy-amount"]')).toContainText('8'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-3"] [data-testid="moneybuy-amount"]')).toContainText('5'); @@ -196,39 +127,15 @@ test.describe('impact slider component - 1', () => { // donate now button should have the amount as £80 await expect(page.locator('[data-testid="ImpactSlider-example-1"] button[type="submit"]')).toContainText('Donate £80 now'); - // add a short wait for the slider to move back from £80 to £50 await page.waitForTimeout(5000); // drag the slider to the left to decrease the amount to £50 - if (slider) { - // Get the bounding box of the slider - sliderBound = await slider.boundingBox(); - - // Get the target position for the mouse move to a donation of £80 - const targetPosition45 = sliderBound.width * (50 / 100); - - // Perform mouse actions to simulate dragging the slider handle to 80 - await page.mouse.move(sliderBound.x, sliderBound.y + sliderBound.height / 2); - await page.mouse.down(); - - while (sliderBound.width * (parseFloat(await moneyBuyElement.innerText()) / 100) !== targetPosition45) { - await page.mouse.move(sliderBound.x + targetPosition45, sliderBound.y + sliderBound.height / 2); - sliderBound = await slider.boundingBox(); - } - - await page.mouse.down(); - - await page.waitForTimeout(2000); - - // Update targetAmountBeforeMoving after the first slider move - targetAmountBeforeMoving = parseFloat(await moneyBuyElement.innerText()); - console.log('Slider decreased to amount: ', targetAmountBeforeMoving); - } + await setSliderValue(page, 'ImpactSlider-example-1', 50); + console.log('Slider decreased to amount: ', await moneyBuyElement.innerText()); await page.waitForTimeout(2000); - // Validate that the slider is at £50 - await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > div > p')).toContainText('A donation of £50 could help pay for:'); + await expect(page.locator('[data-testid="ImpactSlider-example-1"] > [data-preview="ImpactSlider"] > div > div > p')).toContainText('A donation of £50 could help pay for:'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-1"] [data-testid="moneybuy-amount"]')).toContainText('50'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-2"] [data-testid="moneybuy-amount"]')).toContainText('5'); await expect(page.locator('[data-testid="ImpactSlider-example-1"] [data-testid="impact-slider--moneybuy-3"] [data-testid="moneybuy-amount"]')).toContainText('3'); @@ -243,48 +150,25 @@ test.describe('impact slider component - 1', () => { test.describe('impact slider component - 2', () => { test('impact slider - sliding to £45', async ({ page }) => { - await page.goto('/#impactslider'); // Ensure that the slider and its handle are visible - await expect(page.locator('[data-testid="ImpactSlider-example-3"]')).toBeVisible(); - await expect(page.locator('[data-testid="ImpactSlider-example-3"] #ImpactSlider > div:nth-child(4)')).toBeVisible(); - - // slider selector - const sliderSelector = '[data-testid="ImpactSlider-example-3"] #ImpactSlider'; - const slider = await page.$(sliderSelector); - - const moneyBuyElement = page.locator('[data-testid="ImpactSlider-example-3"] [data-testid="impact-slider--moneybuy-1"]'); - const moneyBuyText = await moneyBuyElement.innerText(); - console.log('Target initially: ', moneyBuyText); - - if (slider) { - // Get the bounding box of the slider - let sliderBound = await slider.boundingBox(); - - // Get the target position for the mouse move to a donation of £45 - const targetPosition = sliderBound.width * (45 / 100); - - // Perform mouse actions to simulate dragging the slider handle - await page.mouse.move(sliderBound.x, sliderBound.y + sliderBound.height / 2); - await page.mouse.down(); + await expect(page.locator('[data-testid="ImpactSlider-example-2"]')).toBeVisible(); + await expect(page.locator('[data-testid="ImpactSlider-example-2"] #ImpactSlider > div:nth-child(4)')).toBeVisible(); - while (sliderBound.width * (parseFloat(await moneyBuyElement.innerText()) / 100) !== targetPosition) { - await page.mouse.move(sliderBound.x + targetPosition, sliderBound.y + sliderBound.height / 2); - sliderBound = await slider.boundingBox(); - } + const moneyBuyElement = page.locator('[data-testid="ImpactSlider-example-2"] [data-testid="impact-slider--moneybuy-1"]'); + console.log('Target initially: ', await moneyBuyElement.innerText()); - await page.mouse.up(); - } + await setSliderValue(page, 'ImpactSlider-example-2', 45); - await expect(page.locator('[data-testid="ImpactSlider-example-3"] > [data-preview="ImpactSlider"] > div > div > div > p')).toContainText('A donation of £45 could help pay for:'); - await expect(page.locator('[data-testid="ImpactSlider-example-3"] [data-testid="impact-slider--moneybuy-1"] [data-testid="moneybuy-amount"]')).toContainText('45'); - await expect(page.locator('[data-testid="ImpactSlider-example-3"] [data-testid="impact-slider--moneybuy-2"] [data-testid="moneybuy-amount"]')).toContainText('4'); - await expect(page.locator('[data-testid="ImpactSlider-example-3"] [data-testid="impact-slider--moneybuy-3"] [data-testid="moneybuy-amount"]')).toContainText('3'); - await expect(page.locator('[data-testid="ImpactSlider-example-3"] [data-testid="impact-slider--moneybuy-4"] [data-testid="moneybuy-amount"]')).toContainText('2'); + await expect(page.locator('[data-testid="ImpactSlider-example-2"] > [data-preview="ImpactSlider"] > div > div > p')).toContainText('A donation of £45 could help pay for:'); + await expect(page.locator('[data-testid="ImpactSlider-example-2"] [data-testid="impact-slider--moneybuy-1"] [data-testid="moneybuy-amount"]')).toContainText('45'); + await expect(page.locator('[data-testid="ImpactSlider-example-2"] [data-testid="impact-slider--moneybuy-2"] [data-testid="moneybuy-amount"]')).toContainText('4'); + await expect(page.locator('[data-testid="ImpactSlider-example-2"] [data-testid="impact-slider--moneybuy-3"] [data-testid="moneybuy-amount"]')).toContainText('3'); + await expect(page.locator('[data-testid="ImpactSlider-example-2"] [data-testid="impact-slider--moneybuy-4"] [data-testid="moneybuy-amount"]')).toContainText('2'); // donate now button should have the amount as £45 - await expect(page.locator('[data-testid="ImpactSlider-example-3"] button[type="submit"]')).toContainText('Donate £45 now'); + await expect(page.locator('[data-testid="ImpactSlider-example-2"] button[type="submit"]')).toContainText('Donate £45 now'); await page.waitForTimeout(5000); await page.close(); diff --git a/src/App.jsx b/src/App.jsx new file mode 100644 index 000000000..6716b2440 --- /dev/null +++ b/src/App.jsx @@ -0,0 +1,92 @@ +import React, { useState, useEffect } from 'react'; +import styled from 'styled-components'; +import { atoms, molecules, organisms, docs } from './demos/index.jsx'; +import { Layout, Sidebar, SidebarTitle, SidebarItem, Preview, PreviewHeader, PreviewBox, Logo, IsolateButton } from './App.styles.js'; +import crLogo from './components/Atoms/Logos/assets/cr-logo.svg'; + +const Chevron = styled.span` + font-size: 1.2rem; + transition: transform 0.2s; + transform: ${({ $open }) => ($open ? 'rotate(0deg)' : 'rotate(-90deg)')}; +`; + +const groups = [ + { label: 'Docs', items: docs }, + { label: 'Atoms', items: atoms }, + { label: 'Molecules', items: molecules }, + { label: 'Organisms', items: organisms }, +]; + +// unpack all items in all groups into one flay array +const allItems = groups.flatMap(g => g.items); + +// return the item that matches the url element hash tag +function itemFromHash() { + const hash = window.location.hash.slice(1).toLowerCase(); + return allItems.find(item => item.name.toLowerCase() === hash) || atoms[0]; +} + +export default function App() { + const [selected, setSelected] = useState(itemFromHash); + const [isIsolated, setIsIsolated] = useState(false); + const [openGroups, setOpenGroups] = useState(() => + groups.reduce((acc, g) => ({ ...acc, [g.label]: false }), {}) + ); + + const toggleGroup = label => setOpenGroups(prev => ({ ...prev, [label]: !prev[label] })); + + useEffect(() => { + const onHashChange = () => setSelected(itemFromHash()); + window.addEventListener('hashchange', onHashChange); + return () => window.removeEventListener('hashchange', onHashChange); + }, []); + + const currentItem = allItems.find(item => item.name === selected.name); + + const handleSelect = item => { + window.location.hash = item.name.toLowerCase(); + setSelected(item); + }; + + return ( + + {!isIsolated && ( + + Comic Relief + {groups.map(group => ( +
+ toggleGroup(group.label)}> + {group.label} + + + {openGroups[group.label] && group.items.map(item => ( + handleSelect(item)} + > + {item.name} + + ))} +
+ ))} +
+ )} + + +

{selected.name}

+ setIsIsolated(s => !s)}> + {isIsolated ? 'Show Sidebar' : 'Isolate'} + +
+ {(currentItem?.examples ?? (currentItem?.demo != null ? [currentItem.demo] : [])).map((example, idx) => ( + +
+ {example} +
+
+ ))} +
+
+ ); +} diff --git a/src/App.styles.js b/src/App.styles.js new file mode 100644 index 000000000..4bfc43d0a --- /dev/null +++ b/src/App.styles.js @@ -0,0 +1,111 @@ +import styled from 'styled-components'; +import color from './theme/crTheme/colors'; + +export const Layout = styled.div` + display: flex; + height: 100vh; + font-family: sans-serif; +`; + +export const Sidebar = styled.nav` + width: 240px; + min-width: 240px; + background: ${color('grey_5')}; + color: ${color('white')}; + overflow-y: scroll; + padding: 1rem 0; +`; + +export const SidebarTitle = styled.div` + display: flex; + justify-content: space-between; + align-items: center; + padding: 1.5rem 1rem 0.75rem; + font-size: 0.8rem; + font-weight: 700; + letter-spacing: 0.1em; + text-transform: uppercase; + color: ${color('red')}; + cursor: pointer; + user-select: none; + + &:hover { + opacity: 0.8; + } +`; + +export const SidebarItem = styled.button` + display: block; + width: 100%; + text-align: left; + padding: 0.4rem 1rem; + background: ${({ $active }) => ($active ? color('grey_4_hover') : color('transparent'))}; + color: ${({ $active }) => ($active ? color('white') : color('grey'))}; + border: none; + cursor: pointer; + font-size: 0.85rem; + border-left: 3px solid ${({ $active }) => ($active ? color('red') : color('transparent'))}; + + &:hover { + background: ${color('grey_dark')}; + color: ${color('white')}; + } +`; + +export const Preview = styled.main` + flex: 1; + overflow-y: auto; + padding: 2rem; + background: ${color('grey_light')}; +`; + +export const PreviewHeader = styled.div` + display: flex; + align-items: center; + justify-content: space-between; + margin: 0 0 1.5rem; + border-bottom: 1px solid ${color('grey_medium')}; + padding-bottom: 0.75rem; + + h2 { + margin: 0; + font-size: 1.25rem; + color: ${color('grey_5')}; + } +`; + +export const PreviewBox = styled.div` + background: ${color('white')}; + border: 1px solid ${color('grey_medium')}; + border-radius: 6px; + padding: 2rem; +`; + +export const Logo = styled.div` + padding: 1rem; + border-bottom: 1px solid ${color('grey_dark')}; + margin-bottom: 0.5rem; + + img { + display: block; + width: 50px; + height: auto; + } +`; + +export const IsolateButton = styled.button` + background: ${color('red')}; + border: 1px solid ${color('red')}; + border-radius: 4px; + color: ${color('white')}; + cursor: pointer; + font-size: 0.75rem; + font-weight: 700; + letter-spacing: 0.05em; + padding: 0.25rem 0.6rem; + + &:hover { + background: ${color('red_dark')}; + border-color: ${color('red_dark')}; + } +`; diff --git a/src/styleguide/assets/HeroBannerLogo-Square.png b/src/assets/HeroBannerLogo-Square.png similarity index 100% rename from src/styleguide/assets/HeroBannerLogo-Square.png rename to src/assets/HeroBannerLogo-Square.png diff --git a/src/styleguide/assets/HeroBannerLogo-Tall.png b/src/assets/HeroBannerLogo-Tall.png similarity index 100% rename from src/styleguide/assets/HeroBannerLogo-Tall.png rename to src/assets/HeroBannerLogo-Tall.png diff --git a/src/styleguide/assets/HeroBannerLogo-Wide.png b/src/assets/HeroBannerLogo-Wide.png similarity index 100% rename from src/styleguide/assets/HeroBannerLogo-Wide.png rename to src/assets/HeroBannerLogo-Wide.png diff --git a/src/styleguide/assets/PromoLW.jpg b/src/assets/PromoLW.jpg similarity index 100% rename from src/styleguide/assets/PromoLW.jpg rename to src/assets/PromoLW.jpg diff --git a/src/styleguide/assets/VideoBannerPosterImage.png b/src/assets/VideoBannerPosterImage.png similarity index 100% rename from src/styleguide/assets/VideoBannerPosterImage.png rename to src/assets/VideoBannerPosterImage.png diff --git a/src/styleguide/assets/challenge-1.jpg b/src/assets/challenge-1.jpg similarity index 100% rename from src/styleguide/assets/challenge-1.jpg rename to src/assets/challenge-1.jpg diff --git a/src/styleguide/assets/mobileVideoPosterImage.png b/src/assets/mobileVideoPosterImage.png similarity index 100% rename from src/styleguide/assets/mobileVideoPosterImage.png rename to src/assets/mobileVideoPosterImage.png diff --git a/src/styleguide/assets/picture-1.jpg b/src/assets/picture-1.jpg similarity index 100% rename from src/styleguide/assets/picture-1.jpg rename to src/assets/picture-1.jpg diff --git a/src/styleguide/assets/picture-2.jpg b/src/assets/picture-2.jpg similarity index 100% rename from src/styleguide/assets/picture-2.jpg rename to src/assets/picture-2.jpg diff --git a/src/styleguide/assets/picture-3.jpg b/src/assets/picture-3.jpg similarity index 100% rename from src/styleguide/assets/picture-3.jpg rename to src/assets/picture-3.jpg diff --git a/src/styleguide/assets/promo.jpg b/src/assets/promo.jpg similarity index 100% rename from src/styleguide/assets/promo.jpg rename to src/assets/promo.jpg diff --git a/src/styleguide/assets/tall.jpg b/src/assets/tall.jpg similarity index 100% rename from src/styleguide/assets/tall.jpg rename to src/assets/tall.jpg diff --git a/src/styleguide/assets/wide.jpg b/src/assets/wide.jpg similarity index 100% rename from src/styleguide/assets/wide.jpg rename to src/assets/wide.jpg diff --git a/src/components/Atoms/AmbientVideo/AmbientVideo.md b/src/components/Atoms/AmbientVideo/AmbientVideo.md deleted file mode 100644 index 05730f777..000000000 --- a/src/components/Atoms/AmbientVideo/AmbientVideo.md +++ /dev/null @@ -1,59 +0,0 @@ -# AmbientVideo - -A muted, full-width ambient video component using the HTML5 video element. Ideal for background or decorative video. - -Default (loop, no controls). - -```js -const defaultData = require('../../../styleguide/data/data').defaultData; -const video480 = require('./big-buck-bunny-480p-30sec.mp4'); - -
- -
-``` - -With full controls. - -```js -const defaultData = require('../../../styleguide/data/data').defaultData; -const video480 = require('./big-buck-bunny-480p-30sec.mp4'); - -
- -
-``` - -With play/pause button (hover to reveal). - -```js -const defaultData = require('../../../styleguide/data/data').defaultData; -const video480 = require('./big-buck-bunny-480p-30sec.mp4'); - -
- -
-``` - -Play once (no loop). - -```js -const defaultData = require('../../../styleguide/data/data').defaultData; -const video480 = require('./big-buck-bunny-480p-30sec.mp4'); - -
- -
-``` - -Responsive: 1080p above M breakpoint (740px), 480p below. Resize the browser to see the switch. - -```js -const defaultData = require('../../../styleguide/data/data').defaultData; -const video480 = require('./thetestdatacom_480p_example.mp4'); -const video1080 = require('./big-buck-bunny-1080p-30sec.mp4'); - -
- -
-``` diff --git a/src/components/Atoms/AmbientVideo/AmbientVideoExample.jsx b/src/components/Atoms/AmbientVideo/AmbientVideoExample.jsx new file mode 100644 index 000000000..0ea50d37b --- /dev/null +++ b/src/components/Atoms/AmbientVideo/AmbientVideoExample.jsx @@ -0,0 +1,47 @@ +import React from 'react'; +import styled from 'styled-components'; +import AmbientVideo from './AmbientVideo'; +import { defaultData } from '../../../data/data'; +import video480 from './big-buck-bunny-480p-30sec.mp4'; +import video1080 from './big-buck-bunny-1080p-30sec.mp4'; +import videoMobile from './thetestdatacom_480p_example.mp4'; + +const ExampleContainer = styled.div` + width: 100%; + max-width: ${({ $maxWidth }) => $maxWidth || '600px'}; + aspect-ratio: ${({ $aspectRatio }) => $aspectRatio || '16 / 9'}; + overflow: hidden; +`; + +export default function AmbientVideoExample() { + return ( + <> +

A muted, full-width ambient video component using the HTML5 video element. Ideal for background or decorative video.

+ +

Default (loop, no controls)

+ + + + +

With full controls

+ + + + +

With play/pause button (hover to reveal)

+ + + + +

Play once (no loop)

+ + + + +

Responsive: 1080p above M breakpoint (740px), 480p below. Resize the browser to see the switch

+ + + + + ); +} diff --git a/src/components/Atoms/Button/Button.js b/src/components/Atoms/Button/Button.js index 7a47439b7..fe5ea8ac7 100644 --- a/src/components/Atoms/Button/Button.js +++ b/src/components/Atoms/Button/Button.js @@ -11,7 +11,7 @@ const Button = React.forwardRef(({ buttonType = buttonTypes.PRIMARY, ...rest }, ref) => ( - + {children} )); diff --git a/src/components/Atoms/Button/Button.md b/src/components/Atoms/Button/Button.md deleted file mode 100644 index 48afd3b57..000000000 --- a/src/components/Atoms/Button/Button.md +++ /dev/null @@ -1,101 +0,0 @@ -```js - -import buttonTypes from '../../../theme/crTheme/buttonTypes'; - -<> -

Primary

-
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
-

Secondary

- -
- -
- -
- -
- -
- -
- -
- -
- - -
- -
- -
- -
- -
-

Teritary

- -
- -
- -
- -
- -
- -
- -
- -
- - -
- -
- -
- -
- - - -``` - -```js - -``` - -```js - -``` \ No newline at end of file diff --git a/src/components/Atoms/Button/Button.style.js b/src/components/Atoms/Button/Button.style.js index d789dbce9..9091a041e 100644 --- a/src/components/Atoms/Button/Button.style.js +++ b/src/components/Atoms/Button/Button.style.js @@ -19,18 +19,18 @@ const StyledButton = styled.button` text-decoration: none; } - ${({ color, theme, buttonType }) => (theme.buttonColors(color, buttonType))}; + ${({ $color, theme, $buttonType }) => (theme.buttonColors($color, $buttonType))}; ${({ theme }) => css`${fontHelper(theme, 'button')}`} - + @media ${({ theme }) => theme.allBreakpoints('M')} { - width: ${({ fullWidth }) => (fullWidth ? '100%' : 'auto')}; + width: ${({ $fullWidth }) => ($fullWidth ? '100%' : 'auto')}; } @media ${({ theme }) => theme.allBreakpoints('L')} { // I don't *believe* this needs to be reinstated, but leaving in // place for now, just to avoid breaking anything downstream... - width: ${({ fullWidth }) => (fullWidth ? '100%' : 'auto')}; + width: ${({ $fullWidth }) => ($fullWidth ? '100%' : 'auto')}; } `; diff --git a/src/components/Atoms/Button/Button.test.js b/src/components/Atoms/Button/Button.test.js index 282e00785..4023da9db 100644 --- a/src/components/Atoms/Button/Button.test.js +++ b/src/components/Atoms/Button/Button.test.js @@ -9,93 +9,77 @@ it('renders a standard styled link correctly', () => { ).toJSON(); expect(tree).toMatchInlineSnapshot(` - .c0 { - display: -webkit-inline-box; - display: -webkit-inline-flex; - display: -ms-inline-flexbox; - display: inline-flex; - position: relative; - -webkit-text-decoration: none; - text-decoration: none; - -webkit-transition: all 0.2s; - transition: all 0.2s; - height: 2.5rem; - width: 100%; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; - justify-content: center; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; - border: none; - cursor: pointer; - padding: 0.6rem 1rem; - border-radius: 0.5rem; - background-color: #E52630; - color: #FFFFFF; - font-family: 'Montserrat',Helvetica,Arial,sans-serif; - font-weight: 700; - text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; - letter-spacing: 0; - font-size: 1rem; - line-height: 1.25rem; - } +.c0 { + display: inline-flex; + position: relative; + text-decoration: none; + transition: all 0.2s; + height: 2.5rem; + width: 100%; + justify-content: center; + align-items: center; + border: none; + cursor: pointer; + padding: 0.6rem 1rem; + border-radius: 0.5rem; + background-color: #E52630; + color: #FFFFFF; + font-family: 'Montserrat',Helvetica,Arial,sans-serif; + font-weight: 700; + text-transform: inherit; + letter-spacing: 0; + font-size: 1rem; + line-height: 1.25rem; +} - .c0 > a { - -webkit-text-decoration: none; - text-decoration: none; - } +.c0 >a { + text-decoration: none; +} - .c0:hover, - .c0:focus, - .c0:focus-within, - .c0:focus-visible { - background-color: #890B11; - outline-offset: 3px; - } +.c0:hover, +.c0:focus, +.c0:focus-within, +.c0:focus-visible { + background-color: #890B11; + outline-offset: 3px; +} - .c0:disabled { - cursor: not-allowed; - opacity: 0.5; - } +.c0:disabled { + cursor: not-allowed; + opacity: 0.5; +} - @media (min-width:740px) { - .c0 { - font-size: 1rem; - line-height: 1.25rem; - } - } +@media (min-width: 740px) { + .c0 { + font-size: 1rem; + line-height: 1.25rem; + } +} - @media (min-width:1024px) { - .c0 { - font-size: 1.125rem; - line-height: 1.375rem; - } - } +@media (min-width: 1024px) { + .c0 { + font-size: 1.125rem; + line-height: 1.375rem; + } +} - @media (min-width:740px) { - .c0 { - width: auto; - } - } +@media (min-width: 740px) { + .c0 { + width: auto; + } +} - @media (min-width:1024px) { - .c0 { - width: auto; - } - } +@media (min-width: 1024px) { + .c0 { + width: auto; + } +} - - `); + +`); }); diff --git a/src/components/Atoms/Button/ButtonExample.jsx b/src/components/Atoms/Button/ButtonExample.jsx new file mode 100644 index 000000000..5f878eaf6 --- /dev/null +++ b/src/components/Atoms/Button/ButtonExample.jsx @@ -0,0 +1,112 @@ +import React from 'react'; +import styled from 'styled-components'; +import Button from './Button'; +import buttonTypes from '../../../theme/crTheme/buttonTypes'; + +const ExampleContainer = styled.div` + background-color: ${({ $bg }) => $bg || '#ddd'}; + padding: 15px; + margin-bottom: 10px; + border-radius: 5px; +`; + +export default function ButtonExample() { + return ( + <> +

Primary

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Secondary

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+

Tertiary

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+

Other

+ + + + + + + + + + ); +} diff --git a/src/components/Atoms/ButtonWithStates/ButtonWithStates.js b/src/components/Atoms/ButtonWithStates/ButtonWithStates.js index 8bf10b218..b4943de10 100644 --- a/src/components/Atoms/ButtonWithStates/ButtonWithStates.js +++ b/src/components/Atoms/ButtonWithStates/ButtonWithStates.js @@ -12,7 +12,7 @@ const ButtonWithDisabledState = styled(Button)` } `; -const LoaderContainer = styled.div`${({ withMargin }) => (withMargin ? ` +const LoaderContainer = styled.div`${({ $withMargin }) => ($withMargin ? ` margin-top: ${spacing('xsm')}; margin-left: ${spacing('md')}; ` : '')}`; @@ -41,7 +41,7 @@ const ButtonWithStates = React.forwardRef(({ return ( {loading ? loadingText : children} - + diff --git a/src/components/Atoms/ButtonWithStates/ButtonWithStates.md b/src/components/Atoms/ButtonWithStates/ButtonWithStates.md deleted file mode 100644 index 072670156..000000000 --- a/src/components/Atoms/ButtonWithStates/ButtonWithStates.md +++ /dev/null @@ -1,23 +0,0 @@ -## Disabled and loading - -```js -import ButtonWithStates from './ButtonWithStates'; - - - Enter prize draw - -``` - -## Optional prop `children` - -`children` is an optional prop, this example demonstrates the button will not error without any provided. - -```js -import ButtonWithStates from './ButtonWithStates'; - - -``` diff --git a/src/components/Atoms/ButtonWithStates/ButtonWithStatesExample.jsx b/src/components/Atoms/ButtonWithStates/ButtonWithStatesExample.jsx new file mode 100644 index 000000000..d7f2f994b --- /dev/null +++ b/src/components/Atoms/ButtonWithStates/ButtonWithStatesExample.jsx @@ -0,0 +1,25 @@ +import React from 'react'; +import ButtonWithStates from './ButtonWithStates'; + +export default function ButtonWithStatesExample() { + return ( + <> + + + Enter prize draw + + +

Children are an optional prop. Example to demonstrate the ButtonWithStates will work even with no children provided:

+ + + + + ); +} diff --git a/src/components/Atoms/Checkbox/Checkbox.js b/src/components/Atoms/Checkbox/Checkbox.js index 2bf09a75d..e8a80c7a9 100644 --- a/src/components/Atoms/Checkbox/Checkbox.js +++ b/src/components/Atoms/Checkbox/Checkbox.js @@ -8,9 +8,9 @@ import checkBoxIcon from './assets/tick.svg'; // This label wraps both the input and the span that is the visual square checkbox you see */ const Label = styled.label` display: flex; - ${({ hasLabelAsString }) => hasLabelAsString && 'align-items: center;'} + ${({ $hasLabelAsString }) => $hasLabelAsString && 'align-items: center;'} margin-bottom: 8px; - ${({ theme, labelColour }) => labelColour && `color: ${theme.color(labelColour)}`} + ${({ theme, $labelColour }) => $labelColour && `color: ${theme.color($labelColour)}`} `; const StyledCheckboxInput = styled.input.attrs({ type: 'checkbox' })` @@ -26,26 +26,26 @@ const StyledCheckboxInput = styled.input.attrs({ type: 'checkbox' })` width: 1px; /* This span is actually the visual square Checkbox you see */ - + span { + & + span { margin-right: 12px; width: 24px; height: 24px; border-radius: 4px; - background-color: ${({ theme, checkboxBg }) => (checkboxBg ? theme.color(checkboxBg) : theme.color('white'))}; - border: 1px solid ${({ theme, checkboxBorder }) => (checkboxBorder ? theme.color(checkboxBorder) : theme.color('grey'))}; + background-color: ${({ theme, $checkboxBg }) => ($checkboxBg ? theme.color($checkboxBg) : theme.color('white'))}; + border: 1px solid ${({ theme, $checkboxBorder }) => ($checkboxBorder ? theme.color($checkboxBorder) : theme.color('grey'))}; float: left; flex-shrink: 0; } /* Visual checkbox when ticked */ - :checked + span { + &:checked + span { background: url(${checkBoxIcon}) no-repeat center; background-size: contain; - background-color: ${({ theme, checkboxBgChecked }) => (checkboxBgChecked ? theme.color(checkboxBgChecked) : theme.color('red'))}; - border: 1px solid ${({ theme, checkboxBorderChecked }) => (checkboxBorderChecked ? theme.color(checkboxBorderChecked) : theme.color('red'))}; + background-color: ${({ theme, $checkboxBgChecked }) => ($checkboxBgChecked ? theme.color($checkboxBgChecked) : theme.color('red'))}; + border: 1px solid ${({ theme, $checkboxBorderChecked }) => ($checkboxBorderChecked ? theme.color($checkboxBorderChecked) : theme.color('red'))}; } /* Visual checkbox when focused */ - :focus + span { - border: 1px solid ${({ theme, checkboxBorderFocus }) => (checkboxBorderFocus ? theme.color(checkboxBorderFocus) : theme.color('red'))}; + &:focus + span { + border: 1px solid ${({ theme, $checkboxBorderFocus }) => ($checkboxBorderFocus ? theme.color($checkboxBorderFocus) : theme.color('red'))}; } `; @@ -63,8 +63,8 @@ const Checkbox = React.forwardRef(({ ...rest }, ref) => ( -``` - -```js -import styled from 'styled-components'; - -const StyledInput = styled.input` - max-width: 300px; - font-size: 1.5rem; - height: 2.5rem; - border-radius: 5px; - border-width: 1px; -`; - - -``` diff --git a/src/components/Atoms/Label/LabelExample.jsx b/src/components/Atoms/Label/LabelExample.jsx new file mode 100644 index 000000000..66002735d --- /dev/null +++ b/src/components/Atoms/Label/LabelExample.jsx @@ -0,0 +1,33 @@ +import React from 'react'; +import styled from 'styled-components'; +import Label from './Label'; + +const StyledInput = styled.input` + max-width: 300px; + font-size: 1.5rem; + height: 2.5rem; + border-radius: 5px; + border-width: 1px; +`; + +export default function LabelExample() { + return ( + <> + + +
+ + + + ); +} diff --git a/src/components/Atoms/Link/Link.js b/src/components/Atoms/Link/Link.js index 0eaa92a5f..8bbcf32b1 100755 --- a/src/components/Atoms/Link/Link.js +++ b/src/components/Atoms/Link/Link.js @@ -58,15 +58,15 @@ const Link = ({ {children} {window === '_blank' && (opens in new window)} diff --git a/src/components/Atoms/Link/Link.md b/src/components/Atoms/Link/Link.md deleted file mode 100644 index e4938f3cc..000000000 --- a/src/components/Atoms/Link/Link.md +++ /dev/null @@ -1,223 +0,0 @@ -```js -import { External, Download, Favourite, Internal } from '../Icons/index'; - -
-
- - Link standard - -
-
- } - > - Link standard icon - -
-
- - Link standard white - -
-
; -``` - -```js - -import buttonTypes from '../../../theme/crTheme/buttonTypes'; - -
-
- - Link as button - -
-
- - Link as button - -
-
- - Link as button - -
- - -
- - Link as button (secondary) - -
-
- - Link as button (secondary) - -
-
- - Link as button (secondary) - -
- -
- - Link as button (tertiary) - -
-
- - Link as button (tertiary) - -
-
- - Link as button (tertiary) - -
- -
- -
- - Link as full-width red button - -
-
-
-``` - - -## Iconography -```js -import { External, Download, Favourite, Internal, Chevron, Arrow, AtSign } from '../Icons/index'; - -
-
- } - > - Internal link, 'blue' with red icon on tablet and mobile - -
- -
- } - > - External link (black on mobile, blue on desktop) - -
- -
- } - > - Download link (blue mobile-tablet icon, white desktop icon) - -
- -
- } - > - Favourite link (blue mobile-tablet icon, white desktop icon) - -
- -
- } - > - Chevron Up (blue mobile-tablet icon, white desktop icon) - -
- -
- } - > - Chevron Down (blue mobile-tablet icon, white desktop icon) - -
- -
- } - > - Chevron Left (blue mobile-tablet icon, white desktop icon) - -
- -
- } - > - Chevron Right (blue mobile-tablet icon, white desktop icon) - -
- -
- } - > - Arrow Left (blue mobile-tablet icon, white desktop icon) - -
- -
- } - > - At Sign (blue mobile-tablet icon, white desktop icon) - -
-
; -``` diff --git a/src/components/Atoms/Link/Link.style.js b/src/components/Atoms/Link/Link.style.js index 134b1a2e9..9d36a700b 100644 --- a/src/components/Atoms/Link/Link.style.js +++ b/src/components/Atoms/Link/Link.style.js @@ -17,27 +17,27 @@ const buttonStyle = () => css` padding: 0.6rem 1rem; border-radius: 0.5rem; - ${({ $color, theme, buttonType }) => (theme.buttonColors($color, buttonType))}; + ${({ $color, theme, $buttonType }) => (theme.buttonColors($color, $buttonType))}; ${({ theme }) => css` ${fontHelper(theme, 'button')}`} // Override with mobile-specific colours where available: - ${({ mobileColour, theme, buttonType }) => (mobileColour ? theme.buttonColors(mobileColour, buttonType) : null)}; + ${({ $mobileColour, theme, $buttonType }) => ($mobileColour ? theme.buttonColors($mobileColour, $buttonType) : null)}; @media ${({ theme }) => theme.allBreakpoints('M')} { - width: ${({ fullWidth }) => (fullWidth ? '100%' : 'auto')}; + width: ${({ $fullWidth }) => ($fullWidth ? '100%' : 'auto')}; } @media ${({ theme }) => theme.allBreakpoints('L')} { // I don't *believe* this needs to be reinstated, but leaving in // place for now, just to avoid breaking anything downstream... - width: ${({ fullWidth }) => (fullWidth ? '100%' : 'auto')}; + width: ${({ $fullWidth }) => ($fullWidth ? '100%' : 'auto')}; // Reinstate standard colours for desktop where appropriate: ${({ - mobileColour, theme, buttonType, $color + $mobileColour, theme, $buttonType, $color }) => ( - mobileColour && theme.buttonColors($color, buttonType) + $mobileColour && theme.buttonColors($color, $buttonType) )}; } `; @@ -48,6 +48,7 @@ const linkStyle = () => css` ${({ type, theme }) => (type ? theme.linkStyles(type) : theme.linkStyles('standard'))}; + ${({ $color, theme }) => $color && css`color: ${theme.color($color)};`} `; export const IconWrapper = styled.span` @@ -79,7 +80,7 @@ export const IconWrapper = styled.span` const StyledLink = styled.a` ${props => (props.type === 'button' ? buttonStyle : linkStyle)} - ${({ iconFirst }) => iconFirst + ${({ $iconFirst }) => $iconFirst && css` flex-direction: row-reverse; span[type="button"] { diff --git a/src/components/Atoms/Link/Link.test.js b/src/components/Atoms/Link/Link.test.js index b416e9e90..f23daa3f4 100644 --- a/src/components/Atoms/Link/Link.test.js +++ b/src/components/Atoms/Link/Link.test.js @@ -12,29 +12,29 @@ it('renders a standard styled link correctly', () => { ).toJSON(); expect(tree).toMatchInlineSnapshot(` - .c0 { - position: relative; - display: inline; - color: #000000; - font-weight: normal; - } +.c0 { + position: relative; + display: inline; + color: #000000; + font-weight: normal; + color: #E52630; +} - .c0:hover, - .c0:focus { - color: #000000; - -webkit-text-decoration: none; - text-decoration: none; - } +.c0:hover, +.c0:focus { + color: #000000; + text-decoration: none; +} - - A standard link - - `); + + A standard link + +`); }); it('renders a button with an icon', () => { @@ -50,84 +50,81 @@ it('renders a button with an icon', () => { ).toJSON(); expect(tree).toMatchInlineSnapshot(` - .c1 { - display: -webkit-inline-box; - display: -webkit-inline-flex; - display: -ms-inline-flexbox; - display: inline-flex; - margin-left: 1rem; - -webkit-align-self: center; - -ms-flex-item-align: center; - align-self: center; - right: 1.5rem; - position: absolute; - right: -2rem; - top: 0; - bottom: 0; - } +.c2 { + fill: #FFFFFF; +} - .c0 { - position: relative; - display: inline; - color: #000000; - font-weight: normal; - } +.c1 { + display: inline-flex; + margin-left: 1rem; + align-self: center; + right: 1.5rem; + position: absolute; + right: -2rem; + top: 0; + bottom: 0; +} - .c0:hover, - .c0:focus { - color: #000000; - -webkit-text-decoration: none; - text-decoration: none; - } +.c0 { + position: relative; + display: inline; + color: #000000; + font-weight: normal; + color: #E52630; +} - .c2 { - fill: #FFFFFF; - } +.c0:hover, +.c0:focus { + color: #000000; + text-decoration: none; +} - @media (min-width:740px) { - .c1 { - width: auto; - right: auto; - position: relative; - position: absolute; - right: -2rem; - top: 0; - bottom: 0; - } - } +@media (min-width: 1024px) { + .c2 { + fill: #FFFFFF; + } +} - @media (min-width:1024px) { - .c2 { - fill: #FFFFFF; - } - } +@media (min-width: 740px) { + .c1 { + width: auto; + right: auto; + position: relative; + position: absolute; + right: -2rem; + top: 0; + bottom: 0; + } +} - + Internal link + + - Internal link - - - - - - - `); + + + + +`); }); it('renders a standard styled link correctly with target blank and assistive text', () => { @@ -138,49 +135,47 @@ it('renders a standard styled link correctly with target blank and assistive tex ).toJSON(); expect(tree).toMatchInlineSnapshot(` - .c0 { - position: relative; - display: inline; - color: #000000; - font-weight: normal; - } +.c0 { + position: relative; + display: inline; + color: #000000; + font-weight: normal; + color: #E52630; +} - .c0:hover, - .c0:focus { - color: #000000; - -webkit-text-decoration: none; - text-decoration: none; - } +.c0:hover, +.c0:focus { + color: #000000; + text-decoration: none; +} - .c1 { - border: 0; - -webkit-clip: rect(0 0 0 0); - clip: rect(0 0 0 0); - -webkit-clip-path: inset(50%); - clip-path: inset(50%); - height: 1px; - margin: -1px; - overflow: hidden; - padding: 0; - position: absolute; - white-space: nowrap; - width: 1px; - } +.c1 { + border: 0; + clip: rect(0 0 0 0); + clip-path: inset(50%); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + white-space: nowrap; + width: 1px; +} - - A standard link - - (opens in new window) - - - `); + + A standard link + + (opens in new window) + + +`); }); it('renders link styled as button correctly', () => { @@ -191,89 +186,75 @@ it('renders link styled as button correctly', () => { ).toJSON(); expect(tree).toMatchInlineSnapshot(` - .c0 { - display: -webkit-inline-box; - display: -webkit-inline-flex; - display: -ms-inline-flexbox; - display: inline-flex; - position: relative; - -webkit-text-decoration: none; - text-decoration: none; - -webkit-transition: all 0.2s; - transition: all 0.2s; - height: 2.5rem; - width: 100%; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; - justify-content: center; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; - border: none; - cursor: pointer; - padding: 0.6rem 1rem; - border-radius: 0.5rem; - background-color: #FFE400; - color: #000000; - font-family: 'Montserrat',Helvetica,Arial,sans-serif; - font-weight: 700; - text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; - letter-spacing: 0; - font-size: 1rem; - line-height: 1.25rem; - } +.c0 { + display: inline-flex; + position: relative; + text-decoration: none; + transition: all 0.2s; + height: 2.5rem; + width: 100%; + justify-content: center; + align-items: center; + border: none; + cursor: pointer; + padding: 0.6rem 1rem; + border-radius: 0.5rem; + background-color: #FFE400; + color: #000000; + font-family: 'Montserrat',Helvetica,Arial,sans-serif; + font-weight: 700; + text-transform: inherit; + letter-spacing: 0; + font-size: 1rem; + line-height: 1.25rem; +} - .c0:hover, - .c0:focus, - .c0:focus-within, - .c0:focus-visible { - background-color: #FEFD5A; - outline-offset: 3px; - } +.c0:hover, +.c0:focus, +.c0:focus-within, +.c0:focus-visible { + background-color: #FEFD5A; + outline-offset: 3px; +} - .c0:disabled { - cursor: not-allowed; - opacity: 0.5; - } +.c0:disabled { + cursor: not-allowed; + opacity: 0.5; +} - @media (min-width:740px) { - .c0 { - font-size: 1rem; - line-height: 1.25rem; - } - } +@media (min-width: 740px) { + .c0 { + font-size: 1rem; + line-height: 1.25rem; + } +} - @media (min-width:1024px) { - .c0 { - font-size: 1.125rem; - line-height: 1.375rem; - } - } +@media (min-width: 1024px) { + .c0 { + font-size: 1.125rem; + line-height: 1.375rem; + } +} - @media (min-width:740px) { - .c0 { - width: auto; - } - } +@media (min-width: 740px) { + .c0 { + width: auto; + } +} - @media (min-width:1024px) { - .c0 { - width: auto; - } - } +@media (min-width: 1024px) { + .c0 { + width: auto; + } +} - - A yellow button - - `); + + A yellow button + +`); }); diff --git a/src/components/Atoms/Link/LinkExample.jsx b/src/components/Atoms/Link/LinkExample.jsx new file mode 100644 index 000000000..265342572 --- /dev/null +++ b/src/components/Atoms/Link/LinkExample.jsx @@ -0,0 +1,226 @@ +import React from 'react'; +import Link from './Link'; +import buttonTypes from '../../../theme/crTheme/buttonTypes'; +import { External, Download, Favourite, Internal, Chevron, Arrow, AtSign } from '../Icons/index'; +import Wrapper from '../../../demos/Wrapper'; + +export default function LinkExample() { + return ( + <> +

Standard links

+ + + + Link standard + + + + + } + > + Link standard icon + + + + + + Link standard white + + + +

Link as Buttons

+ + + + Link as button + + + + + + Link as button + + + + + + Link as button + + + +

Link as Secondary

+ + + + Link as button (secondary) + + + + + + Link as button (secondary) + + + + + + Link as button (secondary) + + + +

Link as Tertiary

+ + + + Link as button (tertiary) + + + + + + Link as button (tertiary) + + + + + + Link as button (tertiary) + + + + + + Link as full-width red button + + + +

Iconography

+ + + } + > + Internal link, 'blue' with red icon on tablet and mobile + + + + + } + > + External link (black on mobile, blue on desktop) + + + + + } + > + Download link (blue mobile-tablet icon, white desktop icon) + + + + + } + > + Favourite link (blue mobile-tablet icon, white desktop icon) + + + + + } + > + Chevron Up (blue mobile-tablet icon, white desktop icon) + + + + + } + > + Chevron Down (blue mobile-tablet icon, white desktop icon) + + + + + } + > + Chevron Left (blue mobile-tablet icon, white desktop icon) + + + + + } + > + Chevron Right (blue mobile-tablet icon, white desktop icon) + + + + + } + > + Arrow Left (blue mobile-tablet icon, white desktop icon) + + + + + } + > + At Sign (blue mobile-tablet icon, white desktop icon) + + + + ); +} diff --git a/src/components/Atoms/Logo/Logo.md b/src/components/Atoms/Logo/Logo.md deleted file mode 100644 index b155eaa04..000000000 --- a/src/components/Atoms/Logo/Logo.md +++ /dev/null @@ -1,22 +0,0 @@ -# Comic Relief Logo - -```js - -``` - -# Sport Relief Logo - -```js - -``` - -# Sport Relief Game On Logo - -```js - -``` diff --git a/src/components/Atoms/Logo/Logo.test.js b/src/components/Atoms/Logo/Logo.test.js deleted file mode 100644 index d426b6b8a..000000000 --- a/src/components/Atoms/Logo/Logo.test.js +++ /dev/null @@ -1,45 +0,0 @@ -import React from 'react'; -import 'jest-styled-components'; -import renderWithTheme from '../../../../tests/hoc/shallowWithTheme'; -import Logo from './Logo'; - -it('renders correctly', () => { - const tree = renderWithTheme().toJSON(); - - expect(tree).toMatchInlineSnapshot(` - .c1 { - object-fit: cover; - width: 100%; - display: block; - height: auto; - margin-right: 1rem; - } - - .c0 { - display: inline-block; - z-index: 3; - width: 51px; - -webkit-transform: rotate(-14deg); - -ms-transform: rotate(-14deg); - transform: rotate(-14deg); - vertical-align: bottom; - } - - @media (min-width:1150px) { - .c0 { - width: 70px; - } - } - -
- Comic Relief logo -
- `); -}); diff --git a/src/components/Atoms/LogoNav2026/LogoNav2026.test.js b/src/components/Atoms/LogoNav2026/LogoNav2026.test.js index cff93ec77..aca9c4e75 100644 --- a/src/components/Atoms/LogoNav2026/LogoNav2026.test.js +++ b/src/components/Atoms/LogoNav2026/LogoNav2026.test.js @@ -8,16 +8,13 @@ it('renders correctly', () => { expect(tree).toMatchInlineSnapshot(` .c0 img { - -webkit-animation: jaJSCW 0.4s ease-in-out forwards; - animation: jaJSCW 0.4s ease-in-out forwards; - -webkit-animation-name: blCpAO; - animation-name: blCpAO; + animation: k0 0.4s ease-in-out forwards; + animation-name: k1; } .c0:hover img, .c0:focus img { - -webkit-animation: jaJSCW 0.4s ease-in-out forwards; - animation: jaJSCW 0.4s ease-in-out forwards; + animation: k0 0.4s ease-in-out forwards; } .c1 { @@ -39,13 +36,13 @@ it('renders correctly', () => { display: none; } - @media (min-width:320px) { + @media (min-width: 320px) { .c2 { display: none; } } - @media (min-width:320px) { + @media (min-width: 320px) { .c3 { display: block; width: 132px; @@ -53,14 +50,14 @@ it('renders correctly', () => { } } - @media (min-width:740px) { + @media (min-width: 740px) { .c3 { width: 162px; height: 25px; } } - @media (min-width:1024px) { + @media (min-width: 1024px) { .c3 { width: 162px; min-width: 162px; @@ -68,6 +65,42 @@ it('renders correctly', () => { } } + @keyframes k0 { + from { + transform: scale3d(1,1,1); + } + + 30% { + transform: scale3d(1.04,1.04,1.04); + } + + 60% { + transform: scale3d(1.03,1.03,1.03); + } + + to { + transform: scale3d(1.04,1.04,1.04); + } + } + + @keyframes k1 { + from { + transform: scale3d(1.03,1.03,1.03); + } + + 30% { + transform: scale3d(0.99,0.99,0.99); + } + + 60% { + transform: scale3d(1.01,1.01,1.01); + } + + to { + transform: scale3d(1,1,1); + } + } + props.sizeSm}; - transform: ${props => (props.rotate ? 'rotate(-14deg)' : 'inherit')}; + width: ${props => props.$sizeSm}; + transform: ${props => (props.$rotate ? 'rotate(-14deg)' : 'inherit')}; vertical-align: bottom; // height fix @media ${({ theme }) => theme.allBreakpoints('Nav')} { - width: ${props => props.sizeMd}; + width: ${props => props.$sizeMd}; } `; @@ -44,7 +44,7 @@ const themeSwitcher = theme => { const Logo = ({ rotate = false, sizeSm = '51px', sizeMd = '70px', campaign = 'Comic Relief' }) => ( - + { { + const tree = renderWithTheme().toJSON(); + + expect(tree).toMatchInlineSnapshot(` +.c1 { + object-fit: cover; + width: 100%; + display: block; + height: auto; + margin-right: 1rem; +} + +.c0 { + display: inline-block; + z-index: 3; + width: 51px; + transform: rotate(-14deg); + vertical-align: bottom; +} + +@media (min-width: 1150px) { + .c0 { + width: 70px; + } +} + +
+ Comic Relief logo +
+`); +}); diff --git a/src/components/Atoms/Logos/LogoExample.jsx b/src/components/Atoms/Logos/LogoExample.jsx new file mode 100644 index 000000000..f8f14250d --- /dev/null +++ b/src/components/Atoms/Logos/LogoExample.jsx @@ -0,0 +1,34 @@ +import React from 'react'; +import Logo from './Logo'; +import styled from 'styled-components'; +import LogoNav2026 from '../LogoNav2026/_LogoNav2026'; + +const Wrapper = styled.div` + margin: 50px; +`; + +export default function LogoExample() { + return ( + <> + +

Comic Relief Logo

+ +
+ + +

Sport Relief Logo

+ +
+ + +

Sport Relief Game On Logo

+ +
+ + +

Logo for Nav 2026 rebuild

+ +
+ + ); +} diff --git a/src/components/Atoms/Logo/assets/CR_LOGO_PRIDE_KEY_RGB.svg b/src/components/Atoms/Logos/assets/CR_LOGO_PRIDE_KEY_RGB.svg similarity index 100% rename from src/components/Atoms/Logo/assets/CR_LOGO_PRIDE_KEY_RGB.svg rename to src/components/Atoms/Logos/assets/CR_LOGO_PRIDE_KEY_RGB.svg diff --git a/src/components/Atoms/Logo/assets/cr-logo.svg b/src/components/Atoms/Logos/assets/cr-logo.svg similarity index 100% rename from src/components/Atoms/Logo/assets/cr-logo.svg rename to src/components/Atoms/Logos/assets/cr-logo.svg diff --git a/src/components/Atoms/Logo/assets/cr-pride-logo.svg b/src/components/Atoms/Logos/assets/cr-pride-logo.svg similarity index 100% rename from src/components/Atoms/Logo/assets/cr-pride-logo.svg rename to src/components/Atoms/Logos/assets/cr-pride-logo.svg diff --git a/src/components/Atoms/Logo/assets/sr-gameon-logo.svg b/src/components/Atoms/Logos/assets/sr-gameon-logo.svg similarity index 100% rename from src/components/Atoms/Logo/assets/sr-gameon-logo.svg rename to src/components/Atoms/Logos/assets/sr-gameon-logo.svg diff --git a/src/components/Atoms/Logo/assets/sr-logo.svg b/src/components/Atoms/Logos/assets/sr-logo.svg similarity index 100% rename from src/components/Atoms/Logo/assets/sr-logo.svg rename to src/components/Atoms/Logos/assets/sr-logo.svg diff --git a/src/components/Atoms/Pagination/Item/Item.js b/src/components/Atoms/Pagination/Item/Item.js index 7b25786f5..690fa3511 100644 --- a/src/components/Atoms/Pagination/Item/Item.js +++ b/src/components/Atoms/Pagination/Item/Item.js @@ -2,8 +2,35 @@ import React from 'react'; import PropTypes from 'prop-types'; import StyledItem from './Item.style'; -const Item = ({ children, target, ...restProps }) => ( - +const Item = ({ + children, + target, + color, + backgroundColor, + selectedColor, + selectedBackgroundColor, + disabledColor, + disabledBackgroundColor, + colorOnHover, + backgroundColorOnHover, + selected, + disabled, + ...restProps +}) => ( + {children} ); @@ -11,14 +38,16 @@ const Item = ({ children, target, ...restProps }) => ( Item.propTypes = { children: PropTypes.string.isRequired, target: PropTypes.string.isRequired, - color: PropTypes.string.isRequired, // required for styling in `StyledItem` - backgroundColor: PropTypes.string.isRequired, // required for styling in `StyledItem` - selectedColor: PropTypes.string.isRequired, // required for styling in `StyledItem` - selectedBackgroundColor: PropTypes.string.isRequired, // required for styling in `StyledItem` - disabledColor: PropTypes.string.isRequired, // required for styling in `StyledItem` - disabledBackgroundColor: PropTypes.string.isRequired, // required for styling in `StyledItem` - colorOnHover: PropTypes.string.isRequired, // required for styling in `StyledItem` - backgroundColorOnHover: PropTypes.string.isRequired // required for styling in `StyledItem` + color: PropTypes.string.isRequired, + backgroundColor: PropTypes.string.isRequired, + selectedColor: PropTypes.string.isRequired, + selectedBackgroundColor: PropTypes.string.isRequired, + disabledColor: PropTypes.string.isRequired, + disabledBackgroundColor: PropTypes.string.isRequired, + colorOnHover: PropTypes.string.isRequired, + backgroundColorOnHover: PropTypes.string.isRequired, + selected: PropTypes.bool, + disabled: PropTypes.bool }; export default Item; diff --git a/src/components/Atoms/Pagination/Item/Item.style.js b/src/components/Atoms/Pagination/Item/Item.style.js index b3ef3b8f5..0cf9e4a54 100644 --- a/src/components/Atoms/Pagination/Item/Item.style.js +++ b/src/components/Atoms/Pagination/Item/Item.style.js @@ -6,47 +6,47 @@ const StyledItem = styled.a` text-align: center; text-decoration: none; font-weight: 700; - cursor: ${({ selected, disabled }) => (selected || disabled ? 'default' : 'pointer')}; + cursor: ${({ $selected, $disabled }) => ($selected || $disabled ? 'default' : 'pointer')}; background: ${({ theme, - selected, - disabled, - backgroundColor, - selectedBackgroundColor, - disabledBackgroundColor + $selected, + $disabled, + $backgroundColor, + $selectedBackgroundColor, + $disabledBackgroundColor }) => { - let processedBackgroundColor = backgroundColor; - if (disabled) { - processedBackgroundColor = disabledBackgroundColor; - } else if (selected) { - processedBackgroundColor = selectedBackgroundColor; + let processedBackgroundColor = $backgroundColor; + if ($disabled) { + processedBackgroundColor = $disabledBackgroundColor; + } else if ($selected) { + processedBackgroundColor = $selectedBackgroundColor; } return theme.color(processedBackgroundColor); }}; color: ${({ theme, - selected, - disabled, - color, - selectedColor, - disabledColor + $selected, + $disabled, + $color, + $selectedColor, + $disabledColor }) => { - let processedColor = color; - if (disabled) { - processedColor = disabledColor; - } else if (selected) { - processedColor = selectedColor; + let processedColor = $color; + if ($disabled) { + processedColor = $disabledColor; + } else if ($selected) { + processedColor = $selectedColor; } return theme.color(processedColor); }}; ${({ - theme, selected, disabled, backgroundColorOnHover, colorOnHover + theme, $selected, $disabled, $backgroundColorOnHover, $colorOnHover }) => { - if (!(selected || disabled)) { + if (!($selected || $disabled)) { return css` - :hover { - background: ${theme.color(backgroundColorOnHover)}; - color: ${theme.color(colorOnHover)}; + &:hover { + background: ${theme.color($backgroundColorOnHover)}; + color: ${theme.color($colorOnHover)}; } `; } diff --git a/src/components/Atoms/Pagination/Pagination.md b/src/components/Atoms/Pagination/Pagination.md deleted file mode 100644 index 68d4a067d..000000000 --- a/src/components/Atoms/Pagination/Pagination.md +++ /dev/null @@ -1,159 +0,0 @@ -### Minimalist - -```js - `example.com/page/${value}`} - onSelect={(event, value) => { - event.preventDefault(); - console.log(value); - }} - showFirst={false} - showPrevious={false} - showNext={false} - showLast={false} -/> - - `example.com/page/${value}`} - onSelect={(event, value) => { - event.preventDefault(); - console.log(value); - }} - showFirst={false} - showPrevious={false} - showNext={false} - showLast={false} - selectedBackgroundColor="black" -/> -``` - -### Full size - -```js - `example.com/page/${value}`} - onSelect={(event, value) => { - event.preventDefault(); - console.log(value); - }} - showFirst={true} - showPrevious={true} - showNext={true} - showLast={true} - showMore={true} -/> - - `example.com/page/${value}`} - onSelect={(event, value) => { - event.preventDefault(); - console.log(value); - }} - showFirst={true} - showPrevious={true} - showNext={true} - showLast={true} - showMore={true} - selectedBackgroundColor="purple" -/> - - `example.com/page/${value}`} - onSelect={(event, value) => { - event.preventDefault(); - console.log(value); - }} - showFirst={true} - showPrevious={true} - showNext={true} - showLast={true} - showMore={true} - selectedBackgroundColor="blue" -/> - - `example.com/page/${value}`} - onSelect={(event, value) => { - event.preventDefault(); - console.log(value); - }} - showFirst={true} - showPrevious={true} - showNext={true} - showLast={true} - showMore={true} - selectedBackgroundColor="green" -/> -``` - -### Custom style - -```js - `example.com/page/${value}`} - onSelect={(event, value) => { - event.preventDefault(); - console.log(value); - }} - showFirst={true} - showPrevious={true} - showNext={true} - showLast={true} - showMore={true} - color="red" - backgroundColor="yellow" - selectedColor="yellow" - selectedBackgroundColor="teal" - disabledColor="white" - disabledBackgroundColor="grey_light" - colorOnHover="yellow" - backgroundColorOnHover="teal" -/> -``` - -### Custom labels - -```js - `example.com/page/${value}`} - onSelect={(event, value) => { - event.preventDefault(); - console.log(value); - }} - showFirst={true} - showPrevious={true} - showNext={true} - showLast={true} - showMore={true} - previousLabel="Previous" - nextLabel="Next" - firstLabel="First" - lastLabel="Last" - moreLabel="More" - getPageLabel={value => `Page ${value}`} -/> -``` diff --git a/src/components/Atoms/Pagination/PaginationExample.jsx b/src/components/Atoms/Pagination/PaginationExample.jsx new file mode 100644 index 000000000..65539fc3a --- /dev/null +++ b/src/components/Atoms/Pagination/PaginationExample.jsx @@ -0,0 +1,151 @@ +import React from 'react'; +import Pagination from './Pagination'; + +export default function PaginationExample() { + return ( + <> +

Minimalist

+ `example.com/page/${value}`} + onSelect={(event, value) => { + event.preventDefault(); + console.log(value); + }} + showFirst={false} + showPrevious={false} + showNext={false} + showLast={false} + /> + `example.com/page/${value}`} + onSelect={(event, value) => { + event.preventDefault(); + console.log(value); + }} + showFirst={false} + showPrevious={false} + showNext={false} + showLast={false} + selectedBackgroundColor="black" + /> + +

Full size

+ `example.com/page/${value}`} + onSelect={(event, value) => { + event.preventDefault(); + console.log(value); + }} + showFirst={true} + showPrevious={true} + showNext={true} + showLast={true} + showMore={true} + /> + `example.com/page/${value}`} + onSelect={(event, value) => { + event.preventDefault(); + console.log(value); + }} + showFirst={true} + showPrevious={true} + showNext={true} + showLast={true} + showMore={true} + selectedBackgroundColor="purple" + /> + `example.com/page/${value}`} + onSelect={(event, value) => { + event.preventDefault(); + console.log(value); + }} + showPrevious={true} + showNext={true} + showLast={true} + showMore={true} + selectedBackgroundColor="blue" + /> + `example.com/page/${value}`} + onSelect={(event, value) => { + event.preventDefault(); + console.log(value); + }} + showFirst={true} + showPrevious={true} + showNext={true} + showLast={true} + showMore={true} + selectedBackgroundColor="green" + /> + +

Custom style

+ `example.com/page/${value}`} + onSelect={(event, value) => { + event.preventDefault(); + console.log(value); + }} + showFirst={true} + showPrevious={true} + showNext={true} + showLast={true} + showMore={true} + color="red" + backgroundColor="yellow" + selectedColor="yellow" + selectedBackgroundColor="teal" + disabledColor="white" + disabledBackgroundColor="grey_light" + colorOnHover="yellow" + backgroundColorOnHover="teal" + /> + +

Custom labels

+ `example.com/page/${value}`} + onSelect={(event, value) => { + event.preventDefault(); + console.log(value); + }} + showFirst={true} + showPrevious={true} + showNext={true} + showLast={true} + showMore={true} + previousLabel="Previous" + nextLabel="Next" + firstLabel="First" + lastLabel="Last" + moreLabel="More" + getPageLabel={value => `Page ${value}`} + /> + + ); +} diff --git a/src/components/Atoms/Pagination/__snapshots__/Pagination.test.js.snap b/src/components/Atoms/Pagination/__snapshots__/Pagination.test.js.snap index ade71b55f..c877df6f2 100644 --- a/src/components/Atoms/Pagination/__snapshots__/Pagination.test.js.snap +++ b/src/components/Atoms/Pagination/__snapshots__/Pagination.test.js.snap @@ -2,17 +2,9 @@ exports[`renders correctly in full size with first page selected 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -25,7 +17,6 @@ exports[`renders correctly in full size with first page selected 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -37,7 +28,6 @@ exports[`renders correctly in full size with first page selected 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -49,7 +39,6 @@ exports[`renders correctly in full size with first page selected 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -71,11 +60,8 @@ exports[`renders correctly in full size with first page selected 1`] = `
« @@ -87,11 +73,8 @@ exports[`renders correctly in full size with first page selected 1`] = ` ‹ @@ -103,11 +86,8 @@ exports[`renders correctly in full size with first page selected 1`] = ` 1 @@ -119,11 +99,8 @@ exports[`renders correctly in full size with first page selected 1`] = ` 2 @@ -135,11 +112,8 @@ exports[`renders correctly in full size with first page selected 1`] = ` 3 @@ -151,11 +125,8 @@ exports[`renders correctly in full size with first page selected 1`] = ` 4 @@ -167,11 +138,8 @@ exports[`renders correctly in full size with first page selected 1`] = ` 5 @@ -183,11 +151,8 @@ exports[`renders correctly in full size with first page selected 1`] = ` › @@ -199,11 +164,8 @@ exports[`renders correctly in full size with first page selected 1`] = ` » @@ -214,17 +176,9 @@ exports[`renders correctly in full size with first page selected 1`] = ` exports[`renders correctly in full size with last page selected 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -237,7 +191,6 @@ exports[`renders correctly in full size with last page selected 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -254,7 +207,6 @@ exports[`renders correctly in full size with last page selected 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -266,7 +218,6 @@ exports[`renders correctly in full size with last page selected 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -283,11 +234,8 @@ exports[`renders correctly in full size with last page selected 1`] = ` « @@ -299,11 +247,8 @@ exports[`renders correctly in full size with last page selected 1`] = ` ‹ @@ -315,11 +260,8 @@ exports[`renders correctly in full size with last page selected 1`] = ` 1 @@ -331,11 +273,8 @@ exports[`renders correctly in full size with last page selected 1`] = ` 2 @@ -347,11 +286,8 @@ exports[`renders correctly in full size with last page selected 1`] = ` 3 @@ -363,11 +299,8 @@ exports[`renders correctly in full size with last page selected 1`] = ` 4 @@ -379,11 +312,8 @@ exports[`renders correctly in full size with last page selected 1`] = ` 5 @@ -395,11 +325,8 @@ exports[`renders correctly in full size with last page selected 1`] = ` › @@ -411,11 +338,8 @@ exports[`renders correctly in full size with last page selected 1`] = ` » @@ -426,17 +350,9 @@ exports[`renders correctly in full size with last page selected 1`] = ` exports[`renders correctly in full size with max pages less than current page 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -449,7 +365,6 @@ exports[`renders correctly in full size with max pages less than current page 1` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -466,7 +381,6 @@ exports[`renders correctly in full size with max pages less than current page 1` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -478,7 +392,6 @@ exports[`renders correctly in full size with max pages less than current page 1` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -495,11 +408,8 @@ exports[`renders correctly in full size with max pages less than current page 1` « @@ -511,11 +421,8 @@ exports[`renders correctly in full size with max pages less than current page 1` ‹ @@ -527,11 +434,8 @@ exports[`renders correctly in full size with max pages less than current page 1` ... @@ -543,11 +447,8 @@ exports[`renders correctly in full size with max pages less than current page 1` 16 @@ -559,11 +460,8 @@ exports[`renders correctly in full size with max pages less than current page 1` 17 @@ -575,11 +473,8 @@ exports[`renders correctly in full size with max pages less than current page 1` 18 @@ -591,11 +486,8 @@ exports[`renders correctly in full size with max pages less than current page 1` 19 @@ -607,11 +499,8 @@ exports[`renders correctly in full size with max pages less than current page 1` 20 @@ -623,11 +512,8 @@ exports[`renders correctly in full size with max pages less than current page 1` › @@ -639,11 +525,8 @@ exports[`renders correctly in full size with max pages less than current page 1` » @@ -654,17 +537,9 @@ exports[`renders correctly in full size with max pages less than current page 1` exports[`renders correctly in full size with max pages less than total pages 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -677,7 +552,6 @@ exports[`renders correctly in full size with max pages less than total pages 1`] padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -694,7 +568,6 @@ exports[`renders correctly in full size with max pages less than total pages 1`] padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -706,7 +579,6 @@ exports[`renders correctly in full size with max pages less than total pages 1`] padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -723,11 +595,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] « @@ -739,11 +608,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] ‹ @@ -755,11 +621,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] 1 @@ -771,11 +634,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] 2 @@ -787,11 +647,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] 3 @@ -803,11 +660,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] 4 @@ -819,11 +673,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] 5 @@ -835,11 +686,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] 6 @@ -851,11 +699,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] ... @@ -867,11 +712,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] › @@ -883,11 +725,8 @@ exports[`renders correctly in full size with max pages less than total pages 1`] » @@ -898,17 +737,9 @@ exports[`renders correctly in full size with max pages less than total pages 1`] exports[`renders correctly in full size with max pages more than total pages 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -921,7 +752,6 @@ exports[`renders correctly in full size with max pages more than total pages 1`] padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -938,7 +768,6 @@ exports[`renders correctly in full size with max pages more than total pages 1`] padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -955,11 +784,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] « @@ -971,11 +797,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] ‹ @@ -987,11 +810,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] 1 @@ -1003,11 +823,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] 2 @@ -1019,11 +836,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] 3 @@ -1035,11 +849,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] 4 @@ -1051,11 +862,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] 5 @@ -1067,11 +875,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] 6 @@ -1083,11 +888,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] › @@ -1099,11 +901,8 @@ exports[`renders correctly in full size with max pages more than total pages 1`] » @@ -1114,17 +913,9 @@ exports[`renders correctly in full size with max pages more than total pages 1`] exports[`renders correctly in full size with more on both sides 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -1137,7 +928,6 @@ exports[`renders correctly in full size with more on both sides 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -1154,7 +944,6 @@ exports[`renders correctly in full size with more on both sides 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -1166,7 +955,6 @@ exports[`renders correctly in full size with more on both sides 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -1183,11 +971,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` « @@ -1199,11 +984,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` ‹ @@ -1215,11 +997,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` ... @@ -1231,11 +1010,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` 2 @@ -1247,11 +1023,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` 3 @@ -1263,11 +1036,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` 4 @@ -1279,11 +1049,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` 5 @@ -1295,11 +1062,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` 6 @@ -1311,11 +1075,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` ... @@ -1327,11 +1088,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` › @@ -1343,11 +1101,8 @@ exports[`renders correctly in full size with more on both sides 1`] = ` » @@ -1358,17 +1113,9 @@ exports[`renders correctly in full size with more on both sides 1`] = ` exports[`renders correctly in full size with more on left 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -1381,7 +1128,6 @@ exports[`renders correctly in full size with more on left 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -1398,7 +1144,6 @@ exports[`renders correctly in full size with more on left 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -1410,7 +1155,6 @@ exports[`renders correctly in full size with more on left 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -1427,11 +1171,8 @@ exports[`renders correctly in full size with more on left 1`] = ` « @@ -1443,11 +1184,8 @@ exports[`renders correctly in full size with more on left 1`] = ` ‹ @@ -1459,11 +1197,8 @@ exports[`renders correctly in full size with more on left 1`] = ` ... @@ -1475,11 +1210,8 @@ exports[`renders correctly in full size with more on left 1`] = ` 2 @@ -1491,11 +1223,8 @@ exports[`renders correctly in full size with more on left 1`] = ` 3 @@ -1507,11 +1236,8 @@ exports[`renders correctly in full size with more on left 1`] = ` 4 @@ -1523,11 +1249,8 @@ exports[`renders correctly in full size with more on left 1`] = ` 5 @@ -1539,11 +1262,8 @@ exports[`renders correctly in full size with more on left 1`] = ` 6 @@ -1555,11 +1275,8 @@ exports[`renders correctly in full size with more on left 1`] = ` › @@ -1571,11 +1288,8 @@ exports[`renders correctly in full size with more on left 1`] = ` » @@ -1586,17 +1300,9 @@ exports[`renders correctly in full size with more on left 1`] = ` exports[`renders correctly in full size with more on right 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -1609,7 +1315,6 @@ exports[`renders correctly in full size with more on right 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -1626,7 +1331,6 @@ exports[`renders correctly in full size with more on right 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -1638,7 +1342,6 @@ exports[`renders correctly in full size with more on right 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -1655,11 +1358,8 @@ exports[`renders correctly in full size with more on right 1`] = ` « @@ -1671,11 +1371,8 @@ exports[`renders correctly in full size with more on right 1`] = ` ‹ @@ -1687,11 +1384,8 @@ exports[`renders correctly in full size with more on right 1`] = ` 1 @@ -1703,11 +1397,8 @@ exports[`renders correctly in full size with more on right 1`] = ` 2 @@ -1719,11 +1410,8 @@ exports[`renders correctly in full size with more on right 1`] = ` 3 @@ -1735,11 +1423,8 @@ exports[`renders correctly in full size with more on right 1`] = ` 4 @@ -1751,11 +1436,8 @@ exports[`renders correctly in full size with more on right 1`] = ` 5 @@ -1767,11 +1449,8 @@ exports[`renders correctly in full size with more on right 1`] = ` ... @@ -1783,11 +1462,8 @@ exports[`renders correctly in full size with more on right 1`] = ` › @@ -1799,11 +1475,8 @@ exports[`renders correctly in full size with more on right 1`] = ` » @@ -1814,17 +1487,9 @@ exports[`renders correctly in full size with more on right 1`] = ` exports[`renders correctly in minimalist form 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -1837,7 +1502,6 @@ exports[`renders correctly in minimalist form 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -1854,7 +1518,6 @@ exports[`renders correctly in minimalist form 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -1871,11 +1534,8 @@ exports[`renders correctly in minimalist form 1`] = ` 1 @@ -1887,11 +1547,8 @@ exports[`renders correctly in minimalist form 1`] = ` 2 @@ -1903,11 +1560,8 @@ exports[`renders correctly in minimalist form 1`] = ` 3 @@ -1919,11 +1573,8 @@ exports[`renders correctly in minimalist form 1`] = ` 4 @@ -1935,11 +1586,8 @@ exports[`renders correctly in minimalist form 1`] = ` 5 @@ -1950,17 +1598,9 @@ exports[`renders correctly in minimalist form 1`] = ` exports[`renders correctly in minimalist form with non-default color 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -1973,7 +1613,6 @@ exports[`renders correctly in minimalist form with non-default color 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -1990,7 +1629,6 @@ exports[`renders correctly in minimalist form with non-default color 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -2007,11 +1645,8 @@ exports[`renders correctly in minimalist form with non-default color 1`] = ` 1 @@ -2023,11 +1658,8 @@ exports[`renders correctly in minimalist form with non-default color 1`] = ` 2 @@ -2039,11 +1671,8 @@ exports[`renders correctly in minimalist form with non-default color 1`] = ` 3 @@ -2055,11 +1684,8 @@ exports[`renders correctly in minimalist form with non-default color 1`] = ` 4 @@ -2071,11 +1697,8 @@ exports[`renders correctly in minimalist form with non-default color 1`] = ` 5 @@ -2086,17 +1709,9 @@ exports[`renders correctly in minimalist form with non-default color 1`] = ` exports[`renders correctly with custom labels 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -2109,7 +1724,6 @@ exports[`renders correctly with custom labels 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -2126,7 +1740,6 @@ exports[`renders correctly with custom labels 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -2143,11 +1756,8 @@ exports[`renders correctly with custom labels 1`] = ` First @@ -2159,11 +1769,8 @@ exports[`renders correctly with custom labels 1`] = ` Previous @@ -2175,11 +1782,8 @@ exports[`renders correctly with custom labels 1`] = ` Page 1 @@ -2191,11 +1795,8 @@ exports[`renders correctly with custom labels 1`] = ` Page 2 @@ -2207,11 +1808,8 @@ exports[`renders correctly with custom labels 1`] = ` Page 3 @@ -2223,11 +1821,8 @@ exports[`renders correctly with custom labels 1`] = ` Page 4 @@ -2239,11 +1834,8 @@ exports[`renders correctly with custom labels 1`] = ` Page 5 @@ -2255,11 +1847,8 @@ exports[`renders correctly with custom labels 1`] = ` Next @@ -2271,11 +1860,8 @@ exports[`renders correctly with custom labels 1`] = ` Last @@ -2286,17 +1872,9 @@ exports[`renders correctly with custom labels 1`] = ` exports[`renders correctly with custom style 1`] = ` .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; padding-left: 0; - -webkit-box-pack: center; - -webkit-justify-content: center; - -ms-flex-pack: center; justify-content: center; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; flex-wrap: wrap; list-style-type: none; } @@ -2309,7 +1887,6 @@ exports[`renders correctly with custom style 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: pointer; @@ -2326,7 +1903,6 @@ exports[`renders correctly with custom style 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -2338,7 +1914,6 @@ exports[`renders correctly with custom style 1`] = ` padding: 9px 14px 9px 14px; border-radius: 30px; text-align: center; - -webkit-text-decoration: none; text-decoration: none; font-weight: 700; cursor: default; @@ -2355,11 +1930,8 @@ exports[`renders correctly with custom style 1`] = ` « @@ -2371,11 +1943,8 @@ exports[`renders correctly with custom style 1`] = ` ‹ @@ -2387,11 +1956,8 @@ exports[`renders correctly with custom style 1`] = ` ... @@ -2403,11 +1969,8 @@ exports[`renders correctly with custom style 1`] = ` 3 @@ -2419,11 +1982,8 @@ exports[`renders correctly with custom style 1`] = ` 4 @@ -2435,11 +1995,8 @@ exports[`renders correctly with custom style 1`] = ` 5 @@ -2451,11 +2008,8 @@ exports[`renders correctly with custom style 1`] = ` 6 @@ -2467,11 +2021,8 @@ exports[`renders correctly with custom style 1`] = ` 7 @@ -2483,11 +2034,8 @@ exports[`renders correctly with custom style 1`] = ` ... @@ -2499,11 +2047,8 @@ exports[`renders correctly with custom style 1`] = ` › @@ -2515,11 +2060,8 @@ exports[`renders correctly with custom style 1`] = ` » diff --git a/src/components/Atoms/Picture/Picture.js b/src/components/Atoms/Picture/Picture.js index 97aad9755..f6e04fb3e 100644 --- a/src/components/Atoms/Picture/Picture.js +++ b/src/components/Atoms/Picture/Picture.js @@ -10,25 +10,25 @@ import 'lazysizes/plugins/blur-up/ls.blur-up'; const IMAGE_FALLBACK = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; const Wrapper = styled.div` - ${({ objFitState, nonObjFitImage }) => (!objFitState && nonObjFitImage) && `background-image: url(${nonObjFitImage}); background-size: cover; background-position: center;`}; + ${({ $objFitState, $nonObjFitImage }) => (!$objFitState && $nonObjFitImage) && `background-image: url(${$nonObjFitImage}); background-size: cover; background-position: center;`}; display: block; - width: ${props => (props.width ? props.width : '100%')}; - height: ${props => (props.height ? props.height : '100%')}; + width: ${props => (props.$width ? props.$width : '100%')}; + height: ${props => (props.$height ? props.$height : '100%')}; position: relative; - ${({ isBackgroundImage }) => isBackgroundImage && 'position: absolute; bottom: 0px; left: 0px; right: 0px; height: 100%;'}; + ${({ $isBackgroundImage }) => $isBackgroundImage && 'position: absolute; bottom: 0px; left: 0px; right: 0px; height: 100%;'}; `; const Image = styled.img` width: ${props => (props.width ? props.width : '100%')}; height: ${props => (props.height ? props.height : 'auto')}; display: block; - object-fit: ${props => (props.objectFit === 'none' && 'none') - || (props.objectFit === 'cover' && 'cover') - || (props.objectFit === 'contain' && 'contain')}; - ${({ objectFit, objFitState }) => (objectFit !== 'none' && !objFitState) && 'visibility: hidden;'}; // Allows image to provide the container height, but make it invisible + object-fit: ${props => (props.$objectFit === 'none' && 'none') + || (props.$objectFit === 'cover' && 'cover') + || (props.$objectFit === 'contain' && 'contain')}; + ${({ $objectFit, $objFitState }) => ($objectFit !== 'none' && !$objFitState) && 'visibility: hidden;'}; // Allows image to provide the container height, but make it invisible /* Check for Cards/smallBreakpointRowLayout prop coming from the CMS and adjust styling for row view */ - ${({ smallBreakpointRowLayout }) => (smallBreakpointRowLayout === true) && css` + ${({ $smallBreakpointRowLayout }) => ($smallBreakpointRowLayout === true) && css` @media ${({ theme }) => theme.allBreakpoints('S')} { border-radius: ${spacing('md')}; width: 80px; @@ -43,7 +43,7 @@ const Image = styled.img` `} /* Check for Cards/mediumBreakpointRowLayout prop coming from the CMS and adjust styling for row view */ - ${({ mediumBreakpointRowLayout }) => (mediumBreakpointRowLayout === true) && css` + ${({ $mediumBreakpointRowLayout }) => ($mediumBreakpointRowLayout === true) && css` @media ${({ theme }) => theme.allBreakpoints('M')} { border-radius: ${spacing('md')}; width: 96px; @@ -52,7 +52,7 @@ const Image = styled.img` `} /* Check for Cards/smallBreakpointRowLayout or mediumBreakpointRowLayout prop coming from the CMS and adjust styling back to normal */ - ${({ smallBreakpointRowLayout, mediumBreakpointRowLayout }) => ((smallBreakpointRowLayout === true) || (mediumBreakpointRowLayout === true)) && css` + ${({ $smallBreakpointRowLayout, $mediumBreakpointRowLayout }) => (($smallBreakpointRowLayout === true) || ($mediumBreakpointRowLayout === true)) && css` @media ${({ theme }) => theme.allBreakpoints('L')} { padding: none; border-radius: 0; @@ -99,13 +99,11 @@ const Picture = ({ if (!images) { return ( {alt} @@ -125,22 +123,19 @@ const Picture = ({ return ( {alt} ); diff --git a/src/components/Atoms/Picture/Picture.md b/src/components/Atoms/Picture/Picture.md deleted file mode 100644 index 6c89d89c7..000000000 --- a/src/components/Atoms/Picture/Picture.md +++ /dev/null @@ -1,28 +0,0 @@ -Picture has depenciy of lazysizes for lazyload and blur-up for image loading state. - -Picture - -```js -const defaultData = require('../../../styleguide/data/data').defaultData; -; -``` - -Custom Size. - -```js -const defaultData = require('../../../styleguide/data/data').defaultData; -; -``` - -Single image - -```js -const defaultData = require('../../../styleguide/data/data').defaultData;; -``` diff --git a/src/components/Atoms/Picture/Picture.test.js b/src/components/Atoms/Picture/Picture.test.js index 42657905f..e715a1216 100644 --- a/src/components/Atoms/Picture/Picture.test.js +++ b/src/components/Atoms/Picture/Picture.test.js @@ -1,9 +1,9 @@ -import React from "react"; -import "jest-styled-components"; -import renderWithTheme from "../../../../tests/hoc/shallowWithTheme"; -import Picture from "./Picture"; -import { defaultData } from "../../../styleguide/data/data"; -it("renders correctly", () => { +import React from 'react'; +import 'jest-styled-components'; +import renderWithTheme from '../../../../tests/hoc/shallowWithTheme'; +import Picture from './Picture'; +import { defaultData } from '../../../data/data'; +it('renders correctly', () => { const tree = renderWithTheme( { ).toJSON(); expect(tree).toMatchInlineSnapshot(` - .c0 { - display: block; - width: 100%; - height: auto; - position: relative; - } +.c0 { + display: block; + width: 100%; + height: auto; + position: relative; +} - .c1 { - width: 100%; - height: auto; - display: block; - object-fit: none; - } +.c1 { + width: 100%; + height: auto; + display: block; + object-fit: none; +} -
- Test images -
- `); +
+ Test images +
+`); }); -it("renders correctly with custom props", () => { +it('renders correctly with custom props', () => { const tree = renderWithTheme( { ).toJSON(); expect(tree).toMatchInlineSnapshot(` - .c0 { - display: block; - width: 200px; - height: 100px; - position: relative; - } +.c0 { + display: block; + width: 200px; + height: 100px; + position: relative; +} - .c1 { - width: 200px; - height: 100px; - display: block; - object-fit: cover; - } +.c1 { + width: 200px; + height: 100px; + display: block; + object-fit: cover; +} -
- Test images -
- `); +
+ Test images +
+`); }); diff --git a/src/components/Atoms/Picture/PictureExample.jsx b/src/components/Atoms/Picture/PictureExample.jsx new file mode 100644 index 000000000..38f94a1ed --- /dev/null +++ b/src/components/Atoms/Picture/PictureExample.jsx @@ -0,0 +1,33 @@ +import React from 'react'; +import Picture from './Picture'; +import { defaultData } from '../../../data/data'; + +export default function PictureExample() { + return ( + <> +

Picture

+ + +

Custom Size

+ + +

Single image

+ + + ); +} diff --git a/src/components/Atoms/RadioButton/RadioButton.js b/src/components/Atoms/RadioButton/RadioButton.js index 4403d523e..871a17f3e 100644 --- a/src/components/Atoms/RadioButton/RadioButton.js +++ b/src/components/Atoms/RadioButton/RadioButton.js @@ -19,7 +19,7 @@ const StyledRadioInput = styled.input` left: 0; right: 0; flex-shrink: 0; - + span { + & + span { left: 2px; border-radius: 30px; background-clip: padding-box; @@ -29,10 +29,10 @@ const StyledRadioInput = styled.input` height: 30px; border: 1px solid ${({ theme }) => theme.color('grey_for_forms')}; } - :checked + span { + &:checked + span { background-color: ${({ theme }) => theme.color('purple')}; border: 1px solid ${({ theme }) => theme.color('purple')}; - :before { + &:before { position: absolute; content: ''; top: 8px; diff --git a/src/components/Atoms/RadioButton/RadioButton.md b/src/components/Atoms/RadioButton/RadioButton.md deleted file mode 100644 index e51db6529..000000000 --- a/src/components/Atoms/RadioButton/RadioButton.md +++ /dev/null @@ -1,16 +0,0 @@ -# Radio buttons - -```js - - - -``` diff --git a/src/components/Atoms/RadioButton/RadioButton.test.js b/src/components/Atoms/RadioButton/RadioButton.test.js index 0818545e8..bbff6252f 100644 --- a/src/components/Atoms/RadioButton/RadioButton.test.js +++ b/src/components/Atoms/RadioButton/RadioButton.test.js @@ -12,233 +12,211 @@ it('renders correctly', () => { ).toJSON(); expect(tree).toMatchInlineSnapshot(` - Array [ - .c2 { - font-family: 'Montserrat',Helvetica,Arial,sans-serif; - font-weight: 400; - text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; - letter-spacing: 0; - font-size: 1rem; - line-height: 1.25rem; - } - - .c2 { - font-size: 1rem; - line-height: normal; - font-weight: bold; - } - - .c2 span { - font-size: inherit; - line-height: inherit; - } - - .c1 { - background-color: #FFFFFF; - z-index: 1; - top: 0; - margin: 5px 10px; - width: 30px; - height: 30px; - opacity: 0; - left: 0; - right: 0; - -webkit-flex-shrink: 0; - -ms-flex-negative: 0; - flex-shrink: 0; - } - - .c1 + span { - left: 2px; - border-radius: 30px; - background-clip: padding-box; - position: absolute; - top: 0px; - width: 30px; - height: 30px; - border: 1px solid #666; - } - - .c1:checked + span { - background-color: #6F3AAB; - border: 1px solid #6F3AAB; - } - - .c1:checked + span:before { - position: absolute; - content: ''; - top: 8px; - left: 0; - right: 0; - background-color: #FFFFFF; - border-radius: 30px; - width: 12px; - height: 12px; - z-index: 1; - margin: 0 auto; - opacity: 1; - } - - .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; - position: relative; - } - - @media (min-width:740px) { - .c2 { - font-size: 1rem; - line-height: 1.25rem; - } - } - - @media (min-width:1024px) { - .c2 { - font-size: 1.125rem; - line-height: 1.375rem; - } - } - - , - .c2 { - font-family: 'Montserrat',Helvetica,Arial,sans-serif; - font-weight: 400; - text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; - letter-spacing: 0; - font-size: 1rem; - line-height: 1.25rem; - } - - .c2 { - font-size: 1rem; - line-height: normal; - font-weight: bold; - } - - .c2 span { - font-size: inherit; - line-height: inherit; - } - - .c1 { - background-color: #FFFFFF; - z-index: 1; - top: 0; - margin: 5px 10px; - width: 30px; - height: 30px; - opacity: 0; - left: 0; - right: 0; - -webkit-flex-shrink: 0; - -ms-flex-negative: 0; - flex-shrink: 0; - } - - .c1 + span { - left: 2px; - border-radius: 30px; - background-clip: padding-box; - position: absolute; - top: 0px; - width: 30px; - height: 30px; - border: 1px solid #666; - } - - .c1:checked + span { - background-color: #6F3AAB; - border: 1px solid #6F3AAB; - } - - .c1:checked + span:before { - position: absolute; - content: ''; - top: 8px; - left: 0; - right: 0; - background-color: #FFFFFF; - border-radius: 30px; - width: 12px; - height: 12px; - z-index: 1; - margin: 0 auto; - opacity: 1; - } - - .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; - position: relative; - } - - @media (min-width:740px) { - .c2 { - font-size: 1rem; - line-height: 1.25rem; - } - } - - @media (min-width:1024px) { - .c2 { - font-size: 1.125rem; - line-height: 1.375rem; - } - } - - , - ] - `); +[ + .c2 { + font-family: 'Montserrat',Helvetica,Arial,sans-serif; + font-weight: 400; + text-transform: inherit; + letter-spacing: 0; + font-size: 1rem; + line-height: 1.25rem; +} + +.c2 { + font-size: 1rem; + line-height: normal; + font-weight: bold; +} + +.c2 span { + font-size: inherit; + line-height: inherit; +} + +.c1 { + background-color: #FFFFFF; + z-index: 1; + top: 0; + margin: 5px 10px; + width: 30px; + height: 30px; + opacity: 0; + left: 0; + right: 0; + flex-shrink: 0; +} + +.c1+span { + left: 2px; + border-radius: 30px; + background-clip: padding-box; + position: absolute; + top: 0px; + width: 30px; + height: 30px; + border: 1px solid #666; +} + +.c1:checked+span { + background-color: #6F3AAB; + border: 1px solid #6F3AAB; +} + +.c1:checked+span:before { + position: absolute; + content: ''; + top: 8px; + left: 0; + right: 0; + background-color: #FFFFFF; + border-radius: 30px; + width: 12px; + height: 12px; + z-index: 1; + margin: 0 auto; + opacity: 1; +} + +.c0 { + display: flex; + align-items: center; + position: relative; +} + +@media (min-width: 740px) { + .c2 { + font-size: 1rem; + line-height: 1.25rem; + } +} + +@media (min-width: 1024px) { + .c2 { + font-size: 1.125rem; + line-height: 1.375rem; + } +} + +, + .c2 { + font-family: 'Montserrat',Helvetica,Arial,sans-serif; + font-weight: 400; + text-transform: inherit; + letter-spacing: 0; + font-size: 1rem; + line-height: 1.25rem; +} + +.c2 { + font-size: 1rem; + line-height: normal; + font-weight: bold; +} + +.c2 span { + font-size: inherit; + line-height: inherit; +} + +.c1 { + background-color: #FFFFFF; + z-index: 1; + top: 0; + margin: 5px 10px; + width: 30px; + height: 30px; + opacity: 0; + left: 0; + right: 0; + flex-shrink: 0; +} + +.c1+span { + left: 2px; + border-radius: 30px; + background-clip: padding-box; + position: absolute; + top: 0px; + width: 30px; + height: 30px; + border: 1px solid #666; +} + +.c1:checked+span { + background-color: #6F3AAB; + border: 1px solid #6F3AAB; +} + +.c1:checked+span:before { + position: absolute; + content: ''; + top: 8px; + left: 0; + right: 0; + background-color: #FFFFFF; + border-radius: 30px; + width: 12px; + height: 12px; + z-index: 1; + margin: 0 auto; + opacity: 1; +} + +.c0 { + display: flex; + align-items: center; + position: relative; +} + +@media (min-width: 740px) { + .c2 { + font-size: 1rem; + line-height: 1.25rem; + } +} + +@media (min-width: 1024px) { + .c2 { + font-size: 1.125rem; + line-height: 1.375rem; + } +} + +, +] +`); }); diff --git a/src/components/Atoms/RadioButton/RadioButtonExample.jsx b/src/components/Atoms/RadioButton/RadioButtonExample.jsx new file mode 100644 index 000000000..f9940a1ff --- /dev/null +++ b/src/components/Atoms/RadioButton/RadioButtonExample.jsx @@ -0,0 +1,12 @@ +import React from 'react'; +import RadioButton from './RadioButton'; + +export default function RadioButtonExample() { + return ( + <> + + + + + ); +} diff --git a/src/components/Atoms/RichText/RichText.js b/src/components/Atoms/RichText/RichText.js index 8c8171e5a..898acd71b 100644 --- a/src/components/Atoms/RichText/RichText.js +++ b/src/components/Atoms/RichText/RichText.js @@ -3,12 +3,12 @@ import styled from 'styled-components'; import PropTypes from 'prop-types'; export const Inner = styled.div` - text-align: ${props => props.align}; + text-align: ${props => props.$align}; `; const RichText = ({ align = 'left', markup = '', ...rest }) => ( diff --git a/src/components/Atoms/RichText/RichText.md b/src/components/Atoms/RichText/RichText.md deleted file mode 100644 index 4443a52c3..000000000 --- a/src/components/Atoms/RichText/RichText.md +++ /dev/null @@ -1,8 +0,0 @@ -# RichText - -```js -Some strong test markup

'} ->
-``` diff --git a/src/components/Atoms/RichText/RichText.test.js b/src/components/Atoms/RichText/RichText.test.js index 8568dabb5..829184e77 100644 --- a/src/components/Atoms/RichText/RichText.test.js +++ b/src/components/Atoms/RichText/RichText.test.js @@ -11,17 +11,17 @@ it('It sanitises markup and renders properly', () => { ).toJSON(); expect(tree).toMatchInlineSnapshot(` - .c0 { - text-align: right; +.c0 { + text-align: right; +} + +
Here's some copy

More copy", } - -
Here's some copy

More copy", - } - } - /> - `); + } +/> +`); }); diff --git a/src/components/Atoms/RichText/RichTextExample.jsx b/src/components/Atoms/RichText/RichTextExample.jsx new file mode 100644 index 000000000..6334dbe99 --- /dev/null +++ b/src/components/Atoms/RichText/RichTextExample.jsx @@ -0,0 +1,11 @@ +import React from 'react'; +import RichText from './RichText'; + +export default function RichTextExample() { + return ( + + ); +} diff --git a/src/components/Atoms/Select/Select.js b/src/components/Atoms/Select/Select.js index e52077d88..881459731 100644 --- a/src/components/Atoms/Select/Select.js +++ b/src/components/Atoms/Select/Select.js @@ -19,17 +19,17 @@ const StyledSelect = styled.select` height: 48px; font-weight: 400; font-family: ${({ theme }) => theme.fontFamilies(theme.font.regular)}; - background: ${({ theme, hideArrow }) => (hideArrow + background: ${({ theme, $hideArrow }) => ($hideArrow ? theme.color('grey_light') : `${theme.color('grey_light')} url(${dropDownIcon}) calc(100% - 1.5rem) 14px/20px 1.5rem no-repeat`)}; border: 1px solid; - border-color: ${({ theme, error }) => (error ? theme.color('red') : theme.color('grey'))}; + border-color: ${({ theme, $error }) => ($error ? theme.color('red') : theme.color('grey'))}; box-shadow: none; appearance: none; - color: ${({ theme, greyDescription, hasValue }) => (greyDescription && !hasValue ? 'grey' : theme.color('black'))}; + color: ${({ theme, $greyDescription, $hasValue }) => ($greyDescription && !$hasValue ? 'grey' : theme.color('black'))}; border-radius: 0.5rem; cursor: pointer; - :focus { + &:focus { border: 1px solid ${({ theme }) => theme.color('grey_for_forms')}; } @@ -75,14 +75,14 @@ const Select = React.forwardRef( } }} {...rest} - error={errorMsg} + $error={errorMsg} defaultValue={defaultValue} required={optional === false} aria-required={optional === false} - hasValue={!!value} - greyDescription={greyDescription} + $hasValue={!!value} + $greyDescription={greyDescription} ref={ref} - hideArrow={hideArrow} + $hideArrow={hideArrow} > {/* empty string "" is falsy so will show */ diff --git a/src/components/Atoms/Select/Select.md b/src/components/Atoms/Select/Select.md deleted file mode 100644 index 340b2fb0b..000000000 --- a/src/components/Atoms/Select/Select.md +++ /dev/null @@ -1,47 +0,0 @@ -# Select - -```js -

DROPDOWN MENU

- - -

DROPDOWN MENU - hide arrow / just one option

- + +

DROPDOWN MENU with error

+ + + ); +} diff --git a/src/components/Atoms/Select/__snapshots__/Select.test.js.snap b/src/components/Atoms/Select/__snapshots__/Select.test.js.snap index 5b243e437..ad87a7373 100644 --- a/src/components/Atoms/Select/__snapshots__/Select.test.js.snap +++ b/src/components/Atoms/Select/__snapshots__/Select.test.js.snap @@ -5,9 +5,6 @@ exports[`renders correctly 1`] = ` font-family: 'Montserrat',Helvetica,Arial,sans-serif; font-weight: 400; text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; letter-spacing: 0; font-size: 1rem; line-height: 1.25rem; @@ -21,12 +18,7 @@ exports[`renders correctly 1`] = ` .c0 { width: 100%; position: relative; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; - -webkit-flex-direction: column; - -ms-flex-direction: column; flex-direction: column; color: #000000; } @@ -36,9 +28,6 @@ exports[`renders correctly 1`] = ` font-family: 'Montserrat',Helvetica,Arial,sans-serif; font-weight: 400; text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; letter-spacing: 0; font-size: 1rem; line-height: 1.25rem; @@ -60,8 +49,6 @@ exports[`renders correctly 1`] = ` border: 1px solid; border-color: #969598; box-shadow: none; - -webkit-appearance: none; - -moz-appearance: none; appearance: none; color: #000000; border-radius: 0.5rem; @@ -72,35 +59,35 @@ exports[`renders correctly 1`] = ` border: 1px solid #666; } -@media (min-width:740px) { +@media (min-width: 740px) { .c1 { font-size: 1rem; line-height: 1.25rem; } } -@media (min-width:1024px) { +@media (min-width: 1024px) { .c1 { font-size: 1.125rem; line-height: 1.375rem; } } -@media (min-width:740px) { +@media (min-width: 740px) { .c2 { font-size: 1rem; line-height: 1.25rem; } } -@media (min-width:1024px) { +@media (min-width: 1024px) { .c2 { font-size: 1rem; line-height: 1.25rem; } } -@media (min-width:740px) { +@media (min-width: 740px) { .c3 { max-width: 290px; } @@ -112,7 +99,7 @@ exports[`renders correctly 1`] = ` - `; diff --git a/src/components/Atoms/SocialIcons/Icon/Icon.js b/src/components/Atoms/SocialIcons/Icon/Icon.js index 5de6642df..f047f4449 100755 --- a/src/components/Atoms/SocialIcons/Icon/Icon.js +++ b/src/components/Atoms/SocialIcons/Icon/Icon.js @@ -22,7 +22,7 @@ const StyledLink = styled.a` } // 'isHeader' is only set and passed in Header2025, so the pre-existing Header isn't affected: - ${({ isHeader }) => isHeader && css` + ${({ $isHeader }) => $isHeader && css` overflow: hidden; padding-right: 0px; transition: padding-right ${RevealTextSpeed}s cubic-bezier(0.5, 1.5, 0.5, 0.75); @@ -69,7 +69,7 @@ const StyledLink = styled.a` // New style is rounded square buttons with dark grey background, and animation. // When we've moved fully to the new design, // this prop and the old styles can be removed. - ${({ newStyle }) => newStyle && css` + ${({ $newStyle }) => $newStyle && css` background-color: ${({ theme }) => theme.color('grey_4')}; border-radius: 0.5rem; padding: 0.5rem; @@ -112,7 +112,7 @@ const RevealText = styled(Text)` const StyledImage = styled.img` width: 100%; - ${({ invertColor }) => invertColor && css` + ${({ $invertColor }) => $invertColor && css` filter: brightness(0) invert(1); `} `; @@ -132,10 +132,10 @@ const Icon = ({ title={title} rel="noopener noreferrer" data-test={`${isHeader ? 'header' : 'icon'}-${kebabCase(id)}`} - isHeader={isHeader} - newStyle={newStyle} + $isHeader={isHeader} + $newStyle={newStyle} > - + { isHeader && ( {title} )} diff --git a/src/components/Atoms/SocialIcons/SocialIcons.js b/src/components/Atoms/SocialIcons/SocialIcons.js index 21362c391..1e71011bc 100755 --- a/src/components/Atoms/SocialIcons/SocialIcons.js +++ b/src/components/Atoms/SocialIcons/SocialIcons.js @@ -8,28 +8,28 @@ import spacing from '../../../theme/shared/spacing'; const StyledList = styled.ul` display: flex; - flex-wrap: ${({ newStyle }) => (newStyle ? 'wrap' : 'nowrap')}; - gap: ${({ newStyle }) => (newStyle ? `${spacing('l')}` : '0')}; + flex-wrap: ${({ $newStyle }) => ($newStyle ? 'wrap' : 'nowrap')}; + gap: ${({ $newStyle }) => ($newStyle ? `${spacing('l')}` : '0')}; list-style-type: none; - justify-content: ${newStyle => (newStyle ? 'flex-start' : 'center')}; - margin: ${({ newStyle }) => (newStyle ? `${spacing('lg')} 0` : '0 auto 0 0')}; + justify-content: ${({ $newStyle }) => ($newStyle ? 'flex-start' : 'center')}; + margin: ${({ $newStyle }) => ($newStyle ? `${spacing('lg')} 0` : '0 auto 0 0')}; padding: 0; align-items: center; @media ${({ theme }) => theme.breakpoints2026('M')} { justify-content: start; - margin: ${({ newStyle }) => (newStyle ? `${spacing('sm')} 0` : '0 auto 0 0')}; + margin: ${({ $newStyle }) => ($newStyle ? `${spacing('sm')} 0` : '0 auto 0 0')}; } `; const StyledItem = styled.li` - width: ${({ newStyle }) => (newStyle ? '54px' : '48px')}; - height: ${({ newStyle }) => (newStyle ? '54px' : 'auto')}; - flex: 0 0 ${({ newStyle }) => (newStyle ? '54px' : '48px')}; - margin-right: ${({ newStyle }) => (newStyle ? '0' : spacing('m'))}; + width: ${({ $newStyle }) => ($newStyle ? '54px' : '48px')}; + height: ${({ $newStyle }) => ($newStyle ? '54px' : 'auto')}; + flex: 0 0 ${({ $newStyle }) => ($newStyle ? '54px' : '48px')}; + margin-right: ${({ $newStyle }) => ($newStyle ? '0' : spacing('m'))}; @media ${({ theme }) => theme.breakpoints2026('M')} { - margin-right: ${({ newStyle }) => (newStyle ? 0 : spacing('m'))}; + margin-right: ${({ $newStyle }) => ($newStyle ? 0 : spacing('m'))}; } `; @@ -79,7 +79,7 @@ const SocialIcons = ({ : ['facebook', 'instagram', 'twitter', 'youtube']; return ( - + {brandsToShow .filter(brand => shouldShowIcon(brand)) .map(brand => { @@ -92,7 +92,7 @@ const SocialIcons = ({ return null; } return ( - + - -
-``` - -### Red Nose Day -```js -
- -
-``` - -### Sport Relief with self target -```js -
- -
-``` diff --git a/src/components/Atoms/SocialIcons/SocialIconsExample.jsx b/src/components/Atoms/SocialIcons/SocialIconsExample.jsx new file mode 100644 index 000000000..3867ab125 --- /dev/null +++ b/src/components/Atoms/SocialIcons/SocialIconsExample.jsx @@ -0,0 +1,24 @@ +import React from 'react'; +import SocialIcons from './SocialIcons'; +import Wrapper from '../../../demos/Wrapper'; + +export default function SocialIconsExample() { + return ( + <> +

Comic Relief

+ + + + +

Red Nose Day

+ + + + +

Sport Relief with self target

+ + + + + ); +} diff --git a/src/components/Atoms/SocialIcons/__snapshots__/SocialIcons.test.js.snap b/src/components/Atoms/SocialIcons/__snapshots__/SocialIcons.test.js.snap index f5ca90718..2946cce29 100644 --- a/src/components/Atoms/SocialIcons/__snapshots__/SocialIcons.test.js.snap +++ b/src/components/Atoms/SocialIcons/__snapshots__/SocialIcons.test.js.snap @@ -2,12 +2,10 @@ exports[`renders correctly with Comic Relief links 1`] = ` .c2 { - -webkit-text-decoration: none; text-decoration: none; cursor: pointer; display: block; position: relative; - -webkit-transition: opacity 0.2s; transition: opacity 0.2s; } @@ -21,32 +19,19 @@ exports[`renders correctly with Comic Relief links 1`] = ` } .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; - -webkit-flex-wrap: nowrap; - -ms-flex-wrap: nowrap; flex-wrap: nowrap; gap: 0; list-style-type: none; - -webkit-box-pack: start; - -webkit-justify-content: flex-start; - -ms-flex-pack: start; - justify-content: flex-start; + justify-content: center; margin: 0 auto 0 0; padding: 0; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; align-items: center; } .c1 { width: 48px; height: auto; - -webkit-flex: 0 0 48px; - -ms-flex: 0 0 48px; flex: 0 0 48px; margin-right: 1.5rem; } @@ -55,17 +40,14 @@ exports[`renders correctly with Comic Relief links 1`] = ` width: auto; } -@media (min-width:740px) { +@media (min-width: 740px) { .c0 { - -webkit-box-pack: start; - -webkit-justify-content: start; - -ms-flex-pack: start; justify-content: start; margin: 0 auto 0 0; } } -@media (min-width:740px) { +@media (min-width: 740px) { .c1 { margin-right: 1.5rem; } @@ -151,12 +133,10 @@ exports[`renders correctly with Comic Relief links 1`] = ` exports[`renders correctly with Red Nose Day links and self target 1`] = ` .c2 { - -webkit-text-decoration: none; text-decoration: none; cursor: pointer; display: block; position: relative; - -webkit-transition: opacity 0.2s; transition: opacity 0.2s; } @@ -170,32 +150,19 @@ exports[`renders correctly with Red Nose Day links and self target 1`] = ` } .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; - -webkit-flex-wrap: nowrap; - -ms-flex-wrap: nowrap; flex-wrap: nowrap; gap: 0; list-style-type: none; - -webkit-box-pack: start; - -webkit-justify-content: flex-start; - -ms-flex-pack: start; - justify-content: flex-start; + justify-content: center; margin: 0 auto 0 0; padding: 0; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; align-items: center; } .c1 { width: 48px; height: auto; - -webkit-flex: 0 0 48px; - -ms-flex: 0 0 48px; flex: 0 0 48px; margin-right: 1.5rem; } @@ -204,17 +171,14 @@ exports[`renders correctly with Red Nose Day links and self target 1`] = ` width: auto; } -@media (min-width:740px) { +@media (min-width: 740px) { .c0 { - -webkit-box-pack: start; - -webkit-justify-content: start; - -ms-flex-pack: start; justify-content: start; margin: 0 auto 0 0; } } -@media (min-width:740px) { +@media (min-width: 740px) { .c1 { margin-right: 1.5rem; } @@ -300,12 +264,10 @@ exports[`renders correctly with Red Nose Day links and self target 1`] = ` exports[`renders correctly with Sport Relief links 1`] = ` .c2 { - -webkit-text-decoration: none; text-decoration: none; cursor: pointer; display: block; position: relative; - -webkit-transition: opacity 0.2s; transition: opacity 0.2s; } @@ -319,32 +281,19 @@ exports[`renders correctly with Sport Relief links 1`] = ` } .c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; display: flex; - -webkit-flex-wrap: nowrap; - -ms-flex-wrap: nowrap; flex-wrap: nowrap; gap: 0; list-style-type: none; - -webkit-box-pack: start; - -webkit-justify-content: flex-start; - -ms-flex-pack: start; - justify-content: flex-start; + justify-content: center; margin: 0 auto 0 0; padding: 0; - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; align-items: center; } .c1 { width: 48px; height: auto; - -webkit-flex: 0 0 48px; - -ms-flex: 0 0 48px; flex: 0 0 48px; margin-right: 1.5rem; } @@ -353,17 +302,14 @@ exports[`renders correctly with Sport Relief links 1`] = ` width: auto; } -@media (min-width:740px) { +@media (min-width: 740px) { .c0 { - -webkit-box-pack: start; - -webkit-justify-content: start; - -ms-flex-pack: start; justify-content: start; margin: 0 auto 0 0; } } -@media (min-width:740px) { +@media (min-width: 740px) { .c1 { margin-right: 1.5rem; } diff --git a/src/components/Atoms/Text/Text.md b/src/components/Atoms/Text/Text.md deleted file mode 100644 index 8c8733f73..000000000 --- a/src/components/Atoms/Text/Text.md +++ /dev/null @@ -1,169 +0,0 @@ -```js -import fontConfig from '../../../theme/crTheme/fontConfig'; - -<> -
- - H1 - - - family: {fontConfig['h1'].family} - - mobileColor: blue -
- font size (S / M / L breakpoints): {fontConfig['h1'].small.fontSize} / {fontConfig['h1'].medium.fontSize} / {fontConfig['h1'].large.fontSize} -
- line height (S / M / L breakpoints): {fontConfig['h1'].small.lineHeight} / {fontConfig['h1'].medium.lineHeight} / {fontConfig['h1'].large.lineHeight} -
- - - H2 - - - family: {fontConfig['h2'].family} - - mobileColor: green -
- font size (S / M / L breakpoints): {fontConfig['h2'].small.fontSize} / {fontConfig['h2'].medium.fontSize} / {fontConfig['h2'].large.fontSize} -
- line height (S / M / L breakpoints): {fontConfig['h2'].small.lineHeight} / {fontConfig['h2'].medium.lineHeight} / {fontConfig['h2'].large.lineHeight} -
- - - H3 - - - family: {fontConfig['h3'].family} - - mobileColor: red -
- font size (S / M / L breakpoints): {fontConfig['h3'].small.fontSize} / {fontConfig['h3'].medium.fontSize} / {fontConfig['h3'].large.fontSize} -
- line height (S / M / L breakpoints): {fontConfig['h3'].small.lineHeight} / {fontConfig['h3'].medium.lineHeight} / {fontConfig['h3'].large.lineHeight} -
- - - H4 - - - family: {fontConfig['span'].family} - -
- font size (S / M / L breakpoints): {fontConfig['h4'].small.fontSize} / {fontConfig['h4'].medium.fontSize} / {fontConfig['h4'].large.fontSize} -
- line height (S / M / L breakpoints): {fontConfig['h4'].small.lineHeight} / {fontConfig['h4'].medium.lineHeight} / {fontConfig['h4'].large.lineHeight} -
- - - P (body) - - - family: {fontConfig['p'].family} - -
- font size (S / M / L breakpoints): {fontConfig['p'].small.fontSize} / {fontConfig['p'].medium.fontSize} / {fontConfig['p'].large.fontSize} -
- line height (S / M / L breakpoints): {fontConfig['p'].small.lineHeight} / {fontConfig['p'].medium.lineHeight} / {fontConfig['p'].large.lineHeight} -
- - - Tags to be phased out: - - - - H5 - - - family: {fontConfig['h5'].family} - -
- font size (S / M / L breakpoints): {fontConfig['h5'].small.fontSize} / {fontConfig['h5'].medium.fontSize} / {fontConfig['h5'].large.fontSize} -
- line height (S / M / L breakpoints): {fontConfig['h5'].small.lineHeight} / {fontConfig['h5'].medium.lineHeight} / {fontConfig['h5'].large.lineHeight} -
- - - H6 - - - family: {fontConfig['h6'].family} -
- font size (S / M / L breakpoints): {fontConfig['h6'].small.fontSize} / {fontConfig['h6'].medium.fontSize} / {fontConfig['h6'].large.fontSize} -
- line height (S / M / L breakpoints): {fontConfig['h6'].small.lineHeight} / {fontConfig['h6'].medium.lineHeight} / {fontConfig['h6'].large.lineHeight} -
-
- -
- - Context styles: - - -
-

First paragraph

-

Second paragraph

-

Third and final paragraph

-
- -
-

Only child P

-
- -
-

Only child H1

-
- -
-

First child H1

-

Second child H1

-
- -
-

h1

-

Paragraph

-

Paragraph

-

Paragraph, last child

-
- -
-

A preceding paragraph

-

A preceding paragraph

-

H1 with an added margin-top as it follows a p tag

-

Proceeding paragraph

-

Paragraph, last child

-
- -
-

A preceding paragraph

-

A preceding paragraph

-

H2 with an added margin-top as it follows a p tag

-

Proceeding paragraph

-

Paragraph, last child

-
- -
- -``` diff --git a/src/components/Atoms/Text/TextExample.jsx b/src/components/Atoms/Text/TextExample.jsx new file mode 100644 index 000000000..eac2dbb97 --- /dev/null +++ b/src/components/Atoms/Text/TextExample.jsx @@ -0,0 +1,161 @@ +import React from 'react'; +import styled from 'styled-components'; +import Text from './Text'; +import fontConfig from '../../../theme/crTheme/fontConfig'; + +const Wrapper = styled.div` + padding: 1rem; + background: lightblue; + margin-top: 1rem; + border-radius: 5px; +`; + + const Section = styled.div` + margin-bottom: 50px; + `; + +export default function TextExample() { + return ( + <> +
+

Basic Text Elements:

+ + + + H1 + + + +

family: {fontConfig['h1'].family}

+

mobileColor: blue

+

font size (S / M / L breakpoints): {fontConfig['h1'].small.fontSize} / {fontConfig['h1'].medium.fontSize} / {fontConfig['h1'].large.fontSize}

+

line height (S / M / L breakpoints): {fontConfig['h1'].small.lineHeight} / {fontConfig['h1'].medium.lineHeight} / {fontConfig['h1'].large.lineHeight}

+
+
+ + + + H2 + + +

family: {fontConfig['h2'].family}

+

mobileColor: green

+

font size (S / M / L breakpoints): {fontConfig['h2'].small.fontSize} / {fontConfig['h2'].medium.fontSize} / {fontConfig['h2'].large.fontSize}

+

line height (S / M / L breakpoints): {fontConfig['h2'].small.lineHeight} / {fontConfig['h2'].medium.lineHeight} / {fontConfig['h2'].large.lineHeight}

+
+
+ + + + H3 + + +

family: {fontConfig['h3'].family}

+

mobileColor: red

+

font size (S / M / L breakpoints): {fontConfig['h3'].small.fontSize} / {fontConfig['h3'].medium.fontSize} / {fontConfig['h3'].large.fontSize}

+

line height (S / M / L breakpoints): {fontConfig['h3'].small.lineHeight} / {fontConfig['h3'].medium.lineHeight} / {fontConfig['h3'].large.lineHeight}

+
+
+ + + + H4 + + +

family: {fontConfig['span'].family}

+

font size (S / M / L breakpoints): {fontConfig['h4'].small.fontSize} / {fontConfig['h4'].medium.fontSize} / {fontConfig['h4'].large.fontSize}

+

line height (S / M / L breakpoints): {fontConfig['h4'].small.lineHeight} / {fontConfig['h4'].medium.lineHeight} / {fontConfig['h4'].large.lineHeight}

+
+
+ + + + P (body) + + +

family: {fontConfig['p'].family}

+

font size (S / M / L breakpoints): {fontConfig['p'].small.fontSize} / {fontConfig['p'].medium.fontSize} / {fontConfig['p'].large.fontSize}

+

line height (S / M / L breakpoints): {fontConfig['p'].small.lineHeight} / {fontConfig['p'].medium.lineHeight} / {fontConfig['p'].large.lineHeight}

+
+
+
+ +
+

Text Elements to be phased out:

+ + + + H5 + + +

family: {fontConfig['h5'].family}

+

font size (S / M / L breakpoints): {fontConfig['h5'].small.fontSize} / {fontConfig['h5'].medium.fontSize} / {fontConfig['h5'].large.fontSize}

+

line height (S / M / L breakpoints): {fontConfig['h5'].small.lineHeight} / {fontConfig['h5'].medium.lineHeight} / {fontConfig['h5'].large.lineHeight}

+
+
+ + + + H6 + + +

family: {fontConfig['h6'].family}

+

font size (S / M / L breakpoints): {fontConfig['h6'].small.fontSize} / {fontConfig['h6'].medium.fontSize} / {fontConfig['h6'].large.fontSize}

+

line height (S / M / L breakpoints): {fontConfig['h6'].small.lineHeight} / {fontConfig['h6'].medium.lineHeight} / {fontConfig['h6'].large.lineHeight}

+
+
+
+ +
+

Text Elements in situ / context.

+ + +

First paragraph

+

Second paragraph

+

Third and final paragraph

+
+ + +

Only child paragraph

+
+ + +

h1 Only child

+
+ + +

h1 First child

+

h1 Second child

+
+ + +

h1

+

Paragraph

+

Paragraph

+

Paragraph, last child

+
+ + +

A preceding paragraph

+

A preceding paragraph

+

H1 with an added margin-top as it follows a p tag

+

Proceeding paragraph

+

Paragraph, last child

+
+ + +

A preceding paragraph

+

A preceding paragraph

+

H2 with an added margin-top as it follows a p tag

+

Proceeding paragraph

+

Paragraph, last child

+
+
+ + ); +} diff --git a/src/components/Atoms/Text/__snapshots__/Text.test.js.snap b/src/components/Atoms/Text/__snapshots__/Text.test.js.snap index d087db840..ebc34caba 100644 --- a/src/components/Atoms/Text/__snapshots__/Text.test.js.snap +++ b/src/components/Atoms/Text/__snapshots__/Text.test.js.snap @@ -5,9 +5,6 @@ exports[`renders heavy heading correctly 1`] = ` font-family: 'Montserrat',Helvetica,Arial,sans-serif; font-weight: 700; text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; letter-spacing: 0; font-size: 1.25rem; line-height: 1.5rem; @@ -22,14 +19,14 @@ exports[`renders heavy heading correctly 1`] = ` line-height: inherit; } -@media (min-width:740px) { +@media (min-width: 740px) { .c0 { font-size: 1.25rem; line-height: 1.5rem; } } -@media (min-width:1024px) { +@media (min-width: 1024px) { .c0 { font-size: 1.375rem; line-height: 1.625rem; @@ -48,9 +45,6 @@ exports[`renders high heading correctly 1`] = ` font-family: 'Montserrat',Helvetica,Arial,sans-serif; font-weight: 700; text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; letter-spacing: 0; font-size: 1.25rem; line-height: 1.5rem; @@ -65,14 +59,14 @@ exports[`renders high heading correctly 1`] = ` line-height: inherit; } -@media (min-width:740px) { +@media (min-width: 740px) { .c0 { font-size: 1.25rem; line-height: 1.5rem; } } -@media (min-width:1024px) { +@media (min-width: 1024px) { .c0 { font-size: 1.375rem; line-height: 1.625rem; @@ -91,9 +85,6 @@ exports[`renders large heading correctly 1`] = ` font-family: 'Montserrat',Helvetica,Arial,sans-serif; font-weight: 700; text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; letter-spacing: 0; font-size: 1.25rem; line-height: 1.5rem; @@ -109,14 +100,14 @@ exports[`renders large heading correctly 1`] = ` line-height: inherit; } -@media (min-width:740px) { +@media (min-width: 740px) { .c0 { font-size: 1.25rem; line-height: 1.5rem; } } -@media (min-width:1024px) { +@media (min-width: 1024px) { .c0 { font-size: 1.375rem; line-height: 1.625rem; @@ -135,9 +126,6 @@ exports[`renders xl paragraph with Anton font correctly 1`] = ` font-family: 'Montserrat',Helvetica,Arial,sans-serif; font-weight: 400; text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; letter-spacing: 0; font-size: 1rem; line-height: 1.25rem; @@ -154,14 +142,14 @@ exports[`renders xl paragraph with Anton font correctly 1`] = ` line-height: inherit; } -@media (min-width:740px) { +@media (min-width: 740px) { .c0 { font-size: 1rem; line-height: 1.25rem; } } -@media (min-width:1024px) { +@media (min-width: 1024px) { .c0 { font-size: 1.125rem; line-height: 1.375rem; @@ -180,9 +168,6 @@ exports[`renders xl yellow paragraph correctly 1`] = ` font-family: 'Montserrat',Helvetica,Arial,sans-serif; font-weight: 400; text-transform: inherit; - -webkit-letter-spacing: 0; - -moz-letter-spacing: 0; - -ms-letter-spacing: 0; letter-spacing: 0; font-size: 1rem; line-height: 1.25rem; @@ -199,14 +184,14 @@ exports[`renders xl yellow paragraph correctly 1`] = ` line-height: inherit; } -@media (min-width:740px) { +@media (min-width: 740px) { .c0 { font-size: 1rem; line-height: 1.25rem; } } -@media (min-width:1024px) { +@media (min-width: 1024px) { .c0 { font-size: 1.125rem; line-height: 1.375rem; diff --git a/src/components/Atoms/TextArea/TextArea.js b/src/components/Atoms/TextArea/TextArea.js index e53d84f1c..c87049771 100644 --- a/src/components/Atoms/TextArea/TextArea.js +++ b/src/components/Atoms/TextArea/TextArea.js @@ -6,7 +6,7 @@ import spacing from '../../../theme/shared/spacing'; import Label from '../Label/Label'; import ErrorText from '../ErrorText/ErrorText'; -const StyledTextArea = styled.textarea`${({ theme, error }) => css` +const StyledTextArea = styled.textarea`${({ theme, $error }) => css` box-sizing: border-box; width: 100%; margin: 0; @@ -15,7 +15,7 @@ const StyledTextArea = styled.textarea`${({ theme, error }) => css` background-color: ${theme.color('grey_light')}; border: 1px solid; border-radius: 0.5rem; - border-color: ${error ? theme.color('red') : theme.color('grey_medium')}; + border-color: ${$error ? theme.color('red') : theme.color('grey_medium')}; box-shadow: none; appearance: none; color: ${theme.color('black')}; @@ -45,7 +45,7 @@ const TextArea = React.forwardRef(({ {...rest} placeholder={placeholder} rows={rows} - error={!!errorMsg} + $error={!!errorMsg} id={id} aria-describedby={id} ref={ref} diff --git a/src/components/Atoms/TextArea/TextArea.md b/src/components/Atoms/TextArea/TextArea.md deleted file mode 100644 index c50ed7fa6..000000000 --- a/src/components/Atoms/TextArea/TextArea.md +++ /dev/null @@ -1,21 +0,0 @@ -# TextArea Field - -```js -

Long copy/Message field

-