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

DSD-1884: new template component #1711

Open
wants to merge 16 commits into
base: new-template-feature-branch
Choose a base branch
from

Conversation

oliviawongnyc
Copy link
Collaborator

@oliviawongnyc oliviawongnyc commented Dec 5, 2024

Fixes JIRA ticket DSD-1884 and DSD-1885

This PR does the following:

  • Updates Template wrapper component and children components
  • Adds concept of narrow main content for long text
  • Updates styles to make responsive gaps and sidebar in grid

How has this been tested?

  • In Storybook

Accessibility concerns or updates

  • Documentation not complete

Accessibility Checklist

  • Checked Storybook's "Accessibility" tab for color contrast and other issues.
  • The feature works with keyboard inputs including tabbing back and forward and pressing space, enter, arrow, and esc keys.
  • For hidden text or when aria-live is used, a screenreader was used to verify the text is read.
  • For features that involve UI updates and focusing on DOM refs, focus management was reviewed.
  • The feature works when the page is zoomed in to 200% and 400%.

Open Questions

Checklist:

  • I have updated the Storybook documentation and changelog accordingly.
  • I have added relevant accessibility documentation for this pull request.
  • All new and existing tests passed.

Front End Review:

  • Review the Vercel preview deployment once it is ready.

Copy link

vercel bot commented Dec 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nypl-design-system ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 5:55pm

@oliviawongnyc oliviawongnyc added DON’T MERGE YET When somethign has been approved, but should not be merged just yet. Needs Review Pull requests that are ready for peer review. labels Dec 5, 2024
Copy link
Member

@EdwinGuzman EdwinGuzman left a comment

Choose a reason for hiding this comment

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

You can remove "new" from the component and file names since this is a breaking change update.

CHANGELOG.md Outdated Show resolved Hide resolved
src/components/Template/Template.mdx Outdated Show resolved Hide resolved
src/components/Template/Template.mdx Show resolved Hide resolved
src/components/Template/Template.mdx Outdated Show resolved Hide resolved
language="jsx"
/>
The `TemplateMain` and `TemplateMainNarrow` components render the content as a
`<main>` element with a default "id" of `"mainContent"`. This should be used as
Copy link
Member

Choose a reason for hiding this comment

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

Because of the same shared id value, I think it's fine to explicitly say to use either one but not both.

<TemplateFooter>{footer}</TemplateFooter>
</Template>
);
const { container } = render(<>{templateChildren}</>);
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be good to make templateChildren a function and pass in the value of the sidebar, either left or right. Then you can have two accessibility tests and verify both sidebar variants (and the default without a sidebar) are all accessible.

<TemplateContentPrimary>{contentPrimary}</TemplateContentPrimary>
</TemplateContent>
<TemplateFooter>{footer}</TemplateFooter>
<Template sidebar={sidebar}>
Copy link
Member

Choose a reason for hiding this comment

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

Similar comment here, this is a snapshot for the left sidebar but have snapshots for other variants.

/>
)
.toJSON();
const withChakraProps = renderer
Copy link
Member

Choose a reason for hiding this comment

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

This is still applicable.

/>
)
.toJSON();
const withOtherProps = renderer
Copy link
Member

Choose a reason for hiding this comment

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

This and the ref test below are still applicable.

type: "Update",
affects: ["Functionality", "Styles"],
notes: [
"Major update to component and styles based on the [Template TAD](https://docs.google.com/document/d/1vZJX7Y-DnEM44-iWw5qoXGdxqavHEN6prhr-YDTNr0o/edit?pli=1&tab=t.0).",
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't render as a link in storybook since it can't parse mdx strings. You can leave out the link.

Copy link
Member

Choose a reason for hiding this comment

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

Screenshot 2024-12-06 at 11 08 34 AM

Copy link
Member

@EdwinGuzman EdwinGuzman left a comment

Choose a reason for hiding this comment

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

The update looks good! Some minor things including fixing the story:
Screenshot 2024-12-06 at 5 15 42 PM

I will do a closer test next week by trying to add different components and layouts in my local set up.

CHANGELOG.md Outdated
@@ -8,6 +8,10 @@ Currently, this repo is in Prerelease. When it is released, this project will ad

## Prerelease

### Updates

- [Updates `Template` component(s)](<(https://newyorkpubliclibrary.atlassian.net/browse/DSD-1884)>) and styles per TAD.
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to have the internal <( and )>?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Don't think so!

type="informative"
/>
</TemplateTop>
<TemplateSidebar>
Copy link
Member

Choose a reason for hiding this comment

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

You need to add a case for when "sidebar" is set to "none"

Copy link
Member

Choose a reason for hiding this comment

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

Actually, this also displays correctly when sidebar is either "left" or "right", but we do want to recommend that the DOM follows the styles as well. So if sidebar="right", the DOM should be set in the same manner.

// The `<header>` HTML element has the same meaning as `role="banner"`.
expect(screen.getAllByRole("banner")).toHaveLength(1);
});
it("renders each section with left sidebar", () => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: this should say right

});
const contentBottom = <Placeholder variant="short">Content Bottom</Placeholder>;

const templateComponents = (
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines 52 to 53
const { container } = render(templateComponents("left"));
expect(await axe(container)).toHaveNoViolations();
Copy link
Member

Choose a reason for hiding this comment

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

Add two similar tests for the default and "right".

version: "Prerelease",
type: "Update",
affects: ["Functionality", "Styles"],
notes: ["Major update to component and styles based on the Template TAD."],
Copy link
Member

Choose a reason for hiding this comment

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

It's ok to be more descriptive here! Maybe not all the details but definitely the major ones.

m: "0 auto",
p: "s",
gridTemplateAreas: `"breakout" "top" "main" "bottom"`,
gridTemplateColumns: "repeat(1, minmax(100px, 1fr))",
Copy link
Member

Choose a reason for hiding this comment

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

How did you get 100px for the first value in minmax?

Copy link
Collaborator Author

@oliviawongnyc oliviawongnyc Dec 9, 2024

Choose a reason for hiding this comment

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

Arbitrarily, though I think it looks good.... it should probably be decided on by @bigfishdesign13.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The smallest screen width that designers consider (in theory) is 320px, so I'd suggest changing the min here to 320px.

Why use repeat when it's not repeating?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I'd argue that minmax should be removed altogether from the column styles and instead apply minWidth: "320px" to the full grid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If the smallest screen width is 320, then the minWidth of the grid should be smaller than that, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@oliviawongnyc Yes. That is what I was referring to during our call earlier. It should be 320 minus the value of the padding. For the mobile viewport the padding on either side is 16px, so the minWidth for the grid should be set to "288px".

320px - (16px x 2) = 288px

Copy link
Member

@EdwinGuzman EdwinGuzman left a comment

Choose a reason for hiding this comment

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

Minor comments. I will approve once others get a chance to review the PR (I think I've been looking so often that at this point I will miss things).

Important: make a feature branch and point this PR into that branch. This should not accidentally be merged into development and this feature won't go out until 4.0 is released.

@@ -2,499 +2,121 @@ import { ArgTypes, Canvas, Description, Meta, Source } from "@storybook/blocks";
import ComponentChangelogTable from "../../utils/ComponentChangelogTable";
import { changelogData } from "./templateChangelogData";

import * as TemplateStories from "./Template.stories";
import * as TemplateNewStories from "./Template.stories";
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove "new" where necessary.

expect(await axe(container)).toHaveNoViolations();
});

it("passes axe accessibility test", async () => {
Copy link
Member

Choose a reason for hiding this comment

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

These four tests have the same description. Update this so they are all descriptive to the test.

<Template sidebar={sidebar}>
<TemplateBreakout>{breakout}</TemplateBreakout>
<TemplateTop>{contentTop}</TemplateTop>
{sidebar !== "none" && !useMainNarrow && (
Copy link
Member

Choose a reason for hiding this comment

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

Not too big of a deal since this is a test, but if "sidebar" is "right", the DOM will not be in the right order.

@EdwinGuzman
Copy link
Member

@jackiequach @7emansell @bigfishdesign13 if you get a chance to review, please try to before 12/11.

Copy link
Collaborator

@jackiequach jackiequach left a comment

Choose a reason for hiding this comment

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

The "Template Full Example" is very cramped at 600px screen width. Otherwise, this looks great!

should be wrapped in a `<div>` element or a `<Box>` component.

Basic "template" components structure:
### Using the `Template` with the `Header` and `Footer`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a short description here for better clarity

<Button id="submit">Submit</Button>
</FormField>
</Form>
<Table
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated issue: this table does not scroll properly at 600px screen width

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, for me, the table scrolls at 600px, but you're right that it doesn't look great.

@bigfishdesign13 & @EdwinGuzman, will this be resolved with the new md breakpoint? I believe it's 768px, meaning this would be one column up until then.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Container queries would resolve this issue. The Table will not use a fixed first column for mobile viewports, but what you are seeing can happen when it is dropped in a narrow space. The new mobile breakpoint of 768px will help, but it will still not be ideal.

Another way to improve the UX here would be to turn off the row headers on the Table when the viewport width drops below 960px.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, good points. Won't do anything about it here though.

* Grid layout based on https://www.joshwcomeau.com/css/full-bleed/
*/

export const responsiveGap = { base: "1rem", md: "1.5rem", xl: "1rem" };
Copy link
Collaborator

Choose a reason for hiding this comment

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

is xl supposed to be 2rem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't believe so, but @bigfishdesign13, could you please confirm?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the values for responsiveGap and responsivePadding were flip-flopped. For responsiveGap, the xl value should be "2rem". And for responsivePadding, the xl value should be "1rem".

@oliviawongnyc oliviawongnyc changed the base branch from development to new-template-feature-branch December 10, 2024 17:30
*/

export const responsiveGap = { base: "1rem", md: "1.5rem", xl: "1rem" };
export const responsivePadding = { base: "1rem", md: "1.5rem", xl: "2rem" };
Copy link
Collaborator

Choose a reason for hiding this comment

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

To keep proper alignment in the UI, this same type of responsive padding will be used in a number of other components. The responsive gaps could also be used in some places. Do you think it would make sense to move these into global.ts?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, could this also be a general "DS gap" and "DS padding" set of values that can be used elsewhere? Perhaps exported as design tokens if consuming apps need them.

<Button id="submit">Submit</Button>
</FormField>
</Form>
<Table
Copy link
Collaborator

Choose a reason for hiding this comment

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

Container queries would resolve this issue. The Table will not use a fixed first column for mobile viewports, but what you are seeing can happen when it is dropped in a narrow space. The new mobile breakpoint of 768px will help, but it will still not be ideal.

Another way to improve the UX here would be to turn off the row headers on the Table when the viewport width drops below 960px.

Copy link
Collaborator

@bigfishdesign13 bigfishdesign13 left a comment

Choose a reason for hiding this comment

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

Some suggestions.

baseStyle: defineStyle({
gridColumn: { base: "1", md: "1 / span 2" },
paddingX: "s",
maxWidth: { lg: "720px" },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's see if we can bring this into alignment with the 12-column grid. When using a 12-column grid at 1280px with appropriate padding and gaps, an eight column span is 822px. And interestingly, DC is using 820px max width on the About page.

The underlying grid for desktop would use:

gridTemplateColumns: "1fr 4fr 1fr"

And the content area would be the 4fr column.

For tablet, maybe something like this:

gridTemplateColumns: "1fr 10fr 1fr"

And the next jump would just be "1fr" (full width).

Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I won't be able to work on this myself, but I think we can achieve this in TemplateMainNarrow by adding display: grid and something like gridTemplateColumns: "2fr minmax(800, 8fr) 2fr". This second value would need to be fiddled with.

Then, the component needs to have another div wrapper like so:

const TemplateMainNarrow: React.FC<React.PropsWithChildren<TemplateMainProps>> =
  ({ children, id = "mainContent" }) => {
    const styles = useStyleConfig("TemplateMainNarrow");

    return (
      <Box as="main" id={id} gridArea="main" __css={styles}>
        <div style={{ gridColumn: 2 }}>{children}</div>
      </Box>
    );
  };

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines 87 to 91
Wide lines of text are difficult to read and are proven to make it harder for
people to focus, while short lines of text force the eye to travel back too often,
breaking a reader's rhythm. The `TemplateMain` component has a max width of 1280px,
which is too wide for text. If your content includes long chunks of text, you
should use the `TemplateMainNarrow` component instead.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to mention that this type of scenario is only applicable when the sidebar is not used.

`}
language="jsx"
/>
TBD.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I will work on this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TY!

src/components/Template/Template.mdx Outdated Show resolved Hide resolved
`}
language="jsx"
/>
## Template Sidebar Configuration
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should either expand this section to detail the placement and function of all of the grid regions or we should add a section for each region. I am leaning toward adding separate sections to describe each region.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I think that makes sense! Will leave this work for the documentation ticket.

@bigfishdesign13 bigfishdesign13 added the v4 Updates for the v4.0 feature branch label Dec 16, 2024
@bigfishdesign13 bigfishdesign13 changed the title DSD-1884/new template component DSD-1884: new template component Dec 16, 2024
@EdwinGuzman
Copy link
Member

I'm going to merge this PR in and we can work on subsequent fixes in future PRs as planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DON’T MERGE YET When somethign has been approved, but should not be merged just yet. Needs Review Pull requests that are ready for peer review. v4 Updates for the v4.0 feature branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants