Skip to content

Commit

Permalink
docs(core): add jsdoc to exports in core package
Browse files Browse the repository at this point in the history
  • Loading branch information
andreascorti committed Oct 10, 2024
1 parent cad0845 commit c7c6ebf
Show file tree
Hide file tree
Showing 28 changed files with 576 additions and 4 deletions.
21 changes: 21 additions & 0 deletions core-bootstrap/src/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import type {TransitionFn} from '@agnos-ui/core/services/transitions/baseTransit

export * from '@agnos-ui/core/components/accordion';

/**
* Represents the context for an accordion item within the accordion component.
*/
export type AccordionItemContext = WidgetSlotContext<AccordionItemWidget>;

interface AccordionExtraProps {
Expand Down Expand Up @@ -58,7 +61,13 @@ interface AccordionItemExtraProps {
header: SlotContent<AccordionItemContext>;
}

/**
* Represents the state of an Accordion component.
*/
export interface AccordionState extends CoreState, AccordionExtraProps {}
/**
* Represents the state of an AccordionItem component.
*/
export interface AccordionProps extends CoreProps, AccordionExtraProps {
/**
* The transition to use for the accordion-item body-container when the accordion-item is toggled.
Expand All @@ -71,11 +80,23 @@ export interface AccordionProps extends CoreProps, AccordionExtraProps {
itemTransition: TransitionFn;
}

/**
* Represents an Accordion widget type.
*/
export type AccordionWidget = Widget<AccordionProps, AccordionState, AccordionApi, object, AccordionDirectives>;

/**
* Represents the state of an accordion item, extending the core item state and additional properties specific to the accordion item.
*/
export interface AccordionItemState extends CoreItemState, AccordionItemExtraProps {}
/**
* Represents the properties for an Accordion item component.
*/
export interface AccordionItemProps extends CoreItemProps, AccordionItemExtraProps {}

/**
* Represents a widget for an accordion item.
*/
export type AccordionItemWidget = Widget<AccordionItemProps, AccordionItemState, AccordionItemApi, AccordionItemActions, AccordionItemDirectives>;

const defaultConfigExtraProps: AccordionExtraProps = {
Expand Down
12 changes: 12 additions & 0 deletions core-bootstrap/src/components/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import type {TransitionFn} from '@agnos-ui/core/services/transitions/baseTransit

export * from '@agnos-ui/core/components/alert';

/**
* Represents the context for an Alert component.
*/
export type AlertContext = WidgetSlotContext<AlertWidget>;

interface AlertExtraProps {
Expand All @@ -28,7 +31,13 @@ interface AlertExtraProps {
type: BSContextualClass;
}

/**
* Represents the state of an alert component.
*/
export interface AlertState extends CoreState, AlertExtraProps {}
/**
* Represents the properties for the Alert component.
*/
export interface AlertProps extends CoreProps, AlertExtraProps {
/**
* The transition function will be executed when the alert is displayed or hidden.
Expand All @@ -40,6 +49,9 @@ export interface AlertProps extends CoreProps, AlertExtraProps {
transition: TransitionFn;
}

/**
* Represents an alert widget component.
*/
export type AlertWidget = Widget<AlertProps, AlertState, AlertApi, object, AlertDirectives>;

const defaultConfigExtraProps: AlertExtraProps = {
Expand Down
5 changes: 5 additions & 0 deletions core-bootstrap/src/components/modal/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import type {TransitionFn} from '@agnos-ui/core/services/transitions/baseTransit

export * from '@agnos-ui/core/components/modal';

/**
* Represents the context for a modal component.
*
* @template Data - The type of data associated with the modal.
*/
export type ModalContext<Data> = WidgetSlotContext<ModalWidget<Data>>;

interface ModalExtraProps<Data> {
Expand Down
54 changes: 54 additions & 0 deletions core/src/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ import {typeBoolean, typeFunction, typeString} from '../../utils/writables';
import {bindDirectiveNoArg, createAttributesDirective, directiveSubscribe, mergeDirectives, registrationArray} from '../../utils/directive';
import {generateId} from '../../utils/internal/dom';

/**
* Adjusts the visibility of accordion items based on the provided open items.
* If there are exactly two open items, it keeps the one that is not the old open item visible.
* If there are more than two open items, it keeps the first one visible.
* All other items are set to not visible.
*
* @param items - The array of AccordionItemWidget objects to adjust.
* @param openItems - An array of strings representing the IDs of the open items.
* @param oldOpen - (Optional) The ID of the previously open item.
* @returns The adjusted array of AccordionItemWidget objects.
*/
function adjustItemsCloseOthers(items: AccordionItemWidget[], openItems: string[], oldOpen?: string): AccordionItemWidget[] {
let keepOpen: undefined | string;
if (openItems.length == 2) {
Expand All @@ -28,10 +39,20 @@ function adjustItemsCloseOthers(items: AccordionItemWidget[], openItems: string[
return items;
}

/**
* Retrieves an accordion item by its ID.
*
* @param items - An array of `AccordionItemWidget` objects.
* @param id - The ID of the accordion item to retrieve.
* @returns The `AccordionItemWidget` with the matching ID, or `undefined` if no match is found.
*/
function getItem(items: AccordionItemWidget[], id: string): AccordionItemWidget | undefined {
return items.find((item) => item.stores.id$() === id);
}

/**
* Properties for the Accordion component.
*/
export interface AccordionProps extends WidgetsCommonPropsAndState {
/**
* If `true`, only one accordion-item at the time can stay open.
Expand Down Expand Up @@ -121,13 +142,19 @@ export interface AccordionProps extends WidgetsCommonPropsAndState {
itemHeadingTag: string;
}

/**
* Represents the state of an Accordion component.
*/
export interface AccordionState extends WidgetsCommonPropsAndState {
/**
* Array containing all the accordion-items contained in the accordion.
*/
itemWidgets: AccordionItemWidget[];
}

/**
* Interface representing the API for an accordion component.
*/
export interface AccordionApi {
/**
* Given the itemId, will expand the corresponding accordion-item.
Expand Down Expand Up @@ -163,22 +190,34 @@ export interface AccordionApi {
registerItem(itemConfig?: PropsConfig<AccordionItemProps>): AccordionItemWidget;
}

/**
* Interface representing the directives used in the Accordion component.
*/
export interface AccordionDirectives {
/**
* Directive to put on the accordion DOM element
*/
accordionDirective: Directive;
}

/**
* Represents an Accordion widget with specific properties, state, API, and directives.
*/
export type AccordionWidget = Widget<AccordionProps, AccordionState, AccordionApi, object, AccordionDirectives>;

/**
* Interface representing the actions that can be performed on an accordion item.
*/
export interface AccordionItemActions {
/**
* Action to be called when the user clicks on the accordion-item button. If the accordion-item is disabled nothing will happen.
*/
click(): void;
}

/**
* Interface representing the API for an accordion item.
*/
export interface AccordionItemApi {
/**
* It will collapse the accordion-item.
Expand All @@ -199,6 +238,9 @@ export interface AccordionItemApi {
initDone(): void;
}

/**
* Interface representing the directives used in an accordion item.
*/
export interface AccordionItemDirectives {
/**
* Directive to use in special cases, if the accordion header does not use a button element to control the collapsing.
Expand Down Expand Up @@ -237,6 +279,9 @@ export interface AccordionItemDirectives {
itemDirective: Directive;
}

/**
* Interface representing the common properties and state for an accordion item.
*/
interface AccordionItemCommonPropsAndState extends WidgetsCommonPropsAndState {
/**
* If `true`, the accordion-item will be visible (expanded). Otherwise, it will be hidden (collapsed).
Expand Down Expand Up @@ -274,6 +319,9 @@ interface AccordionItemCommonPropsAndState extends WidgetsCommonPropsAndState {
headingTag: string;
}

/**
* Properties for an AccordionItem component.
*/
export interface AccordionItemProps extends AccordionItemCommonPropsAndState {
/**
* If `true`, accordion-item will be animated.
Expand Down Expand Up @@ -303,6 +351,9 @@ export interface AccordionItemProps extends AccordionItemCommonPropsAndState {
onVisibleChange: (visible: boolean) => void;
}

/**
* Represents the state of an accordion item.
*/
export interface AccordionItemState extends AccordionItemCommonPropsAndState {
/**
* If `true` the content of the accordion-item collapse should be in DOM. Its value depends on the
Expand All @@ -311,6 +362,9 @@ export interface AccordionItemState extends AccordionItemCommonPropsAndState {
shouldBeInDOM: boolean;
}

/**
* Represents a widget for an accordion item.
*/
export type AccordionItemWidget = Widget<AccordionItemProps, AccordionItemState, AccordionItemApi, AccordionItemActions, AccordionItemDirectives>;

const defaultAccordionConfig: AccordionProps = {
Expand Down
21 changes: 21 additions & 0 deletions core/src/components/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,31 @@ import type {CommonAlertApi, CommonAlertDirectives, CommonAlertProps, CommonAler
import {createCommonAlert, getCommonAlertDefaultConfig} from './common';
import type {Widget, WidgetFactory} from '../../types';

/**
* Represents the state of an alert component.
* This interface extends the `CommonAlertState` interface, inheriting its properties.
*/
export interface AlertState extends CommonAlertState {}

/**
* Represents the properties for the Alert component.
*/
export interface AlertProps extends CommonAlertProps {}
/**
* Represents the API for an alert component.
*
* This interface extends the `CommonAlertApi` interface, inheriting its properties and methods.
* It is used to define the structure and behavior of alert components within the application.
*/
export interface AlertApi extends CommonAlertApi {}
/**
* This interface extends the `CommonAlertDirectives` and is used to define
* the directives specific to the Alert component in the application.
*/
export interface AlertDirectives extends CommonAlertDirectives {}
/**
* Represents an alert widget with specific properties, state, API, and directives.
*/
export type AlertWidget = Widget<AlertProps, AlertState, AlertApi, object, AlertDirectives>;

/**
Expand Down
18 changes: 18 additions & 0 deletions core/src/components/alert/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {stateStores, writablesForProps} from '../../utils/stores';
import {bindDirectiveNoArg} from '../../utils/directive';
import {typeBoolean} from '../../utils/writables';

/**
* Interface representing the common properties and state for an alert component.
*/
export interface CommonAlertCommonPropsAndState extends WidgetsCommonPropsAndState {
/**
* If `true`, alert can be dismissed by the user.
Expand All @@ -30,13 +33,19 @@ export interface CommonAlertCommonPropsAndState extends WidgetsCommonPropsAndSta
ariaCloseButtonLabel: string;
}

/**
* Represents the state of a common alert component.
*/
export interface CommonAlertState extends CommonAlertCommonPropsAndState {
/**
* Is `true` when the alert is hidden. Compared to `visible`, this is updated after the transition is executed.
*/
hidden: boolean;
}

/**
* Interface representing the common properties for an alert component.
*/
export interface CommonAlertProps extends CommonAlertCommonPropsAndState {
/**
* Callback called when the alert visibility changed.
Expand Down Expand Up @@ -100,6 +109,9 @@ export interface CommonAlertProps extends CommonAlertCommonPropsAndState {
animated: boolean;
}

/**
* Interface representing the common API for alert components.
*/
export interface CommonAlertApi {
/**
* Triggers alert closing programmatically (same as clicking on the close button (×)).
Expand All @@ -112,13 +124,19 @@ export interface CommonAlertApi {
open(): void;
}

/**
* Interface representing common alert directives.
*/
export interface CommonAlertDirectives {
/**
* the transition directive, piloting what is the visual effect of going from hidden to visible
*/
transitionDirective: Directive;
}

/**
* Represents a common alert widget with specified properties, state, API, and directives.
*/
export type CommonAlertWidget = Widget<CommonAlertProps, CommonAlertState, CommonAlertApi, object, CommonAlertDirectives>;

const defaultCommonAlertConfig: CommonAlertProps = {
Expand Down
3 changes: 3 additions & 0 deletions core/src/components/commonProps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Interface representing the common properties and state for widgets.
*/
export interface WidgetsCommonPropsAndState {
/**
* CSS classes to be applied on the widget main container
Expand Down
Loading

0 comments on commit c7c6ebf

Please sign in to comment.