@ternarytech-io/gears-ui 0.4.0 → 0.6.0

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.
package/src/types.ts CHANGED
@@ -1,222 +1,234 @@
1
- // Shared prop types. Colors and sizes use the same names as Nuxt UI, so code moving from it keeps
2
- // its props; `toTabler` maps a color to the name Tabler's classes use.
3
-
4
- export type Color = 'primary' | 'neutral' | 'success' | 'warning' | 'error' | 'info'
5
- export type Size = 'xs' | 'sm' | 'md' | 'lg'
6
-
7
- const tablerColors: Record<Color, string> = {
8
- primary: 'primary',
9
- neutral: 'secondary',
10
- success: 'success',
11
- warning: 'warning',
12
- error: 'danger',
13
- info: 'info'
14
- }
15
-
16
- export function toTabler(color: Color): string {
17
- return tablerColors[color]
18
- }
19
-
20
- // A route location for RouterLink, or a plain URL.
21
- export type Target = string | Record<string, unknown>
22
-
23
- export interface DropdownItem {
24
- label?: string
25
- description?: string
26
- icon?: string
27
- trailingIcon?: string
28
- // `label` items are headings; they can't be chosen.
29
- type?: 'item' | 'label'
30
- color?: Color
31
- to?: Target
32
- href?: string
33
- disabled?: boolean
34
- onSelect?: (event: Event) => void
35
- }
36
-
37
- export interface NavItem {
38
- label: string
39
- icon?: string
40
- to?: Target
41
- // Active only on this exact route, not on routes under it.
42
- exact?: boolean
43
- badge?: string | { label: string; color?: Color }
44
- children?: NavItem[]
45
- defaultOpen?: boolean
46
- }
47
-
48
- export interface SelectItem<T = unknown> {
49
- label: string
50
- value: T
51
- description?: string
52
- disabled?: boolean
53
- // Items with the same group are listed together under it.
54
- group?: string
55
- }
56
-
57
- // An item of TAdvancedSelect: an icon or avatar initials can show beside the label.
58
- export interface AdvancedSelectItem<T = unknown> extends SelectItem<T> {
59
- icon?: string
60
- avatar?: string
61
- }
62
-
63
- /** An item of a TCheckboxTree: a leaf, or a parent with children. */
64
- export interface TreeItem<T = string> {
65
- label: string
66
- value: T
67
- children?: TreeItem<T>[]
68
- disabled?: boolean
69
- }
70
-
71
- export interface TabItem {
72
- label: string
73
- value: string
74
- icon?: string
75
- badge?: string | number
76
- disabled?: boolean
77
- }
78
-
79
- export interface TableColumn<Row = Record<string, unknown>> {
80
- key: string
81
- label?: string
82
- align?: 'start' | 'center' | 'end'
83
- width?: string
84
- sortable?: boolean
85
- // TAdvancedTable: whether the column has a filter (on unless false; columns without a label have none).
86
- filterable?: boolean
87
- // Shown when the cell has no slot; defaults to `row[key]`.
88
- value?: (row: Row) => unknown
89
- }
90
-
91
- // TChart: what it draws, and a named list of values along its categories.
92
- export type ChartType = 'line' | 'area' | 'bar' | 'column' | 'pie' | 'donut'
93
- export interface ChartSeries {
94
- name: string
95
- data: (number | null)[]
96
- // A named color ('success') or any CSS color; by default the theme's next chart color.
97
- color?: Color | string
98
- }
99
-
100
- // TEditableTable: a column's kind decides how its cells are written, aligned and edited.
101
- export type EditableTableColumnType = 'text' | 'number' | 'date' | 'boolean'
102
- export interface EditableTableColumn<Row = Record<string, unknown>> extends TableColumn<Row> {
103
- type?: EditableTableColumnType
104
- // Cells can be edited in place (when the table is editable).
105
- editable?: boolean
106
- // Long values are cut to one line, at this width (CSS), with the whole value on hover.
107
- truncate?: string
108
- // Writes the cell's value; by default numbers and dates in the browser's format.
109
- format?: (value: unknown, row: Row) => string
110
- }
111
-
112
- // A TEditableTable cell edited in place: the row, the column's key and the new value.
113
- export interface TableEdit<Row = Record<string, unknown>> {
114
- row: Row
115
- key: string
116
- value: unknown
117
- }
118
-
119
- // TDataGrid: a label and its value, in Tabler's datagrid. `key` names the slot that draws the value
120
- // (`#{key}`); `copy` adds a button that copies it; an empty value is written as a dash.
121
- export interface DataGridItem {
122
- key?: string
123
- label: string
124
- value?: string | number | boolean | null
125
- copy?: boolean
126
- }
127
-
128
- export interface TableSort {
129
- key: string
130
- direction: 'asc' | 'desc'
131
- }
132
-
133
- // How a TAdvancedTable column filter compares a cell with its value.
134
- export type TableFilterOperator = 'equals' | 'notEquals' | 'contains' | 'greaterThan' | 'lessThan' | 'atLeast' | 'atMost'
135
-
136
- export interface TableFilter {
137
- operator: TableFilterOperator
138
- value: string
139
- }
140
-
141
- export interface StepItem {
142
- title: string
143
- description?: string
144
- }
145
-
146
- export interface LogLine {
147
- id?: string | number
148
- time?: string
149
- text: string
150
- level?: 'error' | 'warning' | 'highlight' | 'muted'
151
- }
152
-
153
- // A suggestion a TCodeEditor offers while typing.
154
- export interface CodeCompletion {
155
- label: string
156
- kind?: 'keyword' | 'table' | 'field' | 'function' | 'value' | 'snippet'
157
- // What's inserted; the label when omitted.
158
- insertText?: string
159
- detail?: string
160
- }
161
-
162
- export interface PanelListItem<T = string> {
163
- value: T
164
- label: string
165
- icon?: string
166
- // Small text at the item's end, such as a count or a tag.
167
- trailing?: string
168
- title?: string
169
- // Shown in red: something in it needs fixing.
170
- invalid?: boolean
171
- }
172
-
173
- // An item of TCommandPalette: a page to go to (`to`) or an action (`onSelect`).
174
- export interface CommandItem {
175
- label: string
176
- icon?: string
177
- // Shown after the label, smaller; searched too (a project's namespace, a page's section).
178
- suffix?: string
179
- // More words that find the item without being shown.
180
- keywords?: string[]
181
- to?: Target
182
- onSelect?: () => void
183
- }
184
-
185
- export interface CommandGroup {
186
- id: string
187
- label?: string
188
- items: CommandItem[]
189
- }
190
-
191
- // An application's theme, as Tabler's theme settings (the data-bs-theme-* attributes) take it.
192
- export type ThemeFont = 'sans-serif' | 'serif' | 'monospace' | 'comic'
193
- export type ThemeBase = 'slate' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'mist'
194
- export type ThemeRadius = '0' | '0.5' | '1' | '1.5' | '2' | '2.5'
195
- // Tabler's named colors, or a custom color as #rrggbb.
196
- export type ThemeAccent = 'blue' | 'azure' | 'indigo' | 'purple' | 'pink' | 'red' | 'orange' | 'yellow' | 'lime' | 'green' | 'teal' | 'cyan' | (string & {})
197
-
198
- // An application's layout: where its navigation goes and how it behaves, how much room things
199
- // get, and whether the page sits in a box.
200
- export type ThemeNav = 'left' | 'top'
201
- export type ThemeDensity = 'compact' | 'comfortable' | 'spacious'
202
- export type ThemeContainer = 'boxed' | 'fluid'
203
-
204
- export interface ThemeSettings {
205
- accent?: ThemeAccent
206
- font?: ThemeFont
207
- base?: ThemeBase
208
- radius?: ThemeRadius
209
- // Light or dark; unset follows the surrounding page.
210
- mode?: 'light' | 'dark'
211
- // Padding and gaps (TThemeScope applies it).
212
- density?: ThemeDensity
213
- // The rest is layout (TAppLayout applies it).
214
- nav?: ThemeNav
215
- // Left navigation: whether it folds to icons.
216
- navFoldable?: boolean
217
- // Top navigation: whether it stays at the top while the page scrolls, and whether it floats
218
- // apart from the page's edges.
219
- navSticky?: boolean
220
- navFloating?: boolean
221
- container?: ThemeContainer
222
- }
1
+ // Shared prop types. Colors and sizes use the same names as Nuxt UI, so code moving from it keeps
2
+ // its props; `toTabler` maps a color to the name Tabler's classes use.
3
+
4
+ export type Color = 'primary' | 'neutral' | 'success' | 'warning' | 'error' | 'info'
5
+ export type Size = 'xs' | 'sm' | 'md' | 'lg'
6
+
7
+ const tablerColors: Record<Color, string> = {
8
+ primary: 'primary',
9
+ neutral: 'secondary',
10
+ success: 'success',
11
+ warning: 'warning',
12
+ error: 'danger',
13
+ info: 'info'
14
+ }
15
+
16
+ export function toTabler(color: Color): string {
17
+ return tablerColors[color]
18
+ }
19
+
20
+ // A route location for RouterLink, or a plain URL.
21
+ export type Target = string | Record<string, unknown>
22
+
23
+ export interface DropdownItem {
24
+ label?: string
25
+ description?: string
26
+ icon?: string
27
+ trailingIcon?: string
28
+ // `label` items are headings; they can't be chosen.
29
+ type?: 'item' | 'label'
30
+ color?: Color
31
+ to?: Target
32
+ href?: string
33
+ disabled?: boolean
34
+ onSelect?: (event: Event) => void
35
+ }
36
+
37
+ /** A button of a TButtonGroup: a label and/or an icon (give an icon-only one a tooltip). */
38
+ export interface ButtonGroupItem {
39
+ label?: string
40
+ icon?: string
41
+ tooltip?: string
42
+ disabled?: boolean
43
+ /** Its own color, instead of the group's. */
44
+ color?: Color
45
+ /** Names it (and keys it): reported with its click. */
46
+ value?: string
47
+ }
48
+
49
+ export interface NavItem {
50
+ label: string
51
+ icon?: string
52
+ to?: Target
53
+ // Active only on this exact route, not on routes under it.
54
+ exact?: boolean
55
+ badge?: string | { label: string; color?: Color }
56
+ children?: NavItem[]
57
+ defaultOpen?: boolean
58
+ }
59
+
60
+ export interface SelectItem<T = unknown> {
61
+ label: string
62
+ value: T
63
+ description?: string
64
+ disabled?: boolean
65
+ // Items with the same group are listed together under it.
66
+ group?: string
67
+ }
68
+
69
+ // An item of TAdvancedSelect: an icon or avatar initials can show beside the label.
70
+ export interface AdvancedSelectItem<T = unknown> extends SelectItem<T> {
71
+ icon?: string
72
+ avatar?: string
73
+ }
74
+
75
+ /** An item of a TCheckboxTree: a leaf, or a parent with children. */
76
+ export interface TreeItem<T = string> {
77
+ label: string
78
+ value: T
79
+ children?: TreeItem<T>[]
80
+ disabled?: boolean
81
+ }
82
+
83
+ export interface TabItem {
84
+ label: string
85
+ value: string
86
+ icon?: string
87
+ badge?: string | number
88
+ disabled?: boolean
89
+ }
90
+
91
+ export interface TableColumn<Row = Record<string, unknown>> {
92
+ key: string
93
+ label?: string
94
+ align?: 'start' | 'center' | 'end'
95
+ width?: string
96
+ sortable?: boolean
97
+ // TAdvancedTable: whether the column has a filter (on unless false; columns without a label have none).
98
+ filterable?: boolean
99
+ // Shown when the cell has no slot; defaults to `row[key]`.
100
+ value?: (row: Row) => unknown
101
+ }
102
+
103
+ // TChart: what it draws, and a named list of values along its categories.
104
+ export type ChartType = 'line' | 'area' | 'bar' | 'column' | 'pie' | 'donut'
105
+ export interface ChartSeries {
106
+ name: string
107
+ data: (number | null)[]
108
+ // A named color ('success') or any CSS color; by default the theme's next chart color.
109
+ color?: Color | string
110
+ }
111
+
112
+ // TEditableTable: a column's kind decides how its cells are written, aligned and edited.
113
+ export type EditableTableColumnType = 'text' | 'number' | 'date' | 'boolean'
114
+ export interface EditableTableColumn<Row = Record<string, unknown>> extends TableColumn<Row> {
115
+ type?: EditableTableColumnType
116
+ // Cells can be edited in place (when the table is editable).
117
+ editable?: boolean
118
+ // Long values are cut to one line, at this width (CSS), with the whole value on hover.
119
+ truncate?: string
120
+ // Writes the cell's value; by default numbers and dates in the browser's format.
121
+ format?: (value: unknown, row: Row) => string
122
+ }
123
+
124
+ // A TEditableTable cell edited in place: the row, the column's key and the new value.
125
+ export interface TableEdit<Row = Record<string, unknown>> {
126
+ row: Row
127
+ key: string
128
+ value: unknown
129
+ }
130
+
131
+ // TDataGrid: a label and its value, in Tabler's datagrid. `key` names the slot that draws the value
132
+ // (`#{key}`); `copy` adds a button that copies it; an empty value is written as a dash.
133
+ export interface DataGridItem {
134
+ key?: string
135
+ label: string
136
+ value?: string | number | boolean | null
137
+ copy?: boolean
138
+ }
139
+
140
+ export interface TableSort {
141
+ key: string
142
+ direction: 'asc' | 'desc'
143
+ }
144
+
145
+ // How a TAdvancedTable column filter compares a cell with its value.
146
+ export type TableFilterOperator = 'equals' | 'notEquals' | 'contains' | 'greaterThan' | 'lessThan' | 'atLeast' | 'atMost'
147
+
148
+ export interface TableFilter {
149
+ operator: TableFilterOperator
150
+ value: string
151
+ }
152
+
153
+ export interface StepItem {
154
+ title: string
155
+ description?: string
156
+ }
157
+
158
+ export interface LogLine {
159
+ id?: string | number
160
+ time?: string
161
+ text: string
162
+ level?: 'error' | 'warning' | 'highlight' | 'muted'
163
+ }
164
+
165
+ // A suggestion a TCodeEditor offers while typing.
166
+ export interface CodeCompletion {
167
+ label: string
168
+ kind?: 'keyword' | 'table' | 'field' | 'function' | 'value' | 'snippet'
169
+ // What's inserted; the label when omitted.
170
+ insertText?: string
171
+ detail?: string
172
+ }
173
+
174
+ export interface PanelListItem<T = string> {
175
+ value: T
176
+ label: string
177
+ icon?: string
178
+ // Small text at the item's end, such as a count or a tag.
179
+ trailing?: string
180
+ title?: string
181
+ // Shown in red: something in it needs fixing.
182
+ invalid?: boolean
183
+ }
184
+
185
+ // An item of TCommandPalette: a page to go to (`to`) or an action (`onSelect`).
186
+ export interface CommandItem {
187
+ label: string
188
+ icon?: string
189
+ // Shown after the label, smaller; searched too (a project's namespace, a page's section).
190
+ suffix?: string
191
+ // More words that find the item without being shown.
192
+ keywords?: string[]
193
+ to?: Target
194
+ onSelect?: () => void
195
+ }
196
+
197
+ export interface CommandGroup {
198
+ id: string
199
+ label?: string
200
+ items: CommandItem[]
201
+ }
202
+
203
+ // An application's theme, as Tabler's theme settings (the data-bs-theme-* attributes) take it.
204
+ export type ThemeFont = 'sans-serif' | 'serif' | 'monospace' | 'comic'
205
+ export type ThemeBase = 'slate' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'mist'
206
+ export type ThemeRadius = '0' | '0.5' | '1' | '1.5' | '2' | '2.5'
207
+ // Tabler's named colors, or a custom color as #rrggbb.
208
+ export type ThemeAccent = 'blue' | 'azure' | 'indigo' | 'purple' | 'pink' | 'red' | 'orange' | 'yellow' | 'lime' | 'green' | 'teal' | 'cyan' | (string & {})
209
+
210
+ // An application's layout: where its navigation goes and how it behaves, how much room things
211
+ // get, and whether the page sits in a box.
212
+ export type ThemeNav = 'left' | 'top'
213
+ export type ThemeDensity = 'compact' | 'comfortable' | 'spacious'
214
+ export type ThemeContainer = 'boxed' | 'fluid'
215
+
216
+ export interface ThemeSettings {
217
+ accent?: ThemeAccent
218
+ font?: ThemeFont
219
+ base?: ThemeBase
220
+ radius?: ThemeRadius
221
+ // Light or dark; unset follows the surrounding page.
222
+ mode?: 'light' | 'dark'
223
+ // Padding and gaps (TThemeScope applies it).
224
+ density?: ThemeDensity
225
+ // The rest is layout (TAppLayout applies it).
226
+ nav?: ThemeNav
227
+ // Left navigation: whether it folds to icons.
228
+ navFoldable?: boolean
229
+ // Top navigation: whether it stays at the top while the page scrolls, and whether it floats
230
+ // apart from the page's edges.
231
+ navSticky?: boolean
232
+ navFloating?: boolean
233
+ container?: ThemeContainer
234
+ }