Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maxWidth prop & containerXL support to various components #1921

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

stowball
Copy link
Contributor

@stowball stowball commented Jan 3, 2025

A request is to allow our page components to support wider screens up to 1920px. This PR adds a new containerXL token and maxWidth prop to the various page components to support this.

I have made the standard maxWidth prop support tokens and overridden the maxWidth of these components to obfuscate where the actualy token gets applied.

Playroom demo

View preview

Checklist

Preflight

  • Prefix the PR title with the slug of the package or component - e.g. accordion: Updated padding or docs: Updated header links
  • Describe the changes clearly in the PR description
  • Read and check your code before tagging someone for review
  • Create a changeset file by running yarn changeset. Learn more about change management.

Testing

  • x ] Manually test component in various modern browsers at various sizes (use Browserstack)
  • Manually test component in various devices (phone, tablet, desktop)
  • Manually test component using a keyboard
  • Manually test component using a screen reader
  • Manually tested in dark mode
  • Component meets Web Content Accessibility Guidelines (WCAG) 2.1 standards
  • Add any necessary unit tests (HTML validation, snapshots etc)
  • Run yarn test to ensure tests are passing. If required, run yarn test -u to update any generated snapshots.

Copy link

changeset-bot bot commented Jan 3, 2025

🦋 Changeset detected

Latest commit: d0d9912

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@ag.ds-next/react Minor
@ag.ds-next/docs Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jan 3, 2025

PR Preview Action v1.4.8
🚀 Deployed preview to https://agriculturegovau.github.io/agds-next/pr-preview/pr-1921/
on branch gh-pages at 2025-01-06 22:52 UTC

css={packs.print.hidden}
css={[
{
height: '100%',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures the right content is the same height as the logo should users want to centre something

@@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These keep changing, so adding them

mq,
packs,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding packs to be used in playroom and docs editors

@stowball stowball requested a review from ChrisLaneAU January 5, 2025 22:10
) {
return mapResponsiveProp(
maxWidth,
// @ts-expect-error stowey
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisLaneAU

I don't know how to get rid of this TS error:

Element implicitly has an 'any' type because expression of type 'NonNullable<string | number | undefined>' can't be used to index type '{ readonly bodyText: "42em"; readonly container: "80rem"; readonly containerXL: "120rem"; readonly field: { readonly xs: "5rem"; readonly sm: "8rem"; readonly md: "13rem"; readonly lg: "18rem"; readonly xl: "24rem"; }; }'.
  No index signature with a parameter of type 'string' was found on type '{ readonly bodyText: "42em"; readonly container: "80rem"; readonly containerXL: "120rem"; readonly field: { readonly xs: "5rem"; readonly sm: "8rem"; readonly md: "13rem"; readonly lg: "18rem"; readonly xl: "24rem"; }; }'.ts(7053)

I hoped creating this function would do it, but nah. If a custom function is unnecessary, then doing the value mapping on L392 would be preferable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the object lookup on L345 occurs, TypeScript thinks value is any string (despite your efforts to tell it otherwise - it's conflating all the specific strings from MaxWidth with the broader string type). So, you still need to convince TypeScript that you're only passing a key of tokens.maxWidth in during that lookup. I think your best bet is a guard clause.

L392 can be:

maxWidth: mapResponsiveProp(maxWidth, (value) => (isKeyOfMaxWidth(value) && tokens.maxWidth[value]) || value),

And you can replace mapMaxWidth with the isKeyOfMaxWidth guard clause:

const isKeyOfMaxWidth = (value: string | number | undefined): value is MaxWidth =>
  !!value && value in tokens.maxWidth;

Copy link

sonarqubecloud bot commented Jan 6, 2025

@stowball stowball changed the title Add containerWidth prop to various components Add maxWidth prop & containerXL support to various components Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants