@inglorious/ui 0.1.0 → 1.0.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.
- package/README.md +45 -0
- package/package.json +190 -15
- package/src/all.css +7 -0
- package/src/controls/button/button.stories.js +35 -15
- package/src/controls/button/index.js +1 -3
- package/src/controls/button/style.css +80 -37
- package/src/controls/button/template.js +23 -26
- package/src/controls/button-group/button-group.stories.js +19 -15
- package/src/controls/button-group/index.js +1 -2
- package/src/controls/button-group/style.css +0 -7
- package/src/controls/button-group/template.js +46 -56
- package/src/controls/checkbox/checkbox.stories.js +16 -13
- package/src/controls/checkbox/index.js +1 -2
- package/src/controls/checkbox/style.css +23 -2
- package/src/controls/checkbox/template.js +20 -18
- package/src/controls/combobox/combobox.stories.js +92 -0
- package/src/controls/{select → combobox}/handlers.js +8 -5
- package/src/controls/combobox/helpers.js +91 -0
- package/src/controls/combobox/index.js +43 -0
- package/src/controls/combobox/style.css +203 -0
- package/src/controls/combobox/template.js +340 -0
- package/src/controls/controls.css +12 -0
- package/src/controls/fab/fab.stories.js +11 -11
- package/src/controls/fab/index.js +1 -2
- package/src/controls/fab/template.js +21 -19
- package/src/controls/icon-button/icon-button.stories.js +8 -10
- package/src/controls/icon-button/index.js +1 -2
- package/src/controls/icon-button/template.js +13 -19
- package/src/controls/input/index.js +1 -2
- package/src/controls/input/input.stories.js +24 -23
- package/src/controls/input/style.css +9 -7
- package/src/controls/input/template.js +28 -31
- package/src/controls/radio-group/index.js +1 -2
- package/src/controls/radio-group/radio-group.stories.js +11 -8
- package/src/controls/radio-group/style.css +22 -1
- package/src/controls/radio-group/template.js +20 -15
- package/src/controls/rating/index.js +1 -2
- package/src/controls/rating/rating.stories.js +7 -10
- package/src/controls/rating/style.css +1 -2
- package/src/controls/rating/template.js +20 -17
- package/src/controls/select/helpers.js +2 -21
- package/src/controls/select/index.js +1 -13
- package/src/controls/select/select.stories.js +68 -64
- package/src/controls/select/style.css +66 -189
- package/src/controls/select/template.js +77 -406
- package/src/controls/slider/index.js +1 -2
- package/src/controls/slider/slider.stories.js +15 -12
- package/src/controls/slider/style.css +24 -3
- package/src/controls/slider/template.js +30 -23
- package/src/controls/switch/index.js +1 -2
- package/src/controls/switch/style.css +23 -2
- package/src/controls/switch/switch.stories.js +14 -11
- package/src/controls/switch/template.js +18 -16
- package/src/data-display/avatar/avatar.stories.js +106 -0
- package/src/data-display/avatar/index.js +3 -0
- package/src/data-display/avatar/style.css +64 -0
- package/src/data-display/avatar/template.js +81 -0
- package/src/data-display/badge/badge.stories.js +64 -0
- package/src/data-display/badge/index.js +3 -0
- package/src/data-display/badge/style.css +84 -0
- package/src/data-display/badge/template.js +46 -0
- package/src/data-display/chip/chip.stories.js +57 -0
- package/src/data-display/chip/index.js +3 -0
- package/src/data-display/chip/style.css +84 -0
- package/src/data-display/chip/template.js +32 -0
- package/src/data-display/data-display.css +11 -0
- package/src/data-display/data-grid/base.css +58 -0
- package/src/data-display/data-grid/data-grid.stories.js +158 -0
- package/src/data-display/data-grid/filters/helpers.js +8 -0
- package/src/data-display/data-grid/filters/index.js +21 -0
- package/src/data-display/data-grid/filters/input.js +24 -0
- package/src/data-display/data-grid/filters/range.js +48 -0
- package/src/data-display/data-grid/filters/select.js +17 -0
- package/src/data-display/data-grid/handlers.js +523 -0
- package/src/data-display/data-grid/helpers.js +248 -0
- package/src/data-display/data-grid/index.js +64 -0
- package/src/data-display/data-grid/style.css +14 -0
- package/src/data-display/data-grid/template.js +458 -0
- package/src/data-display/data-grid/theme.css +148 -0
- package/src/data-display/divider/divider.stories.js +48 -0
- package/src/data-display/divider/index.js +3 -0
- package/src/data-display/divider/style.css +18 -0
- package/src/data-display/divider/template.js +17 -0
- package/src/data-display/icon/icon-implementations.mdx +160 -0
- package/src/data-display/icon/icon-utf8.stories.js +156 -0
- package/src/data-display/icon/icon.stories.js +38 -0
- package/src/data-display/icon/index.js +3 -0
- package/src/data-display/icon/style.css +17 -0
- package/src/data-display/icon/template.js +19 -0
- package/src/data-display/list/handlers.js +25 -0
- package/src/data-display/list/index.js +4 -0
- package/src/data-display/list/list.stories.js +187 -0
- package/src/data-display/list/style.css +119 -0
- package/src/data-display/list/template.js +302 -0
- package/src/data-display/material-icon/index.js +3 -0
- package/src/data-display/material-icon/material-icon.stories.js +99 -0
- package/src/data-display/material-icon/style.css +27 -0
- package/src/data-display/material-icon/template.js +21 -0
- package/src/data-display/table/index.js +1 -0
- package/src/data-display/table/style.css +42 -0
- package/src/data-display/table/table.stories.js +40 -0
- package/src/data-display/table/template.js +114 -0
- package/src/data-display/tooltip/index.js +3 -0
- package/src/data-display/tooltip/style.css +57 -0
- package/src/data-display/tooltip/template.js +58 -0
- package/src/data-display/tooltip/tooltip.stories.js +44 -0
- package/src/data-display/typography/index.js +3 -0
- package/src/data-display/typography/style.css +49 -0
- package/src/data-display/typography/template.js +110 -0
- package/src/data-display/typography/typography.stories.js +48 -0
- package/src/data-display/virtual-list/handlers.js +68 -0
- package/src/data-display/virtual-list/index.js +4 -0
- package/src/data-display/virtual-list/template.js +101 -0
- package/src/examples/dashboard/app-drawer.js +255 -0
- package/src/examples/dashboard/app-header.js +149 -0
- package/src/examples/dashboard/dashboard.js +85 -0
- package/src/examples/dashboard/dashboard.stories.js +47 -0
- package/src/examples/dashboard/data.js +205 -0
- package/src/examples/dashboard/mode.js +27 -0
- package/src/examples/dashboard/primitive-content.js +1325 -0
- package/src/examples/dashboard/primitive-section.js +158 -0
- package/src/examples/dashboard/router.js +13 -0
- package/src/examples/dashboard/social-card.js +73 -0
- package/src/examples/dashboard/stat-card.js +84 -0
- package/src/examples/dashboard/style.css +339 -0
- package/src/examples/dashboard/theme-utils.js +95 -0
- package/src/examples/dashboard/theme.js +27 -0
- package/src/examples/dashboard/traffic-card.js +108 -0
- package/src/examples/dashboard/traffic-sales-card.js +267 -0
- package/src/feedback/alert/alert.stories.js +70 -0
- package/src/feedback/alert/index.js +3 -0
- package/src/feedback/alert/style.css +98 -0
- package/src/feedback/alert/template.js +74 -0
- package/src/feedback/backdrop/backdrop.stories.js +21 -0
- package/src/feedback/backdrop/index.js +3 -0
- package/src/feedback/backdrop/style.css +25 -0
- package/src/feedback/backdrop/template.js +31 -0
- package/src/feedback/dialog/dialog.stories.js +27 -0
- package/src/feedback/dialog/index.js +3 -0
- package/src/feedback/dialog/style.css +68 -0
- package/src/feedback/dialog/template.js +64 -0
- package/src/feedback/feedback.css +6 -0
- package/src/feedback/progress/index.js +3 -0
- package/src/feedback/progress/progress.stories.js +54 -0
- package/src/feedback/progress/style.css +95 -0
- package/src/feedback/progress/template.js +88 -0
- package/src/feedback/skeleton/index.js +3 -0
- package/src/feedback/skeleton/skeleton.stories.js +44 -0
- package/src/feedback/skeleton/style.css +41 -0
- package/src/feedback/skeleton/template.js +48 -0
- package/src/feedback/snackbar/index.js +3 -0
- package/src/feedback/snackbar/snackbar.stories.js +25 -0
- package/src/feedback/snackbar/style.css +64 -0
- package/src/feedback/snackbar/template.js +55 -0
- package/src/index.js +32 -1
- package/src/layout/container/container.stories.js +105 -0
- package/src/layout/container/index.js +3 -0
- package/src/layout/container/style.css +34 -0
- package/src/layout/container/template.js +119 -0
- package/src/layout/flex/flex.stories.js +28 -10
- package/src/layout/flex/index.js +1 -2
- package/src/layout/flex/style.css +20 -0
- package/src/layout/flex/template.js +40 -13
- package/src/layout/grid/grid.stories.js +46 -30
- package/src/layout/grid/index.js +1 -2
- package/src/layout/grid/style.css +20 -0
- package/src/layout/grid/template.js +100 -20
- package/src/layout/layout.css +3 -0
- package/src/navigation/bottom-navigation/bottom-navigation.stories.js +33 -0
- package/src/navigation/bottom-navigation/index.js +1 -0
- package/src/navigation/bottom-navigation/style.css +32 -0
- package/src/navigation/bottom-navigation/template.js +74 -0
- package/src/navigation/breadcrumbs/breadcrumbs.stories.js +33 -0
- package/src/navigation/breadcrumbs/index.js +1 -0
- package/src/navigation/breadcrumbs/style.css +27 -0
- package/src/navigation/breadcrumbs/template.js +79 -0
- package/src/navigation/drawer/drawer.stories.js +60 -0
- package/src/navigation/drawer/index.js +3 -0
- package/src/navigation/drawer/style.css +125 -0
- package/src/navigation/drawer/template.js +131 -0
- package/src/navigation/link/index.js +3 -0
- package/src/navigation/link/link.stories.js +53 -0
- package/src/navigation/link/style.css +40 -0
- package/src/navigation/link/template.js +53 -0
- package/src/navigation/menu/index.js +1 -0
- package/src/navigation/menu/menu.stories.js +36 -0
- package/src/navigation/menu/style.css +44 -0
- package/src/navigation/menu/template.js +81 -0
- package/src/navigation/navigation.css +9 -0
- package/src/navigation/pagination/index.js +1 -0
- package/src/navigation/pagination/pagination.stories.js +61 -0
- package/src/navigation/pagination/style.css +29 -0
- package/src/navigation/pagination/template.js +140 -0
- package/src/navigation/speed-dial/index.js +1 -0
- package/src/navigation/speed-dial/speed-dial.stories.js +40 -0
- package/src/navigation/speed-dial/style.css +38 -0
- package/src/navigation/speed-dial/template.js +68 -0
- package/src/navigation/stepper/index.js +1 -0
- package/src/navigation/stepper/stepper.stories.js +35 -0
- package/src/navigation/stepper/style.css +49 -0
- package/src/navigation/stepper/template.js +61 -0
- package/src/navigation/tabs/index.js +1 -0
- package/src/navigation/tabs/style.css +35 -0
- package/src/navigation/tabs/tabs.stories.js +40 -0
- package/src/navigation/tabs/template.js +79 -0
- package/src/overview.mdx +39 -0
- package/src/stories/notifyStory.js +22 -25
- package/src/styles/base.css +2 -0
- package/src/styles/reset.css +15 -0
- package/src/{themes → styles/themes}/bootstrap.css +2 -0
- package/src/{themes → styles/themes}/inglorious.css +9 -1
- package/src/{themes → styles/themes}/material.css +2 -0
- package/src/{tokens/index.css → styles/tokens.css} +9 -0
- package/src/surfaces/accordion/accordion.stories.js +60 -0
- package/src/surfaces/accordion/index.js +1 -0
- package/src/surfaces/accordion/style.css +64 -0
- package/src/surfaces/accordion/template.js +85 -0
- package/src/surfaces/app-bar/app-bar.stories.js +109 -0
- package/src/surfaces/app-bar/index.js +3 -0
- package/src/surfaces/app-bar/style.css +109 -0
- package/src/surfaces/app-bar/template.js +78 -0
- package/src/surfaces/card/card.stories.js +108 -0
- package/src/surfaces/card/index.js +1 -0
- package/src/surfaces/card/style.css +107 -0
- package/src/surfaces/card/template.js +163 -0
- package/src/surfaces/paper/index.js +3 -0
- package/src/surfaces/paper/paper.stories.js +97 -0
- package/src/surfaces/paper/style.css +73 -0
- package/src/surfaces/paper/template.js +76 -0
- package/src/surfaces/surfaces.css +4 -0
- package/types/controls/button-group.d.ts +8 -7
- package/types/controls/button.d.ts +10 -7
- package/types/controls/checkbox.d.ts +8 -6
- package/types/controls/combobox.d.ts +66 -0
- package/types/controls/fab.d.ts +6 -5
- package/types/controls/icon-button.d.ts +8 -7
- package/types/controls/input.d.ts +18 -11
- package/types/controls/radio-group.d.ts +7 -5
- package/types/controls/rating.d.ts +6 -5
- package/types/controls/select.d.ts +11 -34
- package/types/controls/slider.d.ts +8 -6
- package/types/controls/switch.d.ts +7 -5
- package/types/data-display/avatar.d.ts +30 -0
- package/types/data-display/badge.d.ts +20 -0
- package/types/data-display/chip.d.ts +25 -0
- package/types/data-display/data-grid.d.ts +151 -0
- package/types/data-display/divider.d.ts +14 -0
- package/types/data-display/icon.d.ts +16 -0
- package/types/data-display/list.d.ts +66 -0
- package/types/data-display/material-icon.d.ts +15 -0
- package/types/data-display/table.d.ts +45 -0
- package/types/data-display/tooltip.d.ts +20 -0
- package/types/data-display/typography.d.ts +28 -0
- package/types/data-display/virtual-list.d.ts +94 -0
- package/types/feedback/alert.d.ts +22 -0
- package/types/feedback/backdrop.d.ts +17 -0
- package/types/feedback/dialog.d.ts +21 -0
- package/types/feedback/progress.d.ts +18 -0
- package/types/feedback/skeleton.d.ts +18 -0
- package/types/feedback/snackbar.d.ts +19 -0
- package/types/index.d.ts +92 -14
- package/types/layout/container.d.ts +28 -0
- package/types/layout/flex.d.ts +16 -5
- package/types/layout/grid.d.ts +15 -4
- package/types/navigation/bottom-navigation.d.ts +33 -0
- package/types/navigation/breadcrumbs.d.ts +29 -0
- package/types/navigation/drawer.d.ts +23 -0
- package/types/navigation/link.d.ts +22 -0
- package/types/navigation/menu.d.ts +32 -0
- package/types/navigation/pagination.d.ts +50 -0
- package/types/navigation/speed-dial.d.ts +35 -0
- package/types/navigation/stepper.d.ts +26 -0
- package/types/navigation/tabs.d.ts +31 -0
- package/types/surfaces/accordion.d.ts +32 -0
- package/types/surfaces/app-bar.d.ts +25 -0
- package/types/surfaces/card.d.ts +39 -0
- package/types/surfaces/paper.d.ts +28 -0
- package/src/shared/withRenderValidation.js +0 -19
- package/src/widgets/card/card.stories.js +0 -135
- package/src/widgets/card/index.js +0 -4
- package/src/widgets/card/style.css +0 -53
- package/src/widgets/card/template.js +0 -97
- package/types/widgets/card.d.ts +0 -21
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../../../types/data-display/table').TableProps} TableProps
|
|
3
|
+
* @typedef {import('../../../types/data-display/table').TableColumn} TableColumn
|
|
4
|
+
* @typedef {import('@inglorious/web').TemplateResult} TemplateResult
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { classMap, html, ref, repeat } from "@inglorious/web"
|
|
8
|
+
|
|
9
|
+
import { applyElementProps } from "../../shared/applyElementProps.js"
|
|
10
|
+
|
|
11
|
+
const EVEN_ROW_DIVISOR = 2
|
|
12
|
+
const STRIPED_OFFSET = 1
|
|
13
|
+
|
|
14
|
+
export const table = {
|
|
15
|
+
/**
|
|
16
|
+
* @param {TableProps} props
|
|
17
|
+
* @returns {TemplateResult}
|
|
18
|
+
*/
|
|
19
|
+
render(props) {
|
|
20
|
+
const {
|
|
21
|
+
columns = [],
|
|
22
|
+
rows = [],
|
|
23
|
+
isFullWidth = false,
|
|
24
|
+
isStriped = false,
|
|
25
|
+
onRowClick,
|
|
26
|
+
...rest
|
|
27
|
+
} = props
|
|
28
|
+
|
|
29
|
+
const classes = {
|
|
30
|
+
"iw-table": true,
|
|
31
|
+
"iw-table-full-width": isFullWidth,
|
|
32
|
+
"iw-table-striped": isStriped,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return html`
|
|
36
|
+
<div class="iw-table-wrap">
|
|
37
|
+
<table
|
|
38
|
+
class=${classMap(classes)}
|
|
39
|
+
${ref((el) => applyElementProps(el, rest))}
|
|
40
|
+
>
|
|
41
|
+
<thead>
|
|
42
|
+
<tr>
|
|
43
|
+
${repeat(
|
|
44
|
+
columns,
|
|
45
|
+
(column, index) => column.id ?? `${index}`,
|
|
46
|
+
(column, index) =>
|
|
47
|
+
this.renderHeaderCell(props, { column, index }),
|
|
48
|
+
)}
|
|
49
|
+
</tr>
|
|
50
|
+
</thead>
|
|
51
|
+
<tbody>
|
|
52
|
+
${repeat(
|
|
53
|
+
rows,
|
|
54
|
+
(row, index) => row?.id ?? `${index}`,
|
|
55
|
+
(row, index) => this.renderRow(props, { row, index, onRowClick }),
|
|
56
|
+
)}
|
|
57
|
+
</tbody>
|
|
58
|
+
</table>
|
|
59
|
+
</div>
|
|
60
|
+
`
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {TableProps} _props
|
|
65
|
+
* @param {{column: TableColumn, index: number}} payload
|
|
66
|
+
* @returns {TemplateResult}
|
|
67
|
+
*/
|
|
68
|
+
renderHeaderCell(_props, { column }) {
|
|
69
|
+
const title = column.label ?? column.title ?? column.id
|
|
70
|
+
return html`<th class="iw-table-header-cell">${title}</th>`
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {TableProps} props
|
|
75
|
+
* @param {{row: Record<string, unknown>, index: number}} payload
|
|
76
|
+
* @returns {TemplateResult}
|
|
77
|
+
*/
|
|
78
|
+
renderRow(props, { row, index, onRowClick }) {
|
|
79
|
+
const columns = props.columns ?? []
|
|
80
|
+
|
|
81
|
+
return html`<tr
|
|
82
|
+
class=${classMap({
|
|
83
|
+
"iw-table-row": true,
|
|
84
|
+
"iw-table-row-even": index % EVEN_ROW_DIVISOR === STRIPED_OFFSET,
|
|
85
|
+
})}
|
|
86
|
+
@click=${() => onRowClick(row)}
|
|
87
|
+
>
|
|
88
|
+
${repeat(
|
|
89
|
+
columns,
|
|
90
|
+
(column, columnIndex) => column.id ?? `${columnIndex}`,
|
|
91
|
+
(column, columnIndex) =>
|
|
92
|
+
this.renderCell(props, { column, row, index, columnIndex }),
|
|
93
|
+
)}
|
|
94
|
+
</tr>`
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {TableProps} _props
|
|
99
|
+
* @param {{column: TableColumn, row: Record<string, unknown>}} payload
|
|
100
|
+
* @returns {TemplateResult}
|
|
101
|
+
*/
|
|
102
|
+
renderCell(_props, { column, row }) {
|
|
103
|
+
const value = row?.[column.id]
|
|
104
|
+
|
|
105
|
+
return html`<td
|
|
106
|
+
class=${classMap({
|
|
107
|
+
"iw-table-cell": true,
|
|
108
|
+
"iw-table-cell-number": column.align === "right",
|
|
109
|
+
})}
|
|
110
|
+
>
|
|
111
|
+
${value}
|
|
112
|
+
</td>`
|
|
113
|
+
},
|
|
114
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
.iw-tooltip {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
|
|
6
|
+
.iw-tooltip-bubble {
|
|
7
|
+
position: absolute;
|
|
8
|
+
z-index: var(--iw-z-tooltip);
|
|
9
|
+
opacity: 0;
|
|
10
|
+
pointer-events: none;
|
|
11
|
+
background: var(--iw-color-bg-elevated, var(--iw-color-surface));
|
|
12
|
+
color: var(--iw-color-text);
|
|
13
|
+
border: 1px solid var(--iw-color-border);
|
|
14
|
+
border-radius: var(--iw-radius-sm);
|
|
15
|
+
padding: var(--iw-space-2) var(--iw-space-3);
|
|
16
|
+
box-shadow: var(--iw-shadow-md);
|
|
17
|
+
transition: opacity 150ms ease;
|
|
18
|
+
left: 50%;
|
|
19
|
+
bottom: calc(100% + var(--iw-space-2));
|
|
20
|
+
transform: translateX(-50%);
|
|
21
|
+
white-space: normal;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&.iw-tooltip-size-sm .iw-tooltip-bubble {
|
|
25
|
+
font-size: var(--iw-font-size-sm);
|
|
26
|
+
padding: var(--iw-space-1) var(--iw-space-2);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&.iw-tooltip-size-lg .iw-tooltip-bubble {
|
|
30
|
+
font-size: var(--iw-font-size-lg);
|
|
31
|
+
padding: var(--iw-space-3) var(--iw-space-4);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&:hover .iw-tooltip-bubble,
|
|
35
|
+
&:focus-within .iw-tooltip-bubble,
|
|
36
|
+
&.iw-tooltip-open .iw-tooltip-bubble {
|
|
37
|
+
opacity: 1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&.iw-tooltip-bottom .iw-tooltip-bubble {
|
|
41
|
+
top: calc(100% + var(--iw-space-2));
|
|
42
|
+
bottom: auto;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&.iw-tooltip-left .iw-tooltip-bubble {
|
|
46
|
+
left: auto;
|
|
47
|
+
right: calc(100% + var(--iw-space-2));
|
|
48
|
+
bottom: 50%;
|
|
49
|
+
transform: translateY(50%);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&.iw-tooltip-right .iw-tooltip-bubble {
|
|
53
|
+
left: calc(100% + var(--iw-space-2));
|
|
54
|
+
bottom: 50%;
|
|
55
|
+
transform: translateY(50%);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../../../types/data-display/tooltip').TooltipProps} TooltipProps
|
|
3
|
+
* @typedef {import('@inglorious/web').TemplateResult} TemplateResult
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { classMap, html, ref } from "@inglorious/web"
|
|
7
|
+
|
|
8
|
+
import { applyElementProps } from "../../shared/applyElementProps.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {TooltipProps} props
|
|
12
|
+
* @returns {TemplateResult}
|
|
13
|
+
*/
|
|
14
|
+
export function render(props) {
|
|
15
|
+
const {
|
|
16
|
+
children,
|
|
17
|
+
content,
|
|
18
|
+
position = "top",
|
|
19
|
+
size = "md",
|
|
20
|
+
isOpen = false,
|
|
21
|
+
maxWidth = "20rem",
|
|
22
|
+
className = "",
|
|
23
|
+
onClick,
|
|
24
|
+
...rest
|
|
25
|
+
} = props
|
|
26
|
+
|
|
27
|
+
const extraClasses = Object.fromEntries(
|
|
28
|
+
className
|
|
29
|
+
.split(/\s+/)
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.map((name) => [name, true]),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const classes = {
|
|
35
|
+
"iw-tooltip": true,
|
|
36
|
+
"iw-tooltip-open": isOpen,
|
|
37
|
+
[`iw-tooltip-${position}`]: position !== "top",
|
|
38
|
+
[`iw-tooltip-size-${size}`]: size !== "md",
|
|
39
|
+
...extraClasses,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return html`
|
|
43
|
+
<span
|
|
44
|
+
class=${classMap(classes)}
|
|
45
|
+
${ref((el) => applyElementProps(el, rest))}
|
|
46
|
+
@click=${onClick}
|
|
47
|
+
>
|
|
48
|
+
<span class="iw-tooltip-trigger">${children ?? "?"}</span>
|
|
49
|
+
<span
|
|
50
|
+
class="iw-tooltip-bubble"
|
|
51
|
+
role="tooltip"
|
|
52
|
+
style=${`max-width: ${maxWidth};`}
|
|
53
|
+
>
|
|
54
|
+
${content}
|
|
55
|
+
</span>
|
|
56
|
+
</span>
|
|
57
|
+
`
|
|
58
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { html } from "@inglorious/web"
|
|
2
|
+
|
|
3
|
+
import { createRender } from "../../stories/notifyStory.js"
|
|
4
|
+
import { tooltip } from "."
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: "Data Display/Tooltip",
|
|
8
|
+
tags: ["autodocs"],
|
|
9
|
+
render: createRender(tooltip),
|
|
10
|
+
argTypes: {
|
|
11
|
+
content: { control: "text", description: "Tooltip text." },
|
|
12
|
+
position: {
|
|
13
|
+
control: "select",
|
|
14
|
+
options: ["top", "right", "bottom", "left"],
|
|
15
|
+
description: "Tooltip placement.",
|
|
16
|
+
},
|
|
17
|
+
size: {
|
|
18
|
+
control: "select",
|
|
19
|
+
options: ["sm", "md", "lg"],
|
|
20
|
+
description: "Tooltip size scale.",
|
|
21
|
+
},
|
|
22
|
+
isOpen: { control: "boolean", description: "Force tooltip visible." },
|
|
23
|
+
maxWidth: { control: "text", description: "Max width CSS value." },
|
|
24
|
+
onClick: { action: "onClick" },
|
|
25
|
+
},
|
|
26
|
+
parameters: {
|
|
27
|
+
docs: {
|
|
28
|
+
description: {
|
|
29
|
+
component: "Hover/focus tooltip primitive with configurable placement.",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const Default = {
|
|
36
|
+
args: {
|
|
37
|
+
children: html`<button type="button">Hover me</button>`,
|
|
38
|
+
content: "Tooltip content",
|
|
39
|
+
position: "bottom",
|
|
40
|
+
size: "md",
|
|
41
|
+
isOpen: false,
|
|
42
|
+
maxWidth: "20rem",
|
|
43
|
+
},
|
|
44
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
.iw-typography {
|
|
2
|
+
margin: 0;
|
|
3
|
+
color: var(--iw-color-text);
|
|
4
|
+
line-height: 1.45;
|
|
5
|
+
|
|
6
|
+
&.iw-typography-h1 {
|
|
7
|
+
font-size: var(--iw-font-size-4xl);
|
|
8
|
+
line-height: 1.1;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&.iw-typography-h2 {
|
|
12
|
+
font-size: var(--iw-font-size-3xl);
|
|
13
|
+
line-height: 1.15;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&.iw-typography-h3 {
|
|
17
|
+
font-size: var(--iw-font-size-2xl);
|
|
18
|
+
line-height: 1.2;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&.iw-typography-caption {
|
|
22
|
+
font-size: var(--iw-font-size-sm);
|
|
23
|
+
opacity: 0.85;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&.iw-typography-overline {
|
|
27
|
+
font-size: var(--iw-font-size-xs);
|
|
28
|
+
text-transform: uppercase;
|
|
29
|
+
letter-spacing: 0.08em;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&.iw-typography-align-center {
|
|
33
|
+
text-align: center;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&.iw-typography-align-right {
|
|
37
|
+
text-align: right;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&.iw-typography-nowrap {
|
|
41
|
+
white-space: nowrap;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
text-overflow: ellipsis;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
&.iw-typography-gutter-bottom {
|
|
47
|
+
margin-bottom: var(--iw-space-3);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../../../types/data-display/typography').TypographyProps} TypographyProps
|
|
3
|
+
* @typedef {import('@inglorious/web').TemplateResult} TemplateResult
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { classMap, html, ref } from "@inglorious/web"
|
|
7
|
+
|
|
8
|
+
import { applyElementProps } from "../../shared/applyElementProps.js"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {TypographyProps} props
|
|
12
|
+
* @returns {TemplateResult}
|
|
13
|
+
*/
|
|
14
|
+
export function render(props) {
|
|
15
|
+
const {
|
|
16
|
+
children,
|
|
17
|
+
variant = "body",
|
|
18
|
+
align = "left",
|
|
19
|
+
weight,
|
|
20
|
+
color,
|
|
21
|
+
isNoWrap = false,
|
|
22
|
+
hasGutterBottom = false,
|
|
23
|
+
className = "",
|
|
24
|
+
...rest
|
|
25
|
+
} = props
|
|
26
|
+
|
|
27
|
+
const extraClasses = Object.fromEntries(
|
|
28
|
+
className
|
|
29
|
+
.split(/\s+/)
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.map((name) => [name, true]),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const classes = {
|
|
35
|
+
"iw-typography": true,
|
|
36
|
+
[`iw-typography-${variant}`]: variant !== "body",
|
|
37
|
+
[`iw-typography-align-${align}`]: align !== "left",
|
|
38
|
+
"iw-typography-nowrap": isNoWrap,
|
|
39
|
+
"iw-typography-gutter-bottom": hasGutterBottom,
|
|
40
|
+
...extraClasses,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return renderTag(variant, classes, children, { weight, color, rest })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function renderTag(variant, classes, children, options) {
|
|
47
|
+
const { weight, color, rest } = options
|
|
48
|
+
|
|
49
|
+
if (variant === "h1") {
|
|
50
|
+
return html`<h1
|
|
51
|
+
class=${classMap(classes)}
|
|
52
|
+
style=${buildStyle(weight, color)}
|
|
53
|
+
${ref((el) => applyElementProps(el, rest))}
|
|
54
|
+
>
|
|
55
|
+
${children}
|
|
56
|
+
</h1>`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (variant === "h2") {
|
|
60
|
+
return html`<h2
|
|
61
|
+
class=${classMap(classes)}
|
|
62
|
+
style=${buildStyle(weight, color)}
|
|
63
|
+
${ref((el) => applyElementProps(el, rest))}
|
|
64
|
+
>
|
|
65
|
+
${children}
|
|
66
|
+
</h2>`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (variant === "h3") {
|
|
70
|
+
return html`<h3
|
|
71
|
+
class=${classMap(classes)}
|
|
72
|
+
style=${buildStyle(weight, color)}
|
|
73
|
+
${ref((el) => applyElementProps(el, rest))}
|
|
74
|
+
>
|
|
75
|
+
${children}
|
|
76
|
+
</h3>`
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (variant === "caption" || variant === "overline") {
|
|
80
|
+
return html`<span
|
|
81
|
+
class=${classMap(classes)}
|
|
82
|
+
style=${buildStyle(weight, color)}
|
|
83
|
+
${ref((el) => applyElementProps(el, rest))}
|
|
84
|
+
>
|
|
85
|
+
${children}
|
|
86
|
+
</span>`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return html`<p
|
|
90
|
+
class=${classMap(classes)}
|
|
91
|
+
style=${buildStyle(weight, color)}
|
|
92
|
+
${ref((el) => applyElementProps(el, rest))}
|
|
93
|
+
>
|
|
94
|
+
${children}
|
|
95
|
+
</p>`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function buildStyle(weight, color) {
|
|
99
|
+
const parts = []
|
|
100
|
+
|
|
101
|
+
if (weight) {
|
|
102
|
+
parts.push(`font-weight: ${weight};`)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (color) {
|
|
106
|
+
parts.push(`color: ${color};`)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return parts.join(" ")
|
|
110
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createRender } from "../../stories/notifyStory.js"
|
|
2
|
+
import { typography } from "."
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: "Data Display/Typography",
|
|
6
|
+
tags: ["autodocs"],
|
|
7
|
+
render: createRender(typography),
|
|
8
|
+
argTypes: {
|
|
9
|
+
children: { control: "text", description: "Text content." },
|
|
10
|
+
variant: {
|
|
11
|
+
control: "select",
|
|
12
|
+
options: ["body", "h1", "h2", "h3", "caption", "overline"],
|
|
13
|
+
description: "Visual text variant.",
|
|
14
|
+
},
|
|
15
|
+
align: {
|
|
16
|
+
control: "select",
|
|
17
|
+
options: ["left", "center", "right"],
|
|
18
|
+
description: "Horizontal text alignment.",
|
|
19
|
+
},
|
|
20
|
+
weight: { control: "text", description: "Optional CSS font-weight value." },
|
|
21
|
+
color: { control: "text", description: "Optional CSS color value." },
|
|
22
|
+
isNoWrap: {
|
|
23
|
+
control: "boolean",
|
|
24
|
+
description: "Single-line ellipsis behavior.",
|
|
25
|
+
},
|
|
26
|
+
hasGutterBottom: {
|
|
27
|
+
control: "boolean",
|
|
28
|
+
description: "Add bottom spacing.",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
parameters: {
|
|
32
|
+
docs: {
|
|
33
|
+
description: {
|
|
34
|
+
component: "Typography primitive for headings, body text, and labels.",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const Default = {
|
|
41
|
+
args: {
|
|
42
|
+
children: "The quick brown fox jumps over the lazy dog.",
|
|
43
|
+
variant: "body",
|
|
44
|
+
align: "left",
|
|
45
|
+
isNoWrap: false,
|
|
46
|
+
hasGutterBottom: false,
|
|
47
|
+
},
|
|
48
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../../../types/data-display/virtual-list').VirtualListEntity} VirtualListEntity
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const LIST_START = 0
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the virtual list entity with default state.
|
|
9
|
+
* @param {VirtualListEntity} entity
|
|
10
|
+
*/
|
|
11
|
+
export function create(entity) {
|
|
12
|
+
resetList(entity)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Handles the scroll event to update the visible range.
|
|
17
|
+
* @param {VirtualListEntity} entity
|
|
18
|
+
* @param {HTMLElement} containerEl
|
|
19
|
+
*/
|
|
20
|
+
export function scroll(entity, containerEl) {
|
|
21
|
+
const scrollTop = containerEl.scrollTop
|
|
22
|
+
const { items, bufferSize, itemHeight, estimatedHeight, viewportHeight } =
|
|
23
|
+
entity
|
|
24
|
+
const height = itemHeight || estimatedHeight
|
|
25
|
+
|
|
26
|
+
const start = Math.max(
|
|
27
|
+
LIST_START,
|
|
28
|
+
Math.floor(scrollTop / height) - bufferSize,
|
|
29
|
+
)
|
|
30
|
+
const visibleCount = Math.ceil(viewportHeight / height)
|
|
31
|
+
const end = Math.min(start + visibleCount + bufferSize, items.length)
|
|
32
|
+
|
|
33
|
+
if (entity.visibleRange.start === start && entity.visibleRange.end === end) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
entity.scrollTop = scrollTop
|
|
38
|
+
entity.visibleRange = { start, end }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Mounts the list, measuring the first item to determine item height.
|
|
43
|
+
* @param {VirtualListEntity} entity
|
|
44
|
+
* @param {HTMLElement} containerEl
|
|
45
|
+
*/
|
|
46
|
+
export function mount(entity, containerEl) {
|
|
47
|
+
const firstItem = containerEl.querySelector("[data-index]")
|
|
48
|
+
if (!firstItem) return
|
|
49
|
+
|
|
50
|
+
entity.itemHeight = firstItem.offsetHeight
|
|
51
|
+
entity.visibleRange = {
|
|
52
|
+
start: 0,
|
|
53
|
+
end: Math.ceil(entity.viewportHeight / entity.itemHeight),
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Resets the list entity state.
|
|
59
|
+
* @param {VirtualListEntity} entity
|
|
60
|
+
*/
|
|
61
|
+
function resetList(entity) {
|
|
62
|
+
entity.scrollTop = 0
|
|
63
|
+
entity.visibleRange ??= { start: 0, end: 20 }
|
|
64
|
+
entity.viewportHeight ??= 600
|
|
65
|
+
entity.bufferSize ??= 5
|
|
66
|
+
entity.itemHeight ??= null
|
|
67
|
+
entity.estimatedHeight ??= 50
|
|
68
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../../../types/data-display/virtual-list').VirtualListEntity} VirtualListEntity
|
|
3
|
+
* @typedef {import('@inglorious/web').TemplateResult} TemplateResult
|
|
4
|
+
* @typedef {import('@inglorious/web').Api} Api
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { html, ref, repeat, styleMap } from "@inglorious/web"
|
|
8
|
+
|
|
9
|
+
const PRETTY_INDEX = 1
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Renders the virtualized list component.
|
|
13
|
+
* @param {VirtualListEntity} entity The list entity state.
|
|
14
|
+
* @param {Api} api The API object.
|
|
15
|
+
* @returns {TemplateResult} The rendered list.
|
|
16
|
+
*/
|
|
17
|
+
export function render(entity, api) {
|
|
18
|
+
const {
|
|
19
|
+
items,
|
|
20
|
+
visibleRange,
|
|
21
|
+
viewportHeight,
|
|
22
|
+
itemHeight,
|
|
23
|
+
estimatedHeight,
|
|
24
|
+
className,
|
|
25
|
+
} = entity
|
|
26
|
+
const type = api.getType(entity.type)
|
|
27
|
+
|
|
28
|
+
if (!items) {
|
|
29
|
+
console.warn(`virtual list entity ${entity.id} needs 'items'`)
|
|
30
|
+
return html``
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!type.renderItem) {
|
|
34
|
+
console.warn(`type ${entity.type} needs 'renderItem' method`)
|
|
35
|
+
return html``
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const visibleItems = items.slice(visibleRange.start, visibleRange.end)
|
|
39
|
+
const height = itemHeight || estimatedHeight
|
|
40
|
+
const totalHeight = items.length * height
|
|
41
|
+
|
|
42
|
+
return html`
|
|
43
|
+
<div
|
|
44
|
+
class=${className ?? ""}
|
|
45
|
+
style=${styleMap({ height: `${viewportHeight}px`, overflow: "auto" })}
|
|
46
|
+
@scroll=${(e) => api.notify(`#${entity.id}:scroll`, e.currentTarget)}
|
|
47
|
+
${ref((el) => {
|
|
48
|
+
if (el && !itemHeight) {
|
|
49
|
+
queueMicrotask(() => {
|
|
50
|
+
api.notify(`#${entity.id}:mount`, el)
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
})}
|
|
54
|
+
>
|
|
55
|
+
<div
|
|
56
|
+
style=${styleMap({
|
|
57
|
+
height: `${totalHeight}px`,
|
|
58
|
+
position: "relative",
|
|
59
|
+
})}
|
|
60
|
+
>
|
|
61
|
+
${repeat(
|
|
62
|
+
visibleItems,
|
|
63
|
+
(item) => item.id,
|
|
64
|
+
(item, index) => {
|
|
65
|
+
const absoluteIndex = visibleRange.start + index
|
|
66
|
+
const top = absoluteIndex * height
|
|
67
|
+
|
|
68
|
+
return html`
|
|
69
|
+
<div
|
|
70
|
+
style=${styleMap({
|
|
71
|
+
position: "absolute",
|
|
72
|
+
top: `${top}px`,
|
|
73
|
+
width: "100%",
|
|
74
|
+
})}
|
|
75
|
+
data-index=${absoluteIndex}
|
|
76
|
+
>
|
|
77
|
+
${type.renderItem(entity, { item, index: absoluteIndex }, api)}
|
|
78
|
+
</div>
|
|
79
|
+
`
|
|
80
|
+
},
|
|
81
|
+
)}
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Default item renderer.
|
|
89
|
+
* @param {VirtualListEntity} entity The list entity.
|
|
90
|
+
* @param {object} payload The payload for rendering the item.
|
|
91
|
+
* @param {any} payload.item The item data.
|
|
92
|
+
* @param {number} payload.index The item's absolute index in the full list.
|
|
93
|
+
* @param {Api} api The API object.
|
|
94
|
+
* @returns {TemplateResult} The rendered list item.
|
|
95
|
+
*/
|
|
96
|
+
// eslint-disable-next-line no-unused-vars
|
|
97
|
+
export function renderItem(entity, { item, index }, api) {
|
|
98
|
+
return html`<div class="iw-list-item">
|
|
99
|
+
${index + PRETTY_INDEX}. ${JSON.stringify(item)}
|
|
100
|
+
</div>`
|
|
101
|
+
}
|