taipy-gui.d.ts 16 KB

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