taipy-gui.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * Copyright 2021-2024 Avaiga Private Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  5. * the License. You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  10. * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  11. * specific language governing permissions and limitations under the License.
  12. */
  13. import * as React from "react";
  14. /**
  15. * Extracts the backend name of a property.
  16. *
  17. * @param updateVars - The value held by the property *updateVars*.
  18. * @param name - The name of a bound property.
  19. * @returns The backend-generated variable name.
  20. */
  21. export declare const getUpdateVar: (updateVars: string, name: string) => string | undefined;
  22. export interface TaipyActiveProps extends TaipyDynamicProps, TaipyHoverProps {
  23. defaultActive?: boolean;
  24. active?: boolean;
  25. }
  26. export interface TaipyHoverProps {
  27. hoverText?: string;
  28. defaultHoverText?: string;
  29. }
  30. export interface TaipyDynamicProps extends TaipyBaseProps {
  31. updateVarName?: string;
  32. propagate?: boolean;
  33. updateVars?: string;
  34. }
  35. export interface TaipyBaseProps {
  36. id?: string;
  37. libClassName?: string;
  38. className?: string;
  39. dynamicClassName?: string;
  40. }
  41. export interface DialogProps extends TaipyActiveProps {
  42. title: string;
  43. onAction?: string;
  44. closeLabel?: string;
  45. labels?: string;
  46. page?: string;
  47. partial?: boolean;
  48. open?: boolean;
  49. defaultOpen?: string | boolean;
  50. children?: React.ReactNode;
  51. height?: string | number;
  52. width?: string | number;
  53. localAction?: (idx: number) => void;
  54. }
  55. export declare const Dialog: (props: DialogProps) => JSX.Element;
  56. export interface ChartProp extends TaipyActiveProps, TaipyChangeProps {
  57. title?: string;
  58. width?: string | number;
  59. height?: string | number;
  60. defaultConfig: string;
  61. config?: string;
  62. data?: Record<string, TraceValueType>;
  63. defaultLayout?: string;
  64. layout?: string;
  65. plotConfig?: string;
  66. onRangeChange?: string;
  67. testId?: string;
  68. render?: boolean;
  69. defaultRender?: boolean;
  70. template?: string;
  71. template_Dark_?: string;
  72. template_Light_?: string;
  73. }
  74. export type TraceValueType = Record<string, (string | number)[]>;
  75. export declare const Chart: (props: ChartProp) => JSX.Element;
  76. export interface TaipyMultiSelectProps {
  77. selected?: number[];
  78. }
  79. export interface TaipyChangeProps {
  80. onChange?: string;
  81. }
  82. export type TableValueType = Record<string, Record<string, any>>;
  83. export interface TaipyTableProps extends TaipyActiveProps, TaipyMultiSelectProps {
  84. data?: TableValueType;
  85. columns?: string;
  86. defaultColumns: string;
  87. height?: string;
  88. width?: string;
  89. pageSize?: number;
  90. onEdit?: string;
  91. onDelete?: string;
  92. onAdd?: string;
  93. onAction?: string;
  94. editable?: boolean;
  95. defaultEditable?: boolean;
  96. lineStyle?: string;
  97. tooltip?: string;
  98. cellTooltip?: string;
  99. nanValue?: string;
  100. filter?: boolean;
  101. size?: "small" | "medium";
  102. userData?: unknown;
  103. }
  104. export interface TaipyPaginatedTableProps extends TaipyTableProps {
  105. pageSizeOptions?: string;
  106. allowAllRows?: boolean;
  107. showAll?: boolean;
  108. }
  109. export interface TableProps extends TaipyPaginatedTableProps {
  110. autoLoading?: boolean;
  111. }
  112. export declare const Table: (props: TableProps) => JSX.Element;
  113. export interface FilterDesc {
  114. col: string;
  115. action: string;
  116. value: string | number | boolean | Date;
  117. }
  118. export interface TableFilterProps {
  119. columns: Record<string, ColumnDesc>;
  120. colsOrder?: Array<string>;
  121. onValidate: (data: Array<FilterDesc>) => void;
  122. appliedFilters?: Array<FilterDesc>;
  123. className?: string;
  124. filteredCount: number;
  125. }
  126. export declare const TableFilter: (props: TableFilterProps) => JSX.Element;
  127. export interface SortDesc {
  128. col: string;
  129. order: boolean;
  130. }
  131. export interface TableSortProps {
  132. columns: Record<string, ColumnDesc>;
  133. colsOrder?: Array<string>;
  134. onValidate: (data: Array<SortDesc>) => void;
  135. appliedSorts?: Array<SortDesc>;
  136. className?: string;
  137. }
  138. export declare const TableSort: (props: TableSortProps) => JSX.Element;
  139. export declare const Router: () => JSX.Element;
  140. /**
  141. * An Icon representation.
  142. */
  143. export interface Icon {
  144. /** The URL to the image. */
  145. path: string;
  146. /** The text. */
  147. text: string;
  148. /** light theme path */
  149. lightPath?: string;
  150. /** dark theme path */
  151. darkPath?: string;
  152. }
  153. /**
  154. * A string or an icon.
  155. */
  156. export declare type stringIcon = string | Icon;
  157. /**
  158. * An item in a List of Values (LoV).
  159. */
  160. export interface LovItem {
  161. /** The unique identifier of this item. */
  162. id: string;
  163. /** The items label (string and/or icon). */
  164. item: stringIcon;
  165. /** The array of child items. */
  166. children?: LovItem[];
  167. }
  168. /**
  169. * A LoV (list of value) element.
  170. *
  171. * Each `LoVElt` holds:
  172. *
  173. * - Its identifier as a string;
  174. * - Its label (or icon) as a `stringIcon`;
  175. * - Potential child elements as an array of `LoVElt`s.
  176. */
  177. export declare type LoVElt = [
  178. /** The identifier. */
  179. string,
  180. /** The label or icon. */
  181. stringIcon,
  182. /** The list of children. */
  183. LoVElt[]?
  184. ];
  185. /**
  186. * A series of LoV elements.
  187. */
  188. export declare type LoV = LoVElt[];
  189. /**
  190. * A React hook that returns a LoV list from the LoV default value and the LoV bound value.
  191. * @param lov - The bound lov value.
  192. * @param defaultLov - The JSON-stringified default LoV value.
  193. * @param tree - This flag indicates if the LoV list is a tree or a flat list (default is false).
  194. * @returns A list of LoV items.
  195. */
  196. export declare const useLovListMemo: (lov: LoV | undefined, defaultLov: string, tree?: boolean) => LovItem[];
  197. /**
  198. * The state of the underlying Taipy application.
  199. */
  200. export interface State {}
  201. /**
  202. * Application actions as used by the application reducer.
  203. */
  204. export interface Action {}
  205. /**
  206. * Create a *send update* `Action` that will be used to update `Context`.
  207. *
  208. * This action will update the variable *name* (if *propagate* is true) and trigger the
  209. * invocation of the `on_change` Python function on the backend.
  210. * @param name - The name of the variable holding the requested data
  211. * as received as a property.
  212. * @param value - The new value for the variable named *name*.
  213. * @param context - The execution context (property `context`).
  214. * @param onChange - The name of the `on_change` Python function to
  215. * invoke on the backend (default is "on_change").
  216. * @param propagate - A flag indicating that the variable should be
  217. * automatically updated on the backend.
  218. * @param relName - The name of the related variable (for
  219. * example the lov when a lov value is updated).
  220. * @returns The action fed to the reducer.
  221. */
  222. export declare const createSendUpdateAction: (
  223. name: string | undefined,
  224. value: unknown,
  225. context: string | undefined,
  226. onChange?: string,
  227. propagate?: boolean,
  228. relName?: string
  229. ) => Action;
  230. /**
  231. * Create an *action* `Action` that will be used to update `Context`.
  232. *
  233. * This action will trigger the invocation of the `on_action` Python function on the backend,
  234. * providing all the parameters as a payload.
  235. * @param name - The name of the action function on the backend.
  236. * @param context - The execution context (property `context`).
  237. * @param value - The value associated with the action. This can be an object or
  238. * any type of value.
  239. * @param args - Additional information associated to the action.
  240. * @returns The action fed to the reducer.
  241. */
  242. export declare const createSendActionNameAction: (
  243. name: string | undefined,
  244. context: string | undefined,
  245. value: unknown,
  246. ...args: unknown[]
  247. ) => Action;
  248. /**
  249. * Create a *request data update* `Action` that will be used to update the `Context`.
  250. *
  251. * This action will provoke the invocation of the `get_data()` method of the backend
  252. * library. That invocation generates an update of the elements holding the data named
  253. * *name* on the frontend.
  254. * @param name - The name of the variable holding the requested data as received as
  255. * a property.
  256. * @param id - The identifier of the visual element.
  257. * @param context - The execution context (property `context`).
  258. * @param columns - The list of the columns needed by the element that emitted this
  259. * action.
  260. * @param pageKey - The unique identifier of the data that will be received from
  261. * this action.
  262. * @param payload - The payload (specific to the type of component
  263. * ie table, chart...).
  264. * @param allData - The flag indicating if all the data is requested.
  265. * @param library - The name of the {@link extension} library.
  266. * @returns The action fed to the reducer.
  267. */
  268. export declare const createRequestDataUpdateAction: (
  269. name: string | undefined,
  270. id: string | undefined,
  271. context: string | undefined,
  272. columns: string[],
  273. pageKey: string,
  274. payload: Record<string, unknown>,
  275. allData?: boolean,
  276. library?: string
  277. ) => Action;
  278. /**
  279. * Create a *request update* `Action` that will be used to update the `Context`.
  280. *
  281. * This action will generate an update of the elements holding the variables named
  282. * *names* on the front-end.
  283. * @param id - The identifier of the visual element.
  284. * @param context - The execution context (property `context`).
  285. * @param names - The names of the requested variables as received in updateVarName and/or updateVars properties.
  286. * @param forceRefresh - Should Taipy re-evaluate the variables or use the current values.
  287. * @returns The action fed to the reducer.
  288. */
  289. export declare const createRequestUpdateAction: (
  290. id: string | undefined,
  291. context: string | undefined,
  292. names: string[],
  293. forceRefresh?: boolean,
  294. stateContext?: Record<string, unknown>
  295. ) => Action;
  296. /**
  297. * A column description as received by the backend.
  298. */
  299. export interface ColumnDesc {
  300. /** The unique column identifier. */
  301. dfid: string;
  302. /** The column type. */
  303. type: string;
  304. /** The value format. */
  305. format?: string;
  306. /** The column title. */
  307. title?: string;
  308. /** The order of the column. */
  309. index: number;
  310. /** The column width. */
  311. width?: number | string;
  312. /** If true, the column cannot be edited. */
  313. notEditable?: boolean;
  314. /** The name of the column that holds the CSS classname to
  315. * apply to the cells. */
  316. style?: string;
  317. /** The name of the column that holds the tooltip to
  318. * show on the cells. */
  319. tooltip?: string;
  320. /** The value that would replace a NaN value. */
  321. nanValue?: string;
  322. /** The TimeZone identifier used if the type is `date`. */
  323. tz?: string;
  324. /** The flag that allows filtering. */
  325. filter?: boolean;
  326. /** The name of the aggregation function. */
  327. apply?: string;
  328. /** The flag that allows the user to aggregate the column. */
  329. groupBy?: boolean;
  330. widthHint?: number;
  331. /** The list of values that can be used on edit. */
  332. lov?: string[];
  333. /** If true the user can enter any value besides the lov values. */
  334. freeLov?: boolean;
  335. }
  336. /**
  337. * A cell value type.
  338. */
  339. export declare type RowValue = string | number | boolean | null;
  340. /**
  341. * The definition of a table row.
  342. *
  343. * A row definition associates a name (a string) to a type (a {@link RowValue}).
  344. */
  345. export declare type RowType = Record<string, RowValue>;
  346. /**
  347. * The Taipy Store.
  348. */
  349. export interface Store {
  350. /** The State of the Taipy application. */
  351. state: State;
  352. /** The React *dispatch* function. */
  353. dispatch: React.Dispatch<Action>;
  354. }
  355. /**
  356. * The Taipy-specific React context.
  357. *
  358. * The type of this variable is `React.Context<Store>`.
  359. */
  360. export declare const Context: React.Context<Store>;
  361. /**
  362. * A React hook to manage a dynamic scalar property.
  363. *
  364. * A dynamic scalar property is defined by a default property and a bound property.
  365. * @typeParam T - The dynamic property type.
  366. * @param value - The bound value.
  367. * @param defaultValue - The default value.
  368. * @param defaultStatic - The default static value.
  369. * @returns The latest updated value.
  370. */
  371. export declare const useDynamicProperty: <T>(value: T, defaultValue: T, defaultStatic: T) => T;
  372. /**
  373. * A React hook to manage a dynamic json property.
  374. *
  375. * A dynamic scalar property is defined by a default property and a bound property.
  376. * @typeParam T - The dynamic property type.
  377. * @param value - The bound value.
  378. * @param defaultValue - The default value.
  379. * @param defaultStatic - The default static value.
  380. * @returns The latest updated value.
  381. */
  382. export const useDynamicJsonProperty: <T>(value: string | T, defaultValue: string, defaultStatic: T) => T;
  383. /**
  384. * A React hook that requests an update for every dynamic property of the element.
  385. * @param dispatch - The React dispatcher associated to `TaipyContext`.
  386. * @param id - The identifier of the element.
  387. * @param context - The execution context (property `context`).
  388. * @param updateVars - The content of the property `updateVars`.
  389. * @param varName - The default property backend provided variable (through property `updateVarName`).
  390. * @param forceRefresh - Should Taipy re-evaluate the variables or use the current values.
  391. */
  392. export declare const useDispatchRequestUpdateOnFirstRender: (
  393. dispatch: React.Dispatch<Action>,
  394. id?: string,
  395. context?: string,
  396. updateVars?: string,
  397. varName?: string,
  398. forceRefresh?: boolean
  399. ) => void;
  400. /**
  401. * A React hook that returns the *dispatch* function.
  402. *
  403. * The *dispatch* function allows to send Actions to the Store and initiate backend\
  404. * communications.
  405. * @returns The *dispatch* function.
  406. */
  407. export declare const useDispatch: () => React.Dispatch<Action>;
  408. /**
  409. * A React hook that returns the page module.
  410. *
  411. * The *module* Needs to be added to all Actions to allow for the correct execution of backend functions.
  412. * @returns The page module.
  413. */
  414. export declare const useModule: () => string | undefined;