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

feat(alert): add pf-alert #2593

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Changes from 3 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
46 changes: 20 additions & 26 deletions core/pfe-core/controllers/slot-controller.ts
Original file line number Diff line number Diff line change
@@ -106,21 +106,6 @@ export class SlotController implements ReactiveController {
this.#mo.disconnect();
}

/**
* Returns a boolean statement of whether or not any of those slots exists in the light DOM.
*
* @param {String|Array} name The slot name.
* @example this.hasSlotted("header");
*/
hasSlotted(...names: string[]): boolean {
if (!names.length) {
return this.#nodes.get(SlotController.default)?.hasContent ?? false;
} else {
return names.some(x =>
this.#nodes.get(x)?.hasContent ?? false);
}
}

/**
* Given a slot name or slot names, returns elements assigned to the requested slots as an array.
* If no value is provided, it returns all children not assigned to a slot (without a slot attribute).
@@ -150,22 +135,31 @@ export class SlotController implements ReactiveController {
}

/**
* Returns a boolean statement of whether or not the requested slot is empty.
* Returns a boolean statement of whether or not any of those slots exists in the light DOM.
*
* @param {String} slotName The slot name. If no value is provided, it returns the default slot.
* @example this.isEmpty("header");
* @example this.isEmpty();
* @returns {Boolean}
* @param names The slot names to check.
* @example this.hasSlotted('header');
*/

isEmpty(slotName?: string): boolean {
if (!slotName) {
return !this.#nodes.get(SlotController.default)?.hasContent ?? true;
} else {
return !this.#nodes.get(slotName)?.hasContent ?? true;
hasSlotted(...names: (string | null | undefined)[]): boolean {
const { anonymous } = SlotController;
const slotNames = Array.from(names, x => x == null ? anonymous : x);
if (!slotNames.length) {
slotNames.push(anonymous);
}
return slotNames.some(x => this.#nodes.get(x)?.hasContent ?? false);
}

/**
* Whether or not all the requested slots are empty.
*
* @param slots The slot name. If no value is provided, it returns the default slot.
* @example this.isEmpty('header', 'footer');
* @example this.isEmpty();
* @returns {Boolean}
*/
isEmpty(...names: (string | null | undefined)[]): boolean {
return !this.hasSlotted(...names);
}

#onSlotChange = (event: Event & { target: HTMLSlotElement }) => {
const slotName = event.target.name;