-
Notifications
You must be signed in to change notification settings - Fork 233
feat(badge): s2 styling and render #5718
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
Conversation
|
📚 Branch Preview🔍 Visual Regression Test ResultsWhen a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:
Deployed to Azure Blob Storage: If the changes are expected, update the |
Tachometer resultsCurrently, no packages are changed by this PR... |
b2f7410
to
76955a7
Compare
second-gen/packages/core/components/progress-circle/ProgressCircle.base.ts
Outdated
Show resolved
Hide resolved
second-gen/packages/core/components/progress-circle/ProgressCircle.base.ts
Outdated
Show resolved
Hide resolved
typeof this.fixed !== 'undefined', | ||
})} | ||
> | ||
${when( |
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 updated the ternary to use when
instead but let me know if there's a reason not to use that here.
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.
👍 Since the 2nd-gen render()
method is conceptually free to diverge from the 1st-gen method in whatever way is useful (provided there is no impact on the component API), there's no reason not to opt for when
here.
</div> | ||
` | ||
)} | ||
<div class="spectrum-Badge-label"> |
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 tested adding this class to the slot itself and it didn't render padding correctly. Maybe just a case of needing the appropriate display settings but I didn't dig into it too much. Would be good to have a standard "best practice" in place for whether we want to wrap slots to apply styles or style slot containers directly.
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.
Yes, it looks like adding a rule to the component styles that sets display: block;
on the slot also works.
I think in general it would be better to avoid systematically wrapping slots for styling purposes.
@property({ type: Boolean, reflect: true }) | ||
public subtle: boolean = false; | ||
|
||
public set fixed(fixed: FixedValues | undefined) { |
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 seems to me to be how the @Property works by default. I don't see any regressions when I simplify this but let me know if I've missed a nuance here.
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.
At a glance, I think you're right—at least, I can't immediately see why this property would need a bespoke getter and setter.
That said, the aim of the Barebones milestone is to avoid any changes not strictly related to migrating these components to the new architecture, so I think the best course of action here would be to add a @todo
comment rather than making a change in this PR.
second-gen/packages/swc/components/progress-circle/stories/progress-circle.stories.ts
Outdated
Show resolved
Hide resolved
second-gen/packages/swc/components/progress-circle/stories/progress-circle.stories.ts
Show resolved
Hide resolved
second-gen/packages/swc/components/progress-circle/ProgressCircle.ts
Outdated
Show resolved
Hide resolved
import { ObserveSlotText } from '@swc/core/shared/observe-slot-text'; | ||
|
||
export const BADGE_VARIANTS = [ | ||
export const BADGE_VARIANTS_SEMANTIC = [ |
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.
Separating out the semantic variants from the color variants helps us in Storybook (and possibly down the road) because only semantic variants support outline styling.
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.
Yes, this seems like a good idea!
BadgeBase, | ||
} from '@swc/core/components/badge'; | ||
|
||
export const BADGE_VARIANTS_COLOR = [ |
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 re-exports the const with the addition of the new colors.
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.
Yes, we definitely need to define a constant representing the full set of S2 colors. As I mentioned in an earlier comment, I've done some additional exploration into patterns for managing differences in S1 & S2 types, which I'll put in a separate PR (to land after this one).
...BADGE_VARIANTS_SEMANTIC, | ||
...BADGE_VARIANTS_COLOR, | ||
] as const; | ||
export type BadgeVariant = (typeof BADGE_VARIANTS)[number]; |
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'm not sure if I need to redefine this since technically it's the same but the content of the BADGE_VARIANTS has changed so I went ahead and did that.
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.
@rubencarvalho Do you know how that works in Typescript? Would it calculate the value of BadgeVariant at the time of use based on the new definition of BADGE_VARIANTS?
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.
Yes, as far as TypeScript is concerned, the type defined in this module is completely different from the type defined in the core
module, though they share the same name, so it would in fact need to be exported here.
Again, though, I'll make a separate follow-on PR to propose some patterns for managing S1 and S2 types.
|
||
/** | ||
* @element sp-badge-base | ||
* @slot - The text label to display in the badge. |
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.
Since this doesn't have a render, should we define these only on the render layer?
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 it's better to define them here on the base class, since these slots are effectively part of the component architecture dictated by the base class (i.e., any concrete implementation building on this base class will need to include the slots), and the base class includes the mixin functionality associated with the slots.
e00d4cc
to
3924d40
Compare
second-gen/packages/core/components/progress-circle/ProgressCircle.base.ts
Outdated
Show resolved
Hide resolved
second-gen/packages/core/components/progress-circle/ProgressCircle.base.ts
Outdated
Show resolved
Hide resolved
second-gen/packages/core/components/progress-circle/ProgressCircle.base.ts
Show resolved
Hide resolved
@castastrophe The S2 addition of these are sooooo lovely!! I'd love to contribute to this!! |
3924d40
to
6bebb21
Compare
87fe0e1
to
e670fbe
Compare
import { ObserveSlotText } from '@swc/core/shared/observe-slot-text'; | ||
|
||
export const BADGE_VARIANTS = [ | ||
export const BADGE_VARIANTS_SEMANTIC = [ |
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.
@rubencarvalho Initially I started updating these assets per the S2 guidelines before I realized this is the base class being imported into S1 components as well. Would it make sense to hoist this folder to sit between the first- and second-get folders so it's clear that it's a shared resource?
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 the key here is just going to be to make it clear (via docs and other means) that the S1/S2 distinction is not the same as the 1st-gen/2nd-gen distinction.
The core
library is in 2nd-gen because it, along with 2nd-gen SWC, is going to use our 2nd-gen tooling and infrastructure, and because we have a sense that the core
layer may prove useful even after the 1st-gen to 2nd-gen transition is complete. (If it does not, we can remove it when we eventually stop supporting 1st-gen.)
As a layer of the architecture that explicitly supports both S1 and S2, I think it's actually OK if core
ends up including some type definitions that are S1- and S2-aware, allowing us to manage the differences in one place. I've done some further exploration of what this might look like that I'll put in a separate PR.
15bc02b
to
8e6f89b
Compare
8e6f89b
to
e1d5a14
Compare
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.
@castastrophe Thank you for blazing the trail here and getting the S2 Badge rendering and styling migrated!
The patterns you explored around the nuances of the factoring between the abstract base components in core
and the concrete rendering components in 1st- and 2nd-gen SWC, and for managing type differences between the S1 and S2 components, were also very informative. 🙏
As I mentioned in a few specific review comments, what we'd like to do is go ahead and merge this PR into the barebones
branch (along with your work on ProgressCircle), after which I'll make a follow-on PR proposing some general patterns for use on the remaining Barebones components.
I've gone ahead and approved this PR; no need to make any further changes on this branch as far as I'm concerned.
import { ObserveSlotText } from '@swc/core/shared/observe-slot-text'; | ||
|
||
export const BADGE_VARIANTS = [ | ||
export const BADGE_VARIANTS_SEMANTIC = [ |
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.
Yes, this seems like a good idea!
import { ObserveSlotText } from '@swc/core/shared/observe-slot-text'; | ||
|
||
export const BADGE_VARIANTS = [ | ||
export const BADGE_VARIANTS_SEMANTIC = [ |
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 the key here is just going to be to make it clear (via docs and other means) that the S1/S2 distinction is not the same as the 1st-gen/2nd-gen distinction.
The core
library is in 2nd-gen because it, along with 2nd-gen SWC, is going to use our 2nd-gen tooling and infrastructure, and because we have a sense that the core
layer may prove useful even after the 1st-gen to 2nd-gen transition is complete. (If it does not, we can remove it when we eventually stop supporting 1st-gen.)
As a layer of the architecture that explicitly supports both S1 and S2, I think it's actually OK if core
ends up including some type definitions that are S1- and S2-aware, allowing us to manage the differences in one place. I've done some further exploration of what this might look like that I'll put in a separate PR.
typeof this.fixed !== 'undefined', | ||
})} | ||
> | ||
${when( |
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.
👍 Since the 2nd-gen render()
method is conceptually free to diverge from the 1st-gen method in whatever way is useful (provided there is no impact on the component API), there's no reason not to opt for when
here.
</div> | ||
` | ||
)} | ||
<div class="spectrum-Badge-label"> |
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.
Yes, it looks like adding a rule to the component styles that sets display: block;
on the slot also works.
I think in general it would be better to avoid systematically wrapping slots for styling purposes.
|
||
/** | ||
* @element sp-badge-base | ||
* @slot - The text label to display in the badge. |
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 it's better to define them here on the base class, since these slots are effectively part of the component architecture dictated by the base class (i.e., any concrete implementation building on this base class will need to include the slots), and the base class includes the mixin functionality associated with the slots.
@property({ type: Boolean, reflect: true }) | ||
public subtle: boolean = false; | ||
|
||
public set fixed(fixed: FixedValues | undefined) { |
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.
At a glance, I think you're right—at least, I can't immediately see why this property would need a bespoke getter and setter.
That said, the aim of the Barebones milestone is to avoid any changes not strictly related to migrating these components to the new architecture, so I think the best course of action here would be to add a @todo
comment rather than making a change in this PR.
BadgeBase, | ||
} from '@swc/core/components/badge'; | ||
|
||
export const BADGE_VARIANTS_COLOR = [ |
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.
Yes, we definitely need to define a constant representing the full set of S2 colors. As I mentioned in an earlier comment, I've done some additional exploration into patterns for managing differences in S1 & S2 types, which I'll put in a separate PR (to land after this one).
...BADGE_VARIANTS_SEMANTIC, | ||
...BADGE_VARIANTS_COLOR, | ||
] as const; | ||
export type BadgeVariant = (typeof BADGE_VARIANTS)[number]; |
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.
Yes, as far as TypeScript is concerned, the type defined in this module is completely different from the type defined in the core
module, though they share the same name, so it would in fact need to be exported here.
Again, though, I'll make a separate follow-on PR to propose some patterns for managing S1 and S2 types.
* @status stable | ||
* @github https://github.com/adobe/spectrum-web-components/tree/main/... | ||
* @figma https://www.figma.com/design/... | ||
* @figma https://www.figma.com/design/Mngz9H7WZLbrCvGQf3GnsY/S2-%2F-Desktop?node-id=36806-6551 |
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, since we're not going to be releasing any S2 components for a while (even in preview form), we might as well take the conservative approach and not include any real Figma links for the time being.
e1d5a14
to
c243d3e
Compare
c243d3e
to
5b47c1c
Compare
Description
Using the approach outlined in the styling RFC; brought in the existing S2 stylings from the CSS
spectrum-two
branch and noted any questions, concerns, and API implications as comments on this PR.Focused on the
badge
component.Motivation and context
Related issue(s)
Screenshots (if appropriate)
Author's checklist
Reviewer's checklist
patch
,minor
, ormajor
features