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

refactor: add useOpenClose controller #11309

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 5 additions & 8 deletions packages/calcite-components/src/components/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,21 @@ export class Alert extends LitElement implements OpenCloseComponent, LoadableCom

async load(): Promise<void> {
setUpLoadableComponent(this);
if (this.open) {
onToggleOpenCloseComponent(this);
}
}

override willUpdate(changes: PropertyValues<this>): void {
/* TODO: [MIGRATION] First time Lit calls willUpdate(), changes will include not just properties provided by the user, but also any default values your component set.
To account for this semantics change, the checks for (this.hasUpdated || value != defaultValue) was added in this method
Please refactor your code to reduce the need for this check.
Docs: https://qawebgis.esri.com/arcgis-components/?path=/docs/lumina-transition-from-stencil--docs#watching-for-property-changes */
if (changes.has("active") && (this.hasUpdated || this.active !== false)) {
this.handleActiveChange();
}

if (changes.has("open") && (this.hasUpdated || this.open !== false)) {
this.openHandler();
}

if (changes.has("active") && (this.hasUpdated || this.active !== false)) {
this.handleActiveChange();
}

if (
changes.has("autoCloseDuration") &&
(this.hasUpdated || this.autoCloseDuration !== "medium")
Expand Down Expand Up @@ -272,6 +269,7 @@ export class Alert extends LitElement implements OpenCloseComponent, LoadableCom
// #region Private Methods

private handleActiveChange(): void {
onToggleOpenCloseComponent(this);
this.clearAutoCloseTimeout();
if (this.active && this.autoClose && !this.autoCloseTimeoutId) {
this.initialOpenTime = Date.now();
Expand All @@ -283,7 +281,6 @@ export class Alert extends LitElement implements OpenCloseComponent, LoadableCom
}

private openHandler(): void {
onToggleOpenCloseComponent(this);
if (this.open) {
manager.registerElement(this.el);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,24 +421,13 @@ export class Autocomplete
connectLabel(this);
connectForm(this);
this.defaultInputValue = this.inputValue || "";

this.getAllItemsDebounced();

if (this.open) {
this.openHandler();
onToggleOpenCloseComponent(this);
}

connectFloatingUI(this);
}

async load(): Promise<void> {
setUpLoadableComponent(this);
this.getAllItemsDebounced();

if (this.open) {
onToggleOpenCloseComponent(this);
}
}

override willUpdate(changes: PropertyValues<this>): void {
Expand Down
4 changes: 0 additions & 4 deletions packages/calcite-components/src/components/block/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ export class Block
load(): void {
setUpLoadableComponent(this);

if (this.open) {
onToggleOpenCloseComponent(this);
}

if (!this.heading && !this.label) {
logger.warn(
`${this.el.tagName} is missing both heading & label. Please provide a heading or label for the component to be accessible.`,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,6 @@ export class Combobox
this.mutationObserver?.observe(this.el, { childList: true, subtree: true });

this.setFilteredPlacements();

if (this.open) {
this.openHandler();
onToggleOpenCloseComponent(this);
}

connectFloatingUI(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ export class Dropdown
override connectedCallback(): void {
this.mutationObserver?.observe(this.el, { childList: true, subtree: true });
this.setFilteredPlacements();
if (this.open) {
this.openHandler();
onToggleOpenCloseComponent(this);
}
this.updateItems();
connectFloatingUI(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,6 @@ export class InputDatePicker
useGrouping: false,
};

if (this.open) {
onToggleOpenCloseComponent(this);
}

connectFloatingUI(this);
}

Expand Down
3 changes: 0 additions & 3 deletions packages/calcite-components/src/components/notice/notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ export class Notice extends LitElement implements LoadableComponent, OpenCloseCo
async load(): Promise<void> {
setUpLoadableComponent(this);
this.requestedIcon = setRequestedIcon(KindIcons, this.icon, this.kind);
if (this.open) {
onToggleOpenCloseComponent(this);
}
}

override willUpdate(changes: PropertyValues<this>): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,6 @@ export class Popover
this.setUpReferenceElement();
}

if (this.open) {
onToggleOpenCloseComponent(this);
}
this.hasLoaded = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,6 @@ export class Tooltip extends LitElement implements FloatingUIComponent, OpenClos

override connectedCallback(): void {
this.setUpReferenceElement(true);
if (this.open) {
onToggleOpenCloseComponent(this);
}
}

load(): void {
if (this.open) {
onToggleOpenCloseComponent(this);
}
}

override willUpdate(changes: PropertyValues<this>): void {
Expand Down
14 changes: 14 additions & 0 deletions packages/calcite-components/src/controllers/useOpenClose
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { makeGenericController } from "@arcgis/components-controllers";
import { onToggleOpenCloseComponent, OpenCloseComponent } from "../utils/openCloseComponent";

export interface UseOpenClose {
afterToggle: () => void;
}

export const useOpenClose = makeGenericController<UseOpenClose, OpenCloseComponent>((component, controller) => {
return {
afterToggle: () => {
onToggleOpenCloseComponent(component);
},
};
});
4 changes: 4 additions & 0 deletions packages/calcite-components/src/demos/flow.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
text-align: right;
flex: 0 0 15%;
}

:root {
--calcite-duration-factor: 1;
}
</style>

<script src="./_assets/head.ts"></script>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading