Added a ton of documentation; made the failure message configurable.
This commit is contained in:
@ -16,20 +16,55 @@ export interface IAggregateCard {
|
|||||||
leftJustified?: boolean;
|
leftJustified?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class AggregateCard
|
||||||
|
* element ak-aggregate-card
|
||||||
|
*
|
||||||
|
* @slot - The main content of the card
|
||||||
|
*
|
||||||
|
* Card component with a specific layout for quick informational blurbs
|
||||||
|
*/
|
||||||
@customElement("ak-aggregate-card")
|
@customElement("ak-aggregate-card")
|
||||||
export class AggregateCard extends AKElement implements IAggregateCard {
|
export class AggregateCard extends AKElement implements IAggregateCard {
|
||||||
|
/**
|
||||||
|
* If this contains an `fa-` style string, the FontAwesome icon specified will be shown next to
|
||||||
|
* the header.
|
||||||
|
*
|
||||||
|
* @attr
|
||||||
|
*/
|
||||||
@property()
|
@property()
|
||||||
icon?: string;
|
icon?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The title of the card.
|
||||||
|
*
|
||||||
|
* @attr
|
||||||
|
*/
|
||||||
@property()
|
@property()
|
||||||
header?: string;
|
header?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this is non-empty, a link icon will be shown in the upper-right corner of the card.
|
||||||
|
*
|
||||||
|
* @attr
|
||||||
|
*/
|
||||||
@property()
|
@property()
|
||||||
headerLink?: string;
|
headerLink?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this is non-empty, a small-text footer will be shown at the bottom of the card
|
||||||
|
*
|
||||||
|
* @attr
|
||||||
|
*/
|
||||||
@property()
|
@property()
|
||||||
subtext?: string;
|
subtext?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this is set, the contents of the card will be left-justified; otherwise they will be
|
||||||
|
* centered by default.
|
||||||
|
*
|
||||||
|
* @attr
|
||||||
|
*/
|
||||||
@property({ type: Boolean, attribute: "left-justified" })
|
@property({ type: Boolean, attribute: "left-justified" })
|
||||||
leftJustified = false;
|
leftJustified = false;
|
||||||
|
|
||||||
|
|||||||
@ -9,13 +9,38 @@ import { until } from "lit/directives/until.js";
|
|||||||
|
|
||||||
export interface IAggregatePromiseCard extends IAggregateCard {
|
export interface IAggregatePromiseCard extends IAggregateCard {
|
||||||
promise?: Promise<Record<string, unknown>>;
|
promise?: Promise<Record<string, unknown>>;
|
||||||
|
failureMessage?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class AggregatePromiseCard
|
||||||
|
* element ak-aggregate-card-promise
|
||||||
|
*
|
||||||
|
* Card component with a specific layout for quick informational blurbs, fills in its main content
|
||||||
|
* with the results of a promise; shows a spinner when the promise has not yet resolved. Inherits
|
||||||
|
* from [AggregateCard](./AggregateCard.ts).
|
||||||
|
*/
|
||||||
|
|
||||||
@customElement("ak-aggregate-card-promise")
|
@customElement("ak-aggregate-card-promise")
|
||||||
export class AggregatePromiseCard extends AggregateCard implements IAggregatePromiseCard {
|
export class AggregatePromiseCard extends AggregateCard implements IAggregatePromiseCard {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this contains an `fa-` style string, the FontAwesome icon specified will be shown next to
|
||||||
|
* the header.
|
||||||
|
*
|
||||||
|
* @attr
|
||||||
|
*/
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
promise?: Promise<Record<string, unknown>>;
|
promise?: Promise<Record<string, unknown>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The error message if the promise is rejected or throws an exception.
|
||||||
|
*
|
||||||
|
* @attr
|
||||||
|
*/
|
||||||
|
@property()
|
||||||
|
failureMessage = msg("Operation failed to complete");
|
||||||
|
|
||||||
async promiseProxy(): Promise<TemplateResult | typeof nothing> {
|
async promiseProxy(): Promise<TemplateResult | typeof nothing> {
|
||||||
if (!this.promise) {
|
if (!this.promise) {
|
||||||
return nothing;
|
return nothing;
|
||||||
@ -25,9 +50,7 @@ export class AggregatePromiseCard extends AggregateCard implements IAggregatePro
|
|||||||
return html`<i class="fa fa-check-circle"></i> ${value.toString()}`;
|
return html`<i class="fa fa-check-circle"></i> ${value.toString()}`;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.warn(error);
|
console.warn(error);
|
||||||
return html`<i class="fa fa-exclamation-circle"></i> ${msg(
|
return html`<i class="fa fa-exclamation-circle"></i> ${this.failureMessage}`;
|
||||||
"Operation failed to complete",
|
|
||||||
)}`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@ const metadata: Meta<AggregatePromiseCard> = {
|
|||||||
headerLink: { control: "text" },
|
headerLink: { control: "text" },
|
||||||
subtext: { control: "text" },
|
subtext: { control: "text" },
|
||||||
leftJustified: { control: "boolean" },
|
leftJustified: { control: "boolean" },
|
||||||
|
failureMessage: { control: "text" },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,8 +69,9 @@ export const PromiseRejected: StoryObj = {
|
|||||||
headerLink: undefined,
|
headerLink: undefined,
|
||||||
subtext: "Demo has an eight second delay until rejection",
|
subtext: "Demo has an eight second delay until rejection",
|
||||||
leftJustified: false,
|
leftJustified: false,
|
||||||
|
failureMessage: undefined,
|
||||||
},
|
},
|
||||||
render: ({ icon, header, headerLink, subtext, leftJustified }: IAggregatePromiseCard) => {
|
render: ({ icon, header, headerLink, subtext, leftJustified, failureMessage }: IAggregatePromiseCard) => {
|
||||||
const runThis = (timeout: number, value: string) =>
|
const runThis = (timeout: number, value: string) =>
|
||||||
new Promise((_resolve, reject) => setTimeout(reject, timeout, value));
|
new Promise((_resolve, reject) => setTimeout(reject, timeout, value));
|
||||||
|
|
||||||
@ -86,6 +88,7 @@ export const PromiseRejected: StoryObj = {
|
|||||||
headerLink=${ifDefined(headerLink)}
|
headerLink=${ifDefined(headerLink)}
|
||||||
subtext=${ifDefined(subtext)}
|
subtext=${ifDefined(subtext)}
|
||||||
icon=${ifDefined(icon)}
|
icon=${ifDefined(icon)}
|
||||||
|
failureMessage=${ifDefined(failureMessage)}
|
||||||
?left-justified=${leftJustified}
|
?left-justified=${leftJustified}
|
||||||
.promise=${runThis(8000, text)}
|
.promise=${runThis(8000, text)}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user