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

Updates to NJWDS button web component + new icon component #8

Merged
merged 37 commits into from
Sep 26, 2024

Conversation

jasnoo
Copy link
Contributor

@jasnoo jasnoo commented Sep 23, 2024

Description

NJWDS Web components created/updated

Button component

  • button components updated per design (Design)
  • Includes variant styling - primary, secondary, and link
  • Includes mode styling across all variants - light mode, dark mode, danger
  • Includes icon button - can be leading, trailing, or icon only button
  • Previously implemented version included here: Implement basic njwds-button component #4

Icon component

  • icon component (Design)
  • Implemented in the button component

The core of the changes that are actually made in the repo would be the following

  • packages/stencil-library/src/components/button/button.tsx - button component
  • packages/stencil-library/src/components/button/button.e2e.ts - button component tests
  • packages/stencil-library/src/components/icon/icon.tsx - icon component test
  • packages/stencil-library/src/components/icon/icon.e2e.ts and packages/stencil-library/src/components/icon/icon.spec.ts - icon component tests

Note these are generated during the build process

  • packages/stencil-library/src/components.d.ts
  • packages/react-library/ directory

Steps to Test

To run in dev:

  • npm i
  • Go into packages/stencil-library directory > npm run start

To test:

  • In packages/stencil-library directory > npm run test

@jasnoo jasnoo changed the title Updates to NJWDS button web component + icon component Updates to NJWDS button web component + new icon component Sep 23, 2024
Copy link
Collaborator

@ezhangy ezhangy left a comment

Choose a reason for hiding this comment

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

Looks good to me! A couple small comments and a couple things I think we should document as issues and return to in the future.

return "usa-button--unstyled usa-button--outline usa-button--inverse"
return "usa-button--unstyled unstyled-button-dark"
default:
return 'primary-button-dark'
Copy link
Collaborator

Choose a reason for hiding this comment

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

[dust] I think it might be a good idea to add "usa" or "nj" as a prefix to these custom classes in order to avoid styling naming conflicts in projects.

Maybe we can create an issue in the repo to track for later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think issue will be good here, we should align this across the njwds repo as well

return element.className.split(' ').sort();
};

const variant: Record<ButtonVariant, ButtonVariant> = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[dust] I really like the pattern of using Record objects for variant, etc. to make the tests clearer!

packages/stencil-library/src/components/icon/icon.e2e.ts Outdated Show resolved Hide resolved
packages/stencil-library/src/components/icon/icon.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

[dust] just confirming all of the new files in the react-component-lib directory were auto-generated by stencil? I assumed this was the case so I didn't check any of these files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, they were generated by stencil!

packages/stencil-library/src/index.html Outdated Show resolved Hide resolved
Copy link

@namanaman namanaman left a comment

Choose a reason for hiding this comment

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

Looks great, thorough testing!

@@ -1 +1,3 @@
export type Mode = 'light' | 'dark';
export type Mode = 'light' | 'dark' | 'danger';

Choose a reason for hiding this comment

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

[Dust] Why is danger a mode rather than a variant?

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 aligns with the design where there's the 3 variants (primary/secondary/link) and each has a version of each mode.


private getButtonClassName(): string {

const getVariantClassName = (variant: ButtonVariant): string => {

Choose a reason for hiding this comment

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

[Dust] Should be this be named getLightModeVariantClassName to align with the other 2?

return this.mode === "light"
? `usa-button ${getVariantClassName(this.variant)}`
: `usa-button ${getDarkModeVariantClassName(this.variant)}`
let getClassName;

Choose a reason for hiding this comment

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

[Dust] IMO setting the value of the classname (by invoking the function) rather than setting the function to call may be clearer for a dev

let iconClass = ''
switch (this.iconPosition) {
case "leading":
iconClass += ' margin-right-105'

Choose a reason for hiding this comment

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

[Dust] Why += vs. just setting it directly? Since the initial class is empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, originally I had other text in iconClass but I took it out

Comment on lines 83 to 92
if (this.iconPosition === 'icon-only') {
return (
<njwds-icon icon={this.icon} size="3" decorative={false} iconTitle={this.iconTitle}></njwds-icon>
)

} else {
return (
<njwds-icon class={iconClass} icon={this.icon} size="3" decorative={true} iconTitle={this.iconTitle}></njwds-icon>
)
}

Choose a reason for hiding this comment

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

[Dust] I'm wondering if it'd be clearer if we just had a single return statement and we conditionally change the attribute for decorative and class so we don't need to repeat the rest of the attributes for both. It may be clearer to the dev which things are static and which are changing

Choose a reason for hiding this comment

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

[Praise] Such a comprehensive test, nice!

@Prop() decorative: boolean = false;
@Prop() iconTitle?: string

componentWillLoad() {

Choose a reason for hiding this comment

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

[Dust] Any reason why this falls in componentWillLoad vs. another lifecycle method?

Comment on lines 22 to 26
const sizeToClass = {
"scale": "",
"3": "usa-icon--size-3",
"4": "usa-icon--size-4"
}

Choose a reason for hiding this comment

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

[Pebble] This could be a constant outside of the component scope to make it clearer that it's not dependent on the internals of the function or class

Comment on lines 31 to 42
return this.decorative
? (
<svg class={iconClass} aria-hidden="true" focusable="false" role="img">
<use xlinkHref={iconSrc}></use>
</svg>
)
: (
<svg class={iconClass} aria-labelledby={iconTitleId} role="img" focusable="false">
<title id={iconTitleId}>{this.iconTitle ?? this.icon}</title>
<use xlinkHref={iconSrc}></use>
</svg>
)

Choose a reason for hiding this comment

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

[Dust] Similar question as button icon where can we return just 1 thing and conditionally adjust the attributes that are dynamic within there? This would make it easier to see what's constant and also mean if we change something in a constant part (use xlinkHref) in one place, we don't have to do it twice.

@jasnoo jasnoo merged commit ebd53b4 into main Sep 26, 2024
1 check passed
@jasnoo jasnoo deleted the button-component-tests branch September 26, 2024 13:04
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.

3 participants