-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
There was a problem hiding this 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' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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> = { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this 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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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> | ||
) | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
const sizeToClass = { | ||
"scale": "", | ||
"3": "usa-icon--size-3", | ||
"4": "usa-icon--size-4" | ||
} |
There was a problem hiding this comment.
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
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> | ||
) |
There was a problem hiding this comment.
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.
Description
NJWDS Web components created/updated
Button component
Icon 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 componentpackages/stencil-library/src/components/button/button.e2e.ts
- button component testspackages/stencil-library/src/components/icon/icon.tsx
- icon component testpackages/stencil-library/src/components/icon/icon.e2e.ts
andpackages/stencil-library/src/components/icon/icon.spec.ts
- icon component testsNote these are generated during the build process
packages/stencil-library/src/components.d.ts
packages/react-library/
directorySteps to Test
To run in dev:
npm i
packages/stencil-library
directory >npm run start
To test:
packages/stencil-library
directory >npm run test