taipy-gui.d.ts 15 KB

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