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

docs: updated docs based on copilot recommendations #4987

Draft
wants to merge 23 commits into
base: garage-week/docsapalooza
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a9beac0
docs(accordion): added missing JS doc for properties
nikkimk Dec 5, 2024
907c717
docs(accordion): added copilot updates to JS Doc
nikkimk Dec 6, 2024
24b26db
docs(accordion): updated comments based on co-pilot recommendations
nikkimk Dec 6, 2024
10b775b
docs(action-bar): updated comments based on co-pilot recommendations
nikkimk Dec 6, 2024
6c720a8
fix(action-button): updated comments based on co-pilot recommendations
nikkimk Dec 6, 2024
5da6cec
docs(action-button): updated docs based on copilot
nikkimk Dec 9, 2024
bba2131
docs(action-menu): updated docs according to copilot recommendations
nikkimk Dec 9, 2024
36f5721
docs(action-bar): updated docs based on copilot recommendations
nikkimk Dec 9, 2024
4eeef9e
docs(alert-banner): updated based on copilot suggestions
nikkimk Dec 9, 2024
7e4e26e
docs(alert-dialog): updated based on copilot suggestions
nikkimk Dec 9, 2024
b3375e5
docs: fixes to updated docs
nikkimk Dec 9, 2024
1d834ca
Merge branch 'garage-week/docsapalooza' into nikkimk/docsapalooza
nikkimk Dec 10, 2024
1c69cb4
docs: updated with suggestions from copilot
nikkimk Dec 10, 2024
4c7c097
Merge branch 'nikkimk/docsapalooza' of github.com:adobe/spectrum-web-…
nikkimk Dec 10, 2024
f010f93
docs(button): updated based on copilot suggestions
nikkimk Dec 10, 2024
72b69b3
docs(action-group): reordered to place properties first
nikkimk Dec 10, 2024
3bfd100
docs(button): updated based on copilot suggestions
nikkimk Dec 10, 2024
5a9adfc
docs: updated absed on copilot suggestions
nikkimk Dec 10, 2024
064c44f
docs: updated according to copilot suggestions
nikkimk Dec 10, 2024
a8c3089
docs: updated based on copilot suggestions
nikkimk Dec 10, 2024
6418b8a
docs: updated based on copilot suggestions
nikkimk Dec 10, 2024
df03f72
Merge branch 'garage-week/docsapalooza' of github.com:adobe/spectrum-…
nikkimk Dec 10, 2024
45929dc
fix(button): undo copilot changes to ButtonBase's code
nikkimk Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/button-group/src/ButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ export class ButtonGroup extends SizedMixin(SpectrumElement, {
return [styles];
}

/**
* When true, the button group is displayed vertically.
*/
@property({ type: Boolean, reflect: true })
public vertical = false;

/**
* Handles the slotchange event for the button group.
* Updates the size of the assigned button elements.
*/
protected handleSlotchange({
target: slot,
}: Event & { target: HTMLSlotElement }): void {
Expand All @@ -45,6 +52,10 @@ export class ButtonGroup extends SizedMixin(SpectrumElement, {
});
}

/**
* Renders the button group.
* Includes the slot for the button elements.
*/
protected override render(): TemplateResult {
return html`
<slot @slotchange=${this.handleSlotchange}></slot>
Expand Down
69 changes: 50 additions & 19 deletions packages/button/src/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,30 @@ import { ButtonBase } from './ButtonBase.js';
import buttonStyles from './button.css.js';
import { PendingStateController } from '@spectrum-web-components/reactive-controllers/src/PendingState.js';

/**
* Type definition for deprecated button variants.
*/
export type DeprecatedButtonVariants = 'cta' | 'overBackground';

/**
* Type definition for button static colors.
*/
export type ButtonStaticColors = 'white' | 'black';

/**
* Type definition for button variants.
*/
export type ButtonVariants =
| 'accent'
| 'primary'
| 'secondary'
| 'negative'
| ButtonStaticColors
| DeprecatedButtonVariants;

/**
* List of valid button variants.
*/
export const VALID_VARIANTS = [
'accent',
'primary',
Expand All @@ -38,8 +53,15 @@ export const VALID_VARIANTS = [
'white',
'black',
];

/**
* List of valid static colors for buttons.
*/
export const VALID_STATIC_COLORS = ['white', 'black'];

/**
* Type definition for button treatments.
*/
export type ButtonTreatments = 'fill' | 'outline';

/**
Expand All @@ -53,30 +75,17 @@ export class Button extends SizedMixin(ButtonBase, { noDefaultSize: true }) {
return [...super.styles, buttonStyles];
}

/**
* The label to display when the button is in a pending state.
*/
@property({ type: String, attribute: 'pending-label' })
public pendingLabel = 'Pending';

// Use this property to set the button into a pending state
@property({ type: Boolean, reflect: true, attribute: true })
public pending = false;

public pendingStateController: PendingStateController<this>;

/**
* Initializes the `PendingStateController` for the Button component.
* The `PendingStateController` manages the pending state of the Button.
* Use this property to set the button into a pending state.
*/
constructor() {
super();
this.pendingStateController = new PendingStateController(this);
}

public override click(): void {
if (this.pending) {
return;
}
super.click();
}
@property({ type: Boolean, reflect: true, attribute: true })
public pending = false;

/**
* The visual variant to apply to this button.
Expand Down Expand Up @@ -185,6 +194,24 @@ export class Button extends SizedMixin(ButtonBase, { noDefaultSize: true }) {
return this.treatment === 'outline';
}

public pendingStateController: PendingStateController<this>;

/**
* Initializes the `PendingStateController` for the Button component.
* The `PendingStateController` manages the pending state of the Button.
*/
constructor() {
super();
this.pendingStateController = new PendingStateController(this);
}

public override click(): void {
if (this.pending) {
return;
}
super.click();
}

protected override firstUpdated(changes: PropertyValues<this>): void {
super.firstUpdated(changes);
// There is no Spectrum design context for an `<sp-button>` without a variant
Expand All @@ -198,6 +225,10 @@ export class Button extends SizedMixin(ButtonBase, { noDefaultSize: true }) {
}
}

/**
* Renders the button content.
* Includes the button content and the pending state.
*/
protected override renderButton(): TemplateResult {
return html`
${this.buttonContent}
Expand Down
53 changes: 51 additions & 2 deletions packages/button/src/ButtonBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
return [buttonStyles];
}

// TODO we need to document this property for consumers,
// as it's not a 1:1 equivalent to active
/**
* Indicates whether the button is active.
* This is not a 1:1 equivalent to the active state.
*/
@property({ type: Boolean, reflect: true })
public active = false;

Expand All @@ -58,10 +60,17 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
return this;
}

/**
* Checks if the button has a label.
*/
protected get hasLabel(): boolean {
return this.slotHasContent;
}

/**
* Retrieves the content to be rendered inside the button.
* Includes the icon slot and the label slot.
*/
protected get buttonContent(): TemplateResult[] {
const content = [
html`
Expand All @@ -85,6 +94,11 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
});
}

/**
* Handles the click event capture phase.
* Prevents the default action and stops propagation if the button is disabled.
* Proxies the click event if necessary.
*/
private handleClickCapture(event: Event): void | boolean {
if (this.disabled) {
event.preventDefault();
Expand All @@ -98,10 +112,17 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
}
}

/**
* Proxies the focus event to the button element.
*/
private proxyFocus(): void {
this.focus();
}

/**
* Determines if the click event should be proxied.
* Proxies the click event to the anchor element or creates a proxy button element if necessary.
*/
private shouldProxyClick(): boolean {
let handled = false;
if (this.anchorElement) {
Expand All @@ -121,6 +142,10 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
return handled;
}

/**
* Renders the anchor element for the button.
* Includes the button content and the anchor element.
*/
public override renderAnchor(): TemplateResult {
return html`
${this.buttonContent}
Expand All @@ -132,18 +157,29 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
`;
}

/**
* Renders the button content.
* Includes the button content.
*/
protected renderButton(): TemplateResult {
return html`
${this.buttonContent}
`;
}

/**
* Renders the button or anchor element based on the href property.
*/
protected override render(): TemplateResult {
return this.href && this.href.length > 0
? this.renderAnchor()
: this.renderButton();
}

/**
* Handles the keydown event for the button.
* Activates the button when the Space key is pressed.
*/
protected handleKeydown(event: KeyboardEvent): void {
const { code } = event;
switch (code) {
Expand All @@ -160,6 +196,10 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
}
}

/**
* Handles the keypress event for the button.
* Activates the button or link when the Enter or NumpadEnter key is pressed.
*/
private handleKeypress(event: KeyboardEvent): void {
const { code } = event;
switch (code) {
Expand All @@ -173,6 +213,10 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
}
}

/**
* Handles the keyup event for the button.
* Deactivates the button when the Space key is released.
*/
protected handleKeyup(event: KeyboardEvent): void {
const { code } = event;
switch (code) {
Expand All @@ -186,6 +230,10 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
}
}

/**
* Manages the role attribute for the anchor element.
* Sets the role to 'link' if the href property is set, otherwise sets it to 'button'.
*/
private manageAnchor(): void {
// for a link
if (this.href && this.href.length > 0) {
Expand Down Expand Up @@ -238,6 +286,7 @@ export class ButtonBase extends ObserveSlotText(LikeAnchor(Focusable), '', [
this.anchorElement.tabIndex = -1;
}
}

protected override update(changes: PropertyValues): void {
super.update(changes);
if (changes.has('label')) {
Expand Down
11 changes: 11 additions & 0 deletions packages/button/src/ClearButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import '@spectrum-web-components/icons-ui/icons/sp-icon-cross300.js';
import crossMediumStyles from '@spectrum-web-components/icon/src/spectrum-icon-cross.css.js';
import crossMediumOverrides from '@spectrum-web-components/icon/src/icon-cross-overrides.css.js';

/**
* A record of cross icon templates for different sizes.
*/
const crossIcon: Record<string, () => TemplateResult> = {
s: () => html`
<sp-icon-cross75
Expand Down Expand Up @@ -77,10 +80,18 @@ export class ClearButton extends SizedMixin(StyledButton, {
@property({ reflect: true })
public variant: 'overBackground' | '' = '';

/**
* Retrieves the content to be rendered inside the button.
* Includes the cross icon based on the button size.
*/
protected override get buttonContent(): TemplateResult[] {
return [crossIcon[this.size]()];
}

/**
* Renders the clear button.
* Wraps the button content in a div with class "fill".
*/
protected override render(): TemplateResult {
return html`
<div class="fill">${super.render()}</div>
Expand Down
10 changes: 10 additions & 0 deletions packages/button/src/CloseButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import crossMediumStyles from '@spectrum-web-components/icon/src/spectrum-icon-c
import crossMediumOverrides from '@spectrum-web-components/icon/src/icon-cross-overrides.css.js';
import type { ButtonStaticColors } from './Button.js';

/**
* A record of cross icon templates for different sizes.
*/
const crossIcon: Record<string, () => TemplateResult> = {
s: () => html`
<sp-icon-cross200
Expand Down Expand Up @@ -78,9 +81,16 @@ export class CloseButton extends SizedMixin(StyledButton, {
@property({ reflect: true })
public variant: ButtonStaticColors | '' = '';

/**
* The static color variant to use for this button.
*/
@property({ reflect: true, attribute: 'static-color' })
public staticColor?: 'black' | 'white';

/**
* Retrieves the content to be rendered inside the button.
* Includes the cross icon based on the button size.
*/
protected override get buttonContent(): TemplateResult[] {
return [crossIcon[this.size]()];
}
Expand Down
Loading
Loading