@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
|
@@ -1,44 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {import('../../../types/controls/button').
|
|
3
|
-
* @typedef {import('@inglorious/web').Api} Api
|
|
2
|
+
* @typedef {import('../../../types/controls/button').ButtonProps} ButtonProps
|
|
4
3
|
* @typedef {import('@inglorious/web').TemplateResult} TemplateResult
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import { classMap, html, ref } from "@inglorious/web"
|
|
8
7
|
|
|
9
|
-
import { applyElementProps } from "
|
|
8
|
+
import { applyElementProps } from "../../shared/applyElementProps.js"
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Button type for Inglorious Web.
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
15
14
|
* // Stateless usage
|
|
16
|
-
* button.render({ children: 'Click me', variant: 'primary' }
|
|
15
|
+
* button.render({ children: 'Click me', variant: 'primary' })
|
|
17
16
|
*
|
|
18
|
-
* @
|
|
19
|
-
* // Stateful usage with event handling
|
|
20
|
-
* // Entity: { type: 'button', id: 'submitBtn', children: 'Submit' }
|
|
21
|
-
* // In store: api.render('submitBtn')
|
|
22
|
-
*
|
|
23
|
-
* @param {ButtonEntity} entity
|
|
24
|
-
* @param {Api} api
|
|
17
|
+
* @param {ButtonProps} props
|
|
25
18
|
* @returns {TemplateResult}
|
|
26
19
|
*/
|
|
27
|
-
export function render(
|
|
20
|
+
export function render(props) {
|
|
28
21
|
const {
|
|
22
|
+
type, // eslint-disable-line no-unused-vars
|
|
29
23
|
children,
|
|
30
24
|
variant = "default",
|
|
31
|
-
color = "
|
|
25
|
+
color = "default",
|
|
32
26
|
size = "md",
|
|
33
27
|
shape = "rectangle",
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
isDisabled = false,
|
|
29
|
+
isPressed = false,
|
|
30
|
+
isFullWidth = false,
|
|
31
|
+
buttonType = "button",
|
|
37
32
|
ariaLabel = "",
|
|
38
|
-
|
|
33
|
+
isAriaPressed = false,
|
|
39
34
|
className = "",
|
|
35
|
+
onClick,
|
|
40
36
|
...rest
|
|
41
|
-
} =
|
|
37
|
+
} = props
|
|
42
38
|
|
|
43
39
|
const extraClasses = Object.fromEntries(
|
|
44
40
|
className
|
|
@@ -50,22 +46,23 @@ export function render(entity, api) {
|
|
|
50
46
|
const classes = {
|
|
51
47
|
"iw-button": true,
|
|
52
48
|
[`iw-button-${variant}`]: variant !== "default",
|
|
53
|
-
[`iw-button-${color}`]:
|
|
54
|
-
[`iw-button-${size}`]:
|
|
49
|
+
[`iw-button-${color}`]: true,
|
|
50
|
+
[`iw-button-${size}`]: true,
|
|
51
|
+
[`iw-button-pressed`]: isPressed,
|
|
55
52
|
[`iw-button-shape-${shape}`]: shape !== "rectangle",
|
|
56
|
-
"iw-button-full-width":
|
|
57
|
-
"iw-button-disabled":
|
|
53
|
+
"iw-button-full-width": isFullWidth,
|
|
54
|
+
"iw-button-disabled": isDisabled,
|
|
58
55
|
...extraClasses,
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
return html`
|
|
62
59
|
<button
|
|
63
|
-
type=${
|
|
60
|
+
type=${buttonType}
|
|
64
61
|
aria-label=${ariaLabel}
|
|
65
|
-
aria-pressed=${
|
|
62
|
+
aria-pressed=${isAriaPressed}
|
|
66
63
|
class=${classMap(classes)}
|
|
67
|
-
?disabled=${
|
|
68
|
-
@click=${
|
|
64
|
+
?disabled=${isDisabled}
|
|
65
|
+
@click=${onClick}
|
|
69
66
|
${ref((element) => applyElementProps(element, rest))}
|
|
70
67
|
>
|
|
71
68
|
${children}
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
makeStoryRender,
|
|
3
|
-
notifyActionArgType,
|
|
4
|
-
} from "../../stories/notifyStory.js"
|
|
1
|
+
import { createRender } from "../../stories/notifyStory.js"
|
|
5
2
|
import { buttonGroup } from "."
|
|
6
3
|
|
|
7
4
|
export default {
|
|
8
5
|
title: "Controls/ButtonGroup",
|
|
9
6
|
tags: ["autodocs"],
|
|
10
|
-
render:
|
|
7
|
+
render: createRender(buttonGroup),
|
|
11
8
|
argTypes: {
|
|
12
|
-
...notifyActionArgType,
|
|
13
9
|
value: {
|
|
14
10
|
control: "object",
|
|
15
11
|
description:
|
|
16
12
|
"Selected value(s). String for single mode, array for multiple mode.",
|
|
17
13
|
},
|
|
18
|
-
|
|
14
|
+
isMultiple: {
|
|
19
15
|
control: "boolean",
|
|
20
16
|
description: "Enable multi-selection mode.",
|
|
21
17
|
},
|
|
@@ -24,7 +20,7 @@ export default {
|
|
|
24
20
|
options: ["row", "column"],
|
|
25
21
|
description: "Group direction.",
|
|
26
22
|
},
|
|
27
|
-
|
|
23
|
+
isAttached: {
|
|
28
24
|
control: "boolean",
|
|
29
25
|
description: "Visually attach adjacent buttons.",
|
|
30
26
|
},
|
|
@@ -40,10 +36,18 @@ export default {
|
|
|
40
36
|
},
|
|
41
37
|
color: {
|
|
42
38
|
control: "select",
|
|
43
|
-
options: [
|
|
39
|
+
options: [
|
|
40
|
+
"default",
|
|
41
|
+
"primary",
|
|
42
|
+
"secondary",
|
|
43
|
+
"success",
|
|
44
|
+
"warning",
|
|
45
|
+
"error",
|
|
46
|
+
"info",
|
|
47
|
+
],
|
|
44
48
|
description: "Default color intent for items.",
|
|
45
49
|
},
|
|
46
|
-
|
|
50
|
+
isDisabled: {
|
|
47
51
|
control: "boolean",
|
|
48
52
|
description: "Disables all buttons.",
|
|
49
53
|
},
|
|
@@ -51,6 +55,7 @@ export default {
|
|
|
51
55
|
control: "object",
|
|
52
56
|
description: "Items rendered as grouped buttons.",
|
|
53
57
|
},
|
|
58
|
+
onChange: { action: "onChange" },
|
|
54
59
|
},
|
|
55
60
|
parameters: {
|
|
56
61
|
docs: {
|
|
@@ -64,13 +69,12 @@ export default {
|
|
|
64
69
|
export const Default = {}
|
|
65
70
|
Default.args = {
|
|
66
71
|
value: "",
|
|
67
|
-
|
|
72
|
+
isMultiple: false,
|
|
68
73
|
direction: "row",
|
|
69
|
-
|
|
74
|
+
isAttached: true,
|
|
70
75
|
size: "md",
|
|
71
76
|
variant: "outline",
|
|
72
|
-
|
|
73
|
-
disabled: false,
|
|
77
|
+
isDisabled: false,
|
|
74
78
|
buttons: [
|
|
75
79
|
{ id: "left", value: "left", label: "Left" },
|
|
76
80
|
{ id: "center", value: "center", label: "Center" },
|
|
@@ -98,7 +102,7 @@ SingleSelection.args = {
|
|
|
98
102
|
export const MultiSelection = {}
|
|
99
103
|
MultiSelection.args = {
|
|
100
104
|
...Default.args,
|
|
101
|
-
|
|
105
|
+
isMultiple: true,
|
|
102
106
|
value: ["left", "right"],
|
|
103
107
|
buttons: [
|
|
104
108
|
{ id: "left", value: "left", label: "Left" },
|
|
@@ -48,11 +48,4 @@
|
|
|
48
48
|
&:not(.iw-button-group-attached) {
|
|
49
49
|
gap: var(--iw-space-2);
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
&.iw-button-group-selection .iw-button.iw-button-pressed {
|
|
53
|
-
background-color: var(--iw-button-bg-active);
|
|
54
|
-
border-color: var(--iw-button-bg-active);
|
|
55
|
-
color: var(--iw-button-text);
|
|
56
|
-
box-shadow: var(--iw-button-shadow-active);
|
|
57
|
-
}
|
|
58
51
|
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {import('../../../types/controls/button-group').
|
|
3
|
-
* @typedef {import('@inglorious/web').Api} Api
|
|
2
|
+
* @typedef {import('../../../types/controls/button-group').ButtonGroupProps} ButtonGroupProps
|
|
4
3
|
* @typedef {import('@inglorious/web').TemplateResult} TemplateResult
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import { classMap, html, ref } from "@inglorious/web"
|
|
8
|
-
import { applyElementProps } from "@/shared/applyElementProps.js"
|
|
9
7
|
|
|
10
|
-
import {
|
|
8
|
+
import { applyElementProps } from "../../shared/applyElementProps.js"
|
|
9
|
+
import { button } from "../button/index.js"
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Button group control for grouped actions.
|
|
14
13
|
*
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {Api} api
|
|
14
|
+
* @param {ButtonGroupProps} props
|
|
17
15
|
* @returns {TemplateResult}
|
|
18
16
|
*/
|
|
19
|
-
export function render(
|
|
17
|
+
export function render(props) {
|
|
20
18
|
const {
|
|
19
|
+
type, // eslint-disable-line no-unused-vars
|
|
21
20
|
buttons = [],
|
|
22
21
|
value,
|
|
23
|
-
|
|
22
|
+
isMultiple = false,
|
|
24
23
|
direction = "row",
|
|
25
|
-
|
|
24
|
+
isAttached = true,
|
|
26
25
|
size = "md",
|
|
27
26
|
variant = "default",
|
|
28
|
-
color = "
|
|
29
|
-
|
|
27
|
+
color = "default",
|
|
28
|
+
isDisabled = false,
|
|
29
|
+
onChange,
|
|
30
30
|
...rest
|
|
31
|
-
} =
|
|
31
|
+
} = props
|
|
32
32
|
|
|
33
33
|
const groupClasses = {
|
|
34
34
|
"iw-button-group": true,
|
|
35
|
-
"iw-button-group-selection": value != null ||
|
|
35
|
+
"iw-button-group-selection": value != null || isMultiple,
|
|
36
36
|
[`iw-button-group-${direction}`]: true,
|
|
37
|
-
"iw-button-group-attached":
|
|
37
|
+
"iw-button-group-attached": isAttached,
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const selectedValues =
|
|
40
|
+
const selectedValues = isMultiple
|
|
41
41
|
? new Set(Array.isArray(value) ? value : [])
|
|
42
42
|
: null
|
|
43
43
|
|
|
@@ -47,13 +47,13 @@ export function render(entity, api) {
|
|
|
47
47
|
role="group"
|
|
48
48
|
${ref((element) => applyElementProps(element, rest))}
|
|
49
49
|
>
|
|
50
|
-
${buttons.map((item
|
|
50
|
+
${buttons.map((item) => {
|
|
51
51
|
const {
|
|
52
52
|
id: itemId,
|
|
53
53
|
value: explicitValue,
|
|
54
54
|
label,
|
|
55
55
|
children,
|
|
56
|
-
|
|
56
|
+
isDisabled: itemDisabled,
|
|
57
57
|
variant: itemVariant,
|
|
58
58
|
color: itemColor,
|
|
59
59
|
size: itemSize,
|
|
@@ -62,55 +62,45 @@ export function render(entity, api) {
|
|
|
62
62
|
...itemRest
|
|
63
63
|
} = item
|
|
64
64
|
|
|
65
|
-
const childId = `${entity.id}-btn-${itemId ?? index}`
|
|
66
65
|
const itemValue = explicitValue ?? itemId
|
|
67
|
-
const
|
|
66
|
+
const isPressed = isMultiple
|
|
68
67
|
? selectedValues.has(itemValue)
|
|
69
68
|
: value != null
|
|
70
69
|
? value === itemValue
|
|
71
70
|
: false
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
72
|
+
return button.render({
|
|
73
|
+
children: html`
|
|
74
|
+
${icon ? html`<span class="iw-button-icon">${icon}</span>` : null}
|
|
75
|
+
${children ?? label}
|
|
76
|
+
${iconAfter
|
|
77
|
+
? html`<span class="iw-button-icon">${iconAfter}</span>`
|
|
78
|
+
: null}
|
|
79
|
+
`,
|
|
80
|
+
variant: itemVariant ?? variant,
|
|
81
|
+
color: itemColor ?? color,
|
|
82
|
+
size: itemSize ?? size,
|
|
83
|
+
isDisabled: isDisabled || !!itemDisabled,
|
|
84
|
+
isPressed,
|
|
85
|
+
isAriaPressed: isPressed ? true : undefined,
|
|
86
|
+
onClick: () => {
|
|
87
|
+
if (!onChange) return
|
|
88
|
+
|
|
89
|
+
if (isMultiple) {
|
|
90
|
+
const next = new Set(selectedValues)
|
|
91
|
+
if (next.has(itemValue)) {
|
|
92
|
+
next.delete(itemValue)
|
|
93
|
+
} else {
|
|
94
|
+
next.add(itemValue)
|
|
86
95
|
}
|
|
87
|
-
|
|
96
|
+
|
|
97
|
+
return onChange([...next])
|
|
88
98
|
}
|
|
89
|
-
return api.notify(type, payload)
|
|
90
|
-
},
|
|
91
|
-
}
|
|
92
99
|
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
id: childId,
|
|
96
|
-
children: html`
|
|
97
|
-
${icon ? html`<span class="iw-button-icon">${icon}</span>` : null}
|
|
98
|
-
${children ?? label}
|
|
99
|
-
${iconAfter
|
|
100
|
-
? html`<span class="iw-button-icon">${iconAfter}</span>`
|
|
101
|
-
: null}
|
|
102
|
-
`,
|
|
103
|
-
variant: itemVariant ?? variant,
|
|
104
|
-
color: itemColor ?? color,
|
|
105
|
-
size: itemSize ?? size,
|
|
106
|
-
disabled: disabled || !!itemDisabled,
|
|
107
|
-
ariaPressed: pressed ? true : undefined,
|
|
108
|
-
className: pressed ? "iw-button-pressed" : "",
|
|
109
|
-
type: "button",
|
|
110
|
-
...itemRest,
|
|
100
|
+
return onChange(itemValue)
|
|
111
101
|
},
|
|
112
|
-
|
|
113
|
-
)
|
|
102
|
+
...itemRest,
|
|
103
|
+
})
|
|
114
104
|
})}
|
|
115
105
|
</div>
|
|
116
106
|
`
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
makeStoryRender,
|
|
3
|
-
notifyActionArgType,
|
|
4
|
-
} from "../../stories/notifyStory.js"
|
|
1
|
+
import { createRender } from "../../stories/notifyStory.js"
|
|
5
2
|
import { checkbox } from "."
|
|
6
3
|
|
|
7
4
|
export default {
|
|
8
5
|
title: "Controls/Checkbox",
|
|
9
6
|
tags: ["autodocs"],
|
|
10
|
-
render:
|
|
7
|
+
render: createRender(checkbox),
|
|
11
8
|
argTypes: {
|
|
12
|
-
...notifyActionArgType,
|
|
13
9
|
label: { control: "text", description: "Label text." },
|
|
14
10
|
name: { control: "text", description: "Native HTML name attribute." },
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
isChecked: { control: "boolean", description: "Current checked state." },
|
|
12
|
+
isDisabled: { control: "boolean", description: "Disables interaction." },
|
|
13
|
+
isRequired: { control: "boolean", description: "Marks input as required." },
|
|
14
|
+
color: {
|
|
15
|
+
control: "select",
|
|
16
|
+
options: ["primary", "secondary", "success", "warning", "error", "info"],
|
|
17
|
+
description: "Semantic accent color.",
|
|
18
|
+
},
|
|
18
19
|
size: {
|
|
19
20
|
control: "select",
|
|
20
21
|
options: ["sm", "md", "lg"],
|
|
21
22
|
description: "Label size scale.",
|
|
22
23
|
},
|
|
24
|
+
onChange: { action: "onChange" },
|
|
23
25
|
},
|
|
24
26
|
parameters: {
|
|
25
27
|
docs: {
|
|
@@ -34,14 +36,15 @@ export const Default = {}
|
|
|
34
36
|
Default.args = {
|
|
35
37
|
label: "Accept terms",
|
|
36
38
|
name: "terms",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
isChecked: false,
|
|
40
|
+
isDisabled: false,
|
|
41
|
+
isRequired: false,
|
|
42
|
+
color: "primary",
|
|
40
43
|
size: "md",
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
export const Checked = {}
|
|
44
47
|
Checked.args = {
|
|
45
48
|
...Default.args,
|
|
46
|
-
|
|
49
|
+
isChecked: true,
|
|
47
50
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
.iw-checkbox
|
|
1
|
+
.iw-checkbox {
|
|
2
|
+
--iw-checkbox-accent: var(--iw-color-primary);
|
|
2
3
|
display: inline-flex;
|
|
3
4
|
align-items: center;
|
|
4
5
|
gap: var(--iw-space-2);
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
width: 1rem;
|
|
11
12
|
height: 1rem;
|
|
12
13
|
margin: 0;
|
|
13
|
-
accent-color: var(--iw-
|
|
14
|
+
accent-color: var(--iw-checkbox-accent);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
.iw-checkbox-label {
|
|
@@ -30,4 +31,24 @@
|
|
|
30
31
|
opacity: 0.6;
|
|
31
32
|
cursor: not-allowed;
|
|
32
33
|
}
|
|
34
|
+
|
|
35
|
+
&.iw-checkbox-secondary {
|
|
36
|
+
--iw-checkbox-accent: var(--iw-color-gray-600);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&.iw-checkbox-success {
|
|
40
|
+
--iw-checkbox-accent: var(--iw-color-success);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&.iw-checkbox-warning {
|
|
44
|
+
--iw-checkbox-accent: var(--iw-color-warning);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.iw-checkbox-error {
|
|
48
|
+
--iw-checkbox-accent: var(--iw-color-error);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&.iw-checkbox-info {
|
|
52
|
+
--iw-checkbox-accent: var(--iw-color-info);
|
|
53
|
+
}
|
|
33
54
|
}
|
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {import('../../../types/controls/checkbox').
|
|
3
|
-
* @typedef {import('@inglorious/web').Api} Api
|
|
2
|
+
* @typedef {import('../../../types/controls/checkbox').CheckboxProps} CheckboxProps
|
|
4
3
|
* @typedef {import('@inglorious/web').TemplateResult} TemplateResult
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import { classMap, html, ref } from "@inglorious/web"
|
|
8
7
|
|
|
9
|
-
import { applyElementProps } from "
|
|
8
|
+
import { applyElementProps } from "../../shared/applyElementProps.js"
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Checkbox control for boolean values.
|
|
13
12
|
*
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {Api} api
|
|
13
|
+
* @param {CheckboxProps} props
|
|
16
14
|
* @returns {TemplateResult}
|
|
17
15
|
*/
|
|
18
|
-
export function render(
|
|
16
|
+
export function render(props) {
|
|
19
17
|
const {
|
|
18
|
+
id,
|
|
19
|
+
type, // eslint-disable-line no-unused-vars
|
|
20
20
|
name = "",
|
|
21
21
|
label = "",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
isChecked = false,
|
|
23
|
+
isDisabled = false,
|
|
24
|
+
isRequired = false,
|
|
25
|
+
color = "primary",
|
|
25
26
|
size = "md",
|
|
27
|
+
onChange,
|
|
26
28
|
...rest
|
|
27
|
-
} =
|
|
29
|
+
} = props
|
|
28
30
|
|
|
29
|
-
const inputId =
|
|
31
|
+
const inputId = id || name
|
|
30
32
|
|
|
31
33
|
const classes = {
|
|
32
|
-
"iw-checkbox
|
|
33
|
-
"iw-checkbox-disabled":
|
|
34
|
+
"iw-checkbox": true,
|
|
35
|
+
"iw-checkbox-disabled": isDisabled,
|
|
36
|
+
[`iw-checkbox-${color}`]: color !== "primary",
|
|
34
37
|
[`iw-checkbox-${size}`]: size !== "md",
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -41,11 +44,10 @@ export function render(entity, api) {
|
|
|
41
44
|
class="iw-checkbox"
|
|
42
45
|
type="checkbox"
|
|
43
46
|
name=${name}
|
|
44
|
-
.checked=${
|
|
45
|
-
?disabled=${
|
|
46
|
-
?required=${
|
|
47
|
-
@change=${(event) =>
|
|
48
|
-
api.notify(`#${entity.id}:change`, event.target.checked)}
|
|
47
|
+
.checked=${isChecked}
|
|
48
|
+
?disabled=${isDisabled}
|
|
49
|
+
?required=${isRequired}
|
|
50
|
+
@change=${(event) => onChange?.(event.target.checked)}
|
|
49
51
|
${ref((element) => applyElementProps(element, rest))}
|
|
50
52
|
/>
|
|
51
53
|
<span class="iw-checkbox-label">${label}</span>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEntityRender,
|
|
3
|
+
notifyActionArgType,
|
|
4
|
+
} from "../../stories/notifyStory.js"
|
|
5
|
+
import { combobox } from "./index.js"
|
|
6
|
+
|
|
7
|
+
const options = [
|
|
8
|
+
{ label: "Italy", value: "it" },
|
|
9
|
+
{ label: "France", value: "fr" },
|
|
10
|
+
{ label: "Spain", value: "es" },
|
|
11
|
+
{ label: "Germany", value: "de" },
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
title: "Controls/Combobox",
|
|
16
|
+
tags: ["autodocs"],
|
|
17
|
+
render: createEntityRender({ combobox }),
|
|
18
|
+
argTypes: {
|
|
19
|
+
...notifyActionArgType,
|
|
20
|
+
label: { control: "text", description: "Field label." },
|
|
21
|
+
selectedValue: {
|
|
22
|
+
control: "object",
|
|
23
|
+
description: "Current selection. Value or array of values in multi mode.",
|
|
24
|
+
},
|
|
25
|
+
isMulti: { control: "boolean", description: "Enable multiple selection." },
|
|
26
|
+
isOpen: {
|
|
27
|
+
control: "boolean",
|
|
28
|
+
description: "Controls dropdown visibility.",
|
|
29
|
+
},
|
|
30
|
+
isSearchable: { control: "boolean", description: "Show search input." },
|
|
31
|
+
isClearable: { control: "boolean", description: "Show clear button." },
|
|
32
|
+
isDisabled: { control: "boolean", description: "Disable the control." },
|
|
33
|
+
isLoading: { control: "boolean", description: "Show loading state." },
|
|
34
|
+
searchTerm: { control: "text", description: "Current search filter." },
|
|
35
|
+
placeholder: { control: "text", description: "Placeholder text." },
|
|
36
|
+
noOptionsMessage: { control: "text", description: "No results message." },
|
|
37
|
+
loadingMessage: { control: "text", description: "Loading message." },
|
|
38
|
+
isFullWidth: {
|
|
39
|
+
control: "boolean",
|
|
40
|
+
description: "Expand to container width.",
|
|
41
|
+
},
|
|
42
|
+
size: {
|
|
43
|
+
control: "select",
|
|
44
|
+
options: ["sm", "md", "lg"],
|
|
45
|
+
description: "Control size.",
|
|
46
|
+
},
|
|
47
|
+
options: { control: "object", description: "Available options." },
|
|
48
|
+
},
|
|
49
|
+
parameters: {
|
|
50
|
+
docs: {
|
|
51
|
+
description: {
|
|
52
|
+
component:
|
|
53
|
+
"Theme-aware custom select with searchable dropdown, clear action, and optional multi-selection.",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const SingleClosed = {}
|
|
60
|
+
SingleClosed.args = {
|
|
61
|
+
id: "combobox",
|
|
62
|
+
type: "combobox",
|
|
63
|
+
label: "Country",
|
|
64
|
+
selectedValue: "it",
|
|
65
|
+
isMulti: false,
|
|
66
|
+
isOpen: false,
|
|
67
|
+
isSearchable: true,
|
|
68
|
+
isClearable: true,
|
|
69
|
+
isDisabled: false,
|
|
70
|
+
isLoading: false,
|
|
71
|
+
searchTerm: "",
|
|
72
|
+
placeholder: "Select...",
|
|
73
|
+
noOptionsMessage: "No options",
|
|
74
|
+
loadingMessage: "Loading...",
|
|
75
|
+
isFullWidth: false,
|
|
76
|
+
size: "md",
|
|
77
|
+
options,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const SingleOpen = {}
|
|
81
|
+
SingleOpen.args = {
|
|
82
|
+
...SingleClosed.args,
|
|
83
|
+
isOpen: true,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const MultiOpen = {}
|
|
87
|
+
MultiOpen.args = {
|
|
88
|
+
...SingleClosed.args,
|
|
89
|
+
isMulti: true,
|
|
90
|
+
selectedValue: ["it", "fr"],
|
|
91
|
+
isOpen: true,
|
|
92
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/* eslint-disable no-magic-numbers */
|
|
2
1
|
/**
|
|
3
|
-
* @typedef {import('../../../types/controls/select').
|
|
4
|
-
* @typedef {import('../../../types/controls/select').SelectOption} SelectOption
|
|
2
|
+
* @typedef {import('../../../types/controls/select.js').SelectProps} SelectEntity
|
|
3
|
+
* @typedef {import('../../../types/controls/select.js').SelectOption} SelectOption
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
import { filterOptions, formatOption, getOptionValue } from "./helpers.js"
|
|
@@ -11,6 +10,10 @@ import { filterOptions, formatOption, getOptionValue } from "./helpers.js"
|
|
|
11
10
|
* @param {SelectEntity} entity
|
|
12
11
|
*/
|
|
13
12
|
export function create(entity) {
|
|
13
|
+
entity.size ??= "md"
|
|
14
|
+
entity.isFullWidth ??= false
|
|
15
|
+
entity.label ??= ""
|
|
16
|
+
|
|
14
17
|
entity.isOpen ??= false
|
|
15
18
|
entity.searchTerm ??= ""
|
|
16
19
|
entity.focusedIndex ??= -1
|
|
@@ -23,8 +26,8 @@ export function create(entity) {
|
|
|
23
26
|
|
|
24
27
|
entity.isLoading ??= false
|
|
25
28
|
entity.isDisabled ??= false
|
|
26
|
-
entity.isSearchable ??=
|
|
27
|
-
entity.isClearable ??=
|
|
29
|
+
entity.isSearchable ??= false
|
|
30
|
+
entity.isClearable ??= false
|
|
28
31
|
|
|
29
32
|
entity.placeholder ??= "Select..."
|
|
30
33
|
entity.noOptionsMessage ??= "No options"
|