taipy-gui.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. type: string;
  118. }
  119. export interface TableFilterProps {
  120. fieldHeader?: string;
  121. fieldHeaderTooltip?: string;
  122. columns: Record<string, ColumnDesc>;
  123. colsOrder?: Array<string>;
  124. onValidate: (data: Array<FilterDesc>) => void;
  125. appliedFilters?: Array<FilterDesc>;
  126. className?: string;
  127. filteredCount: number;
  128. }
  129. export declare const TableFilter: (props: TableFilterProps) => JSX.Element;
  130. export interface SortDesc {
  131. col: string;
  132. order: boolean;
  133. }
  134. export interface TableSortProps {
  135. fieldHeader?: string;
  136. fieldHeaderTooltip?: string;
  137. columns: Record<string, ColumnDesc>;
  138. colsOrder?: Array<string>;
  139. onValidate: (data: Array<SortDesc>) => void;
  140. appliedSorts?: Array<SortDesc>;
  141. className?: string;
  142. }
  143. export declare const TableSort: (props: TableSortProps) => JSX.Element;
  144. export interface FileSelectorProps extends TaipyActiveProps {
  145. onAction?: string;
  146. defaultLabel?: string;
  147. label?: string;
  148. multiple?: boolean;
  149. extensions?: string;
  150. dropMessage?: string;
  151. notify?: boolean;
  152. width?: string | number;
  153. icon?: React.ReactNode;
  154. withBorder?: boolean;
  155. onUploadAction?: string;
  156. uploadData?: string;
  157. }
  158. export declare const FileSelector: (props: FileSelectorProps) => JSX.Element;
  159. export declare const Router: () => JSX.Element;
  160. /**
  161. * An Icon representation.
  162. */
  163. export interface Icon {
  164. /** The URL to the image. */
  165. path: string;
  166. /** The text. */
  167. text: string;
  168. /** light theme path */
  169. lightPath?: string;
  170. /** dark theme path */
  171. darkPath?: string;
  172. }
  173. /**
  174. * A string or an icon.
  175. */
  176. export declare type stringIcon = string | Icon;
  177. /**
  178. * An item in a List of Values (LoV).
  179. */
  180. export interface LovItem {
  181. /** The unique identifier of this item. */
  182. id: string;
  183. /** The items label (string and/or icon). */
  184. item: stringIcon;
  185. /** The array of child items. */
  186. children?: LovItem[];
  187. }
  188. /**
  189. * A LoV (list of value) element.
  190. *
  191. * Each `LoVElt` holds:
  192. *
  193. * - Its identifier as a string;
  194. * - Its label (or icon) as a `stringIcon`;
  195. * - Potential child elements as an array of `LoVElt`s.
  196. */
  197. export declare type LoVElt = [
  198. /** The identifier. */
  199. string,
  200. /** The label or icon. */
  201. stringIcon,
  202. /** The list of children. */
  203. LoVElt[]?
  204. ];
  205. /**
  206. * A series of LoV elements.
  207. */
  208. export declare type LoV = LoVElt[];
  209. /**
  210. * A React hook that returns a LoV list from the LoV default value and the LoV bound value.
  211. * @param lov - The bound lov value.
  212. * @param defaultLov - The JSON-stringified default LoV value.
  213. * @param tree - This flag indicates if the LoV list is a tree or a flat list (default is false).
  214. * @returns A list of LoV items.
  215. */
  216. export declare const useLovListMemo: (lov: LoV | undefined, defaultLov: string, tree?: boolean) => LovItem[];
  217. /**
  218. * The state of the underlying Taipy application.
  219. */
  220. export interface State {}
  221. /**
  222. * Application actions as used by the application reducer.
  223. */
  224. export interface Action {}
  225. /**
  226. * Create a *send update* `Action` that will be used to update `Context`.
  227. *
  228. * This action will update the variable *name* (if *propagate* is true) and trigger the
  229. * invocation of the `on_change` Python function on the backend.
  230. * @param name - The name of the variable holding the requested data
  231. * as received as a property.
  232. * @param value - The new value for the variable named *name*.
  233. * @param context - The execution context (property `context`).
  234. * @param onChange - The name of the `on_change` Python function to
  235. * invoke on the backend (default is "on_change").
  236. * @param propagate - A flag indicating that the variable should be
  237. * automatically updated on the backend.
  238. * @param relName - The name of the related variable (for
  239. * example the lov when a lov value is updated).
  240. * @returns The action fed to the reducer.
  241. */
  242. export declare const createSendUpdateAction: (
  243. name: string | undefined,
  244. value: unknown,
  245. context: string | undefined,
  246. onChange?: string,
  247. propagate?: boolean,
  248. relName?: string
  249. ) => Action;
  250. /**
  251. * Create an *action* `Action` that will be used to update `Context`.
  252. *
  253. * This action will trigger the invocation of the `on_action` Python function on the backend,
  254. * providing all the parameters as a payload.
  255. * @param name - The name of the action function on the backend.
  256. * @param context - The execution context (property `context`).
  257. * @param value - The value associated with the action. This can be an object or
  258. * any type of value.
  259. * @param args - Additional information associated to the action.
  260. * @returns The action fed to the reducer.
  261. */
  262. export declare const createSendActionNameAction: (
  263. name: string | undefined,
  264. context: string | undefined,
  265. value: unknown,
  266. ...args: unknown[]
  267. ) => Action;
  268. /**
  269. * Create a *request data update* `Action` that will be used to update the `Context`.
  270. *
  271. * This action will provoke the invocation of the `get_data()` method of the backend
  272. * library. That invocation generates an update of the elements holding the data named
  273. * *name* on the frontend.
  274. * @param name - The name of the variable holding the requested data as received as
  275. * a property.
  276. * @param id - The identifier of the visual element.
  277. * @param context - The execution context (property `context`).
  278. * @param columns - The list of the columns needed by the element that emitted this
  279. * action.
  280. * @param pageKey - The unique identifier of the data that will be received from
  281. * this action.
  282. * @param payload - The payload (specific to the type of component
  283. * ie table, chart...).
  284. * @param allData - The flag indicating if all the data is requested.
  285. * @param library - The name of the {@link extension} library.
  286. * @returns The action fed to the reducer.
  287. */
  288. export declare const createRequestDataUpdateAction: (
  289. name: string | undefined,
  290. id: string | undefined,
  291. context: string | undefined,
  292. columns: string[],
  293. pageKey: string,
  294. payload: Record<string, unknown>,
  295. allData?: boolean,
  296. library?: string
  297. ) => Action;
  298. /**
  299. * Create a *request update* `Action` that will be used to update the `Context`.
  300. *
  301. * This action will generate an update of the elements holding the variables named
  302. * *names* on the front-end.
  303. * @param id - The identifier of the visual element.
  304. * @param context - The execution context (property `context`).
  305. * @param names - The names of the requested variables as received in updateVarName and/or updateVars properties.
  306. * @param forceRefresh - Should Taipy re-evaluate the variables or use the current values.
  307. * @returns The action fed to the reducer.
  308. */
  309. export declare const createRequestUpdateAction: (
  310. id: string | undefined,
  311. context: string | undefined,
  312. names: string[],
  313. forceRefresh?: boolean,
  314. stateContext?: Record<string, unknown>
  315. ) => Action;
  316. /**
  317. * A column description as received by the backend.
  318. */
  319. export interface ColumnDesc {
  320. /** The unique column identifier. */
  321. dfid: string;
  322. /** The column type. */
  323. type: string;
  324. /** The value format. */
  325. format?: string;
  326. /** The column title. */
  327. title?: string;
  328. /** The order of the column. */
  329. index: number;
  330. /** The column width. */
  331. width?: number | string;
  332. /** If true, the column cannot be edited. */
  333. notEditable?: boolean;
  334. /** The name of the column that holds the CSS className to
  335. * apply to the cells. */
  336. className?: string;
  337. /** The name of the column that holds the tooltip to
  338. * show on the cells. */
  339. tooltip?: string;
  340. /** The name of the column that holds the formatted value to
  341. * show on the cells. */
  342. formatFn?: string;
  343. /** The value that would replace a NaN value. */
  344. nanValue?: string;
  345. /** The TimeZone identifier used if the type is `date`. */
  346. tz?: string;
  347. /** The flag that allows filtering. */
  348. filter?: boolean;
  349. /** The name of the aggregation function. */
  350. apply?: string;
  351. /** The flag that allows the user to aggregate the column. */
  352. groupBy?: boolean;
  353. /** The list of values that can be used on edit. */
  354. lov?: string[];
  355. /** If true the user can enter any value besides the lov values. */
  356. freeLov?: boolean;
  357. /** If false, the column cannot be sorted */
  358. sortable?: boolean;
  359. /** If true or not set, line breaks are transformed into <BR>. */
  360. lineBreak?: boolean;
  361. }
  362. /**
  363. * A cell value type.
  364. */
  365. export declare type RowValue = string | number | boolean | null;
  366. /**
  367. * The definition of a table row.
  368. *
  369. * A row definition associates a name (a string) to a type (a {@link RowValue}).
  370. */
  371. export declare type RowType = Record<string, RowValue>;
  372. /**
  373. * The Taipy Store.
  374. */
  375. export interface Store {
  376. /** The State of the Taipy application. */
  377. state: State;
  378. /** The React *dispatch* function. */
  379. dispatch: React.Dispatch<Action>;
  380. }
  381. /**
  382. * The Taipy-specific React context.
  383. *
  384. * The type of this variable is `React.Context<Store>`.
  385. */
  386. export declare const Context: React.Context<Store>;
  387. /**
  388. * A React hook to manage a dynamic scalar property.
  389. *
  390. * A dynamic scalar property is defined by a default property and a bound property.
  391. * @typeParam T - The dynamic property type.
  392. * @param value - The bound value.
  393. * @param defaultValue - The default value.
  394. * @param defaultStatic - The default static value.
  395. * @returns The latest updated value.
  396. */
  397. export declare const useDynamicProperty: <T>(value: T, defaultValue: T, defaultStatic: T) => T;
  398. /**
  399. * A React hook to manage a dynamic json property.
  400. *
  401. * A dynamic scalar property is defined by a default property and a bound property.
  402. * @typeParam T - The dynamic property type.
  403. * @param value - The bound value.
  404. * @param defaultValue - The default value.
  405. * @param defaultStatic - The default static value.
  406. * @returns The latest updated value.
  407. */
  408. export const useDynamicJsonProperty: <T>(value: string | T, defaultValue: string, defaultStatic: T) => T;
  409. /**
  410. * A React hook that requests an update for every dynamic property of the element.
  411. * @param dispatch - The React dispatcher associated to `TaipyContext`.
  412. * @param id - The identifier of the element.
  413. * @param context - The execution context (property `context`).
  414. * @param updateVars - The content of the property `updateVars`.
  415. * @param varName - The default property backend provided variable (through property `updateVarName`).
  416. * @param forceRefresh - Should Taipy re-evaluate the variables or use the current values.
  417. */
  418. export declare const useDispatchRequestUpdateOnFirstRender: (
  419. dispatch: React.Dispatch<Action>,
  420. id?: string,
  421. context?: string,
  422. updateVars?: string,
  423. varName?: string,
  424. forceRefresh?: boolean
  425. ) => void;
  426. /**
  427. * A React hook that returns the *dispatch* function.
  428. *
  429. * The *dispatch* function allows to send Actions to the Store and initiate backend\
  430. * communications.
  431. * @returns The *dispatch* function.
  432. */
  433. export declare const useDispatch: () => React.Dispatch<Action>;
  434. /**
  435. * A React hook that returns the page module.
  436. *
  437. * The *module* Needs to be added to all Actions to allow for the correct execution of backend functions.
  438. * @returns The page module.
  439. */
  440. export declare const useModule: () => string | undefined;