@hbdlzy/ui-core 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,174 @@
1
+ export type BaseTableCssValue = string | number
2
+ export type BaseTableAlign = 'left' | 'center' | 'right'
3
+ export type BaseTableColumnKind = 'text' | 'link' | 'actions' | 'image' | 'tag' | 'html' | 'input'
4
+ export type BaseTableSortOrder = 'ascending' | 'descending' | null
5
+ export type BaseTableSortDirection = string | null
6
+
7
+ export interface BaseTableOption {
8
+ label: string
9
+ value: string | number | boolean
10
+ tagType?: '' | 'success' | 'warning' | 'info' | 'danger' | 'primary'
11
+ color?: string
12
+ }
13
+
14
+ export interface BaseTableAction<Row = Record<string, any>> {
15
+ label: string
16
+ type: string
17
+ buttonType?: '' | 'primary' | 'success' | 'warning' | 'info' | 'danger'
18
+ disabled?: boolean | ((row: Row) => boolean)
19
+ visible?: boolean | ((row: Row) => boolean)
20
+ }
21
+
22
+ export interface BaseTableColumn<Row = Record<string, any>> {
23
+ label: string
24
+ prop?: keyof Row | string
25
+ kind?: BaseTableColumnKind
26
+ type?: string
27
+ width?: BaseTableCssValue
28
+ minWidth?: BaseTableCssValue
29
+ align?: BaseTableAlign
30
+ headerAlign?: BaseTableAlign
31
+ fixed?: boolean | 'left' | 'right'
32
+ sortable?: boolean | 'custom'
33
+ sortField?: string
34
+ showOverflowTooltip?: boolean
35
+ className?: string
36
+ headerClassName?: string
37
+ actions?: BaseTableAction<Row>[]
38
+ clickable?: boolean
39
+ options?: BaseTableOption[]
40
+ optionValueKey?: string
41
+ optionLabelKey?: string
42
+ optionTagTypeKey?: string
43
+ emptyText?: string
44
+ inputType?: string
45
+ imageFit?: '' | 'fill' | 'contain' | 'cover' | 'none' | 'scale-down'
46
+ imageWidth?: BaseTableCssValue
47
+ imageHeight?: BaseTableCssValue
48
+ slotName?: string
49
+ headerSlotName?: string
50
+ formatter?: (row: Row, column: BaseTableColumn<Row>) => unknown
51
+ html?: (row: Row, column: BaseTableColumn<Row>) => string
52
+ clickHandler?: (row: Row, column: BaseTableColumn<Row>) => void
53
+ inputHandler?: (value: string, row: Row, column: BaseTableColumn<Row>) => void
54
+ }
55
+
56
+ export interface BaseTablePagination {
57
+ currentPage: number
58
+ pageSize: number
59
+ total: number
60
+ pageSizes: number[]
61
+ }
62
+
63
+ export interface BaseTableRequestParams {
64
+ currentPage: number
65
+ pageSize: number
66
+ [key: string]: unknown
67
+ }
68
+
69
+ export interface BaseTableSortState {
70
+ prop?: string
71
+ order: BaseTableSortOrder
72
+ }
73
+
74
+ export interface BaseTableSortOrderMap {
75
+ ascending: string
76
+ descending: string
77
+ }
78
+
79
+ export interface BaseTableRequestResult<Row = Record<string, any>> {
80
+ records?: Row[]
81
+ list?: Row[]
82
+ items?: Row[]
83
+ total?: number
84
+ data?: {
85
+ records?: Row[]
86
+ list?: Row[]
87
+ items?: Row[]
88
+ total?: number
89
+ }
90
+ }
91
+
92
+ export interface BaseTableNormalizedResult<Row = Record<string, any>> {
93
+ rows?: Row[]
94
+ total?: number
95
+ }
96
+
97
+ export type BaseTableRequestHandler<Row = Record<string, any>> = (
98
+ params: BaseTableRequestParams
99
+ ) => Promise<BaseTableRequestResult<Row> | Row[]>
100
+
101
+ export type BaseTableResultAdapter<Row = Record<string, any>> = (
102
+ result: unknown,
103
+ params: BaseTableRequestParams
104
+ ) => BaseTableNormalizedResult<Row>
105
+
106
+ export interface BaseTableProps<Row = Record<string, any>> {
107
+ columns: BaseTableColumn<Row>[]
108
+ data?: Row[]
109
+ request?: BaseTableRequestHandler<Row>
110
+ requestParams?: Record<string, unknown>
111
+ resultAdapter?: BaseTableResultAdapter<Row>
112
+ autoLoad?: boolean
113
+ reloadOnParamsChange?: boolean
114
+ reloadOnSortChange?: boolean
115
+ rowKey?: string
116
+ height?: BaseTableCssValue
117
+ border?: boolean
118
+ stripe?: boolean
119
+ showToolbar?: boolean
120
+ showPagination?: boolean
121
+ hasSelection?: boolean
122
+ hasIndex?: boolean
123
+ indexLabel?: string
124
+ indexWidth?: BaseTableCssValue
125
+ selectionWidth?: BaseTableCssValue
126
+ rowSelectable?: (row: Row, index: number) => boolean
127
+ pagination?: Partial<BaseTablePagination>
128
+ currentPageKey?: string
129
+ pageSizeKey?: string
130
+ defaultSort?: BaseTableSortState
131
+ sortFieldKey?: string
132
+ sortOrderKey?: string
133
+ sortOrderMap?: BaseTableSortOrderMap
134
+ sortMapper?: (payload: BaseTableSortPayload<Row>) => Record<string, unknown> | void
135
+ emptyText?: string
136
+ loadingText?: string
137
+ }
138
+
139
+ export interface BaseTableSortPayload<Row = Record<string, any>> {
140
+ column: BaseTableColumn<Row> | undefined
141
+ prop?: string
142
+ order: BaseTableSortOrder
143
+ field?: string
144
+ direction: BaseTableSortDirection
145
+ }
146
+
147
+ export interface BaseTableRowActionPayload<Row = Record<string, any>> {
148
+ row: Row
149
+ action: BaseTableAction<Row>
150
+ column: BaseTableColumn<Row>
151
+ }
152
+
153
+ export interface BaseTableCellPayload<Row = Record<string, any>> {
154
+ row: Row
155
+ column: BaseTableColumn<Row>
156
+ value: unknown
157
+ }
158
+
159
+ export interface BaseTableLoadedPayload<Row = Record<string, any>> {
160
+ rows: Row[]
161
+ total: number
162
+ params: BaseTableRequestParams
163
+ }
164
+
165
+ export interface BaseTableExpose<Row = Record<string, any>> {
166
+ load: (data?: Row[]) => Promise<void>
167
+ refresh: () => Promise<void>
168
+ setData: (data: Row[]) => void
169
+ resetPage: () => Promise<void>
170
+ clearSelection: () => void
171
+ toggleRowSelection: (row: Row, selected?: boolean) => void
172
+ getSelectionRows: () => Row[]
173
+ getRows: () => Row[]
174
+ }