Skip to content

Commit

Permalink
コードフォーマット
Browse files Browse the repository at this point in the history
  • Loading branch information
oki07 committed Nov 23, 2024
1 parent 82c835f commit 90bed05
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/dropdownAction/dropdown-action.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
background: var(--color-semantic-surface-regular-1);
border: 1px solid var(--color-semantic-border-regular);
border-radius: 5px;
box-shadow: 0px 3px 12px 0px var(--color-semantic-elevation-regular);
box-shadow: 0 3px 12px 0 var(--color-semantic-elevation-regular);
}
8 changes: 5 additions & 3 deletions src/components/dropdownAction/sp-dropdown-action-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import dropdownActionButtonStyle from "./dropdown-action-button.css?inline" asse
import "../icon/sp-icon";

const styles = new CSSStyleSheet();
styles.replaceSync(`${foundationStyle} ${buttonStyle} ${dropdownActionButtonStyle}`);
styles.replaceSync(
`${foundationStyle} ${buttonStyle} ${dropdownActionButtonStyle}`,
);

export class SpDropdownActionButton extends UbButton {
constructor() {
Expand All @@ -34,11 +36,11 @@ export class SpDropdownActionButton extends UbButton {
iconElement.size = "small";
this.buttonElement.insertBefore(iconElement, this.textElement.nextSibling);
}

setAriaHasPopup(value: string) {
this.buttonElement.setAttribute("aria-haspopup", value);
}

setAriaExpanded(value: string) {
this.buttonElement.setAttribute("aria-expanded", value);
}
Expand Down
28 changes: 18 additions & 10 deletions src/components/dropdownAction/sp-dropdown-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class SpDropdownAction extends HTMLElement {
#buttonElement = document.createElement("sp-dropdown-action-button");
#menuElement = document.createElement("div");
#menuSlotElement = document.createElement("slot");

#menuId = createMenuId();

#open: boolean = false;
Expand All @@ -42,7 +42,7 @@ export class SpDropdownAction extends HTMLElement {
}
set open(value: boolean) {
this.#open = value;

if (value) {
this.#buttonElement.setAttribute("selected", "");
} else {
Expand All @@ -60,7 +60,7 @@ export class SpDropdownAction extends HTMLElement {
this.#buttonElement.disabled = value;
this.#updateMenuDisplay();
}

get position() {
return this.#position;
}
Expand Down Expand Up @@ -92,6 +92,7 @@ export class SpDropdownAction extends HTMLElement {
}

connectedCallback() {
this.#buttonElement.setAttribute("part", "button");
this.#buttonElement.addEventListener(
"click",
this.#handleClickButton.bind(this),
Expand All @@ -103,7 +104,10 @@ export class SpDropdownAction extends HTMLElement {
this.#menuElement.role = "menu";
this.#menuElement.appendChild(this.#menuSlotElement);

this.#menuSlotElement.addEventListener("click", this.#handleClickMenu.bind(this));
this.#menuSlotElement.addEventListener(
"click",
this.#handleClickMenu.bind(this),
);
window.addEventListener("click", this.#handleClickOutside.bind(this));

this.#baseElement.appendChild(this.#menuElement);
Expand All @@ -116,7 +120,10 @@ export class SpDropdownAction extends HTMLElement {
}

disconnectedCallback() {
this.#menuSlotElement.removeEventListener("click", this.#handleClickMenu.bind(this));
this.#menuSlotElement.removeEventListener(
"click",
this.#handleClickMenu.bind(this),
);
window.removeEventListener("click", this.#handleClickOutside.bind(this));
}

Expand Down Expand Up @@ -155,7 +162,7 @@ export class SpDropdownAction extends HTMLElement {
this.open = false;
this.#updateAriaExpandedAttribute();
}

#handleClickOutside(event: MouseEvent) {
event.stopPropagation();

Expand All @@ -164,9 +171,10 @@ export class SpDropdownAction extends HTMLElement {
this.#updateAriaExpandedAttribute();
}
}

#updateMenuDisplay() {
this.#menuElement.style.display = this.open && !this.disabled ? "block" : "none";
this.#menuElement.style.display =
this.open && !this.disabled ? "block" : "none";
}

#setupAccessibilityAttributes() {
Expand All @@ -175,11 +183,11 @@ export class SpDropdownAction extends HTMLElement {
this.#menuElement.setAttribute("id", this.#menuId);
this.#updateAriaExpandedAttribute();
}

#updateAriaExpandedAttribute() {
this.#buttonElement.setAriaExpanded(this.open ? "true" : "false");
}

#syncMenuMinWidthWithButtonWidth() {
const buttonWidth = this.#buttonElement.offsetWidth;
this.#menuElement.style.minWidth = `${buttonWidth}px`;
Expand Down
16 changes: 12 additions & 4 deletions stories/dropdownAction/sp-dropdown-action.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ type Story = StoryObj;
export const Basic: Story = {
render: () => html`
<sp-dropdown-action label="ダッシュボード新規作成">
<sp-dropdown-action-item @click=${() => alert("企業を作成")}>企業を作成</sp-dropdown-action-item>
<sp-dropdown-action-item @click=${() => alert("業界を作成")}>業界を作成</sp-dropdown-action-item>
<sp-dropdown-action-item @click=${() => alert("企業を作成")}
>企業を作成</sp-dropdown-action-item
>
<sp-dropdown-action-item @click=${() => alert("業界を作成")}
>業界を作成</sp-dropdown-action-item
>
</sp-dropdown-action>
`,
};

export const LongText: Story = {
render: () => html`
<sp-dropdown-action label="ダッシュボード新規作成">
<sp-dropdown-action-item>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</sp-dropdown-action-item>
<sp-dropdown-action-item
>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</sp-dropdown-action-item
>
</sp-dropdown-action>
`,
};
Expand All @@ -33,7 +39,9 @@ export const RightPosition: Story = {
render: () => html`
<div style="display: flex; justify-content: end">
<sp-dropdown-action label="ダッシュボード新規作成" open position="right">
<sp-dropdown-action-item>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</sp-dropdown-action-item>
<sp-dropdown-action-item
>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</sp-dropdown-action-item
>
</sp-dropdown-action>
</div>
`,
Expand Down

0 comments on commit 90bed05

Please sign in to comment.