-
Notifications
You must be signed in to change notification settings - Fork 250
chore(close-button): add structure for s2 migration #6355
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
Open
TarunAdobe
wants to merge
12
commits into
main
Choose a base branch
from
ttomar/migrate-close-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
76e7cab
chore(close-button): add structure for s2 migration
TarunAdobe 878aa08
chore(close-button): add Cross400 and Cross500 icons for l and xl sizes
TarunAdobe 8ffbfaf
docs(close-button): mark Phase 2 setup complete after scaffold
TarunAdobe 3749fbc
fix(close-button): give scaffold CSS dimensions so a11y tests see a v…
TarunAdobe 395a987
fix(close-button): inherit SizedMixin size reflection from ButtonBase
TarunAdobe f2bc3b8
fix(close-button): omit pending from close-button public surface
TarunAdobe f384ec0
fix(close-button): hide inherited pending API via CEM plugin and docs…
TarunAdobe bba5330
refactor(close-button): drop variant alias from 2nd-gen public API
TarunAdobe 0d16983
style(close-button): fix Prettier formatting in CloseButton.ts
TarunAdobe 155f951
refactor(button): split SharedButtonBase and PendingMixin for close-b…
TarunAdobe e26d684
fix(button): restore instanceof SharedButtonBase via single concrete …
TarunAdobe 399baad
Merge branch 'main' into ttomar/migrate-close-button
caseyisonit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
2nd-gen/packages/core/components/button/SharedButton.base.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { PropertyValues } from 'lit'; | ||
| import { property } from 'lit/decorators.js'; | ||
|
|
||
| import { SpectrumElement } from '@spectrum-web-components/core/element/index.js'; | ||
| import { | ||
| ObserveSlotPresence, | ||
| ObserveSlotText, | ||
| SizedMixin, | ||
| } from '@spectrum-web-components/core/mixins/index.js'; | ||
|
|
||
| import { BUTTON_VALID_SIZES } from './Button.types.js'; | ||
|
|
||
| /** | ||
| * Base for button-like components that share sizing, slots, disabled state, and | ||
| * accessible-name resolution without pending semantics. | ||
| * | ||
| * {@link ButtonBase} composes {@link PendingMixin} on this class. Subclasses such | ||
| * as {@link CloseButtonBase} extend it directly so `instanceof SharedButtonBase` | ||
| * works across the button family. | ||
| * | ||
| * Visual API specific to `swc-button` (`variant`, `fill-style`, `static-color`) | ||
| * is intentionally absent so that ActionButton, ClearButton, CloseButton, | ||
| * PickerButton, and InfieldButton can extend this base without inheriting | ||
| * the `swc-button` visual surface or pending behavior. | ||
| * | ||
| * @slot - Visible button label. | ||
| * @slot icon - Optional leading icon. | ||
| * | ||
| * @attribute {ElementSize} size - The size of the button. | ||
| * | ||
| * @todo We currently have 3 levels of mixins on this class, but the mixin | ||
| * composition guide recommends a maximum of 2. Explore reducing after milestone 2. | ||
| */ | ||
| export class SharedButtonBase extends SizedMixin( | ||
| ObserveSlotText(ObserveSlotPresence(SpectrumElement, '[slot="icon"]'), ''), | ||
| { validSizes: BUTTON_VALID_SIZES } | ||
| ) { | ||
| static override shadowRootOptions: ShadowRootInit = { | ||
| ...SpectrumElement.shadowRootOptions, | ||
| delegatesFocus: true, | ||
| }; | ||
|
|
||
| // ────────────────── | ||
| // SHARED API | ||
| // ────────────────── | ||
|
|
||
| /** | ||
| * Whether the button is disabled. Removes focusability and prevents | ||
| * interaction. | ||
| */ | ||
| @property({ type: Boolean, reflect: true }) | ||
| public disabled: boolean = false; | ||
|
|
||
| /** | ||
| * Accessible label forwarded to the internal `<button>` element as | ||
| * `aria-label`. Required for icon-only buttons, which have no visible text. | ||
| */ | ||
| @property({ type: String, attribute: 'accessible-label' }) | ||
| public accessibleLabel?: string; | ||
|
|
||
| // ────────────────────── | ||
| // IMPLEMENTATION | ||
| // ────────────────────── | ||
|
|
||
| protected get hasIcon(): boolean { | ||
| return this.slotContentIsPresent; | ||
| } | ||
|
|
||
| protected get hasLabel(): boolean { | ||
| return this.slotHasContent; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the accessible name for the button from `accessibleLabel` or | ||
| * visible text content. Returns `null` when no accessible name is | ||
| * determinable. | ||
| * | ||
| * @internal | ||
| */ | ||
| protected getResolvedAccessibleName(): string | null { | ||
| return this.accessibleLabel ?? (this.textContent?.trim() || null); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the set of attributes that should be forwarded to the internal | ||
| * semantic `<button>` element, if not otherwise directly managed. | ||
| * | ||
| * @internal | ||
| */ | ||
| protected getForwardedButtonAttributes(): Record< | ||
| string, | ||
| string | boolean | undefined | ||
| > { | ||
| return { | ||
| disabled: this.disabled, | ||
| }; | ||
| } | ||
|
|
||
| protected override update(changedProperties: PropertyValues): void { | ||
| super.update(changedProperties); | ||
| if (window.__swc?.DEBUG) { | ||
| if (this.hasIcon && !this.hasLabel && !this.accessibleLabel) { | ||
| window.__swc.warn( | ||
| this, | ||
| `<${this.localName}> with an icon and no label must have an "accessible-label" attribute to be accessible.`, | ||
| 'https://opensource.adobe.com/spectrum-web-components/components/button/#icon-only', | ||
| { issues: ['accessible-label'] } | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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 would like to advocate that button base be the shared button base. the pending mixin should be applied at the swc button level. if theres disagreement then i will request that shared button base (i would want to discuss the naming of this as well) should be treated like every other base class and have its own directory for discoverability. or we need to discuss architecture of these kinds of components and how we organize them, i can see this coming up with cards too.
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.
the concepts of base classes is that they store core functionality. i would almost argue that we dont need a core base class per component. i would use one button base for all buttons and then in SWC add the differing functionality that makes them unique components. i thought that was the pattern we were aiming for.