Bootstrap

API config

callWidgetFactory

function

callWidgetFactory<W>(__namedParameters): AngularWidget<W>

Type Parameters

W extends Widget<object, object, object, object, object>

Parameters

__namedParameters

__namedParameters.afterInit?

__namedParameters.defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<undefined | Partial<WidgetProps<W>>>

__namedParameters.events?: Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}`>

__namedParameters.factory: WidgetFactory<W>

__namedParameters.widgetName?: null | keyof BootstrapWidgetsConfig

Returns

AngularWidget<W>


createWidgetsConfig

function

createWidgetsConfig<T>(parent$?, adaptParentConfig?): WidgetsConfigStore<T>

Creates a new widgets default configuration store, optionally inheriting from a parent store, and containing its own set of widgets configuration properties that override the same properties form the parent configuration.

Type Parameters

T

Parameters

parent$?: WidgetsConfigStore<T>

optional parent widgets default configuration store.

adaptParentConfig? = identity

optional function that receives a 2-levels copy of the widgets default configuration from parent$ (or an empty object if parent$ is not specified) and returns the widgets default configuration to be used. It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration. It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.

Returns

WidgetsConfigStore<T>

the resulting widgets default configuration store, which contains 3 additional properties that are stores: parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties). The resulting store is writable, its set function is actually the set function of the own$ store.

Remarks

The resulting store has a value computed from the parent store in two steps:

  • first step: the parent configuration is transformed by the adaptParentConfig function (if specified). If adaptParentConfig is not specified, this step is skipped.
  • second step: the configuration from step 1 is merged (2-levels deep) with the own$ store. The own$ store initially contains an empty object (i.e. no property from the parent is overridden). It can be changed by calling set on the store returned by this function.

injectWidgetConfig

function

injectWidgetConfig<N>(widgetName): ReadableSignal<undefined | Partial<WidgetsConfig[N]>>

Type Parameters

N extends keyof BootstrapWidgetsConfig

Parameters

widgetName: N

Returns

ReadableSignal<undefined | Partial<WidgetsConfig[N]>>


injectWidgetsConfig

function

injectWidgetsConfig(config?): WidgetsConfigStore<WidgetsConfig>

Parameters

config?: Partial<object>

Returns

WidgetsConfigStore<WidgetsConfig>


mergeInto

function

mergeInto<T>(destination, source, levels): T

Merges source object into destination object, up to the provided number of levels.

Type Parameters

T

Parameters

destination: T

destination object

source: undefined | T

source object

levels: number = Infinity

number of levels to merge

Returns

T

the destination object in most cases, or the source in some cases (if the source is not undefined and either levels is smaller than 1 or the source is not an object)


Partial2Levels

type alias

Partial2Levels<T>: Partial<{ [Level1 in keyof T]: Partial<T[Level1]> }>

Type Parameters

T


provideWidgetsConfig

function

provideWidgetsConfig(adaptParentConfig?): FactoryProvider

Parameters

adaptParentConfig?: AdaptParentConfig

Returns

FactoryProvider


WidgetsConfig

type alias

WidgetsConfig: object

Type declaration
accordion

accordion: AccordionProps

the accordion widget config

alert

alert: AlertProps

the alert widget config

modal

modal: ModalProps<any>

the modal widget config

pagination

pagination: PaginationProps

the pagination widget config

progressbar

progressbar: ProgressbarProps

the progressbar widget config

rating

rating: RatingProps

the rating widget config

select

select: SelectProps<any>

the select widget config

slider

slider: SliderProps

the slider widget config

toast

toast: ToastProps

the toast widget config


widgetsConfigFactory

function

widgetsConfigFactory<Config>(widgetsConfigInjectionToken): object

A factory to create the utilities to allow widgets to be context-aware.

It can be used when extending the core and creating new widgets.

Type Parameters

Config extends object = WidgetsConfig

Parameters

widgetsConfigInjectionToken: InjectionToken<WidgetsConfigStore<Config>> = ...

the widgets config injection token

Returns

object

the utilities to create / manage widgets and contexts

callWidgetFactory

callWidgetFactory: <W>(__namedParameters) => AngularWidget<W>

Type Parameters

W extends Widget<object, object, object, object, object>

Parameters

__namedParameters

__namedParameters.afterInit?

__namedParameters.defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<undefined | Partial<WidgetProps<W>>> = {}

__namedParameters.events?: Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}`>

__namedParameters.factory: WidgetFactory<W>

__namedParameters.widgetName?: null | keyof Config = null

Returns

AngularWidget<W>

injectWidgetConfig

injectWidgetConfig: <N>(widgetName) => ReadableSignal<undefined | Partial<Config[N]>>

Type Parameters

N extends string | number | symbol

Parameters

widgetName: N

Returns

ReadableSignal<undefined | Partial<Config[N]>>

injectWidgetsConfig

injectWidgetsConfig: InjectWidgetsConfig<Config>

provideWidgetsConfig

provideWidgetsConfig: (adaptParentConfig?) => FactoryProvider

Creates a provider of widgets default configuration that inherits from any widgets default configuration already defined at an upper level in the Angular dependency injection system. It contains its own set of widgets configuration properties that override the same properties form the parent configuration.

Parameters

adaptParentConfig?: AdaptParentConfig<Config>

optional function that receives a 2-levels copy of the widgets default configuration defined at an upper level in the Angular dependency injection system (or an empty object if there is none) and returns the widgets default configuration to be used. It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration. It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change. It is also called in an Angular injection context, so it can call the Angular inject function to get and use dependencies from the Angular dependency injection system.

Returns

FactoryProvider

DI provider to be included a list of providers (for example at a component level or any other level of the Angular dependency injection system)

Remarks

The configuration is computed from the parent configuration in two steps:

  • first step: the parent configuration is transformed by the adaptParentConfig function (if specified). If adaptParentConfig is not specified, this step is skipped.
  • second step: the configuration from step 1 is merged (2-levels deep) with the own$ store. The own$ store initially contains an empty object (i.e. no property from the parent is overridden). It can be changed by calling set on the store returned by injectWidgetsConfig.
Example
@Component({
  // ...
  providers: [
    provideWidgetsConfig((parentConfig) => {
      // first step configuration: transforms the parent configuration
      parentConfig.rating = parentConfig.rating ?? {};
      parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
      return parentConfig;
    })
  ]
})
class MyComponent {
  widgetsConfig = injectWidgetsConfig();
  constructor() {
    this.widgetsConfig.set({
      // second step configuration: overrides the parent configuration
      rating: {
        slotStar: MyCustomSlotStar
      }
    });
  }
  // ...
}
widgetsConfigInjectionToken

widgetsConfigInjectionToken: InjectionToken<WidgetsConfigStore<Config>>

Dependency Injection token which can be used to provide or inject the widgets default configuration store.


widgetsConfigInjectionToken

constant

widgetsConfigInjectionToken: InjectionToken<WidgetsConfigStore<WidgetsConfig>>


WidgetsConfigStore

type alias

WidgetsConfigStore<T>: WritableSignal<Partial2Levels<T>> & object

Type declaration
adaptedParent$

adaptedParent$: undefined | ReadableSignal<Partial2Levels<T>>

own$

own$: WritableSignal<Partial2Levels<T>>

parent$

parent$: undefined | WritableSignal<Partial2Levels<T>>

Type Parameters

T